package com.google.android.gms.measurement.internal;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabaseLockedException;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteFullException;
import android.os.Build;
import android.os.Looper;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.ext.SdkExtensions;
import androidx.media3.common.C;
import androidx.media3.common.PlaybackException;
import com.google.android.gms.common.internal.safeparcel.SafeParcelReader$ParseException;
import com.google.android.gms.internal.measurement.ka;
import com.google.android.gms.internal.measurement.la;
import com.google.android.gms.internal.measurement.y7;
import com.google.android.gms.internal.measurement.z9;
import java.lang.reflect.Method;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: loaded from: classes2.dex */
public final class a3 extends x0 {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final h3 f21471c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public h0 f21472d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public volatile Boolean f21473e;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final androidx.recyclerview.widget.d f21475g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final ArrayList f21476h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final b3 f21477i;

    public a3(m1 m1Var) {
        super(m1Var);
        this.f21476h = new ArrayList();
        this.f21475g = new androidx.recyclerview.widget.d(m1Var.f21762n);
        this.f21471c = new h3(this);
        this.f21474f = new b3(this, m1Var, 0);
        this.f21477i = new b3(this, m1Var, 1);
    }

    @Override // com.google.android.gms.measurement.internal.x0
    public final boolean F() {
        return false;
    }

    public final void G(e eVar) {
        boolean zH;
        com.google.android.gms.common.internal.w.checkNotNull(eVar);
        w();
        D();
        k0 k0VarY = y();
        k0VarY.v();
        byte[] bArrL0 = n4.l0(eVar);
        if (bArrL0.length > 131072) {
            k0VarY.zzj().f21835g.c("Conditional user property too long for local database. Sending directly to service");
            zH = false;
        } else {
            zH = k0VarY.H(2, bArrL0);
        }
        boolean z10 = zH;
        I(new e3(this, S(true), z10, new e(eVar), eVar));
    }

