package o;

import android.animation.Animator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import androidx.work.impl.WorkDatabase_Impl;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.R;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Objects;
import java.util.TreeMap;
import java.util.WeakHashMap;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public class Gm0 implements InterfaceC1823m1, InterfaceC2543tg, InterfaceC3048yv, InterfaceC2956xx, Mo0 {
    public final /* synthetic */ int l;
    public Object m;
    public Object n;

    public /* synthetic */ Gm0(int i, Object obj, Object obj2) {
        this.l = i;
        this.n = obj;
        this.m = obj2;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r4v0 */
    /* JADX WARN: Type inference failed for: r4v1, types: [o.LP] */
    /* JADX WARN: Type inference failed for: r4v10 */
    /* JADX WARN: Type inference failed for: r4v11 */
    /* JADX WARN: Type inference failed for: r4v3 */
    /* JADX WARN: Type inference failed for: r4v4, types: [o.LP] */
    /* JADX WARN: Type inference failed for: r4v5, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r4v6 */
    /* JADX WARN: Type inference failed for: r4v7 */
    /* JADX WARN: Type inference failed for: r4v8 */
    /* JADX WARN: Type inference failed for: r4v9 */
    /* JADX WARN: Type inference failed for: r5v0 */
    /* JADX WARN: Type inference failed for: r5v1 */
    /* JADX WARN: Type inference failed for: r5v10 */
    /* JADX WARN: Type inference failed for: r5v11 */
    /* JADX WARN: Type inference failed for: r5v2 */
    /* JADX WARN: Type inference failed for: r5v3, types: [o.iR] */
    /* JADX WARN: Type inference failed for: r5v4 */
    /* JADX WARN: Type inference failed for: r5v5 */
    /* JADX WARN: Type inference failed for: r5v6, types: [o.iR] */
    /* JADX WARN: Type inference failed for: r5v8 */
    /* JADX WARN: Type inference failed for: r5v9 */
    public static void b(C2420sK c2420sK) {
        if (c2420sK.W > 0) {
            if (c2420sK.O.c == 5 && !c2420sK.n() && !c2420sK.o() && !c2420sK.X && c2420sK.H()) {
                LP lp = (LP) c2420sK.N.g;
                if ((lp.f209o & 256) != 0) {
                    while (lp != null) {
                        if ((lp.n & 256) != 0) {
                            AbstractC0561Vq abstractC0561VqI = lp;
                            ?? c1479iR = 0;
                            while (abstractC0561VqI != 0) {
                                if (abstractC0561VqI instanceof SD) {
                                    SD sd = (SD) abstractC0561VqI;
                                    sd.U(AbstractC2539te.Q(sd, 256));
                                } else if ((abstractC0561VqI.n & 256) != 0 && (abstractC0561VqI instanceof AbstractC0561Vq)) {
                                    LP lp2 = abstractC0561VqI.A;
                                    int i = 0;
                                    abstractC0561VqI = abstractC0561VqI;
                                    c1479iR = c1479iR;
                                    while (lp2 != null) {
                                        if ((lp2.n & 256) != 0) {
                                            i++;
                                            c1479iR = c1479iR;
                                            if (i == 1) {
                                                abstractC0561VqI = lp2;
                                            } else {
                                                if (c1479iR == 0) {
                                                    c1479iR = new C1479iR(new LP[16]);
                                                }
                                                if (abstractC0561VqI != 0) {
                                                    c1479iR.b(abstractC0561VqI);
                                                    abstractC0561VqI = 0;
                                                }
                                                c1479iR.b(lp2);
                                            }
                                        }
                                        lp2 = lp2.q;
                                        abstractC0561VqI = abstractC0561VqI;
                                        c1479iR = c1479iR;
                                    }
                                    if (i == 1) {
                                    }
                                }
                                abstractC0561VqI = AbstractC2539te.i(c1479iR);
                            }
                        }
                        if ((lp.f209o & 256) == 0) {
                            break;
                        } else {
                            lp = lp.q;
                        }
                    }
                }
            }
            c2420sK.V = false;
            C1479iR c1479iRW = c2420sK.w();
            Object[] objArr = c1479iRW.l;
            int i2 = c1479iRW.n;
            for (int i3 = 0; i3 < i2; i3++) {
                b((C2420sK) objArr[i3]);
            }
        }
    }

    public static C0152Fw h(C2891xG c2891xG, Throwable th) {
        if (th instanceof VS) {
            c2891xG.getClass();
            C2279qq c2279qq = c2891xG.u;
            c2279qq.getClass();
            C2279qq c2279qq2 = AbstractC1249g.a;
            c2279qq.getClass();
        } else {
            c2891xG.u.getClass();
            C2279qq c2279qq3 = AbstractC1249g.a;
        }
        return new C0152Fw(null, c2891xG, th);
    }

    public static int i(int i, int i2) {
        int i3 = 0;
        int i4 = 0;
        for (int i5 = 0; i5 < i; i5++) {
            i3++;
            if (i3 == i2) {
                i4++;
                i3 = 0;
            } else if (i3 > i2) {
                i4++;
                i3 = 1;
            }
        }
        return i3 + 1 > i2 ? i4 + 1 : i4;
    }

    @Override // o.Mo0
    public C2062oc0 a(InterfaceC1991no0 interfaceC1991no0) {
        C2062oc0 c2062oc0J = ((C2062oc0) this.m).j();
        String str = (String) this.n;
        c2062oc0J.m(str, interfaceC1991no0);
        ((HashMap) c2062oc0J.d).put(str, Boolean.TRUE);
        return c2062oc0J;
    }

    @Override // o.InterfaceC1823m1
    public boolean c(AbstractC1918n1 abstractC1918n1, Menu menu) {
        return ((InterfaceC1823m1) this.m).c(abstractC1918n1, menu);
    }

    /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, o.x7] */
    @Override // o.InterfaceC1823m1
    public void d(AbstractC1918n1 abstractC1918n1) {
        ((InterfaceC1823m1) this.m).d(abstractC1918n1);
        S7 s7 = (S7) this.n;
        if (s7.H != null) {
            s7.w.getDecorView().removeCallbacks(s7.I);
        }
        if (s7.G != null) {
            C1698kk0 c1698kk0 = s7.J;
            if (c1698kk0 != null) {
                c1698kk0.b();
            }
            C1698kk0 c1698kk0A = Oj0.a(s7.G);
            c1698kk0A.a(0.0f);
            s7.J = c1698kk0A;
            c1698kk0A.d(new I7(2, this));
        }
        s7.y.onSupportActionModeFinished(s7.F);
        s7.F = null;
        ViewGroup viewGroup = s7.L;
        WeakHashMap weakHashMap = Oj0.a;
        Ej0.c(viewGroup);
        s7.I();
    }

    @Override // o.InterfaceC1823m1
    public boolean e(AbstractC1918n1 abstractC1918n1, MenuItem menuItem) {
        return ((InterfaceC1823m1) this.m).e(abstractC1918n1, menuItem);
    }

    @Override // o.InterfaceC3048yv
    public boolean f(CharSequence charSequence, int i, int i2, C2641uh0 c2641uh0) {
        if ((c2641uh0.c & 4) > 0) {
            return true;
        }
        if (((Uh0) this.m) == null) {
            this.m = new Uh0(charSequence instanceof Spannable ? (Spannable) charSequence : new SpannableString(charSequence));
        }
        ((C0688a6) this.n).getClass();
        ((Uh0) this.m).setSpan(new C2736vh0(c2641uh0), i, i2, 33);
        return true;
    }

    @Override // o.InterfaceC1823m1
    public boolean g(AbstractC1918n1 abstractC1918n1, Menu menu) {
        ViewGroup viewGroup = ((S7) this.n).L;
        WeakHashMap weakHashMap = Oj0.a;
        Ej0.c(viewGroup);
        return ((InterfaceC1823m1) this.m).g(abstractC1918n1, menu);
    }

    @Override // o.CZ
    public Object get() {
        switch (this.l) {
            case ConnectionResult.SERVICE_INVALID /* 9 */:
                return new OY((Context) ((G0) this.m).m, (C2643ui0) ((CZ) this.n).get());
            default:
                return new C2121p70((E70) ((CZ) this.m).get(), (E70) ((BZ) this.n).get());
        }
    }

    @Override // o.InterfaceC3048yv
    public Object getResult() {
        return (Uh0) this.m;
    }

    public ArrayList j(String str) {
        WorkDatabase_Impl workDatabase_Impl = (WorkDatabase_Impl) this.m;
        C1449i30 c1449i30D = C1449i30.d(1, "SELECT DISTINCT tag FROM worktag WHERE work_spec_id=?");
        if (str == null) {
            c1449i30D.r(1);
        } else {
            c1449i30D.k(1, str);
        }
        workDatabase_Impl.b();
        Cursor cursorL = workDatabase_Impl.l(c1449i30D);
        try {
            ArrayList arrayList = new ArrayList(cursorL.getCount());
            while (cursorL.moveToNext()) {
                arrayList.add(cursorL.isNull(0) ? null : cursorL.getString(0));
            }
            return arrayList;
        } finally {
            cursorL.close();
            c1449i30D.release();
        }
    }

    public void k() {
        ((SparseIntArray) this.m).clear();
    }

    public void l(Throwable th) {
        C2762vu0 c2762vu0 = (C2762vu0) this.m;
        Xs0 xs0 = (Xs0) this.n;
        xs0.r();
        xs0.i = false;
        Kr0 kr0 = (Kr0) xs0.a;
        C1421ho0 c1421ho0 = kr0.d;
        Nq0 nq0 = kr0.f;
        int i = 2;
        if (c1421ho0.C(null, AbstractC1900mq0.T0)) {
            String message = th.getMessage();
            xs0.n = false;
            if (message != null) {
                if ((th instanceof IllegalStateException) || message.contains("garbage collected") || th.getClass().getSimpleName().equals("ServiceUnavailableException")) {
                    if (message.contains("Background")) {
                        xs0.n = true;
                    }
                    i = 1;
                } else if ((th instanceof SecurityException) && !message.endsWith("READ_DEVICE_CONFIG")) {
                    i = 3;
                }
            }
        }
        int i2 = i - 1;
        if (i2 == 0) {
            Kr0.l(nq0);
            nq0.i.d("registerTriggerAsync failed with retriable error. Will try later. App ID, throwable", Nq0.A(kr0.q().y()), Nq0.A(th.toString()));
            xs0.j = 1;
            xs0.Q().add(c2762vu0);
            return;
        }
        if (i2 != 1) {
            Kr0.l(nq0);
            nq0.f.d("registerTriggerAsync failed. Dropping URI. App ID, Throwable", Nq0.A(kr0.q().y()), th);
            o();
            xs0.j = 1;
            xs0.R();
            return;
        }
        xs0.Q().add(c2762vu0);
        if (xs0.j > ((Integer) AbstractC1900mq0.w0.a(null)).intValue()) {
            xs0.j = 1;
            Kr0.l(nq0);
            nq0.i.d("registerTriggerAsync failed. May try later. App ID, throwable", Nq0.A(kr0.q().y()), Nq0.A(th.toString()));
            return;
        }
        Kr0.l(nq0);
        nq0.i.e("registerTriggerAsync failed. App ID, delay in seconds, throwable", Nq0.A(kr0.q().y()), Nq0.A(String.valueOf(xs0.j)), Nq0.A(th.toString()));
        int i3 = xs0.j;
        if (xs0.k == null) {
            xs0.k = new C3043ys0(xs0, kr0, 1);
        }
        xs0.k.b(i3 * 1000);
        int i4 = xs0.j;
        xs0.j = i4 + i4;
    }

    public void m(Bundle bundle) {
        Locale locale = Locale.US;
        Objects.toString(bundle);
        Log.isLoggable("FirebaseCrashlytics", 2);
        String string = bundle.getString("name");
        if (string != null) {
            Bundle bundle2 = bundle.getBundle("params");
            if (bundle2 == null) {
                bundle2 = new Bundle();
            }
            F2 f2 = "clx".equals(bundle2.getString("_o")) ? (C3126zm0) this.m : (OD) this.n;
            if (f2 == null) {
                return;
            }
            f2.r(string, bundle2);
        }
    }

    public NU n(C2891xG c2891xG, S80 s80) {
        Bitmap.Config config = ((c2891xG.e.isEmpty() || AbstractC2219q9.H(AbstractC1345h.a, c2891xG.d)) && (!AbstractC1904ms0.n(c2891xG.d) || ((!AbstractC1904ms0.n(c2891xG.d) || c2891xG.j) && ((HE) this.n).h(s80)))) ? c2891xG.d : Bitmap.Config.ARGB_8888;
        int i = ((ComponentCallbacks2C1301gc0) this.m).f541o ? c2891xG.y : 4;
        IJ ij = s80.a;
        C0562Vr c0562Vr = C0562Vr.m;
        return new NU(c2891xG.a, config, s80, (ij.equals(c0562Vr) || s80.b.equals(c0562Vr)) ? 2 : c2891xG.z, AbstractC1249g.a(c2891xG), c2891xG.k && c2891xG.e.isEmpty() && config != Bitmap.Config.ALPHA_8, c2891xG.l, c2891xG.g, c2891xG.h, c2891xG.s, c2891xG.w, c2891xG.x, i);
    }

    public void o() {
        Kr0 kr0 = (Kr0) ((Xs0) this.n).a;
        C1617jr0 c1617jr0 = kr0.e;
        Kr0.j(c1617jr0);
        SparseArray sparseArrayY = c1617jr0.y();
        C2762vu0 c2762vu0 = (C2762vu0) this.m;
        sparseArrayY.put(c2762vu0.n, Long.valueOf(c2762vu0.m));
        C1617jr0 c1617jr02 = kr0.e;
        Kr0.j(c1617jr02);
        int[] iArr = new int[sparseArrayY.size()];
        long[] jArr = new long[sparseArrayY.size()];
        for (int i = 0; i < sparseArrayY.size(); i++) {
            iArr[i] = sparseArrayY.keyAt(i);
            jArr[i] = ((Long) sparseArrayY.valueAt(i)).longValue();
        }
        Bundle bundle = new Bundle();
        bundle.putIntArray("uriSources", iArr);
        bundle.putLongArray("uriTimestamps", jArr);
        c1617jr02.n.s(bundle);
    }

    @Override // o.InterfaceC2543tg
    public void onCancel() {
        ((Animator) this.m).end();
        if (androidx.fragment.app.s.F(2)) {
            Objects.toString((androidx.fragment.app.x) this.n);
        }
    }

    public void p(C2062oc0 c2062oc0, C70 c70) {
        Ss0 ss0 = new Ss0(c70);
        TreeMap treeMap = (TreeMap) this.m;
        for (Integer num : treeMap.keySet()) {
            Kn0 kn0Clone = ((Kn0) c70.n).clone();
            InterfaceC1991no0 interfaceC1991no0G = ((C1801lo0) treeMap.get(num)).g(c2062oc0, Collections.singletonList(ss0));
            int iU0 = interfaceC1991no0G instanceof Wn0 ? AbstractC2378rs0.u0(((Wn0) interfaceC1991no0G).l.doubleValue()) : -1;
            if (iU0 == 2 || iU0 == -1) {
                c70.n = kn0Clone;
            }
        }
        TreeMap treeMap2 = (TreeMap) this.n;
        Iterator it = treeMap2.keySet().iterator();
        while (it.hasNext()) {
            InterfaceC1991no0 interfaceC1991no0G2 = ((C1801lo0) treeMap2.get((Integer) it.next())).g(c2062oc0, Collections.singletonList(ss0));
            if (interfaceC1991no0G2 instanceof Wn0) {
                AbstractC2378rs0.u0(((Wn0) interfaceC1991no0G2).l.doubleValue());
            }
        }
    }

    public /* synthetic */ Gm0(int i, Object obj, Object obj2, boolean z) {
        this.l = i;
        this.m = obj;
        this.n = obj2;
    }

    public /* synthetic */ Gm0(int i, boolean z) {
        this.l = i;
    }

    public Gm0(C2961y00 c2961y00, ComponentCallbacks2C1301gc0 componentCallbacks2C1301gc0) {
        Object kg;
        this.l = 10;
        this.m = componentCallbacks2C1301gc0;
        int i = Build.VERSION.SDK_INT;
        if (i < 26) {
            boolean z = AbstractC0866c.a;
        } else {
            if (!AbstractC0866c.a) {
                if (i != 26 && i != 27) {
                    kg = new KG(true);
                } else {
                    kg = new J7(28);
                }
            }
            this.n = kg;
        }
        kg = new KG(false);
        this.n = kg;
    }

    public Gm0(WorkDatabase_Impl workDatabase_Impl) {
        this.l = 0;
        this.m = workDatabase_Impl;
        this.n = new C2945xr(workDatabase_Impl, 6);
        new C1967nc0(workDatabase_Impl, 20);
    }

    public Gm0(Context context) throws Resources.NotFoundException {
        this.l = 2;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(C80.V(context, R.attr.materialCalendarStyle, VN.class.getCanonicalName()).data, XZ.l);
        C0688a6.h(context, typedArrayObtainStyledAttributes.getResourceId(4, 0));
        C0688a6.h(context, typedArrayObtainStyledAttributes.getResourceId(2, 0));
        C0688a6.h(context, typedArrayObtainStyledAttributes.getResourceId(3, 0));
        C0688a6.h(context, typedArrayObtainStyledAttributes.getResourceId(5, 0));
        ColorStateList colorStateListQ = AbstractC2461sm0.q(context, typedArrayObtainStyledAttributes, 7);
        this.m = C0688a6.h(context, typedArrayObtainStyledAttributes.getResourceId(9, 0));
        C0688a6.h(context, typedArrayObtainStyledAttributes.getResourceId(8, 0));
        this.n = C0688a6.h(context, typedArrayObtainStyledAttributes.getResourceId(10, 0));
        new Paint().setColor(colorStateListQ.getDefaultColor());
        typedArrayObtainStyledAttributes.recycle();
    }

    public Gm0(int i) {
        this.l = i;
        switch (i) {
            case 8:
                this.m = new C1479iR(new C2420sK[16]);
                break;
            case 12:
                this.m = new BP(18);
                this.n = new C1283gN(16);
                break;
            case 13:
                this.m = new C1479iR(new Reference[16]);
                this.n = new ReferenceQueue();
                break;
            case 16:
                this.m = new TreeMap();
                this.n = new TreeMap();
                break;
            default:
                this.m = new SparseIntArray();
                this.n = new SparseIntArray();
                break;
        }
    }
}
