package r1;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.util.SparseIntArray;
import com.google.android.gms.common.api.GoogleApiActivity;
import com.google.android.gms.common.api.Status;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import p1.C0930b;
import p1.C0933e;
import r.C0967f;
import s1.C1010l;
import s1.C1011m;
import s1.C1012n;
import s1.L;
import w1.AbstractC1092b;
import y1.AbstractC1111a;

/* JADX INFO: loaded from: classes.dex */
public final class e implements Handler.Callback {

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public static final Status f9634o = new Status(4, "Sign-out occurred while this API call was in progress.", null, null);
    public static final Status p = new Status(4, "The user must be signed in to make this API call.", null, null);
    public static final Object q = new Object();

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static e f9635r;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public long f9636a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public C1012n f9638c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public u1.b f9639d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Context f9640e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final C0933e f9641f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final io.sentry.internal.debugmeta.c f9642g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final AtomicInteger f9643h;
    public final AtomicInteger i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final ConcurrentHashMap f9644j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final C0967f f9645k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final C0967f f9646l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final C1.g f9647m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public volatile boolean f9648n;

    public e(Context context, Looper looper) {
        C0933e c0933e = C0933e.f9458d;
        this.f9636a = 10000L;
        this.f9637b = false;
        this.f9643h = new AtomicInteger(1);
        this.i = new AtomicInteger(0);
        this.f9644j = new ConcurrentHashMap(5, 0.75f, 1);
        this.f9645k = new C0967f(0);
        this.f9646l = new C0967f(0);
        this.f9648n = true;
        this.f9640e = context;
        C1.g gVar = new C1.g(looper, this);
        Looper.getMainLooper();
        this.f9647m = gVar;
        this.f9641f = c0933e;
        this.f9642g = new io.sentry.internal.debugmeta.c(26);
        PackageManager packageManager = context.getPackageManager();
        if (AbstractC1092b.f10624f == null) {
            AbstractC1092b.f10624f = Boolean.valueOf(AbstractC1092b.b() && packageManager.hasSystemFeature("android.hardware.type.automotive"));
        }
        if (AbstractC1092b.f10624f.booleanValue()) {
            this.f9648n = false;
        }
        gVar.sendMessage(gVar.obtainMessage(6));
    }

    public static Status c(C0973b c0973b, C0930b c0930b) {
        return new Status(17, "API: " + ((String) c0973b.f9626b.f7827m) + " is not available on this device. Connection failed with: " + String.valueOf(c0930b), c0930b.f9449m, c0930b);
    }

    public static e f(Context context) {
        e eVar;
        HandlerThread handlerThread;
        synchronized (q) {
            if (f9635r == null) {
                synchronized (L.f9837g) {
                    try {
                        handlerThread = L.i;
                        if (handlerThread == null) {
                            HandlerThread handlerThread2 = new HandlerThread("GoogleApiHandler", 9);
                            L.i = handlerThread2;
                            handlerThread2.start();
                            handlerThread = L.i;
                        }
                    } finally {
                    }
                }
                Looper looper = handlerThread.getLooper();
                Context applicationContext = context.getApplicationContext();
                Object obj = C0933e.f9457c;
                f9635r = new e(applicationContext, looper);
            }
            eVar = f9635r;
        }
        return eVar;
    }

    public final boolean a() {
        if (this.f9637b) {
            return false;
        }
        C1011m c1011m = (C1011m) C1010l.c().f9899a;
        if (c1011m != null && !c1011m.f9901l) {
            return false;
        }
        int i = ((SparseIntArray) this.f9642g.f7826l).get(203400000, -1);
        return i == -1 || i == 0;
    }