    /* JADX WARN: Removed duplicated region for block: B:126:0x0211 A[Catch: all -> 0x00e8, TRY_ENTER, TryCatch #7 {all -> 0x00e8, blocks: (B:33:0x00b8, B:35:0x00be, B:37:0x00cc, B:39:0x00df, B:41:0x00e4, B:56:0x0113, B:57:0x0116, B:55:0x010f, B:60:0x011a, B:62:0x012e, B:77:0x0156, B:78:0x015a, B:79:0x015d, B:75:0x0150, B:82:0x0161, B:86:0x0177, B:100:0x0198, B:136:0x0237, B:126:0x0211, B:128:0x0217, B:129:0x021a, B:144:0x024d, B:101:0x019d, B:102:0x01a0, B:98:0x0192, B:105:0x01a6, B:106:0x01b2, B:109:0x01ca, B:111:0x01d8, B:113:0x01e4, B:118:0x01f4), top: B:219:0x00b8 }] */
    /* JADX WARN: Removed duplicated region for block: B:131:0x0228  */
    /* JADX WARN: Removed duplicated region for block: B:133:0x022d  */
    /* JADX WARN: Removed duplicated region for block: B:139:0x023e  */
    /* JADX WARN: Removed duplicated region for block: B:141:0x0243  */
    /* JADX WARN: Removed duplicated region for block: B:146:0x025b  */
    /* JADX WARN: Removed duplicated region for block: B:148:0x0260  */
    /* JADX WARN: Removed duplicated region for block: B:151:0x026f  */
    /* JADX WARN: Removed duplicated region for block: B:153:0x0274  */
    /* JADX WARN: Removed duplicated region for block: B:261:0x0263 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:263:0x0263 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:265:0x0263 A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void H(h0 h0Var, f8.a aVar, d4 d4Var) throws Throwable {
        ArrayList arrayList;
        int i10;
        int i11;
        Cursor cursorQuery;
        SQLiteDatabase sQLiteDatabaseK;
        String str;
        String[] strArr;
        int i12;
        byte[] blob;
        i4 i4VarCreateFromParcel;
        e eVarCreateFromParcel;
        int size;
        long j10;
        long jElapsedRealtime;
        long jCurrentTimeMillis;
        w();
        D();
        int i13 = 100;
        int i14 = 0;
        int i15 = 100;
        int i16 = 0;
        while (i16 < 1001 && i15 == i13) {
            ArrayList arrayList2 = new ArrayList();
            k0 k0VarY = y();
            k0VarY.w();
            if (k0VarY.f21697d) {
                i10 = i14;
                i11 = i16;
                arrayList = null;
            } else {
                arrayList = new ArrayList();
                if (k0VarY.zza().getDatabasePath("google_app_measurement_local.db").exists()) {
                    int i17 = i14;
                    int i18 = 5;
                    for (int i19 = 5; i17 < i19; i19 = 5) {
                        int i20 = 1;
                        try {
                            sQLiteDatabaseK = k0VarY.K();
                        } catch (SQLiteDatabaseLockedException unused) {
                            i10 = i14;
                            i11 = i16;
                            cursorQuery = null;
                            sQLiteDatabaseK = null;
                        } catch (SQLiteFullException e10) {
                            e = e10;
                            i10 = i14;
                            i11 = i16;
                            cursorQuery = null;
                            sQLiteDatabaseK = null;
                        } catch (SQLiteException e11) {
                            e = e11;
                            i10 = i14;
                            i11 = i16;
                            cursorQuery = null;
                            sQLiteDatabaseK = null;
                        } catch (Throwable th) {
                            th = th;
                            cursorQuery = null;
                            sQLiteDatabaseK = null;
                        }
                        if (sQLiteDatabaseK == null) {
                            try {
                                k0VarY.f21697d = true;
                                if (sQLiteDatabaseK != null) {
                                    sQLiteDatabaseK.close();
                                }
                                i10 = i14;
                                i11 = i16;
                                arrayList = null;
                            } catch (SQLiteDatabaseLockedException unused2) {
                                i10 = i14;
                                i11 = i16;
                                cursorQuery = null;
                                SystemClock.sleep(i18);
                                i18 += 20;
                                if (cursorQuery != null) {
                                }
                                if (sQLiteDatabaseK != null) {
                                }
                                i17++;
                                i14 = i10;
                                i16 = i11;
                                i13 = 100;
                            } catch (SQLiteFullException e12) {
                                e = e12;
                                i10 = i14;
                                i11 = i16;
                                cursorQuery = null;
                                k0VarY.zzj().f21834f.b(e, "Error reading entries from local database");
                                k0VarY.f21697d = true;
                                if (cursorQuery != null) {
                                }
                                if (sQLiteDatabaseK != null) {
                                }
                                i17++;
                                i14 = i10;
                                i16 = i11;
                                i13 = 100;
                            } catch (SQLiteException e13) {
                                e = e13;
                                i10 = i14;
                                i11 = i16;
                                cursorQuery = null;
                                if (sQLiteDatabaseK != null) {
                                }
                                k0VarY.zzj().f21834f.b(e, "Error reading entries from local database");
                                k0VarY.f21697d = true;
                                if (cursorQuery != null) {
                                }
                                if (sQLiteDatabaseK != null) {
                                }
                                i17++;
                                i14 = i10;
                                i16 = i11;
                                i13 = 100;
                            } catch (Throwable th2) {
                                th = th2;
                                cursorQuery = null;
                                if (cursorQuery != null) {
                                }
                                if (sQLiteDatabaseK != null) {
                                }
                                throw th;
                            }
                        } else {
                            sQLiteDatabaseK.beginTransaction();
                            long jG = k0.G(sQLiteDatabaseK);
                            long j11 = -1;
                            if (jG != -1) {
                                String[] strArr2 = new String[1];
                                strArr2[i14] = String.valueOf(jG);
                                str = "rowid<?";
                                strArr = strArr2;
                            } else {
                                str = null;
                                strArr = null;
                            }
                            String[] strArr3 = new String[3];
                            strArr3[i14] = "rowid";
                            strArr3[1] = "type";
                            int i21 = 2;
                            strArr3[2] = "entry";
                            cursorQuery = sQLiteDatabaseK.query("messages", strArr3, str, strArr, null, null, "rowid asc", Integer.toString(i13));
                            while (cursorQuery.moveToNext()) {
                                try {
                                    try {
                                        try {
                                            try {
                                                j11 = cursorQuery.getLong(i14);
                                                i12 = cursorQuery.getInt(i20);
                                                blob = cursorQuery.getBlob(i21);
                                            } catch (SQLiteDatabaseLockedException unused3) {
                                                i11 = i16;
                                                i10 = i14;
                                            }
                                        } catch (SQLiteFullException e14) {
                                            e = e14;
                                            i11 = i16;
                                        } catch (SQLiteException e15) {
                                            e = e15;
                                            i11 = i16;
                                        }
                                    } catch (SQLiteDatabaseLockedException unused4) {
                                        i10 = i14;
                                        i11 = i16;
                                    } catch (SQLiteFullException e16) {
                                        e = e16;
                                        i10 = i14;
                                        i11 = i16;
                                    } catch (SQLiteException e17) {
                                        e = e17;
                                        i10 = i14;
                                        i11 = i16;
                                    }
                                    if (i12 == 0) {
                                        Parcel parcelObtain = Parcel.obtain();
                                        try {
                                            try {
                                                parcelObtain.unmarshall(blob, i14, blob.length);
                                                parcelObtain.setDataPosition(i14);
                                                y yVarCreateFromParcel = y.CREATOR.createFromParcel(parcelObtain);
                                                parcelObtain.recycle();
                                                if (yVarCreateFromParcel != null) {
                                                    arrayList.add(yVarCreateFromParcel);
                                                }
                                            } catch (SafeParcelReader$ParseException unused5) {
                                                k0VarY.zzj().f21834f.c("Failed to load event from local database");
                                                parcelObtain.recycle();
                                            }
                                        } catch (Throwable th3) {
                                            parcelObtain.recycle();
                                            throw th3;
                                        }
                                    } else {
                                        if (i12 == 1) {
                                            try {
                                                Parcel parcelObtain2 = Parcel.obtain();
                                                try {
                                                    try {
                                                        parcelObtain2.unmarshall(blob, 0, blob.length);
                                                        parcelObtain2.setDataPosition(0);
                                                        i4VarCreateFromParcel = i4.CREATOR.createFromParcel(parcelObtain2);
                                                        parcelObtain2.recycle();
                                                    } catch (SafeParcelReader$ParseException unused6) {
                                                        k0VarY.zzj().f21834f.c("Failed to load user property from local database");
                                                        parcelObtain2.recycle();
                                                        i4VarCreateFromParcel = null;
                                                    }
                                                    if (i4VarCreateFromParcel != null) {
                                                        arrayList.add(i4VarCreateFromParcel);
                                                    }
                                                } catch (Throwable th4) {
                                                    parcelObtain2.recycle();
                                                    throw th4;
                                                }
                                            } catch (SQLiteDatabaseLockedException unused7) {
                                                i11 = i16;
                                            }
                                        } else {
                                            i21 = 2;
                                            if (i12 == 2) {
                                                Parcel parcelObtain3 = Parcel.obtain();
                                                try {
                                                    i11 = i16;
                                                    try {
                                                        try {
                                                            parcelObtain3.unmarshall(blob, 0, blob.length);
                                                            parcelObtain3.setDataPosition(0);
                                                            eVarCreateFromParcel = e.CREATOR.createFromParcel(parcelObtain3);
                                                        } catch (SafeParcelReader$ParseException unused8) {
                                                            k0VarY.zzj().f21834f.c("Failed to load conditional user property from local database");
                                                            parcelObtain3.recycle();
                                                            eVarCreateFromParcel = null;
                                                        }
                                                    } catch (Throwable th5) {
                                                        th = th5;
                                                        parcelObtain3.recycle();
                                                        throw th;
                                                    }
                                                } catch (SafeParcelReader$ParseException unused9) {
                                                    i11 = i16;
                                                } catch (Throwable th6) {
                                                    th = th6;
                                                    i11 = i16;
                                                }
                                                try {
                                                    parcelObtain3.recycle();
                                                    if (eVarCreateFromParcel != null) {
                                                        arrayList.add(eVarCreateFromParcel);
                                                    }
                                                    i16 = i11;
                                                    i14 = 0;
                                                    i20 = 1;
                                                } catch (SQLiteDatabaseLockedException unused10) {
                                                } catch (SQLiteFullException e18) {
                                                    e = e18;
                                                    i10 = 0;
                                                    k0VarY.zzj().f21834f.b(e, "Error reading entries from local database");
                                                    k0VarY.f21697d = true;
                                                    if (cursorQuery != null) {
                                                    }
                                                    if (sQLiteDatabaseK != null) {
                                                    }
                                                    i17++;
                                                    i14 = i10;
                                                    i16 = i11;
                                                    i13 = 100;
                                                } catch (SQLiteException e19) {
                                                    e = e19;
                                                    i10 = 0;
                                                    if (sQLiteDatabaseK != null) {
                                                        sQLiteDatabaseK.endTransaction();
                                                    }
                                                    k0VarY.zzj().f21834f.b(e, "Error reading entries from local database");
                                                    k0VarY.f21697d = true;
                                                    if (cursorQuery != null) {
                                                    }
                                                    if (sQLiteDatabaseK != null) {
                                                    }
                                                    i17++;
                                                    i14 = i10;
                                                    i16 = i11;
                                                    i13 = 100;
                                                }
                                            } else {
                                                i11 = i16;
                                                if (i12 == 3) {
                                                    k0VarY.zzj().f21837i.c("Skipping app launch break");
                                                } else {
                                                    k0VarY.zzj().f21834f.c("Unknown record type in local database");
                                                }
                                                i16 = i11;
                                                i14 = 0;
                                                i20 = 1;
                                            }
                                        }
                                        i10 = 0;
                                        SystemClock.sleep(i18);
                                        i18 += 20;
                                        if (cursorQuery != null) {
                                            cursorQuery.close();
                                        }
                                        if (sQLiteDatabaseK != null) {
                                            sQLiteDatabaseK.close();
                                        }
                                    }
                                    i11 = i16;
                                    i21 = 2;
                                    i16 = i11;
                                    i14 = 0;
                                    i20 = 1;
                                } catch (Throwable th7) {
                                    th = th7;
                                    if (cursorQuery != null) {
                                        cursorQuery.close();
                                    }
                                    if (sQLiteDatabaseK != null) {
                                        sQLiteDatabaseK.close();
                                    }
                                    throw th;
                                }
                            }
                            i11 = i16;
                            String[] strArr4 = new String[1];
                            i10 = 0;
                            try {
                                strArr4[0] = Long.toString(j11);
                                if (sQLiteDatabaseK.delete("messages", "rowid <= ?", strArr4) < arrayList.size()) {
                                    k0VarY.zzj().f21834f.c("Fewer entries removed from local database than expected");
                                }
                                sQLiteDatabaseK.setTransactionSuccessful();
                                sQLiteDatabaseK.endTransaction();
                                cursorQuery.close();
                                sQLiteDatabaseK.close();
                            } catch (SQLiteDatabaseLockedException unused11) {
                                SystemClock.sleep(i18);
                                i18 += 20;
                                if (cursorQuery != null) {
                                }
                                if (sQLiteDatabaseK != null) {
                                }
                                i17++;
                                i14 = i10;
                                i16 = i11;
                                i13 = 100;
                            } catch (SQLiteFullException e20) {
                                e = e20;
                                k0VarY.zzj().f21834f.b(e, "Error reading entries from local database");
                                k0VarY.f21697d = true;
                                if (cursorQuery != null) {
                                    cursorQuery.close();
                                }
                                if (sQLiteDatabaseK != null) {
                                    sQLiteDatabaseK.close();
                                }
                                i17++;
                                i14 = i10;
                                i16 = i11;
                                i13 = 100;
                            } catch (SQLiteException e21) {
                                e = e21;
                                if (sQLiteDatabaseK != null && sQLiteDatabaseK.inTransaction()) {
                                    sQLiteDatabaseK.endTransaction();
                                }
                                k0VarY.zzj().f21834f.b(e, "Error reading entries from local database");
                                k0VarY.f21697d = true;
                                if (cursorQuery != null) {
                                    cursorQuery.close();
                                }
                                if (sQLiteDatabaseK != null) {
                                    sQLiteDatabaseK.close();
                                }
                                i17++;
                                i14 = i10;
                                i16 = i11;
                                i13 = 100;
                            }
                        }
                        i17++;
                        i14 = i10;
                        i16 = i11;
                        i13 = 100;
                    }
                    i10 = i14;
                    i11 = i16;
                    k0VarY.zzj().f21837i.c("Failed to read events from database in reasonable time");
                    arrayList = null;
                } else {
                    i10 = i14;
                    i11 = i16;
                }
            }
            if (arrayList != null) {
                arrayList2.addAll(arrayList);
                size = arrayList.size();
            } else {
                size = i10;
            }
            if (aVar != null && size < 100) {
                arrayList2.add(aVar);
            }
            boolean zJ = s().J(null, z.D0);
            int size2 = arrayList2.size();
            int i22 = i10;
            while (i22 < size2) {
                int i23 = i22 + 1;
                f8.a aVar2 = (f8.a) arrayList2.get(i22);
                if (aVar2 instanceof y) {
                    Object obj = this.f31277a;
                    if (zJ) {
                        try {
                            ((m1) obj).f21762n.getClass();
                            jCurrentTimeMillis = System.currentTimeMillis();
                        } catch (RemoteException e22) {
                            e = e22;
                            j10 = 0;
                        }
                        try {
                            ((m1) obj).f21762n.getClass();
                            jElapsedRealtime = SystemClock.elapsedRealtime();
                        } catch (RemoteException e23) {
                            e = e23;
                            j10 = jCurrentTimeMillis;
                            jElapsedRealtime = 0;
                            zzj().f21834f.b(e, "Failed to send event to the service");
                            if (!zJ && j10 != 0) {
                                m1 m1Var = (m1) obj;
                                o0 o0VarA = o0.a(m1Var);
                                m1Var.f21762n.getClass();
                                long jCurrentTimeMillis2 = System.currentTimeMillis();
                                m1Var.f21762n.getClass();
                                o0VarA.b(13, (int) (SystemClock.elapsedRealtime() - jElapsedRealtime), j10, jCurrentTimeMillis2);
                            }
                            i22 = i23;
                        }
                    } else {
                        jCurrentTimeMillis = 0;
                        jElapsedRealtime = 0;
                    }
                    try {
                        h0Var.K2((y) aVar2, d4Var);
                        if (zJ) {
                            zzj().f21842n.c("Logging telemetry for logEvent from database");
                            o0 o0VarA2 = o0.a((m1) obj);
                            ((m1) obj).f21762n.getClass();
                            long jCurrentTimeMillis3 = System.currentTimeMillis();
                            ((m1) obj).f21762n.getClass();
                            o0VarA2.b(0, (int) (SystemClock.elapsedRealtime() - jElapsedRealtime), jCurrentTimeMillis, jCurrentTimeMillis3);
                        }
                    } catch (RemoteException e24) {
                        e = e24;
                        j10 = jCurrentTimeMillis;
                        zzj().f21834f.b(e, "Failed to send event to the service");
                        if (!zJ) {
                        }
                    }
                } else if (aVar2 instanceof i4) {
                    try {
                        h0Var.n0((i4) aVar2, d4Var);
                    } catch (RemoteException e25) {
                        zzj().f21834f.b(e25, "Failed to send user property to the service");
                    }
                } else if (aVar2 instanceof e) {
                    try {
                        h0Var.S0((e) aVar2, d4Var);
                    } catch (RemoteException e26) {
                        zzj().f21834f.b(e26, "Failed to send conditional user property to the service");
                    }
                } else {
                    zzj().f21834f.c("Discarding data. Unrecognized parcel type.");
                }
                i22 = i23;
            }
            i16 = i11 + 1;
            i15 = size;
            i13 = 100;
            i14 = i10;
        }
    }

    public final void I(Runnable runnable) {
        w();
        if (N()) {
            runnable.run();
            return;
        }
        ArrayList arrayList = this.f21476h;
        if (arrayList.size() >= 1000) {
            zzj().f21834f.c("Discarding data. Max runnable queue size reached");
            return;
        }
        arrayList.add(runnable);
        this.f21477i.b(60000L);
        L();
    }

    public final void J(AtomicReference atomicReference) {
        w();
        D();
        I(new n0.a(this, atomicReference, S(false), 16));
    }

    public final void K(boolean z10) {
        w();
        D();
        y7.a();
        if (!s().J(null, z.W0) && z10) {
            y().I();
        }
        if (O()) {
            I(new d3(this, S(false), 4));
        }
    }

    public final void L() {
        w();
        D();
        if (N()) {
            return;
        }
        if (P()) {
            h3 h3Var = this.f21471c;
            h3Var.f21655c.w();
            Context contextZza = h3Var.f21655c.zza();
            synchronized (h3Var) {
                try {
                    if (h3Var.f21653a) {
                        h3Var.f21655c.zzj().f21842n.c("Connection attempt already in progress");
                        return;
                    }
                    if (h3Var.f21654b != null && (h3Var.f21654b.isConnecting() || h3Var.f21654b.isConnected())) {
                        h3Var.f21655c.zzj().f21842n.c("Already awaiting connection attempt");
                        return;
                    }
                    h3Var.f21654b = new n0(contextZza, Looper.getMainLooper(), 93, h3Var, h3Var, null);
                    h3Var.f21655c.zzj().f21842n.c("Connecting to remote service");
                    h3Var.f21653a = true;
                    com.google.android.gms.common.internal.w.checkNotNull(h3Var.f21654b);
                    h3Var.f21654b.checkAvailabilityAndConnect();
                    return;
                } finally {
                }
            }
        }
        if (s().M()) {
            return;
        }
        List<ResolveInfo> listQueryIntentServices = zza().getPackageManager().queryIntentServices(new Intent().setClassName(zza(), "com.google.android.gms.measurement.AppMeasurementService"), C.DEFAULT_BUFFER_SEGMENT_SIZE);
        if (listQueryIntentServices == null || listQueryIntentServices.isEmpty()) {
            zzj().f21834f.c("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(zza(), "com.google.android.gms.measurement.AppMeasurementService"));
        h3 h3Var2 = this.f21471c;
        h3Var2.f21655c.w();
        Context contextZza2 = h3Var2.f21655c.zza();
        h8.a aVarB = h8.a.b();
        synchronized (h3Var2) {
            try {
                if (h3Var2.f21653a) {
                    h3Var2.f21655c.zzj().f21842n.c("Connection attempt already in progress");
                    return;
                }
                h3Var2.f21655c.zzj().f21842n.c("Using local app measurement service");
                h3Var2.f21653a = true;
                aVarB.a(contextZza2, intent, h3Var2.f21655c.f21471c, 129);
            } finally {
            }
        }
    }

    public final void M() {
        w();
        D();
        h3 h3Var = this.f21471c;
        if (h3Var.f21654b != null && (h3Var.f21654b.isConnected() || h3Var.f21654b.isConnecting())) {
            h3Var.f21654b.disconnect();
        }
        h3Var.f21654b = null;
        try {
            h8.a.b().c(zza(), this.f21471c);
        } catch (IllegalArgumentException | IllegalStateException unused) {
        }
        this.f21472d = null;
    }

    public final boolean N() {
        w();
        D();
        return this.f21472d != null;
    }

    public final boolean O() {
        w();
        D();
        return !P() || v().z0() >= ((Integer) z.f22063s0.a(null)).intValue();
    }

    /* JADX WARN: Removed duplicated region for block: B:42:0x00e9  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00ff  */
    /* JADX WARN: Removed duplicated region for block: B:46:0x0101  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean P() {
        w();
        D();
        if (this.f21473e == null) {
            w();
            D();
            y0 y0VarU = u();
            y0VarU.w();
            boolean z10 = false;
            Boolean boolValueOf = !y0VarU.F().contains("use_service") ? null : Boolean.valueOf(y0VarU.F().getBoolean("use_service", false));
            if (boolValueOf == null || !boolValueOf.booleanValue()) {
                l0 l0VarX = x();
                l0VarX.D();
                if (l0VarX.f21727k == 1) {
                    z10 = true;
                    if (!z10 && s().M()) {
                        zzj().f21834f.c("No way to upload. Consider using the full version of Analytics");
                    } else if (z) {
                        y0 y0VarU2 = u();
                        y0VarU2.w();
                        SharedPreferences.Editor editorEdit = y0VarU2.F().edit();
                        editorEdit.putBoolean("use_service", z10);
                        editorEdit.apply();
                    }
                    z = z10;
                } else {
                    zzj().f21842n.c("Checking service availability");
                    int iB = e8.e.f25522b.b(v().zza(), 12451000);
                    if (iB != 0) {
                        if (iB == 1) {
                            zzj().f21842n.c("Service missing");
                        } else if (iB != 2) {
                            if (iB == 3) {
                                zzj().f21837i.c("Service disabled");
                            } else if (iB == 9) {
                                zzj().f21837i.c("Service invalid");
                            } else if (iB != 18) {
                                zzj().f21837i.b(Integer.valueOf(iB), "Unexpected service status");
                            } else {
                                zzj().f21837i.c("Service updating");
                            }
                            z = false;
                        } else {
                            zzj().f21841m.c("Service container out of date");
                            if (v().z0() >= 17443) {
                                z10 = boolValueOf == null;
                                z = false;
                            }
                        }
                        if (!z10) {
                            if (z) {
                            }
                            z = z10;
                        }
                    } else {
                        zzj().f21842n.c("Service available");
                    }
                    z10 = true;
                    if (!z10) {
                    }
                }
            }
            this.f21473e = Boolean.valueOf(z);
        }
        return this.f21473e.booleanValue();
    }

    public final void Q() {
        w();
        p0 p0VarZzj = zzj();
        ArrayList arrayList = this.f21476h;
        p0VarZzj.f21842n.b(Integer.valueOf(arrayList.size()), "Processing queued up service tasks");
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            try {
                ((Runnable) it.next()).run();
            } catch (RuntimeException e10) {
                zzj().f21834f.b(e10, "Task exception while flushing queue");
            }
        }
        arrayList.clear();
        this.f21477i.a();
    }

    public final void R() {
        w();
        androidx.recyclerview.widget.d dVar = this.f21475g;
        ((i8.d) ((i8.c) dVar.f3689c)).getClass();
        dVar.f3688b = SystemClock.elapsedRealtime();
        this.f21474f.b(((Long) z.L.a(null)).longValue());
    }

    public final d4 S(boolean z10) {
        long j10;
        Class<?> clsLoadClass;
        Object objInvoke;
        Boolean boolValueOf;
        String str;
        long jE0;
        String str2;
        String str3;
        String str4;
        int i10;
        long j11;
        ApplicationInfo applicationInfoA;
        int extensionVersion;
        long jE;
        l0 l0VarX = x();
        String str5 = null;
        String strL = z10 ? zzj().L() : null;
        l0VarX.w();
        String strG = l0VarX.G();
        String strH = l0VarX.H();
        l0VarX.D();
        String str6 = l0VarX.f21720d;
        l0VarX.D();
        long j12 = l0VarX.f21721e;
        l0VarX.D();
        com.google.android.gms.common.internal.w.checkNotNull(l0VarX.f21722f);
        String str7 = l0VarX.f21722f;
        l0VarX.D();
        l0VarX.w();
        long j13 = l0VarX.f21723g;
        Object obj = l0VarX.f31277a;
        if (j13 == 0) {
            n4 n4Var = ((m1) obj).f21760l;
            m1.c(n4Var);
            Context contextZza = l0VarX.zza();
            String packageName = l0VarX.zza().getPackageName();
            n4Var.w();
            com.google.android.gms.common.internal.w.checkNotNull(contextZza);
            com.google.android.gms.common.internal.w.checkNotEmpty(packageName);
            PackageManager packageManager = contextZza.getPackageManager();
            MessageDigest messageDigestH0 = n4.H0();
            long j14 = -1;
            if (messageDigestH0 == null) {
                n4Var.zzj().f21834f.c("Could not get MD5 instance");
            } else if (packageManager != null) {
                try {
                } catch (PackageManager.NameNotFoundException e10) {
                    n4Var.zzj().f21834f.b(e10, "Package name not found");
                    jE = 0;
                }
                if (n4Var.s0(contextZza, packageName)) {
                    j14 = 0;
                } else {
                    Signature[] signatureArr = j8.e.a(contextZza).b(64, n4Var.zza().getPackageName()).signatures;
                    if (signatureArr == null || signatureArr.length <= 0) {
                        n4Var.zzj().f21837i.c("Could not get signatures");
                    } else {
                        jE = n4.E(messageDigestH0.digest(signatureArr[0].toByteArray()));
                        l0VarX.f21723g = jE;
                    }
                }
            } else {
                jE = 0;
                l0VarX.f21723g = jE;
            }
            jE = j14;
            l0VarX.f21723g = jE;
        }
        long j15 = l0VarX.f21723g;
        m1 m1Var = (m1) obj;
        boolean zE = m1Var.e();
        boolean z11 = !l0VarX.u().f22001s;
        l0VarX.w();
        if (m1Var.e()) {
            ((ka) la.f20300b.get()).getClass();
            if (l0VarX.s().J(null, z.f22059q0)) {
                l0VarX.zzj().f21842n.c("Disabled IID for tests.");
            } else {
                try {
                    clsLoadClass = l0VarX.zza().getClassLoader().loadClass("com.google.firebase.analytics.FirebaseAnalytics");
                } catch (ClassNotFoundException unused) {
                    j10 = j15;
                }
                if (clsLoadClass != null) {
                    try {
                        Method declaredMethod = clsLoadClass.getDeclaredMethod("getInstance", Context.class);
                        Object[] objArr = new Object[1];
                        j10 = j15;
                        try {
                            objArr[0] = l0VarX.zza();
                            objInvoke = declaredMethod.invoke(null, objArr);
                        } catch (Exception unused2) {
                            l0VarX.zzj().f21838j.c("Failed to obtain Firebase Analytics instance");
                        }
                    } catch (Exception unused3) {
                        j10 = j15;
                    }
                    if (objInvoke == null) {
                        str5 = null;
                    } else {
                        try {
                            str5 = (String) clsLoadClass.getDeclaredMethod("getFirebaseInstanceId", new Class[0]).invoke(objInvoke, new Object[0]);
                        } catch (Exception unused4) {
                            l0VarX.zzj().f21839k.c("Failed to retrieve Firebase Instance Id");
                            str5 = null;
                        }
                    }
                }
            }
            j10 = j15;
        } else {
            j10 = j15;
        }
        y0 y0Var = m1Var.f21756h;
        m1.c(y0Var);
        long jA = y0Var.f21989g.a();
        long j16 = m1Var.H;
        long jMin = jA == 0 ? j16 : Math.min(j16, jA);
        l0VarX.D();
        int i11 = l0VarX.f21727k;
        Boolean boolH = l0VarX.s().H("google_analytics_adid_collection_enabled");
        boolean z12 = boolH == null || boolH.booleanValue();
        y0 y0VarU = l0VarX.u();
        y0VarU.w();
        boolean z13 = y0VarU.F().getBoolean("deferred_analytics_collection", false);
        l0VarX.D();
        String str8 = l0VarX.f21729m;
        if (l0VarX.s().H("google_analytics_default_allow_ad_personalization_signals") == null) {
            str = str8;
            boolValueOf = null;
        } else {
            boolValueOf = Boolean.valueOf(!r3.booleanValue());
            str = str8;
        }
        long j17 = l0VarX.f21724h;
        List list = l0VarX.f21725i;
        String strN = l0VarX.u().H().n();
        if (l0VarX.f21726j == null) {
            l0VarX.f21726j = l0VarX.v().G0();
        }
        String str9 = l0VarX.f21726j;
        y7.a();
        if (!l0VarX.s().J(null, z.W0) || l0VarX.u().H().i(zzje$zza.ANALYTICS_STORAGE)) {
            l0VarX.w();
            jE0 = 0;
            if (l0VarX.f21731o != 0) {
                ((i8.d) l0VarX.zzb()).getClass();
                str2 = str5;
                long jCurrentTimeMillis = System.currentTimeMillis() - l0VarX.f21731o;
                if (l0VarX.f21730n != null && jCurrentTimeMillis > 86400000 && l0VarX.f21732p == null) {
                    l0VarX.I();
                }
            } else {
                str2 = str5;
            }
            if (l0VarX.f21730n == null) {
                l0VarX.I();
            }
            str3 = l0VarX.f21730n;
        } else {
            str2 = str5;
            str3 = null;
            jE0 = 0;
        }
        Boolean boolH2 = l0VarX.s().H("google_analytics_sgtm_upload_enabled");
        boolean zBooleanValue = boolH2 == null ? false : boolH2.booleanValue();
        n4 n4VarV = l0VarX.v();
        String strG2 = l0VarX.G();
        if (n4VarV.zza().getPackageManager() == null) {
            str4 = str;
            j11 = jE0;
        } else {
            try {
                str4 = str;
                i10 = 0;
            } catch (PackageManager.NameNotFoundException unused5) {
                str4 = str;
                i10 = 0;
            }
            try {
                applicationInfoA = j8.e.a(n4VarV.zza()).a(0, strG2);
            } catch (PackageManager.NameNotFoundException unused6) {
                n4VarV.zzj().f21840l.b(strG2, "PackageManager failed to find running app: app_id");
            }
            int i12 = applicationInfoA != null ? applicationInfoA.targetSdkVersion : i10;
            j11 = i12;
        }
        int i13 = l0VarX.u().H().f21487b;
        y0 y0VarU2 = l0VarX.u();
        y0VarU2.w();
        String str10 = q.b(y0VarU2.F().getString("dma_consent_settings", null)).f21863b;
        z9.a();
        g gVarS = l0VarX.s();
        f0 f0Var = z.H0;
        if (gVarS.J(null, f0Var)) {
            l0VarX.v();
            extensionVersion = (Build.VERSION.SDK_INT < 30 || SdkExtensions.getExtensionVersion(30) <= 3) ? 0 : SdkExtensions.getExtensionVersion(PlaybackException.CUSTOM_ERROR_CODE_BASE);
        } else {
            extensionVersion = 0;
        }
        z9.a();
        if (l0VarX.s().J(null, f0Var)) {
            jE0 = l0VarX.v().E0();
        }
        return new d4(strG, strH, str6, j12, str7, 106000L, j10, strL, zE, z11, str2, 0L, jMin, i11, z12, z13, str4, boolValueOf, j17, (List<String>) list, (String) null, strN, str9, str3, zBooleanValue, j11, i13, str10, extensionVersion, jE0, l0VarX.s().f21588c, String.valueOf(b2.a(l0VarX.s().F("google_analytics_default_allow_ad_personalization_signals", true))));
    }
}
