package androidx.core.app;

import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import java.io.Closeable;
import java.util.concurrent.CountDownLatch;

/* JADX INFO: loaded from: classes.dex */
public final class w1 implements Closeable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final CountDownLatch f1683a = new CountDownLatch(1);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f1684b = false;

    @Nullable
    private PendingIntent.OnFinished mCallback;

    public w1(@Nullable PendingIntent.OnFinished onFinished) {
        this.mCallback = onFinished;
    }

    public static void e(w1 w1Var, PendingIntent pendingIntent, Intent intent, int i10, String str, Bundle bundle) {
        w1Var.getClass();
        boolean z10 = false;
        while (true) {
            try {
                w1Var.f1683a.await();
                break;
            } catch (InterruptedException unused) {
                z10 = true;
            } catch (Throwable th) {
                if (z10) {
                    Thread.currentThread().interrupt();
                }
                throw th;
            }
        }
        if (z10) {
            Thread.currentThread().interrupt();
        }
        PendingIntent.OnFinished onFinished = w1Var.mCallback;
        if (onFinished != null) {
            onFinished.onSendFinished(pendingIntent, intent, i10, str, bundle);
            w1Var.mCallback = null;
        }
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        if (!this.f1684b) {
            this.mCallback = null;
        }
        this.f1683a.countDown();
    }

    @Nullable
    public PendingIntent.OnFinished getCallback() {
        if (this.mCallback == null) {
            return null;
        }
        return new PendingIntent.OnFinished() { // from class: androidx.core.app.v1
            @Override // android.app.PendingIntent.OnFinished
            public final void onSendFinished(PendingIntent pendingIntent, Intent intent, int i10, String str, Bundle bundle) {
                w1.e(this.f1679a, pendingIntent, intent, i10, str, bundle);
            }
        };
    }
}
