package W2;

import P2.C0253j;
import P2.w;
import android.content.ContentProviderClient;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.Build;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;
import com.google.android.gms.dynamite.DynamiteModule$DynamiteLoaderClassLoader;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

/* JADX INFO: loaded from: classes.dex */
public final class e {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static Boolean f7078d = null;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static String f7079e = null;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static boolean f7080f = false;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static int f7081g = -1;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static Boolean f7082h;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public static k f7085l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public static l f7086m;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f7087a;
    public static final ThreadLocal i = new ThreadLocal();

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final J3.b f7083j = new J3.b(7);

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final x3.e f7084k = new x3.e(17);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final C4.f f7076b = new C4.f(18);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final C0253j f7077c = new C0253j(18);

    public e(Context context) {
        this.f7087a = context;
    }

    public static int a(Context context, String str) {
        try {
            Class<?> clsLoadClass = context.getApplicationContext().getClassLoader().loadClass("com.google.android.gms.dynamite.descriptors." + str + ".ModuleDescriptor");
            Field declaredField = clsLoadClass.getDeclaredField("MODULE_ID");
            Field declaredField2 = clsLoadClass.getDeclaredField("MODULE_VERSION");
            if (w.i(declaredField.get(null), str)) {
                return declaredField2.getInt(null);
            }
            Log.e("DynamiteModule", "Module descriptor id '" + String.valueOf(declaredField.get(null)) + "' didn't match expected id '" + str + "'");
            return 0;
        } catch (ClassNotFoundException unused) {
            Log.w("DynamiteModule", "Local module descriptor class for " + str + " not found.");
            return 0;
        } catch (Exception e8) {
            Log.e("DynamiteModule", "Failed to load module descriptor class: ".concat(String.valueOf(e8.getMessage())));
            return 0;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:116:0x025f  */
    /* JADX WARN: Removed duplicated region for block: B:117:0x0265  */
    /* JADX WARN: Removed duplicated region for block: B:120:0x026e  */
    /* JADX WARN: Removed duplicated region for block: B:21:0x0091 A[Catch: all -> 0x0085, TRY_LEAVE, TryCatch #2 {all -> 0x0085, blocks: (B:7:0x004b, B:11:0x007f, B:18:0x008b, B:21:0x0091, B:24:0x00a5, B:102:0x020d, B:103:0x0214, B:106:0x0217, B:107:0x0218, B:108:0x021f, B:125:0x027f, B:126:0x0290, B:109:0x0220, B:111:0x023e, B:113:0x024b, B:123:0x0277, B:124:0x027e, B:127:0x0291, B:128:0x02bd), top: B:145:0x004b, inners: #5 }] */
    /* JADX WARN: Removed duplicated region for block: B:23:0x00a3  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static e c(Context context, d dVar, String str) throws Throwable {
        long j8;
        e eVar;
        Boolean bool;
        V2.a aVarM;
        e eVar2;
        l lVar;
        boolean z8;
        V2.a aVarM2;
        Cursor cursor;
        Context applicationContext = context.getApplicationContext();
        if (applicationContext == null) {
            throw new b("null application Context");
        }
        ThreadLocal threadLocal = i;
        i iVar = (i) threadLocal.get();
        i iVar2 = new i();
        threadLocal.set(iVar2);
        J3.b bVar = f7083j;
        Long l8 = (Long) bVar.get();
        long jLongValue = l8.longValue();
        try {
            bVar.set(Long.valueOf(SystemClock.uptimeMillis()));
            R0.h hVarK = dVar.k(context, str, f7084k);
            j8 = jLongValue;
            try {
                Log.i("DynamiteModule", "Considering local module " + str + ":" + hVarK.f5896a + " and remote module " + str + ":" + hVarK.f5897b);
                int i5 = hVarK.f5898c;
                if (i5 != 0) {
                    if (i5 != -1) {
                        if (i5 == 1 || hVarK.f5897b != 0) {
                            if (i5 != -1) {
                                Log.i("DynamiteModule", "Selected local version of ".concat(str));
                                eVar = new e(applicationContext);
                            } else {
                                if (i5 != 1) {
                                    throw new b("VersionPolicy returned invalid code:" + i5);
                                }
                                try {
                                    int i8 = hVarK.f5897b;
                                    try {
                                        synchronized (e.class) {
                                            if (!g(context)) {
                                                throw new b("Remote loading disabled");
                                            }
                                            bool = f7078d;
                                        }
                                        if (bool == null) {
                                            throw new b("Failed to determine which loading route to use.");
                                        }
                                        if (bool.booleanValue()) {
                                            Log.i("DynamiteModule", "Selected remote version of " + str + ", version >= " + i8);
                                            synchronized (e.class) {
                                                lVar = f7086m;
                                            }
                                            if (lVar == null) {
                                                throw new b("DynamiteLoaderV2 was not cached.");
                                            }
                                            i iVar3 = (i) threadLocal.get();
                                            if (iVar3 == null || iVar3.f7096a == null) {
                                                throw new b("No result cursor");
                                            }
                                            Context applicationContext2 = context.getApplicationContext();
                                            Cursor cursor2 = iVar3.f7096a;
                                            new V2.b(null);
                                            synchronized (e.class) {
                                                z8 = f7081g >= 2;
                                            }
                                            if (z8) {
                                                Log.v("DynamiteModule", "Dynamite loader version >= 2, using loadModule2NoCrashUtils");
                                                aVarM2 = lVar.N(new V2.b(applicationContext2), str, i8, new V2.b(cursor2));
                                            } else {
                                                Log.w("DynamiteModule", "Dynamite loader version < 2, falling back to loadModule2");
                                                aVarM2 = lVar.M(new V2.b(applicationContext2), str, i8, new V2.b(cursor2));
                                            }
                                            Context context2 = (Context) V2.b.M(aVarM2);
                                            if (context2 == null) {
                                                throw new b("Failed to get module context");
                                            }
                                            eVar2 = new e(context2);
                                        } else {
                                            Log.i("DynamiteModule", "Selected remote version of " + str + ", version >= " + i8);
                                            k kVarH = h(context);
                                            if (kVarH == null) {
                                                throw new b("Failed to create IDynamiteLoader.");
                                            }
                                            Parcel parcelC = kVarH.c(kVarH.d(), 6);
                                            int i9 = parcelC.readInt();
                                            parcelC.recycle();
                                            if (i9 >= 3) {
                                                i iVar4 = (i) threadLocal.get();
                                                if (iVar4 == null) {
                                                    throw new b("No cached result cursor holder");
                                                }
                                                aVarM = kVarH.N(new V2.b(context), str, i8, new V2.b(iVar4.f7096a));
                                            } else if (i9 == 2) {
                                                Log.w("DynamiteModule", "IDynamite loader version = 2");
                                                aVarM = kVarH.O(new V2.b(context), str, i8);
                                            } else {
                                                Log.w("DynamiteModule", "Dynamite loader version < 2, falling back to createModuleContext");
                                                aVarM = kVarH.M(new V2.b(context), str, i8);
                                            }
                                            Object objM = V2.b.M(aVarM);
                                            if (objM == null) {
                                                throw new b("Failed to load remote module.");
                                            }
                                            eVar2 = new e((Context) objM);
                                        }
                                        eVar = eVar2;
                                    } catch (b e8) {
                                        throw e8;
                                    } catch (RemoteException e9) {
                                        throw new b("Failed to load remote module.", e9);
                                    } catch (Throwable th) {
                                        throw new b("Failed to load remote module.", th);
                                    }
                                } catch (b e10) {
                                    Log.w("DynamiteModule", "Failed to load remote module: " + e10.getMessage());
                                    int i10 = hVarK.f5896a;
                                    if (i10 == 0 || dVar.k(context, str, new j(i10)).f5898c != -1) {
                                        throw new b("Remote load failed. No local fallback found.", e10);
                                    }
                                    Log.i("DynamiteModule", "Selected local version of ".concat(str));
                                    eVar = new e(applicationContext);
                                }
                            }
                            if (j8 != 0) {
                                f7083j.remove();
                            } else {
                                f7083j.set(l8);
                            }
                            cursor = iVar2.f7096a;
                            if (cursor != null) {
                                cursor.close();
                            }
                            i.set(iVar);
                            return eVar;
                        }
                    } else if (hVarK.f5896a != 0) {
                        i5 = -1;
                        if (i5 == 1) {
                        }
                        if (i5 != -1) {
                        }
                        if (j8 != 0) {
                        }
                        cursor = iVar2.f7096a;
                        if (cursor != null) {
                        }
                        i.set(iVar);
                        return eVar;
                    }
                }
                throw new b("No acceptable module " + str + " found. Local version is " + hVarK.f5896a + " and remote version is " + hVarK.f5897b + ".");
            } catch (Throwable th2) {
                th = th2;
                if (j8 == 0) {
                    f7083j.remove();
                } else {
                    f7083j.set(l8);
                }
                Cursor cursor3 = iVar2.f7096a;
                if (cursor3 != null) {
                    cursor3.close();
                }
                i.set(iVar);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            j8 = jLongValue;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:101:0x017f  */
    /* JADX WARN: Removed duplicated region for block: B:103:0x0182 A[Catch: all -> 0x00ec, TRY_ENTER, TRY_LEAVE, TryCatch #7 {all -> 0x00ec, blocks: (B:3:0x0002, B:63:0x00e1, B:65:0x00e7, B:73:0x010d, B:103:0x0182, B:111:0x0197, B:129:0x0219, B:130:0x021c, B:124:0x0210, B:71:0x00f2, B:132:0x021e, B:4:0x0003, B:7:0x000a, B:8:0x0026, B:61:0x00de, B:21:0x004a, B:44:0x00a1, B:47:0x00a4, B:54:0x00bc, B:62:0x00e0, B:60:0x00c2), top: B:143:0x0002, inners: #0, #6 }] */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00b0 A[Catch: all -> 0x0037, TryCatch #11 {, blocks: (B:9:0x0027, B:11:0x0033, B:51:0x00b9, B:16:0x003c, B:18:0x0043, B:20:0x0049, B:25:0x0050, B:27:0x0054, B:30:0x005d, B:32:0x0065, B:35:0x006c, B:42:0x0098, B:43:0x00a0, B:38:0x0073, B:40:0x0079, B:41:0x008a, B:46:0x00a3, B:49:0x00a6, B:50:0x00b0, B:17:0x003f), top: B:147:0x0027, inners: #12 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static int d(Context context, String str, boolean z8) {
        Field declaredField;
        Throwable th;
        RemoteException remoteException;
        int i5;
        Cursor cursor;
        try {
            synchronized (e.class) {
                Boolean bool = f7078d;
                boolean z9 = true;
                Cursor cursor2 = null;
                if (bool == null) {
                    try {
                        declaredField = context.getApplicationContext().getClassLoader().loadClass(DynamiteModule$DynamiteLoaderClassLoader.class.getName()).getDeclaredField("sClassLoader");
                    } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e8) {
                        Log.w("DynamiteModule", "Failed to load module via V2: " + e8.toString());
                        bool = Boolean.FALSE;
                    }
                    synchronized (declaredField.getDeclaringClass()) {
                        ClassLoader classLoader = (ClassLoader) declaredField.get(null);
                        if (classLoader == ClassLoader.getSystemClassLoader()) {
                            bool = Boolean.FALSE;
                        } else if (classLoader != null) {
                            try {
                                f(classLoader);
                            } catch (b unused) {
                            }
                            bool = Boolean.TRUE;
                        } else {
                            if (!g(context)) {
                                return 0;
                            }
                            if (!f7080f) {
                                Boolean bool2 = Boolean.TRUE;
                                if (bool2.equals(null)) {
                                    declaredField.set(null, ClassLoader.getSystemClassLoader());
                                    bool = Boolean.FALSE;
                                } else {
                                    try {
                                        int iE = e(context, str, z8, true);
                                        String str2 = f7079e;
                                        if (str2 != null && !str2.isEmpty()) {
                                            ClassLoader classLoaderM = g.M();
                                            if (classLoaderM == null) {
                                                if (Build.VERSION.SDK_INT >= 29) {
                                                    a.b();
                                                    String str3 = f7079e;
                                                    w.f(str3);
                                                    classLoaderM = a.a(ClassLoader.getSystemClassLoader(), str3);
                                                } else {
                                                    String str4 = f7079e;
                                                    w.f(str4);
                                                    classLoaderM = new h(str4, ClassLoader.getSystemClassLoader());
                                                }
                                            }
                                            f(classLoaderM);
                                            declaredField.set(null, classLoaderM);
                                            f7078d = bool2;
                                            return iE;
                                        }
                                        return iE;
                                    } catch (b unused2) {
                                        declaredField.set(null, ClassLoader.getSystemClassLoader());
                                        bool = Boolean.FALSE;
                                    }
                                }
                            }
                            Log.w("DynamiteModule", "Failed to load module via V2: " + e8.toString());
                            bool = Boolean.FALSE;
                            f7078d = bool;
                        }
                        f7078d = bool;
                    }
                }
                if (bool.booleanValue()) {
                    try {
                        return e(context, str, z8, false);
                    } catch (b e9) {
                        Log.w("DynamiteModule", "Failed to retrieve remote module version: " + e9.getMessage());
                        return 0;
                    }
                }
                k kVarH = h(context);
                try {
                    if (kVarH == null) {
                        return 0;
                    }
                    try {
                        Parcel parcelC = kVarH.c(kVarH.d(), 6);
                        int i8 = parcelC.readInt();
                        parcelC.recycle();
                        if (i8 >= 3) {
                            ThreadLocal threadLocal = i;
                            i iVar = (i) threadLocal.get();
                            if (iVar != null && (cursor = iVar.f7096a) != null) {
                                return cursor.getInt(0);
                            }
                            Cursor cursor3 = (Cursor) V2.b.M(kVarH.P(new V2.b(context), str, z8, ((Long) f7083j.get()).longValue()));
                            if (cursor3 != null) {
                                try {
                                    if (cursor3.moveToFirst()) {
                                        i5 = cursor3.getInt(0);
                                        if (i5 <= 0) {
                                            cursor2 = cursor3;
                                            if (cursor2 != null) {
                                                cursor2.close();
                                            }
                                        } else {
                                            i iVar2 = (i) threadLocal.get();
                                            if (iVar2 == null || iVar2.f7096a != null) {
                                                z9 = false;
                                            } else {
                                                iVar2.f7096a = cursor3;
                                            }
                                            if (!z9) {
                                            }
                                            if (cursor2 != null) {
                                            }
                                        }
                                    }
                                } catch (RemoteException e10) {
                                    remoteException = e10;
                                    cursor2 = cursor3;
                                    Log.w("DynamiteModule", "Failed to retrieve remote module version: " + remoteException.getMessage());
                                    if (cursor2 == null) {
                                        return 0;
                                    }
                                    cursor2.close();
                                    return 0;
                                } catch (Throwable th2) {
                                    th = th2;
                                    cursor2 = cursor3;
                                    if (cursor2 == null) {
                                        throw th;
                                    }
                                    cursor2.close();
                                    throw th;
                                }
                            }
                            Log.w("DynamiteModule", "Failed to retrieve remote module version.");
                            if (cursor3 == null) {
                                return 0;
                            }
                            cursor3.close();
                            return 0;
                        }
                        if (i8 == 2) {
                            Log.w("DynamiteModule", "IDynamite loader version = 2, no high precision latency measurement.");
                            V2.b bVar = new V2.b(context);
                            Parcel parcelD = kVarH.d();
                            Z2.b.c(parcelD, bVar);
                            parcelD.writeString(str);
                            parcelD.writeInt(z8 ? 1 : 0);
                            Parcel parcelC2 = kVarH.c(parcelD, 5);
                            i5 = parcelC2.readInt();
                            parcelC2.recycle();
                        } else {
                            Log.w("DynamiteModule", "IDynamite loader version < 2, falling back to getModuleVersion2");
                            V2.b bVar2 = new V2.b(context);
                            Parcel parcelD2 = kVarH.d();
                            Z2.b.c(parcelD2, bVar2);
                            parcelD2.writeString(str);
                            parcelD2.writeInt(z8 ? 1 : 0);
                            Parcel parcelC3 = kVarH.c(parcelD2, 3);
                            i5 = parcelC3.readInt();
                            parcelC3.recycle();
                        }
                        return i5;
                    } catch (RemoteException e11) {
                        remoteException = e11;
                    }
                } catch (Throwable th3) {
                    th = th3;
                }
            }
        } finally {
        }
    }

    /* JADX WARN: Finally extract failed */
    /* JADX WARN: Removed duplicated region for block: B:125:0x00e4 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:86:0x0137 A[PHI: r12
      0x0137: PHI (r12v10 boolean) = (r12v6 boolean), (r12v14 boolean) binds: [B:59:0x00ee, B:84:0x0134] A[DONT_GENERATE, DONT_INLINE]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static int e(Context context, String str, boolean z8, boolean z9) throws Throwable {
        Exception exc;
        Throwable th;
        Cursor cursorQuery;
        MatrixCursor matrixCursor;
        boolean z10;
        try {
            try {
                boolean z11 = true;
                Uri uriBuild = new Uri.Builder().scheme("content").authority("com.google.android.gms.chimera").path(true != z8 ? "api" : "api_force_staging").appendPath(str).appendQueryParameter("requestStartUptime", String.valueOf(((Long) f7083j.get()).longValue())).build();
                ContentProviderClient contentProviderClientAcquireUnstableContentProviderClient = context.getContentResolver().acquireUnstableContentProviderClient(uriBuild);
                boolean z12 = false;
                if (contentProviderClientAcquireUnstableContentProviderClient != null) {
                    try {
                        cursorQuery = contentProviderClientAcquireUnstableContentProviderClient.query(uriBuild, null, null, null, null);
                    } catch (RemoteException unused) {
                    } catch (Throwable th2) {
                        contentProviderClientAcquireUnstableContentProviderClient.release();
                        throw th2;
                    }
                    if (cursorQuery != null) {
                        try {
                            int count = cursorQuery.getCount();
                            int columnCount = cursorQuery.getColumnCount();
                            matrixCursor = new MatrixCursor(cursorQuery.getColumnNames(), count);
                            for (int i5 = 0; i5 < count; i5++) {
                                if (!cursorQuery.moveToPosition(i5)) {
                                    throw new RemoteException("Cursor read incomplete (ContentProvider dead?)");
                                }
                                Object[] objArr = new Object[columnCount];
                                for (int i8 = 0; i8 < columnCount; i8++) {
                                    int type = cursorQuery.getType(i8);
                                    if (type == 0) {
                                        objArr[i8] = null;
                                    } else if (type == 1) {
                                        objArr[i8] = Long.valueOf(cursorQuery.getLong(i8));
                                    } else if (type == 2) {
                                        objArr[i8] = Double.valueOf(cursorQuery.getDouble(i8));
                                    } else if (type == 3) {
                                        objArr[i8] = cursorQuery.getString(i8);
                                    } else {
                                        if (type != 4) {
                                            throw new RemoteException("Unknown column type");
                                        }
                                        objArr[i8] = cursorQuery.getBlob(i8);
                                    }
                                }
                                matrixCursor.addRow(objArr);
                            }
                            cursorQuery.close();
                            contentProviderClientAcquireUnstableContentProviderClient.release();
                            if (matrixCursor != null) {
                                try {
                                    if (matrixCursor.moveToFirst()) {
                                        int i9 = matrixCursor.getInt(0);
                                        if (i9 > 0) {
                                            synchronized (e.class) {
                                                try {
                                                    f7079e = matrixCursor.getString(2);
                                                    int columnIndex = matrixCursor.getColumnIndex("loaderVersion");
                                                    if (columnIndex >= 0) {
                                                        f7081g = matrixCursor.getInt(columnIndex);
                                                    }
                                                    int columnIndex2 = matrixCursor.getColumnIndex("disableStandaloneDynamiteLoader2");
                                                    if (columnIndex2 >= 0) {
                                                        z10 = matrixCursor.getInt(columnIndex2) != 0;
                                                        f7080f = z10;
                                                    } else {
                                                        z10 = false;
                                                    }
                                                } finally {
                                                }
                                            }
                                            i iVar = (i) i.get();
                                            if (iVar == null || iVar.f7096a != null) {
                                                z11 = false;
                                            } else {
                                                iVar.f7096a = matrixCursor;
                                            }
                                            z12 = z10;
                                            matrixCursor = z11 ? null : matrixCursor;
                                        }
                                        if (z9 && z12) {
                                            throw new b("forcing fallback to container DynamiteLoader impl");
                                        }
                                        if (matrixCursor != null) {
                                            matrixCursor.close();
                                        }
                                        return i9;
                                    }
                                } catch (Exception e8) {
                                    exc = e8;
                                    if (exc instanceof b) {
                                        throw exc;
                                    }
                                    throw new b("V2 version check failed: " + exc.getMessage(), exc);
                                } catch (Throwable th3) {
                                    th = th3;
                                    matrixCursor = matrixCursor;
                                    if (matrixCursor == null) {
                                        throw th;
                                    }
                                    matrixCursor.close();
                                    throw th;
                                }
                            }
                            Log.w("DynamiteModule", "Failed to retrieve remote module version.");
                            throw new b("Failed to connect to dynamite module ContentResolver.");
                        } catch (Throwable th4) {
                            try {
                                cursorQuery.close();
                                throw th4;
                            } catch (Throwable th5) {
                                th4.addSuppressed(th5);
                                throw th4;
                            }
                        }
                    }
                    contentProviderClientAcquireUnstableContentProviderClient.release();
                }
                matrixCursor = null;
                if (matrixCursor != null) {
                }
                Log.w("DynamiteModule", "Failed to retrieve remote module version.");
                throw new b("Failed to connect to dynamite module ContentResolver.");
            } catch (Throwable th6) {
                th = th6;
            }
        } catch (Exception e9) {
            exc = e9;
        }
    }

    public static void f(ClassLoader classLoader) throws b {
        try {
            l lVar = null;
            IBinder iBinder = (IBinder) classLoader.loadClass("com.google.android.gms.dynamiteloader.DynamiteLoaderV2").getConstructor(null).newInstance(null);
            if (iBinder != null) {
                IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.dynamite.IDynamiteLoaderV2");
                if (iInterfaceQueryLocalInterface instanceof l) {
                    lVar = (l) iInterfaceQueryLocalInterface;
                } else {
                    try {
                        lVar = new l(iBinder, "com.google.android.gms.dynamite.IDynamiteLoaderV2", 0);
                    } catch (IllegalAccessException e8) {
                        e = e8;
                        throw new b("Failed to instantiate dynamite loader", e);
                    } catch (InstantiationException e9) {
                        e = e9;
                        throw new b("Failed to instantiate dynamite loader", e);
                    } catch (NoSuchMethodException e10) {
                        e = e10;
                        throw new b("Failed to instantiate dynamite loader", e);
                    } catch (InvocationTargetException e11) {
                        e = e11;
                        throw new b("Failed to instantiate dynamite loader", e);
                    }
                }
            }
            f7086m = lVar;
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e12) {
            e = e12;
        }
    }

    public static boolean g(Context context) {
        ApplicationInfo applicationInfo;
        Boolean bool = Boolean.TRUE;
        if (bool.equals(null) || bool.equals(f7082h)) {
            return true;
        }
        boolean z8 = false;
        if (f7082h == null) {
            ProviderInfo providerInfoResolveContentProvider = context.getPackageManager().resolveContentProvider("com.google.android.gms.chimera", Build.VERSION.SDK_INT >= 29 ? 268435456 : 0);
            if (M2.f.f4167b.b(context, 10000000) == 0 && providerInfoResolveContentProvider != null && "com.google.android.gms".equals(providerInfoResolveContentProvider.packageName)) {
                z8 = true;
            }
            f7082h = Boolean.valueOf(z8);
            if (z8 && (applicationInfo = providerInfoResolveContentProvider.applicationInfo) != null && (applicationInfo.flags & 129) == 0) {
                Log.i("DynamiteModule", "Non-system-image GmsCore APK, forcing V1");
                f7080f = true;
            }
        }
        if (!z8) {
            Log.e("DynamiteModule", "Invalid GmsCore APK, remote loading disabled.");
        }
        return z8;
    }

    public static k h(Context context) {
        k kVar;
        synchronized (e.class) {
            k kVar2 = f7085l;
            if (kVar2 != null) {
                return kVar2;
            }
            try {
                IBinder iBinder = (IBinder) context.createPackageContext("com.google.android.gms", 3).getClassLoader().loadClass("com.google.android.gms.chimera.container.DynamiteLoaderImpl").newInstance();
                if (iBinder == null) {
                    kVar = null;
                } else {
                    IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.dynamite.IDynamiteLoader");
                    kVar = iInterfaceQueryLocalInterface instanceof k ? (k) iInterfaceQueryLocalInterface : new k(iBinder, "com.google.android.gms.dynamite.IDynamiteLoader", 0);
                }
                if (kVar != null) {
                    f7085l = kVar;
                    return kVar;
                }
            } catch (Exception e8) {
                Log.e("DynamiteModule", "Failed to load IDynamiteLoader from GmsCore: " + e8.getMessage());
            }
            return null;
        }
    }

    public final IBinder b(String str) throws b {
        try {
            return (IBinder) this.f7087a.getClassLoader().loadClass(str).newInstance();
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e8) {
            throw new b("Failed to instantiate module class: ".concat(str), e8);
        }
    }
}
