package l8;

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 com.google.android.gms.common.api.internal.x0;
import com.google.android.gms.common.internal.v;
import com.google.android.gms.common.internal.w;
import com.google.android.gms.dynamite.DynamiteModule$DynamiteLoaderClassLoader;
import com.google.android.gms.dynamite.DynamiteModule$LoadingException;
import com.google.android.gms.internal.ads.q0;
import com.google.android.gms.measurement.internal.a0;
import com.google.android.gms.measurement.internal.u1;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

/* JADX INFO: loaded from: classes2.dex */
public final class c {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final g f30169d;

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

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final x0 f30176k;

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

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f30180a;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final ThreadLocal f30175j = new ThreadLocal();

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public static final androidx.window.core.h f30177l = new androidx.window.core.h(28);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final a0 f30167b = new a0(29);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final h f30168c = new h(0);

    static {
        int i10 = 1;
        f30176k = new x0(i10);
        f30169d = new g(i10);
    }

    public c(Context context) {
        w.checkNotNull(context);
        this.f30180a = context;
    }

    public static int a(Context context, String str) {
        try {
            ClassLoader classLoader = context.getApplicationContext().getClassLoader();
            StringBuilder sb = new StringBuilder(str.length() + 61);
            sb.append("com.google.android.gms.dynamite.descriptors.");
            sb.append(str);
            sb.append(".ModuleDescriptor");
            Class<?> clsLoadClass = classLoader.loadClass(sb.toString());
            Field declaredField = clsLoadClass.getDeclaredField("MODULE_ID");
            Field declaredField2 = clsLoadClass.getDeclaredField("MODULE_VERSION");
            if (v.equal(declaredField.get(null), str)) {
                return declaredField2.getInt(null);
            }
            new StringBuilder(String.valueOf(declaredField.get(null)).length() + 50 + str.length() + 1);
            return 0;
        } catch (ClassNotFoundException unused) {
            new StringBuilder(str.length() + 45);
            return 0;
        } catch (Exception e10) {
            "Failed to load module descriptor class: ".concat(String.valueOf(e10.getMessage()));
            return 0;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x0091 A[Catch: all -> 0x0083, TRY_LEAVE, TryCatch #1 {all -> 0x0083, blocks: (B:5:0x0032, B:9:0x007c, B:16:0x008a, B:20:0x0091, B:33:0x00bb, B:113:0x0205, B:114:0x020b, B:115:0x0212, B:118:0x0215, B:119:0x0216, B:120:0x021d, B:121:0x021e, B:123:0x0235, B:125:0x0244, B:136:0x0270, B:137:0x0277, B:138:0x0278, B:139:0x0296, B:140:0x0297, B:141:0x02de), top: B:154:0x0032, inners: #7 }] */
    /* JADX WARN: Removed duplicated region for block: B:30:0x00b7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static c c(Context context, b bVar, String str) throws DynamiteModule$LoadingException {
        c cVar;
        int i10;
        Boolean bool;
        k8.a aVarZ1;
        m mVar;
        Boolean boolValueOf;
        Context applicationContext = context.getApplicationContext();
        if (applicationContext == null) {
            throw new DynamiteModule$LoadingException("null application Context");
        }
        ThreadLocal threadLocal = f30175j;
        i iVar = (i) threadLocal.get();
        i iVar2 = new i();
        threadLocal.set(iVar2);
        x0 x0Var = f30176k;
        long jLongValue = ((Long) x0Var.get()).longValue();
        try {
            x0Var.set(Long.valueOf(SystemClock.uptimeMillis()));
            q0 q0VarB = bVar.b(context, str, f30177l);
            new StringBuilder(str.length() + 26 + String.valueOf(q0VarB.f15558a).length() + 19 + str.length() + 1 + String.valueOf(q0VarB.f15559b).length());
            int i11 = q0VarB.f15560c;
            if (i11 != 0) {
                if (i11 != -1) {
                    if (i11 == 1 || q0VarB.f15559b != 0) {
                        if (i11 != -1) {
                            "Selected local version of ".concat(str);
                            c cVar2 = new c(applicationContext);
                            if (jLongValue == 0) {
                                x0Var.remove();
                            } else {
                                x0Var.set(Long.valueOf(jLongValue));
                            }
                            Cursor cursor = iVar2.f30183a;
                            if (cursor != null) {
                                cursor.close();
                            }
                            threadLocal.set(iVar);
                            return cVar2;
                        }
                        if (i11 != 1) {
                            StringBuilder sb = new StringBuilder(String.valueOf(i11).length() + 36);
                            sb.append("VersionPolicy returned invalid code:");
                            sb.append(i11);
                            throw new DynamiteModule$LoadingException(sb.toString());
                        }
                        try {
                            i10 = q0VarB.f15559b;
                        } catch (DynamiteModule$LoadingException e10) {
                            new StringBuilder(String.valueOf(e10.getMessage()).length() + 30);
                            int i12 = q0VarB.f15558a;
                            if (i12 == 0 || bVar.b(context, str, new k(i12, (u1) null)).f15560c != -1) {
                                throw new DynamiteModule$LoadingException("Remote load failed. No local fallback found.", e10);
                            }
                            "Selected local version of ".concat(str);
                            cVar = new c(applicationContext);
                        }
                        try {
                            synchronized (c.class) {
                                if (!e(context)) {
                                    throw new DynamiteModule$LoadingException("Remote loading disabled");
                                }
                                bool = f30170e;
                            }
                            if (bool == null) {
                                throw new DynamiteModule$LoadingException("Failed to determine which loading route to use.");
                            }
                            if (bool.booleanValue()) {
                                new StringBuilder(str.length() + 40 + String.valueOf(i10).length());
                                synchronized (c.class) {
                                    mVar = f30179n;
                                }
                                if (mVar == null) {
                                    throw new DynamiteModule$LoadingException("DynamiteLoaderV2 was not cached.");
                                }
                                i iVar3 = (i) threadLocal.get();
                                if (iVar3 == null || iVar3.f30183a == null) {
                                    throw new DynamiteModule$LoadingException("No result cursor");
                                }
                                Context applicationContext2 = context.getApplicationContext();
                                Cursor cursor2 = iVar3.f30183a;
                                new k8.b(null);
                                synchronized (c.class) {
                                    boolValueOf = Boolean.valueOf(f30173h >= 2);
                                }
                                Context context2 = (Context) k8.b.O(boolValueOf.booleanValue() ? mVar.Z1(new k8.b(applicationContext2), str, i10, new k8.b(cursor2)) : mVar.w1(new k8.b(applicationContext2), str, i10, new k8.b(cursor2)));
                                if (context2 == null) {
                                    throw new DynamiteModule$LoadingException("Failed to get module context");
                                }
                                cVar = new c(context2);
                            } else {
                                new StringBuilder(str.length() + 40 + String.valueOf(i10).length());
                                l lVarH = h(context);
                                if (lVarH == null) {
                                    throw new DynamiteModule$LoadingException("Failed to create IDynamiteLoader.");
                                }
                                Parcel parcelM = lVarH.M(6, lVarH.O());
                                int i13 = parcelM.readInt();
                                parcelM.recycle();
                                if (i13 >= 3) {
                                    i iVar4 = (i) threadLocal.get();
                                    if (iVar4 == null) {
                                        throw new DynamiteModule$LoadingException("No cached result cursor holder");
                                    }
                                    aVarZ1 = lVarH.Q2(new k8.b(context), str, i10, new k8.b(iVar4.f30183a));
                                } else {
                                    aVarZ1 = i13 == 2 ? lVarH.Z1(new k8.b(context), str, i10) : lVarH.w1(new k8.b(context), str, i10);
                                }
                                Object objO = k8.b.O(aVarZ1);
                                if (objO == null) {
                                    throw new DynamiteModule$LoadingException("Failed to load remote module.");
                                }
                                cVar = new c((Context) objO);
                            }
                            return cVar;
                        } catch (RemoteException e11) {
                            throw new DynamiteModule$LoadingException("Failed to load remote module.", e11);
                        } catch (DynamiteModule$LoadingException e12) {
                            throw e12;
                        } catch (Throwable th) {
                            try {
                                w.checkNotNull(context);
                                w.checkNotNull(th);
                            } catch (Exception unused) {
                            }
                            throw new DynamiteModule$LoadingException("Failed to load remote module.", th);
                        }
                    }
                } else if (q0VarB.f15558a != 0) {
                    i11 = -1;
                    if (i11 == 1) {
                    }
                    if (i11 != -1) {
                    }
                }
            }
            int i14 = q0VarB.f15558a;
            int i15 = q0VarB.f15559b;
            StringBuilder sb2 = new StringBuilder(str.length() + 46 + String.valueOf(i14).length() + 23 + String.valueOf(i15).length() + 1);
            sb2.append("No acceptable module ");
            sb2.append(str);
            sb2.append(" found. Local version is ");
            sb2.append(i14);
            sb2.append(" and remote version is ");
            sb2.append(i15);
            sb2.append(".");
            throw new DynamiteModule$LoadingException(sb2.toString());
        } finally {
            if (jLongValue == 0) {
                f30176k.remove();
            } else {
                f30176k.set(Long.valueOf(jLongValue));
            }
            Cursor cursor3 = iVar2.f30183a;
            if (cursor3 != null) {
                cursor3.close();
            }
            f30175j.set(iVar);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:51:0x00af A[Catch: all -> 0x0036, TryCatch #8 {, blocks: (B:9:0x0026, B:11:0x0032, B:52:0x00b8, B:16:0x003b, B:18:0x0042, B:20:0x0048, B:25:0x004e, B:27:0x0052, B:31:0x005c, B:33:0x0064, B:36:0x006b, B:43:0x0097, B:44:0x009f, B:39:0x0072, B:41:0x0078, B:42:0x0089, B:47:0x00a2, B:50:0x00a5, B:51:0x00af, B:17:0x003e), top: B:138:0x0026, inners: #12 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static int d(Context context, String str, boolean z10) {
        Field declaredField;
        Throwable th;
        RemoteException e10;
        int i10;
        i iVar;
        Cursor cursor;
        try {
            synchronized (c.class) {
                Boolean bool = f30170e;
                Cursor cursor2 = null;
                if (bool == null) {
                    try {
                        declaredField = context.getApplicationContext().getClassLoader().loadClass(DynamiteModule$DynamiteLoaderClassLoader.class.getName()).getDeclaredField("sClassLoader");
                    } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e11) {
                        new StringBuilder(e11.toString().length() + 30);
                        bool = Boolean.FALSE;
                    }
                    synchronized (declaredField.getDeclaringClass()) {
                        ClassLoader classLoader = (ClassLoader) declaredField.get(null);
                        if (classLoader == ClassLoader.getSystemClassLoader()) {
                            bool = Boolean.FALSE;
                        } else if (classLoader != null) {
                            try {
                                g(classLoader);
                            } catch (DynamiteModule$LoadingException unused) {
                            }
                            bool = Boolean.TRUE;
                        } else {
                            if (!e(context)) {
                                return 0;
                            }
                            if (!f30172g) {
                                Boolean bool2 = Boolean.TRUE;
                                if (bool2.equals(null)) {
                                    declaredField.set(null, ClassLoader.getSystemClassLoader());
                                    bool = Boolean.FALSE;
                                } else {
                                    try {
                                        int iF = f(str, context, z10, true);
                                        String str2 = f30171f;
                                        if (str2 != null && !str2.isEmpty()) {
                                            ClassLoader classLoaderZza = e.zza();
                                            if (classLoaderZza == null) {
                                                if (Build.VERSION.SDK_INT >= 29) {
                                                    a4.i.e();
                                                    String str3 = f30171f;
                                                    w.checkNotNull(str3);
                                                    classLoaderZza = a4.i.d(str3, ClassLoader.getSystemClassLoader());
                                                } else {
                                                    String str4 = f30171f;
                                                    w.checkNotNull(str4);
                                                    classLoaderZza = new f(str4, ClassLoader.getSystemClassLoader());
                                                }
                                            }
                                            g(classLoaderZza);
                                            declaredField.set(null, classLoaderZza);
                                            f30170e = bool2;
                                            return iF;
                                        }
                                        return iF;
                                    } catch (DynamiteModule$LoadingException unused2) {
                                        declaredField.set(null, ClassLoader.getSystemClassLoader());
                                        bool = Boolean.FALSE;
                                    }
                                }
                            }
                            new StringBuilder(e11.toString().length() + 30);
                            bool = Boolean.FALSE;
                            f30170e = bool;
                        }
                        f30170e = bool;
                    }
                }
                if (bool.booleanValue()) {
                    try {
                        return f(str, context, z10, false);
                    } catch (DynamiteModule$LoadingException e12) {
                        new StringBuilder(String.valueOf(e12.getMessage()).length() + 42);
                        return 0;
                    }
                }
                l lVarH = h(context);
                try {
                    if (lVarH == null) {
                        return 0;
                    }
                    try {
                        Parcel parcelM = lVarH.M(6, lVarH.O());
                        int i11 = parcelM.readInt();
                        parcelM.recycle();
                        if (i11 >= 3) {
                            ThreadLocal threadLocal = f30175j;
                            i iVar2 = (i) threadLocal.get();
                            if (iVar2 != null && (cursor = iVar2.f30183a) != null) {
                                return cursor.getInt(0);
                            }
                            Cursor cursor3 = (Cursor) k8.b.O(lVarH.C2(new k8.b(context), str, z10, ((Long) f30176k.get()).longValue()));
                            if (cursor3 != null) {
                                try {
                                    if (cursor3.moveToFirst()) {
                                        i10 = cursor3.getInt(0);
                                        if (i10 <= 0 || (iVar = (i) threadLocal.get()) == null || iVar.f30183a != null) {
                                            cursor2 = cursor3;
                                        } else {
                                            iVar.f30183a = cursor3;
                                        }
                                        if (cursor2 != null) {
                                            cursor2.close();
                                        }
                                    }
                                } catch (RemoteException e13) {
                                    e10 = e13;
                                    cursor2 = cursor3;
                                    new StringBuilder(String.valueOf(e10.getMessage()).length() + 42);
                                    if (cursor2 == null) {
                                        return 0;
                                    }
                                    cursor2.close();
                                    return 0;
                                } catch (Throwable th2) {
                                    th = th2;
                                    cursor2 = cursor3;
                                    if (cursor2 != null) {
                                        cursor2.close();
                                    }
                                    throw th;
                                }
                            }
                            if (cursor3 == null) {
                                return 0;
                            }
                            cursor3.close();
                            return 0;
                        }
                        if (i11 == 2) {
                            k8.b bVar = new k8.b(context);
                            Parcel parcelO = lVarH.O();
                            com.google.android.gms.internal.common.f.b(parcelO, bVar);
                            parcelO.writeString(str);
                            parcelO.writeInt(z10 ? 1 : 0);
                            Parcel parcelM2 = lVarH.M(5, parcelO);
                            i10 = parcelM2.readInt();
                            parcelM2.recycle();
                        } else {
                            k8.b bVar2 = new k8.b(context);
                            Parcel parcelO2 = lVarH.O();
                            com.google.android.gms.internal.common.f.b(parcelO2, bVar2);
                            parcelO2.writeString(str);
                            parcelO2.writeInt(z10 ? 1 : 0);
                            Parcel parcelM3 = lVarH.M(3, parcelO2);
                            i10 = parcelM3.readInt();
                            parcelM3.recycle();
                        }
                        return i10;
                    } catch (RemoteException e14) {
                        e10 = e14;
                    }
                } catch (Throwable th3) {
                    th = th3;
                }
            }
        } catch (Throwable th4) {
            try {
                w.checkNotNull(context);
                w.checkNotNull(th4);
            } catch (Exception unused3) {
            }
            throw th4;
        }
    }

    public static boolean e(Context context) {
        ApplicationInfo applicationInfo;
        Boolean bool = Boolean.TRUE;
        if (bool.equals(null) || bool.equals(f30174i)) {
            return true;
        }
        boolean zBooleanValue = false;
        if (f30174i == null) {
            ProviderInfo providerInfoResolveContentProvider = context.getPackageManager().resolveContentProvider("com.google.android.gms.chimera", Build.VERSION.SDK_INT >= 29 ? 268435456 : 0);
            if (e8.e.f25522b.b(context, 10000000) == 0 && providerInfoResolveContentProvider != null && "com.google.android.gms".equals(providerInfoResolveContentProvider.packageName)) {
                zBooleanValue = true;
            }
            Boolean boolValueOf = Boolean.valueOf(zBooleanValue);
            f30174i = boolValueOf;
            zBooleanValue = boolValueOf.booleanValue();
            if (zBooleanValue && (applicationInfo = providerInfoResolveContentProvider.applicationInfo) != null && (applicationInfo.flags & 129) == 0) {
                f30172g = true;
            }
        }
        return zBooleanValue;
    }

    /* JADX WARN: Finally extract failed */
    /* JADX WARN: Removed duplicated region for block: B:120:0x00e9 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:81:0x0134 A[PHI: r5
      0x0134: PHI (r5v10 boolean) = (r5v9 boolean), (r5v12 boolean), (r5v12 boolean) binds: [B:59:0x00f3, B:76:0x012b, B:78:0x012f] A[DONT_GENERATE, DONT_INLINE]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static int f(String str, Context context, boolean z10, boolean z11) throws Throwable {
        Cursor cursorQuery;
        MatrixCursor matrixCursor;
        MatrixCursor matrixCursor2 = null;
        try {
            try {
                boolean z12 = true;
                Uri uriBuild = new Uri.Builder().scheme("content").authority("com.google.android.gms.chimera").path(true != z10 ? "api" : "api_force_staging").appendPath(str).appendQueryParameter("requestStartUptime", String.valueOf(((Long) f30176k.get()).longValue())).build();
                ContentProviderClient contentProviderClientAcquireUnstableContentProviderClient = context.getContentResolver().acquireUnstableContentProviderClient(uriBuild);
                boolean z13 = false;
                if (contentProviderClientAcquireUnstableContentProviderClient != null) {
                    try {
                        cursorQuery = contentProviderClientAcquireUnstableContentProviderClient.query(uriBuild, null, null, null, null);
                    } catch (RemoteException unused) {
                    } catch (Throwable th) {
                        contentProviderClientAcquireUnstableContentProviderClient.release();
                        throw th;
                    }
                    if (cursorQuery != null) {
                        try {
                            int count = cursorQuery.getCount();
                            int columnCount = cursorQuery.getColumnCount();
                            matrixCursor = new MatrixCursor(cursorQuery.getColumnNames(), count);
                            for (int i10 = 0; i10 < count; i10++) {
                                if (!cursorQuery.moveToPosition(i10)) {
                                    throw new RemoteException("Cursor read incomplete (ContentProvider dead?)");
                                }
                                Object[] objArr = new Object[columnCount];
                                for (int i11 = 0; i11 < columnCount; i11++) {
                                    int type = cursorQuery.getType(i11);
                                    if (type == 0) {
                                        objArr[i11] = null;
                                    } else if (type == 1) {
                                        objArr[i11] = Long.valueOf(cursorQuery.getLong(i11));
                                    } else if (type == 2) {
                                        objArr[i11] = Double.valueOf(cursorQuery.getDouble(i11));
                                    } else if (type == 3) {
                                        objArr[i11] = cursorQuery.getString(i11);
                                    } else {
                                        if (type != 4) {
                                            throw new RemoteException("Unknown column type");
                                        }
                                        objArr[i11] = cursorQuery.getBlob(i11);
                                    }
                                }
                                matrixCursor.addRow(objArr);
                            }
                            cursorQuery.close();
                            contentProviderClientAcquireUnstableContentProviderClient.release();
                            if (matrixCursor != null) {
                                try {
                                    if (matrixCursor.moveToFirst()) {
                                        int i12 = matrixCursor.getInt(0);
                                        if (i12 > 0) {
                                            synchronized (c.class) {
                                                try {
                                                    f30171f = matrixCursor.getString(2);
                                                    int columnIndex = matrixCursor.getColumnIndex("loaderVersion");
                                                    if (columnIndex >= 0) {
                                                        f30173h = matrixCursor.getInt(columnIndex);
                                                    }
                                                    int columnIndex2 = matrixCursor.getColumnIndex("disableStandaloneDynamiteLoader2");
                                                    if (columnIndex2 >= 0) {
                                                        if (matrixCursor.getInt(columnIndex2) == 0) {
                                                            z12 = false;
                                                        }
                                                        f30172g = z12;
                                                        z13 = z12;
                                                    }
                                                } finally {
                                                }
                                            }
                                            i iVar = (i) f30175j.get();
                                            if (iVar == null || iVar.f30183a != null) {
                                                matrixCursor2 = matrixCursor;
                                            } else {
                                                iVar.f30183a = matrixCursor;
                                            }
                                        }
                                        if (z11 && z13) {
                                            throw new DynamiteModule$LoadingException("forcing fallback to container DynamiteLoader impl");
                                        }
                                        if (matrixCursor2 != null) {
                                            matrixCursor2.close();
                                        }
                                        return i12;
                                    }
                                } catch (Exception e10) {
                                    e = e10;
                                    if (e instanceof DynamiteModule$LoadingException) {
                                        throw e;
                                    }
                                    String message = e.getMessage();
                                    StringBuilder sb = new StringBuilder(String.valueOf(message).length() + 25);
                                    sb.append("V2 version check failed: ");
                                    sb.append(message);
                                    throw new DynamiteModule$LoadingException(sb.toString(), e);
                                } catch (Throwable th2) {
                                    th = th2;
                                    matrixCursor2 = matrixCursor;
                                    if (matrixCursor2 != null) {
                                        matrixCursor2.close();
                                    }
                                    throw th;
                                }
                            }
                            throw new DynamiteModule$LoadingException("Failed to connect to dynamite module ContentResolver.");
                        } catch (Throwable th3) {
                            try {
                                cursorQuery.close();
                                throw th3;
                            } catch (Throwable th4) {
                                th3.addSuppressed(th4);
                                throw th3;
                            }
                        }
                    }
                    contentProviderClientAcquireUnstableContentProviderClient.release();
                }
                matrixCursor = null;
                if (matrixCursor != null) {
                }
                throw new DynamiteModule$LoadingException("Failed to connect to dynamite module ContentResolver.");
            } catch (Exception e11) {
                e = e11;
            }
        } catch (Throwable th5) {
            th = th5;
        }
    }

    public static void g(ClassLoader classLoader) throws DynamiteModule$LoadingException {
        m mVar;
        try {
            IBinder iBinder = (IBinder) classLoader.loadClass("com.google.android.gms.dynamiteloader.DynamiteLoaderV2").getConstructor(new Class[0]).newInstance(new Object[0]);
            if (iBinder == null) {
                mVar = null;
            } else {
                IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.dynamite.IDynamiteLoaderV2");
                mVar = iInterfaceQueryLocalInterface instanceof m ? (m) iInterfaceQueryLocalInterface : new m(iBinder, "com.google.android.gms.dynamite.IDynamiteLoaderV2", 2);
            }
            f30179n = mVar;
        } catch (ClassNotFoundException e10) {
            e = e10;
            throw new DynamiteModule$LoadingException("Failed to instantiate dynamite loader", e);
        } catch (IllegalAccessException e11) {
            e = e11;
            throw new DynamiteModule$LoadingException("Failed to instantiate dynamite loader", e);
        } catch (InstantiationException e12) {
            e = e12;
            throw new DynamiteModule$LoadingException("Failed to instantiate dynamite loader", e);
        } catch (NoSuchMethodException e13) {
            e = e13;
            throw new DynamiteModule$LoadingException("Failed to instantiate dynamite loader", e);
        } catch (InvocationTargetException e14) {
            e = e14;
            throw new DynamiteModule$LoadingException("Failed to instantiate dynamite loader", e);
        }
    }

    public static l h(Context context) {
        l lVar;
        synchronized (c.class) {
            l lVar2 = f30178m;
            if (lVar2 != null) {
                return lVar2;
            }
            try {
                IBinder iBinder = (IBinder) context.createPackageContext("com.google.android.gms", 3).getClassLoader().loadClass("com.google.android.gms.chimera.container.DynamiteLoaderImpl").newInstance();
                if (iBinder == null) {
                    lVar = null;
                } else {
                    IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.dynamite.IDynamiteLoader");
                    lVar = iInterfaceQueryLocalInterface instanceof l ? (l) iInterfaceQueryLocalInterface : new l(iBinder, "com.google.android.gms.dynamite.IDynamiteLoader", 2);
                }
                if (lVar != null) {
                    f30178m = lVar;
                    return lVar;
                }
            } catch (Exception e10) {
                new StringBuilder(String.valueOf(e10.getMessage()).length() + 45);
            }
            return null;
        }
    }

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