package o;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Looper;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.common.stats.ConnectionTracker;
import com.google.android.gms.common.util.Clock;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Vt0 extends AbstractC2090oq0 {
    public final Qt0 c;
    public InterfaceC2185pq0 d;
    public volatile Boolean e;
    public final At0 f;
    public ScheduledExecutorService g;
    public final C0189Hh h;
    public final ArrayList i;
    public final At0 j;

    public Vt0(Kr0 kr0) {
        super(kr0);
        this.i = new ArrayList();
        this.h = new C0189Hh(kr0.k);
        this.c = new Qt0(this);
        this.f = new At0(this, kr0, 0);
        this.j = new At0(this, kr0, 1);
    }

    public final void A() {
        r();
        t();
        Qt0 qt0 = this.c;
        if (qt0.b != null && (qt0.b.isConnected() || qt0.b.isConnecting())) {
            qt0.b.disconnect();
        }
        qt0.b = null;
        try {
            ConnectionTracker.getInstance().unbindService(((Kr0) this.a).a, qt0);
        } catch (IllegalArgumentException | IllegalStateException unused) {
        }
        this.d = null;
    }

    public final boolean B() {
        r();
        t();
        if (!z()) {
            return true;
        }
        C2574tv0 c2574tv0 = ((Kr0) this.a).i;
        Kr0.j(c2574tv0);
        return c2574tv0.X() >= ((Integer) AbstractC1900mq0.J0.a(null)).intValue();
    }

    public final boolean C() {
        r();
        t();
        if (!z()) {
            return true;
        }
        C2574tv0 c2574tv0 = ((Kr0) this.a).i;
        Kr0.j(c2574tv0);
        return c2574tv0.X() >= 241200;
    }

    public final void D(ComponentName componentName) {
        r();
        if (this.d != null) {
            this.d = null;
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.n.c(componentName, "Disconnected from device MeasurementService");
            r();
            y();
        }
    }

    public final void E() {
        ((Kr0) this.a).getClass();
    }

    public final void F() {
        r();
        C0189Hh c0189Hh = this.h;
        c0189Hh.m = ((Clock) c0189Hh.n).elapsedRealtime();
        ((Kr0) this.a).getClass();
        this.f.b(((Long) AbstractC1900mq0.Y.a(null)).longValue());
    }

    public final void G(Runnable runnable) {
        r();
        if (J()) {
            runnable.run();
            return;
        }
        ArrayList arrayList = this.i;
        long size = arrayList.size();
        Kr0 kr0 = (Kr0) this.a;
        kr0.getClass();
        if (size >= 1000) {
            Nq0 nq0 = kr0.f;
            Kr0.l(nq0);
            nq0.f.b("Discarding data. Max runnable queue size reached");
        } else {
            arrayList.add(runnable);
            this.j.b(60000L);
            y();
        }
    }

    public final void H() {
        r();
        Kr0 kr0 = (Kr0) this.a;
        Nq0 nq0 = kr0.f;
        Kr0.l(nq0);
        C1984nl c1984nl = nq0.n;
        ArrayList arrayList = this.i;
        c1984nl.c(Integer.valueOf(arrayList.size()), "Processing queued up service tasks");
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            try {
                ((Runnable) obj).run();
            } catch (RuntimeException e) {
                Nq0 nq02 = kr0.f;
                Kr0.l(nq02);
                nq02.f.c(e, "Task exception while flushing queue");
            }
        }
        arrayList.clear();
        this.j.c();
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x009e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final o.C1531iw0 I(boolean r11) {
        /*
            r10 = this;
            java.lang.Object r0 = r10.a
            o.Kr0 r0 = (o.Kr0) r0
            r0.getClass()
            o.xq0 r1 = r0.q()
            r2 = 0
            if (r11 == 0) goto Ld0
            o.Nq0 r11 = r0.f
            o.Kr0.l(r11)
            java.lang.Object r11 = r11.a
            o.Kr0 r11 = (o.Kr0) r11
            o.jr0 r0 = r11.e
            o.Kr0.j(r0)
            o.xf0 r0 = r0.e
            if (r0 != 0) goto L22
            goto Ld0
        L22:
            o.jr0 r11 = r11.e
            o.Kr0.j(r11)
            o.xf0 r11 = r11.e
            java.lang.Object r0 = r11.e
            o.jr0 r0 = (o.C1617jr0) r0
            r0.r()
            r0.r()
            java.lang.Object r3 = r11.e
            o.jr0 r3 = (o.C1617jr0) r3
            android.content.SharedPreferences r3 = r3.w()
            java.lang.Object r4 = r11.b
            java.lang.String r4 = (java.lang.String) r4
            r5 = 0
            long r3 = r3.getLong(r4, r5)
            int r7 = (r3 > r5 ? 1 : (r3 == r5 ? 0 : -1))
            if (r7 != 0) goto L4e
            r11.d()
            r3 = r5
            goto L5d
        L4e:
            java.lang.Object r7 = r0.a
            o.Kr0 r7 = (o.Kr0) r7
            com.google.android.gms.common.util.Clock r7 = r7.k
            long r7 = r7.currentTimeMillis()
            long r3 = r3 - r7
            long r3 = java.lang.Math.abs(r3)
        L5d:
            long r7 = r11.a
            int r9 = (r3 > r7 ? 1 : (r3 == r7 ? 0 : -1))
            if (r9 >= 0) goto L65
        L63:
            r11 = r2
            goto L9c
        L65:
            long r7 = r7 + r7
            int r3 = (r3 > r7 ? 1 : (r3 == r7 ? 0 : -1))
            if (r3 <= 0) goto L6e
            r11.d()
            goto L63
        L6e:
            java.lang.Object r3 = r11.d
            java.lang.String r3 = (java.lang.String) r3
            android.content.SharedPreferences r4 = r0.w()
            java.lang.String r3 = r4.getString(r3, r2)
            java.lang.Object r4 = r11.c
            java.lang.String r4 = (java.lang.String) r4
            android.content.SharedPreferences r0 = r0.w()
            long r7 = r0.getLong(r4, r5)
            r11.d()
            if (r3 == 0) goto L9a
            int r11 = (r7 > r5 ? 1 : (r7 == r5 ? 0 : -1))
            if (r11 > 0) goto L90
            goto L9a
        L90:
            android.util.Pair r11 = new android.util.Pair
            java.lang.Long r0 = java.lang.Long.valueOf(r7)
            r11.<init>(r3, r0)
            goto L9c
        L9a:
            android.util.Pair r11 = o.C1617jr0.z
        L9c:
            if (r11 == 0) goto Ld0
            android.util.Pair r0 = o.C1617jr0.z
            if (r11 != r0) goto La3
            goto Ld0
        La3:
            java.lang.Object r0 = r11.second
            java.lang.String r0 = java.lang.String.valueOf(r0)
            java.lang.Object r11 = r11.first
            java.lang.String r11 = (java.lang.String) r11
            int r2 = r0.length()
            java.lang.String r3 = java.lang.String.valueOf(r11)
            int r2 = r2 + 1
            int r3 = r3.length()
            java.lang.StringBuilder r4 = new java.lang.StringBuilder
            int r2 = r2 + r3
            r4.<init>(r2)
            r4.append(r0)
            java.lang.String r0 = ":"
            r4.append(r0)
            r4.append(r11)
            java.lang.String r2 = r4.toString()
        Ld0:
            o.iw0 r11 = r1.w(r2)
            return r11
        */
        throw new UnsupportedOperationException("Method not decompiled: o.Vt0.I(boolean):o.iw0");
    }

    public final boolean J() {
        r();
        t();
        return this.d != null;
    }

    /* JADX WARN: Removed duplicated region for block: B:170:0x02da A[Catch: all -> 0x0202, SQLiteException -> 0x02b4, SQLiteDatabaseLockedException -> 0x02b9, SQLiteFullException -> 0x02bd, TryCatch #59 {all -> 0x0202, blocks: (B:102:0x01dd, B:104:0x01f1, B:106:0x01f6, B:119:0x021a, B:120:0x021d, B:118:0x0216, B:123:0x0223, B:125:0x0237, B:132:0x024f, B:133:0x0258, B:134:0x025b, B:130:0x0249, B:137:0x025f, B:139:0x0273, B:146:0x028b, B:147:0x0295, B:148:0x0298, B:144:0x0285, B:151:0x029c, B:155:0x02b0, B:170:0x02da, B:171:0x02e4, B:172:0x02e7, B:168:0x02d4, B:180:0x02f4, B:181:0x0301, B:206:0x0366), top: B:418:0x01dd }] */
    /* JADX WARN: Removed duplicated region for block: B:259:0x0444 A[Catch: all -> 0x0480, TRY_ENTER, TryCatch #56 {all -> 0x0480, blocks: (B:269:0x0470, B:259:0x0444, B:261:0x044a, B:262:0x044d, B:279:0x0491, B:208:0x037b, B:210:0x0385, B:215:0x0396), top: B:416:0x0470 }] */
    /* JADX WARN: Removed duplicated region for block: B:264:0x045c  */
    /* JADX WARN: Removed duplicated region for block: B:272:0x0477  */
    /* JADX WARN: Removed duplicated region for block: B:274:0x047c A[PHI: r5 r6 r24 r25 r27 r37 r38
      0x047c: PHI (r5v15 android.database.sqlite.SQLiteDatabase) = 
      (r5v12 android.database.sqlite.SQLiteDatabase)
      (r5v13 android.database.sqlite.SQLiteDatabase)
      (r5v16 android.database.sqlite.SQLiteDatabase)
     binds: [B:265:0x045f, B:282:0x04a3, B:273:0x047a] A[DONT_GENERATE, DONT_INLINE]
      0x047c: PHI (r6v5 int) = (r6v3 int), (r6v3 int), (r6v6 int) binds: [B:265:0x045f, B:282:0x04a3, B:273:0x047a] A[DONT_GENERATE, DONT_INLINE]
      0x047c: PHI (r24v9 int) = (r24v6 int), (r24v7 int), (r24v10 int) binds: [B:265:0x045f, B:282:0x04a3, B:273:0x047a] A[DONT_GENERATE, DONT_INLINE]
      0x047c: PHI (r25v9 java.lang.String) = (r25v6 java.lang.String), (r25v7 java.lang.String), (r25v10 java.lang.String) binds: [B:265:0x045f, B:282:0x04a3, B:273:0x047a] A[DONT_GENERATE, DONT_INLINE]
      0x047c: PHI (r27v9 java.lang.String) = (r27v6 java.lang.String), (r27v7 java.lang.String), (r27v10 java.lang.String) binds: [B:265:0x045f, B:282:0x04a3, B:273:0x047a] A[DONT_GENERATE, DONT_INLINE]
      0x047c: PHI (r37v9 int) = (r37v6 int), (r37v7 int), (r37v10 int) binds: [B:265:0x045f, B:282:0x04a3, B:273:0x047a] A[DONT_GENERATE, DONT_INLINE]
      0x047c: PHI (r38v9 java.lang.String) = (r38v6 java.lang.String), (r38v7 java.lang.String), (r38v10 java.lang.String) binds: [B:265:0x045f, B:282:0x04a3, B:273:0x047a] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:281:0x04a0  */
    /* JADX WARN: Removed duplicated region for block: B:286:0x04b4  */
    /* JADX WARN: Removed duplicated region for block: B:288:0x04b9  */
    /* JADX WARN: Removed duplicated region for block: B:293:0x04d3  */
    /* JADX WARN: Removed duplicated region for block: B:294:0x04dc  */
    /* JADX WARN: Removed duplicated region for block: B:301:0x04fd  */
    /* JADX WARN: Removed duplicated region for block: B:351:0x0634  */
    /* JADX WARN: Removed duplicated region for block: B:355:0x063c  */
    /* JADX WARN: Removed duplicated region for block: B:475:0x04a6 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:476:0x04a6 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:478:0x04a6 A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void K(o.InterfaceC2185pq0 r67, com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable r68, o.C1531iw0 r69) throws java.lang.Throwable {
        /*
            Method dump skipped, instructions count: 1761
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.Vt0.K(o.pq0, com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable, o.iw0):void");
    }

    public final void L(Xn0 xn0) {
        boolean z;
        Preconditions.checkNotNull(xn0);
        r();
        t();
        Kr0 kr0 = (Kr0) this.a;
        kr0.getClass();
        Cq0 cq0N = kr0.n();
        Kr0 kr02 = (Kr0) cq0N.a;
        Kr0.j(kr02.i);
        byte[] bArrV = C2574tv0.V(xn0);
        if (bArrV.length > 131072) {
            Nq0 nq0 = kr02.f;
            Kr0.l(nq0);
            nq0.g.b("Conditional user property too long for local database. Sending directly to service");
            z = false;
        } else {
            z = cq0N.z(2, bArrV);
        }
        G(new RunnableC2760vt0(this, I(true), z, new Xn0(xn0)));
    }

    @Override // o.AbstractC2090oq0
    public final boolean v() {
        return false;
    }

    public final void w(AtomicReference atomicReference) {
        r();
        t();
        G(new RunnableC0245Jl(this, atomicReference, I(false)));
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0056  */
    /* JADX WARN: Removed duplicated region for block: B:14:0x0059  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void x(android.os.Bundle r8) {
        /*
            r7 = this;
            r7.r()
            r7.t()
            o.Lo0 r4 = new o.Lo0
            r4.<init>(r8)
            r7.E()
            java.lang.Object r0 = r7.a
            o.Kr0 r0 = (o.Kr0) r0
            o.ho0 r1 = r0.d
            r2 = 0
            o.lq0 r3 = o.AbstractC1900mq0.b1
            boolean r1 = r1.C(r2, r3)
            r2 = 0
            if (r1 == 0) goto L59
            o.Cq0 r0 = r0.n()
            java.lang.Object r1 = r0.a
            o.Kr0 r1 = (o.Kr0) r1
            o.tv0 r3 = r1.i
            o.Nq0 r1 = r1.f
            o.Kr0.j(r3)
            byte[] r3 = o.C2574tv0.V(r4)
            if (r3 != 0) goto L3f
            o.Kr0.l(r1)
            o.nl r0 = r1.g
            java.lang.String r1 = "Null default event parameters; not writing to database"
            r0.b(r1)
        L3d:
            r0 = r2
            goto L54
        L3f:
            int r5 = r3.length
            r6 = 131072(0x20000, float:1.83671E-40)
            if (r5 <= r6) goto L4f
            o.Kr0.l(r1)
            o.nl r0 = r1.g
            java.lang.String r1 = "Default event parameters too long for local database. Sending directly to service"
            r0.b(r1)
            goto L3d
        L4f:
            r1 = 4
            boolean r0 = r0.z(r1, r3)
        L54:
            if (r0 == 0) goto L59
            r0 = 1
            r3 = r0
            goto L5a
        L59:
            r3 = r2
        L5a:
            o.iw0 r2 = r7.I(r2)
            o.Zq0 r0 = new o.Zq0
            r1 = r7
            r5 = r8
            r0.<init>(r1, r2, r3, r4, r5)
            r7.G(r0)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: o.Vt0.x(android.os.Bundle):void");
    }

    public final void y() {
        r();
        t();
        if (J()) {
            return;
        }
        if (z()) {
            Qt0 qt0 = this.c;
            Vt0 vt0 = qt0.c;
            vt0.r();
            Context context = ((Kr0) vt0.a).a;
            synchronized (qt0) {
                try {
                    if (qt0.a) {
                        Nq0 nq0 = ((Kr0) qt0.c.a).f;
                        Kr0.l(nq0);
                        nq0.n.b("Connection attempt already in progress");
                        return;
                    } else {
                        if (qt0.b != null && (qt0.b.isConnecting() || qt0.b.isConnected())) {
                            Nq0 nq02 = ((Kr0) qt0.c.a).f;
                            Kr0.l(nq02);
                            nq02.n.b("Already awaiting connection attempt");
                            return;
                        }
                        qt0.b = new Gq0(context, Looper.getMainLooper(), 93, qt0, qt0, null);
                        Nq0 nq03 = ((Kr0) qt0.c.a).f;
                        Kr0.l(nq03);
                        nq03.n.b("Connecting to remote service");
                        qt0.a = true;
                        Preconditions.checkNotNull(qt0.b);
                        qt0.b.checkAvailabilityAndConnect();
                        return;
                    }
                } finally {
                }
            }
        }
        Kr0 kr0 = (Kr0) this.a;
        if (kr0.d.v()) {
            return;
        }
        List<ResolveInfo> listQueryIntentServices = kr0.a.getPackageManager().queryIntentServices(new Intent().setClassName(kr0.a, "com.google.android.gms.measurement.AppMeasurementService"), 65536);
        if (listQueryIntentServices == null || listQueryIntentServices.isEmpty()) {
            Nq0 nq04 = kr0.f;
            Kr0.l(nq04);
            nq04.f.b("Unable to use remote or local measurement implementation. Please register the AppMeasurementService service in the app manifest");
            return;
        }
        Intent intent = new Intent("com.google.android.gms.measurement.START");
        intent.setComponent(new ComponentName(kr0.a, "com.google.android.gms.measurement.AppMeasurementService"));
        Qt0 qt02 = this.c;
        Vt0 vt02 = qt02.c;
        vt02.r();
        Context context2 = ((Kr0) vt02.a).a;
        ConnectionTracker connectionTracker = ConnectionTracker.getInstance();
        synchronized (qt02) {
            try {
                if (qt02.a) {
                    Nq0 nq05 = ((Kr0) qt02.c.a).f;
                    Kr0.l(nq05);
                    nq05.n.b("Connection attempt already in progress");
                } else {
                    Vt0 vt03 = qt02.c;
                    Nq0 nq06 = ((Kr0) vt03.a).f;
                    Kr0.l(nq06);
                    nq06.n.b("Using local app measurement service");
                    qt02.a = true;
                    connectionTracker.bindService(context2, intent, vt03.c, 129);
                }
            } finally {
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:42:0x0101  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x0116  */
    /* JADX WARN: Removed duplicated region for block: B:46:0x0118  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean z() {
        /*
            Method dump skipped, instructions count: 316
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.Vt0.z():boolean");
    }
}