    public final boolean b(C0930b c0930b, int i) {
        C0933e c0933e = this.f9641f;
        c0933e.getClass();
        Context context = this.f9640e;
        if (!AbstractC1111a.h(context)) {
            int i5 = c0930b.f9448l;
            PendingIntent activity = c0930b.f9449m;
            if (!((i5 == 0 || activity == null) ? false : true)) {
                activity = null;
                Intent intentA = c0933e.a(i5, context, null);
                if (intentA != null) {
                    activity = PendingIntent.getActivity(context, 0, intentA, 201326592);
                }
            }
            if (activity != null) {
                int i6 = GoogleApiActivity.f4811l;
                Intent intent = new Intent(context, (Class<?>) GoogleApiActivity.class);
                intent.putExtra("pending_intent", activity);
                intent.putExtra("failing_client_id", i);
                intent.putExtra("notify_manager", true);
                c0933e.f(context, i5, PendingIntent.getActivity(context, 0, intent, C1.f.f287a | 134217728));
                return true;
            }
        }
        return false;
    }

    public final l d(q1.f fVar) {
        ConcurrentHashMap concurrentHashMap = this.f9644j;
        C0973b c0973b = fVar.f9550e;
        l lVar = (l) concurrentHashMap.get(c0973b);
        if (lVar == null) {
            lVar = new l(this, fVar);
            concurrentHashMap.put(c0973b, lVar);
        }
        if (lVar.f9653d.m()) {
            this.f9646l.add(c0973b);
        }
        lVar.m();
        return lVar;
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x0044  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void e(P1.i r9, int r10, q1.f r11) {
        /*
            r8 = this;
            if (r10 == 0) goto L77
            r1.b r3 = r11.f9550e
            boolean r11 = r8.a()
            if (r11 != 0) goto Lb
            goto L47
        Lb:
            s1.l r11 = s1.C1010l.c()
            java.lang.Object r11 = r11.f9899a
            s1.m r11 = (s1.C1011m) r11
            r0 = 1
            if (r11 == 0) goto L4a
            boolean r1 = r11.f9901l
            if (r1 == 0) goto L47
            java.util.concurrent.ConcurrentHashMap r1 = r8.f9644j
            java.lang.Object r1 = r1.get(r3)
            r1.l r1 = (r1.l) r1
            if (r1 == 0) goto L44
            q1.c r2 = r1.f9653d
            boolean r4 = r2 instanceof s1.AbstractC1003e
            if (r4 == 0) goto L47
            s1.e r2 = (s1.AbstractC1003e) r2
            s1.G r4 = r2.f9866v
            if (r4 == 0) goto L44
            boolean r4 = r2.f()
            if (r4 != 0) goto L44
            s1.g r11 = r1.q.a(r1, r2, r10)
            if (r11 == 0) goto L47
            int r2 = r1.f9662n
            int r2 = r2 + r0
            r1.f9662n = r2
            boolean r0 = r11.f9872m
            goto L4a
        L44:
            boolean r0 = r11.f9902m
            goto L4a
        L47:
            r10 = 0
            r1 = r8
            goto L64
        L4a:
            r1.q r11 = new r1.q
            r1 = 0
            if (r0 == 0) goto L55
            long r4 = java.lang.System.currentTimeMillis()
            goto L56
        L55:
            r4 = r1
        L56:
            if (r0 == 0) goto L5c
            long r1 = android.os.SystemClock.elapsedRealtime()
        L5c:
            r0 = r11
            r6 = r1
            r1 = r8
            r2 = r10
            r0.<init>(r1, r2, r3, r4, r6)
            r10 = r0
        L64:
            if (r10 == 0) goto L78
            P1.o r9 = r9.f2505a
            C1.g r11 = r1.f9647m
            r11.getClass()
            L1.Q0 r0 = new L1.Q0
            r2 = 3
            r0.<init>(r2, r11)
            r9.b(r0, r10)
            return
        L77:
            r1 = r8
        L78:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: r1.e.e(P1.i, int, q1.f):void");
    }

    public final void g(C0930b c0930b, int i) {
        if (b(c0930b, i)) {
            return;
        }
        C1.g gVar = this.f9647m;
        gVar.sendMessage(gVar.obtainMessage(5, i, 0, c0930b));
    }

    /* JADX WARN: Removed duplicated region for block: B:163:0x0330  */
    @Override // android.os.Handler.Callback
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final boolean handleMessage(android.os.Message r13) {
        /*
            Method dump skipped, instruction units count: 1120
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: r1.e.handleMessage(android.os.Message):boolean");
    }
}
