package defpackage;

import android.app.ActivityManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.SparseIntArray;
import com.google.android.gms.common.api.GoogleApiActivity;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.common.api.UnsupportedApiCallException;
import j$.util.concurrent.ConcurrentHashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: renamed from: ᵢᐧ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C3282 implements Handler.Callback {

    /* JADX INFO: renamed from: ᵛˑﹳ, reason: contains not printable characters */
    public static C3282 f12584;

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public final C0513 f12585;

    /* JADX INFO: renamed from: ˁˌᵩ, reason: contains not printable characters */
    public volatile boolean f12586;

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public final ʽᵺᴵ f12587;

    /* JADX INFO: renamed from: ˉᵵᵜ, reason: contains not printable characters */
    public final HandlerC1185 f12588;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public long f12589;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public final AtomicInteger f12590;

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public final ConcurrentHashMap f12591;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public C4495 f12592;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public boolean f12593;

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public final C0513 f12594;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public C5153 f12595;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public final Context f12596;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public final C2762 f12597;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public final AtomicInteger f12598;

    /* JADX INFO: renamed from: ˀᵭ, reason: contains not printable characters */
    public static final Status f12581 = new Status(4, "Sign-out occurred while this API call was in progress.", null, null);

    /* JADX INFO: renamed from: ˊᵾʽʼ, reason: contains not printable characters */
    public static final Status f12583 = new Status(4, "The user must be signed in to make this API call.", null, null);

    /* JADX INFO: renamed from: ˊᵡᵗʨ, reason: contains not printable characters */
    public static final Object f12582 = new Object();

    public C3282(Context context, Looper looper) {
        C2762 c2762 = C2762.f10619;
        this.f12589 = 10000L;
        this.f12593 = false;
        this.f12590 = new AtomicInteger(1);
        this.f12598 = new AtomicInteger(0);
        this.f12591 = new ConcurrentHashMap(5, 0.75f, 1);
        this.f12585 = new C0513(0);
        this.f12594 = new C0513(0);
        this.f12586 = true;
        this.f12596 = context;
        HandlerC1185 handlerC1185 = new HandlerC1185(looper, this);
        Looper.getMainLooper();
        this.f12588 = handlerC1185;
        this.f12597 = c2762;
        this.f12587 = new ʽᵺᴵ(6);
        PackageManager packageManager = context.getPackageManager();
        if (ᵘᵞʿⁱ.ᵠˏˏ == null) {
            ᵘᵞʿⁱ.ᵠˏˏ = Boolean.valueOf(ᵶᵦ.ˊᵙᵾᵲ() && packageManager.hasSystemFeature("android.hardware.type.automotive"));
        }
        if (ᵘᵞʿⁱ.ᵠˏˏ.booleanValue()) {
            this.f12586 = false;
        }
        handlerC1185.sendMessage(handlerC1185.obtainMessage(6));
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static Status m7520(C0996 c0996, C2646 c2646) {
        return new Status(17, AbstractC0793.m2874("API: ", (String) c0996.f4360.f3432, " is not available on this device. Connection failed with: ", String.valueOf(c2646)), c2646.f10258, c2646);
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static C3282 m7521(Context context) {
        C3282 c3282;
        synchronized (f12582) {
            try {
                if (f12584 == null) {
                    Looper looper = C4569.m9653().getLooper();
                    Context applicationContext = context.getApplicationContext();
                    Object obj = C2762.f10618;
                    f12584 = new C3282(applicationContext, looper);
                }
                c3282 = f12584;
            } catch (Throwable th) {
                throw th;
            }
        }
        return c3282;
    }

    /* JADX WARN: Removed duplicated region for block: B:147:0x02bf  */
    @Override // android.os.Handler.Callback
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean handleMessage(Message message) {
        C1394 c1394;
        boolean z;
        C4625[] c4625ArrMo4984;
        int i = message.what;
        C0767 c0767 = C5153.f19368;
        C1916 c1916 = C1916.f7623;
        Context context = this.f12596;
        HandlerC1185 handlerC1185 = this.f12588;
        ConcurrentHashMap concurrentHashMap = this.f12591;
        switch (i) {
            case 1:
                this.f12589 = true == ((Boolean) message.obj).booleanValue() ? 10000L : 300000L;
                handlerC1185.removeMessages(12);
                Iterator it = concurrentHashMap.keySet().iterator();
                while (it.hasNext()) {
                    handlerC1185.sendMessageDelayed(handlerC1185.obtainMessage(12, (C0996) it.next()), this.f12589);
                }
                return true;
            case 2:
                throw AbstractC0659.m2422(message.obj);
            case 3:
                for (C1394 c13942 : concurrentHashMap.values()) {
                    ᵘᵞʿⁱ.ᵵᵽ(c13942.f5763.f12588);
                    c13942.f5760 = null;
                    c13942.m4000();
                }
                return true;
            case 4:
            case C5224.BYTES_FIELD_NUMBER /* 8 */:
            case 13:
                C2006 c2006 = (C2006) message.obj;
                AbstractC2323 abstractC2323 = c2006.f7937;
                AbstractC3067 abstractC3067 = c2006.f7938;
                C1394 c1394M7524 = (C1394) concurrentHashMap.get(abstractC2323.f9133);
                if (c1394M7524 == null) {
                    c1394M7524 = m7524(c2006.f7937);
                }
                if (!c1394M7524.f5765.mo1918() || this.f12598.get() == c2006.f7936) {
                    c1394M7524.m4004(abstractC3067);
                    return true;
                }
                abstractC3067.mo4986(f12581);
                c1394M7524.m3998();
                return true;
            case 5:
                int i2 = message.arg1;
                C2646 c2646 = (C2646) message.obj;
                Iterator it2 = concurrentHashMap.values().iterator();
                while (true) {
                    if (it2.hasNext()) {
                        c1394 = (C1394) it2.next();
                        if (c1394.f5762 == i2) {
                        }
                    } else {
                        c1394 = null;
                    }
                }
                if (c1394 == null) {
                    new Exception();
                    return true;
                }
                int i3 = c2646.f10259;
                if (i3 != 13) {
                    c1394.m4010(m7520(c1394.f5757, c2646));
                    return true;
                }
                this.f12597.getClass();
                int i4 = AbstractC3932.f15022;
                c1394.m4010(new Status(17, AbstractC0793.m2874("Error resolution was canceled by the user, original error message: ", C2646.m6416(i3), ": ", c2646.f10260), null, null));
                return true;
            case C5224.STRING_SET_FIELD_NUMBER /* 6 */:
                if (context.getApplicationContext() instanceof Application) {
                    ComponentCallbacks2C1363.m3908((Application) context.getApplicationContext());
                    ComponentCallbacks2C1363 componentCallbacks2C1363 = ComponentCallbacks2C1363.f5638;
                    componentCallbacks2C1363.m3910(new C2620(this));
                    AtomicBoolean atomicBoolean = componentCallbacks2C1363.f5639;
                    AtomicBoolean atomicBoolean2 = componentCallbacks2C1363.f5641;
                    if (atomicBoolean2.get()) {
                        z = atomicBoolean.get();
                        if (!z) {
                            this.f12589 = 300000L;
                            return true;
                        }
                    } else if (AbstractC0562.m2172()) {
                        z = true;
                        if (!z) {
                        }
                    } else {
                        ActivityManager.RunningAppProcessInfo runningAppProcessInfo = new ActivityManager.RunningAppProcessInfo();
                        ActivityManager.getMyMemoryState(runningAppProcessInfo);
                        if (!atomicBoolean2.getAndSet(true) && runningAppProcessInfo.importance > 100) {
                            atomicBoolean.set(true);
                        }
                        z = atomicBoolean.get();
                        if (!z) {
                        }
                    }
                }
                return true;
            case C5224.DOUBLE_FIELD_NUMBER /* 7 */:
                m7524((AbstractC2323) message.obj);
                return true;
            case 9:
                if (concurrentHashMap.containsKey(message.obj)) {
                    C1394 c13943 = (C1394) concurrentHashMap.get(message.obj);
                    ᵘᵞʿⁱ.ᵵᵽ(c13943.f5763.f12588);
                    if (c13943.f5758) {
                        c13943.m4000();
                        return true;
                    }
                }
                return true;
            case 10:
                C0513 c0513 = this.f12594;
                c0513.getClass();
                C4797 c4797 = new C4797(c0513);
                while (c4797.hasNext()) {
                    C1394 c13944 = (C1394) concurrentHashMap.remove((C0996) c4797.next());
                    if (c13944 != null) {
                        c13944.m3998();
                    }
                }
                c0513.clear();
                return true;
            case 11:
                if (concurrentHashMap.containsKey(message.obj)) {
                    C1394 c13945 = (C1394) concurrentHashMap.get(message.obj);
                    C3282 c3282 = c13945.f5763;
                    ᵘᵞʿⁱ.ᵵᵽ(c3282.f12588);
                    boolean z2 = c13945.f5758;
                    if (z2) {
                        C0996 c0996 = c13945.f5757;
                        HandlerC1185 handlerC11852 = c13945.f5763.f12588;
                        if (z2) {
                            handlerC11852.removeMessages(11, c0996);
                            handlerC11852.removeMessages(9, c0996);
                            c13945.f5758 = false;
                        }
                        c13945.m4010(c3282.f12597.m10399(c3282.f12596, C5073.f19130) == 18 ? new Status(21, "Connection timed out waiting for Google Play services update to complete.", null, null) : new Status(22, "API failed to connect while resuming due to an unknown error.", null, null));
                        c13945.f5765.m6593("Timing out connection while resuming.");
                        return true;
                    }
                }
                return true;
            case 12:
                if (concurrentHashMap.containsKey(message.obj)) {
                    C1394 c13946 = (C1394) concurrentHashMap.get(message.obj);
                    ᵘᵞʿⁱ.ᵵᵽ(c13946.f5763.f12588);
                    InterfaceC2709 interfaceC2709 = c13946.f5765;
                    if (interfaceC2709.m6598() && c13946.f5766.isEmpty()) {
                        C0032 c0032 = c13946.f5767;
                        if (c0032.f1170.isEmpty() && c0032.f1169.isEmpty()) {
                            interfaceC2709.m6593("Timing out service connection.");
                            return true;
                        }
                        c13946.m4009();
                    }
                    return true;
                }
                return true;
            case 14:
                throw AbstractC0659.m2422(message.obj);
            case 15:
                C0687 c0687 = (C0687) message.obj;
                if (concurrentHashMap.containsKey(c0687.f3137)) {
                    C1394 c13947 = (C1394) concurrentHashMap.get(c0687.f3137);
                    if (c13947.f5761.contains(c0687) && !c13947.f5758) {
                        if (c13947.f5765.m6598()) {
                            c13947.m3999();
                            return true;
                        }
                        c13947.m4000();
                        return true;
                    }
                }
                return true;
            case 16:
                C0687 c06872 = (C0687) message.obj;
                if (concurrentHashMap.containsKey(c06872.f3137)) {
                    C1394 c13948 = (C1394) concurrentHashMap.get(c06872.f3137);
                    ArrayList arrayList = c13948.f5761;
                    HandlerC1185 handlerC11853 = c13948.f5763.f12588;
                    LinkedList<AbstractC3067> linkedList = c13948.f5768;
                    if (arrayList.remove(c06872)) {
                        handlerC11853.removeMessages(15, c06872);
                        handlerC11853.removeMessages(16, c06872);
                        C4625 c4625 = c06872.f3136;
                        ArrayList arrayList2 = new ArrayList(linkedList.size());
                        for (AbstractC3067 abstractC30672 : linkedList) {
                            if (abstractC30672 != null && (c4625ArrMo4984 = abstractC30672.mo4984(c13948)) != null) {
                                int length = c4625ArrMo4984.length;
                                int i5 = 0;
                                while (true) {
                                    if (i5 >= length) {
                                    }
                                    if (!ᵬʕˎʽ.ᵻʽᵯ(c4625ArrMo4984[i5], c4625)) {
                                        i5++;
                                    } else if (i5 >= 0) {
                                        arrayList2.add(abstractC30672);
                                    }
                                    break;
                                }
                            }
                        }
                        int size = arrayList2.size();
                        for (int i6 = 0; i6 < size; i6++) {
                            AbstractC3067 abstractC30673 = (AbstractC3067) arrayList2.get(i6);
                            linkedList.remove(abstractC30673);
                            abstractC30673.mo4989(new UnsupportedApiCallException(c4625));
                        }
                    }
                }
                return true;
            case 17:
                C4495 c4495 = this.f12592;
                if (c4495 != null) {
                    if (c4495.f17130 > 0 || m7523()) {
                        if (this.f12595 == null) {
                            this.f12595 = new C5153(context, c0767, c1916, C1601.f6415);
                        }
                        this.f12595.m10658(c4495);
                    }
                    this.f12592 = null;
                    return true;
                }
                return true;
            case 18:
                ((AbstractC4736) message.obj).getClass();
                if (0 == 0) {
                    C4495 c44952 = new C4495(0, Arrays.asList(null));
                    if (this.f12595 == null) {
                        this.f12595 = new C5153(context, c0767, c1916, C1601.f6415);
                    }
                    this.f12595.m10658(c44952);
                    return true;
                }
                C4495 c44953 = this.f12592;
                if (c44953 != null) {
                    List list = c44953.f17131;
                    if (c44953.f17130 != 0 || (list != null && list.size() >= 0)) {
                        handlerC1185.removeMessages(17);
                        C4495 c44954 = this.f12592;
                        if (c44954 != null) {
                            if (c44954.f17130 > 0 || m7523()) {
                                if (this.f12595 == null) {
                                    this.f12595 = new C5153(context, c0767, c1916, C1601.f6415);
                                }
                                this.f12595.m10658(c44954);
                            }
                            this.f12592 = null;
                        }
                    } else {
                        C4495 c44955 = this.f12592;
                        if (c44955.f17131 == null) {
                            c44955.f17131 = new ArrayList();
                        }
                        c44955.f17131.add(null);
                    }
                }
                if (this.f12592 == null) {
                    ArrayList arrayList3 = new ArrayList();
                    arrayList3.add(null);
                    this.f12592 = new C4495(0, arrayList3);
                    handlerC1185.sendMessageDelayed(handlerC1185.obtainMessage(17), 0L);
                    return true;
                }
                return true;
            case 19:
                this.f12593 = false;
                return true;
            default:
                return false;
        }
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final boolean m7522(C2646 c2646, int i) {
        C2762 c2762 = this.f12597;
        c2762.getClass();
        Context context = this.f12596;
        if (!AbstractC1554.m4384(context)) {
            int i2 = c2646.f10259;
            PendingIntent activity = c2646.f10258;
            if (!((i2 == 0 || activity == null) ? false : true)) {
                activity = null;
                Intent intentM10400 = c2762.m10400(i2, context, null);
                if (intentM10400 != null) {
                    activity = PendingIntent.getActivity(context, 0, intentM10400, 201326592);
                }
            }
            if (activity != null) {
                int i3 = GoogleApiActivity.ᵜᵪʾ;
                Intent intent = new Intent(context, (Class<?>) GoogleApiActivity.class);
                intent.putExtra("pending_intent", activity);
                intent.putExtra("failing_client_id", i);
                intent.putExtra("notify_manager", true);
                c2762.m6672(context, i2, PendingIntent.getActivity(context, 0, intent, AbstractC3456.f13326 | 134217728));
                return true;
            }
        }
        return false;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final boolean m7523() {
        if (this.f12593) {
            return false;
        }
        C3664.m8258().getClass();
        int i = ((SparseIntArray) this.f12587.ᵜᵪʾ).get(203400000, -1);
        return i == -1 || i == 0;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final C1394 m7524(AbstractC2323 abstractC2323) {
        C0996 c0996 = abstractC2323.f9133;
        ConcurrentHashMap concurrentHashMap = this.f12591;
        C1394 c1394 = (C1394) concurrentHashMap.get(c0996);
        if (c1394 == null) {
            c1394 = new C1394(this, abstractC2323);
            concurrentHashMap.put(c0996, c1394);
        }
        if (c1394.f5765.mo1918()) {
            this.f12594.add(c0996);
        }
        c1394.m4000();
        return c1394;
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final void m7525(C2646 c2646, int i) {
        if (m7522(c2646, i)) {
            return;
        }
        HandlerC1185 handlerC1185 = this.f12588;
        handlerC1185.sendMessage(handlerC1185.obtainMessage(5, i, 0, c2646));
    }
}
