package defpackage;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.DeadObjectException;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.SparseIntArray;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.common.api.UnsupportedApiCallException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;

/* renamed from: ᵹʿˇ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C5024 implements InterfaceC3613, InterfaceC0424 {

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final int f18763;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final InterfaceC5393 f18764;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final C3260 f18766;

    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public final /* synthetic */ C2757 f18767;

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public boolean f18768;

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public final BinderC1312 f18769;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final C0753 f18773;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final LinkedList f18765 = new LinkedList();

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final HashSet f18771 = new HashSet();

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final HashMap f18772 = new HashMap();

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public final ArrayList f18770 = new ArrayList();

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public C0548 f18762 = null;

    /* JADX WARN: Multi-variable type inference failed */
    public C5024(C2757 c2757, AbstractC0686 abstractC0686) {
        this.f18767 = c2757;
        Looper looper = c2757.f10656.getLooper();
        ᵧˉʙ r1 = abstractC0686.m2667();
        C3460 c3460 = new C3460((String) r1.ᵿʗᵝʽ, (String) r1.ᵾᵬ, (C0277) r1.ᵢˇᵭ);
        ᵙᵛᵯ r2 = (ᵙᵛᵯ) abstractC0686.f3358.f10548;
        ᵩʛʽ.ᵝᵵᵺ(r2);
        InterfaceC5393 interfaceC5393 = r2.ᵥᵯˎ(abstractC0686.f3360, looper, c3460, abstractC0686.f3363, this, this);
        String str = abstractC0686.f3361;
        if (str != null && (interfaceC5393 instanceof AbstractC1187)) {
            ((AbstractC1187) interfaceC5393).f5051 = str;
        }
        if (str != null && (interfaceC5393 instanceof AbstractServiceConnectionC5311)) {
            AbstractC4486.m9552(interfaceC5393);
            throw null;
        }
        this.f18764 = interfaceC5393;
        this.f18773 = abstractC0686.f3355;
        this.f18766 = new C3260();
        this.f18763 = abstractC0686.f3356;
        if (!interfaceC5393.mo3720()) {
            this.f18769 = null;
            return;
        }
        Context context = c2757.f10652;
        HandlerC5094 handlerC5094 = c2757.f10656;
        ᵧˉʙ r11 = abstractC0686.m2667();
        this.f18769 = new BinderC1312(context, handlerC5094, new C3460((String) r11.ᵿʗᵝʽ, (String) r11.ᵾᵬ, (C0277) r11.ᵢˇᵭ));
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final void m10463(Status status, Exception exc, boolean z) {
        ᵩʛʽ.ˇʼʤˎ(this.f18767.f10656);
        if ((status == null) == (exc == null)) {
            ᵹˉᵞ.ˌᵜᵹᵩ("Status XOR exception should be null");
            return;
        }
        Iterator it = this.f18765.iterator();
        while (it.hasNext()) {
            AbstractC5231 abstractC5231 = (AbstractC5231) it.next();
            if (!z || abstractC5231.f19604 == 2) {
                if (status != null) {
                    abstractC5231.mo5673(status);
                } else {
                    abstractC5231.mo5677(exc);
                }
                it.remove();
            }
        }
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final void m10464(C0548 c0548, RuntimeException runtimeException) {
        C2035 c2035;
        ᵩʛʽ.ˇʼʤˎ(this.f18767.f10656);
        BinderC1312 binderC1312 = this.f18769;
        if (binderC1312 != null && (c2035 = binderC1312.f5406) != null) {
            c2035.m3717();
        }
        ᵩʛʽ.ˇʼʤˎ(this.f18767.f10656);
        this.f18762 = null;
        ((SparseIntArray) this.f18767.f10645.f2892).clear();
        m10466(c0548);
        if ((this.f18764 instanceof C0159) && c0548.f2846 != 24) {
            C2757 c2757 = this.f18767;
            c2757.f10651 = true;
            HandlerC5094 handlerC5094 = c2757.f10656;
            handlerC5094.sendMessageDelayed(handlerC5094.obtainMessage(19), 300000L);
        }
        if (c0548.f2846 == 4) {
            m10477(C2757.f10641);
            return;
        }
        if (this.f18765.isEmpty()) {
            this.f18762 = c0548;
            return;
        }
        C2757 c27572 = this.f18767;
        if (runtimeException != null) {
            ᵩʛʽ.ˇʼʤˎ(c27572.f10656);
            m10463(null, runtimeException, false);
            return;
        }
        boolean z = c27572.f10648;
        C0753 c0753 = this.f18773;
        if (!z) {
            m10477(C2757.m6793(c0753, c0548));
            return;
        }
        m10463(C2757.m6793(c0753, c0548), null, true);
        if (this.f18765.isEmpty() || m10470(c0548) || this.f18767.m6796(c0548, this.f18763)) {
            return;
        }
        if (c0548.f2846 == 18) {
            this.f18768 = true;
        }
        if (!this.f18768) {
            m10477(C2757.m6793(this.f18773, c0548));
            return;
        }
        C2757 c27573 = this.f18767;
        C0753 c07532 = this.f18773;
        HandlerC5094 handlerC50942 = c27573.f10656;
        handlerC50942.sendMessageDelayed(Message.obtain(handlerC50942, 9, c07532), 5000L);
    }

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final boolean m10465(AbstractC5231 abstractC5231) {
        if (abstractC5231 == null) {
            C3260 c3260 = this.f18766;
            InterfaceC5393 interfaceC5393 = this.f18764;
            abstractC5231.mo5672(c3260, interfaceC5393.mo3720());
            try {
                abstractC5231.mo5671(this);
                return true;
            } catch (DeadObjectException unused) {
                mo4036(1);
                interfaceC5393.m11052("DeadObjectException thrown while running ApiCallRunner.");
                return true;
            }
        }
        C0377 c0377M10472 = m10472(abstractC5231.mo5675(this));
        if (c0377M10472 == null) {
            C3260 c32602 = this.f18766;
            InterfaceC5393 interfaceC53932 = this.f18764;
            abstractC5231.mo5672(c32602, interfaceC53932.mo3720());
            try {
                abstractC5231.mo5671(this);
                return true;
            } catch (DeadObjectException unused2) {
                mo4036(1);
                interfaceC53932.m11052("DeadObjectException thrown while running ApiCallRunner.");
                return true;
            }
        }
        this.f18764.getClass();
        if (!this.f18767.f10648 || !abstractC5231.mo5674(this)) {
            abstractC5231.mo5677(new UnsupportedApiCallException(c0377M10472));
            return true;
        }
        C3623 c3623 = new C3623(this.f18773, c0377M10472);
        int iIndexOf = this.f18770.indexOf(c3623);
        ArrayList arrayList = this.f18770;
        if (iIndexOf >= 0) {
            C3623 c36232 = (C3623) arrayList.get(iIndexOf);
            this.f18767.f10656.removeMessages(15, c36232);
            HandlerC5094 handlerC5094 = this.f18767.f10656;
            handlerC5094.sendMessageDelayed(Message.obtain(handlerC5094, 15, c36232), 5000L);
            return false;
        }
        arrayList.add(c3623);
        HandlerC5094 handlerC50942 = this.f18767.f10656;
        handlerC50942.sendMessageDelayed(Message.obtain(handlerC50942, 15, c3623), 5000L);
        HandlerC5094 handlerC50943 = this.f18767.f10656;
        handlerC50943.sendMessageDelayed(Message.obtain(handlerC50943, 16, c3623), 120000L);
        C0548 c0548 = new C0548(2, null, null);
        if (m10470(c0548)) {
            return false;
        }
        this.f18767.m6796(c0548, this.f18763);
        return false;
    }

    @Override // defpackage.InterfaceC3613
    /* renamed from: ˎˏʜʾ */
    public final void mo4035() {
        Looper looperMyLooper = Looper.myLooper();
        HandlerC5094 handlerC5094 = this.f18767.f10656;
        if (looperMyLooper == handlerC5094.getLooper()) {
            m10467();
        } else {
            handlerC5094.post(new RunnableC2802(27, this));
        }
    }

    @Override // defpackage.InterfaceC3613
    /* renamed from: ˏˋٴ */
    public final void mo4036(int i) {
        Looper looperMyLooper = Looper.myLooper();
        HandlerC5094 handlerC5094 = this.f18767.f10656;
        if (looperMyLooper == handlerC5094.getLooper()) {
            m10473(i);
        } else {
            handlerC5094.post(new RunnableC4456(this, i));
        }
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void m10466(C0548 c0548) {
        HashSet hashSet = this.f18771;
        Iterator it = hashSet.iterator();
        if (!it.hasNext()) {
            hashSet.clear();
        } else if (it.next() != null) {
            C0910.m3050();
        } else {
            if (ˉᵜˆ.ᵶᵷᵕ(c0548, C0548.f2845)) {
                this.f18764.m11046();
            }
            throw null;
        }
    }

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final void m10467() {
        InterfaceC5393 interfaceC5393 = this.f18764;
        C2757 c2757 = this.f18767;
        ᵩʛʽ.ˇʼʤˎ(c2757.f10656);
        this.f18762 = null;
        m10466(C0548.f2845);
        HandlerC5094 handlerC5094 = c2757.f10656;
        if (this.f18768) {
            C0753 c0753 = this.f18773;
            handlerC5094.removeMessages(11, c0753);
            handlerC5094.removeMessages(9, c0753);
            this.f18768 = false;
        }
        Iterator it = this.f18772.values().iterator();
        while (it.hasNext()) {
            C4842 c4842 = (C4842) it.next();
            if (m10472((C0377[]) c4842.f17983.f17375) != null) {
                it.remove();
            } else {
                try {
                    C4699 c4699 = c4842.f17983;
                    new C3921();
                    C1570 c1570 = (C1570) ((C1002) c4699.f17374).f4434;
                    c1570.getClass();
                    C3017 c3017 = (C3017) ((C2935) interfaceC5393).m3715();
                    BinderC3533 binderC3533 = new BinderC3533((C2182) c1570.f6227, (C3664) c1570.f6229);
                    String str = (String) c1570.f6230;
                    Parcel parcelM8908 = c3017.m8908();
                    parcelM8908.writeString(str);
                    AbstractC3092.m7422(parcelM8908, binderC3533);
                    c3017.m8910(parcelM8908, 28);
                } catch (DeadObjectException unused) {
                    mo4036(3);
                    interfaceC5393.m11052("DeadObjectException thrown while calling register listener method.");
                } catch (RemoteException unused2) {
                    it.remove();
                }
            }
        }
        m10476();
        m10475();
    }

    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public final void m10468(C0548 c0548) {
        ᵩʛʽ.ˇʼʤˎ(this.f18767.f10656);
        InterfaceC5393 interfaceC5393 = this.f18764;
        interfaceC5393.m11052("onSignInFailed for " + interfaceC5393.getClass().getName() + " with " + String.valueOf(c0548));
        m10464(c0548, null);
    }

    @Override // defpackage.InterfaceC0424
    /* renamed from: ᵥᵯˎ */
    public final void mo1972(C0548 c0548) {
        m10464(c0548, null);
    }

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public final void m10469() throws PackageManager.NameNotFoundException {
        C2757 c2757 = this.f18767;
        ᵩʛʽ.ˇʼʤˎ(c2757.f10656);
        InterfaceC5393 interfaceC5393 = this.f18764;
        if (interfaceC5393.m11048() || interfaceC5393.m11054()) {
            return;
        }
        try {
            C0553 c0553 = c2757.f10645;
            Context context = c2757.f10652;
            SparseIntArray sparseIntArray = (SparseIntArray) c0553.f2892;
            ᵩʛʽ.ᵝᵵᵺ(context);
            int iMo1329 = interfaceC5393.mo1329();
            int iM3394 = ((SparseIntArray) c0553.f2892).get(iMo1329, -1);
            if (iM3394 == -1) {
                iM3394 = 0;
                int i = 0;
                while (true) {
                    if (i >= sparseIntArray.size()) {
                        iM3394 = -1;
                        break;
                    }
                    int iKeyAt = sparseIntArray.keyAt(i);
                    if (iKeyAt > iMo1329 && sparseIntArray.get(iKeyAt) == 0) {
                        break;
                    } else {
                        i++;
                    }
                }
                if (iM3394 == -1) {
                    iM3394 = ((C4815) c0553.f2894).m3394(context, iMo1329);
                }
                sparseIntArray.put(iMo1329, iM3394);
            }
            if (iM3394 != 0) {
                C0548 c0548 = new C0548(iM3394, null, null);
                c0548.toString();
                m10464(c0548, null);
                return;
            }
            C4775 c4775 = new C4775(c2757, interfaceC5393, this.f18773);
            if (interfaceC5393.mo3720()) {
                BinderC1312 binderC1312 = this.f18769;
                ᵩʛʽ.ᵝᵵᵺ(binderC1312);
                Handler handler = binderC1312.f5412;
                C3460 c3460 = binderC1312.f5411;
                C2035 c2035 = binderC1312.f5406;
                if (c2035 != null) {
                    c2035.m3717();
                }
                c3460.f12989 = Integer.valueOf(System.identityHashCode(binderC1312));
                binderC1312.f5406 = (C2035) binderC1312.f5408.m2709(binderC1312.f5407, handler.getLooper(), c3460, (C0930) c3460.f12986, binderC1312, binderC1312);
                binderC1312.f5409 = c4775;
                Set set = binderC1312.f5410;
                if (set == null || set.isEmpty()) {
                    handler.post(new RunnableC2802(29, binderC1312));
                } else {
                    C2035 c20352 = binderC1312.f5406;
                    c20352.getClass();
                    c20352.m3710(new ˊᵘʛ(c20352));
                }
            }
            try {
                interfaceC5393.m11049(c4775);
            } catch (SecurityException e) {
                m10464(new C0548(10, null, null), e);
            }
        } catch (IllegalStateException e2) {
            m10464(new C0548(10, null, null), e2);
        }
    }

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public final boolean m10470(C0548 c0548) {
        synchronized (C2757.f10644) {
        }
        return false;
    }

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public final void m10471(AbstractC5231 abstractC5231) throws PackageManager.NameNotFoundException {
        ᵩʛʽ.ˇʼʤˎ(this.f18767.f10656);
        boolean zM11048 = this.f18764.m11048();
        LinkedList linkedList = this.f18765;
        if (zM11048) {
            if (m10465(abstractC5231)) {
                m10475();
                return;
            } else {
                linkedList.add(abstractC5231);
                return;
            }
        }
        linkedList.add(abstractC5231);
        C0548 c0548 = this.f18762;
        if (c0548 == null || c0548.f2846 == 0 || c0548.f2850 == null) {
            m10469();
        } else {
            m10464(c0548, null);
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final C0377 m10472(C0377[] c0377Arr) {
        if (c0377Arr == null || c0377Arr.length == 0) {
            return null;
        }
        C0377[] c0377ArrM11051 = this.f18764.m11051();
        if (c0377ArrM11051 == null) {
            c0377ArrM11051 = new C0377[0];
        }
        C1200 c1200 = new C1200(c0377ArrM11051.length);
        for (C0377 c0377 : c0377ArrM11051) {
            c1200.put(c0377.f2172, Long.valueOf(c0377.m1814()));
        }
        for (C0377 c03772 : c0377Arr) {
            Long l = (Long) c1200.get(c03772.f2172);
            if (l == null || l.longValue() < c03772.m1814()) {
                return c03772;
            }
        }
        return null;
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final void m10473(int i) {
        C2757 c2757 = this.f18767;
        HandlerC5094 handlerC5094 = c2757.f10656;
        ᵩʛʽ.ˇʼʤˎ(c2757.f10656);
        this.f18762 = null;
        this.f18768 = true;
        String strM11053 = this.f18764.m11053();
        C3260 c3260 = this.f18766;
        c3260.getClass();
        StringBuilder sb = new StringBuilder("The connection to Google Play services was lost");
        if (i == 1) {
            sb.append(" due to service disconnection.");
        } else if (i == 3) {
            sb.append(" due to dead object exception.");
        }
        if (strM11053 != null) {
            sb.append(" Last reason for disconnect: ");
            sb.append(strM11053);
        }
        c3260.m7626(true, new Status(20, sb.toString(), null, null));
        C0753 c0753 = this.f18773;
        handlerC5094.sendMessageDelayed(Message.obtain(handlerC5094, 9, c0753), 5000L);
        handlerC5094.sendMessageDelayed(Message.obtain(handlerC5094, 11, c0753), 120000L);
        ((SparseIntArray) c2757.f10645.f2892).clear();
        Iterator it = this.f18772.values().iterator();
        while (it.hasNext()) {
            ((C4842) it.next()).getClass();
        }
    }

    /* renamed from: ᵸʓᵠ, reason: contains not printable characters */
    public final void m10474() throws PackageManager.NameNotFoundException {
        ᵩʛʽ.ˇʼʤˎ(this.f18767.f10656);
        Status status = C2757.f10643;
        m10477(status);
        this.f18766.m7626(false, status);
        for (C5395 c5395 : (C5395[]) this.f18772.keySet().toArray(new C5395[0])) {
            m10471(new C2081(c5395, new C1353()));
        }
        m10466(new C0548(4, null, null));
        InterfaceC5393 interfaceC5393 = this.f18764;
        if (interfaceC5393.m11048()) {
            interfaceC5393.m11050(new C4457(3, this));
        }
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final void m10475() {
        C2757 c2757 = this.f18767;
        HandlerC5094 handlerC5094 = c2757.f10656;
        C0753 c0753 = this.f18773;
        handlerC5094.removeMessages(12, c0753);
        handlerC5094.sendMessageDelayed(handlerC5094.obtainMessage(12, c0753), c2757.f10654);
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final void m10476() {
        LinkedList linkedList = this.f18765;
        ArrayList arrayList = new ArrayList(linkedList);
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            AbstractC5231 abstractC5231 = (AbstractC5231) arrayList.get(i);
            if (!this.f18764.m11048()) {
                return;
            }
            if (m10465(abstractC5231)) {
                linkedList.remove(abstractC5231);
            }
        }
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final void m10477(Status status) {
        ᵩʛʽ.ˇʼʤˎ(this.f18767.f10656);
        m10463(status, null, false);
    }
}
