package com.google.android.gms.dynamite; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.ProviderInfo; import android.database.Cursor; import android.os.Build; import android.os.IBinder; import android.os.IInterface; import android.os.RemoteException; import android.os.SystemClock; import android.util.Log; import com.google.android.gms.common.GoogleApiAvailabilityLight; import com.google.android.gms.common.annotation.KeepForSdk; import com.google.android.gms.common.internal.Objects; import com.google.android.gms.common.internal.Preconditions; import com.google.android.gms.common.util.CrashUtils; import com.google.android.gms.common.util.DynamiteApi; import com.google.android.gms.dynamic.IObjectWrapper; import com.google.android.gms.dynamic.ObjectWrapper; import com.google.errorprone.annotations.ResultIgnorabilityUnspecified; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @KeepForSdk /* loaded from: classes.dex */ public final class DynamiteModule { @KeepForSdk public static final int LOCAL = -1; @KeepForSdk public static final int NONE = 0; @KeepForSdk public static final int NO_SELECTION = 0; @KeepForSdk public static final int REMOTE = 1; private static Boolean zzb = null; private static String zzc = null; private static boolean zzd = false; private static int zze = -1; private static Boolean zzf; private static zzq zzk; private static zzr zzl; private final Context zzj; private static final ThreadLocal zzg = new ThreadLocal(); private static final ThreadLocal zzh = new zzd(); private static final VersionPolicy.IVersions zzi = new zze(); @KeepForSdk public static final VersionPolicy PREFER_REMOTE = new zzf(); @KeepForSdk public static final VersionPolicy PREFER_LOCAL = new zzg(); @KeepForSdk public static final VersionPolicy PREFER_REMOTE_VERSION_NO_FORCE_STAGING = new zzh(); @KeepForSdk public static final VersionPolicy PREFER_HIGHEST_OR_LOCAL_VERSION = new zzi(); @KeepForSdk public static final VersionPolicy PREFER_HIGHEST_OR_LOCAL_VERSION_NO_FORCE_STAGING = new zzj(); @KeepForSdk public static final VersionPolicy PREFER_HIGHEST_OR_REMOTE_VERSION = new zzk(); public static final VersionPolicy zza = new zzl(); @DynamiteApi public static class DynamiteLoaderClassLoader { public static ClassLoader sClassLoader; } @KeepForSdk public static class LoadingException extends Exception { /* synthetic */ LoadingException(String str, zzp zzpVar) { super(str); } /* synthetic */ LoadingException(String str, Throwable th, zzp zzpVar) { super(str, th); } } public interface VersionPolicy { @KeepForSdk public interface IVersions { int zza(Context context, String str); int zzb(Context context, String str, boolean z10); } @KeepForSdk public static class SelectionResult { @KeepForSdk public int localVersion = 0; @KeepForSdk public int remoteVersion = 0; @KeepForSdk public int selection = 0; } @KeepForSdk SelectionResult selectModule(Context context, String str, IVersions iVersions); } private DynamiteModule(Context context) { Preconditions.checkNotNull(context); this.zzj = context; } @KeepForSdk public static int getLocalVersion(Context context, String str) { try { Class loadClass = context.getApplicationContext().getClassLoader().loadClass("com.google.android.gms.dynamite.descriptors." + str + ".ModuleDescriptor"); Field declaredField = loadClass.getDeclaredField("MODULE_ID"); Field declaredField2 = loadClass.getDeclaredField("MODULE_VERSION"); if (Objects.equal(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 e10) { Log.e("DynamiteModule", "Failed to load module descriptor class: ".concat(String.valueOf(e10.getMessage()))); return 0; } } @KeepForSdk public static int getRemoteVersion(Context context, String str) { return zza(context, str, false); } @ResultIgnorabilityUnspecified @KeepForSdk public static DynamiteModule load(Context context, VersionPolicy versionPolicy, String str) { DynamiteModule zzc2; Boolean bool; IObjectWrapper zzh2; DynamiteModule dynamiteModule; zzr zzrVar; Boolean valueOf; IObjectWrapper zze2; Context applicationContext = context.getApplicationContext(); if (applicationContext == null) { throw new LoadingException("null application Context", null); } ThreadLocal threadLocal = zzg; zzn zznVar = (zzn) threadLocal.get(); zzn zznVar2 = new zzn(null); threadLocal.set(zznVar2); ThreadLocal threadLocal2 = zzh; long longValue = ((Long) threadLocal2.get()).longValue(); try { threadLocal2.set(Long.valueOf(SystemClock.elapsedRealtime())); VersionPolicy.SelectionResult selectModule = versionPolicy.selectModule(context, str, zzi); Log.i("DynamiteModule", "Considering local module " + str + ":" + selectModule.localVersion + " and remote module " + str + ":" + selectModule.remoteVersion); int i10 = selectModule.selection; if (i10 != 0) { if (i10 == -1) { if (selectModule.localVersion != 0) { i10 = -1; } } if (i10 != 1 || selectModule.remoteVersion != 0) { if (i10 == -1) { zzc2 = zzc(applicationContext, str); } else { if (i10 != 1) { throw new LoadingException("VersionPolicy returned invalid code:" + i10, null); } try { int i11 = selectModule.remoteVersion; try { synchronized (DynamiteModule.class) { if (!zzf(context)) { throw new LoadingException("Remote loading disabled", null); } bool = zzb; } if (bool == null) { throw new LoadingException("Failed to determine which loading route to use.", null); } if (bool.booleanValue()) { Log.i("DynamiteModule", "Selected remote version of " + str + ", version >= " + i11); synchronized (DynamiteModule.class) { zzrVar = zzl; } if (zzrVar == null) { throw new LoadingException("DynamiteLoaderV2 was not cached.", null); } zzn zznVar3 = (zzn) threadLocal.get(); if (zznVar3 == null || zznVar3.zza == null) { throw new LoadingException("No result cursor", null); } Context applicationContext2 = context.getApplicationContext(); Cursor cursor = zznVar3.zza; ObjectWrapper.wrap(null); synchronized (DynamiteModule.class) { valueOf = Boolean.valueOf(zze >= 2); } if (valueOf.booleanValue()) { Log.v("DynamiteModule", "Dynamite loader version >= 2, using loadModule2NoCrashUtils"); zze2 = zzrVar.zzf(ObjectWrapper.wrap(applicationContext2), str, i11, ObjectWrapper.wrap(cursor)); } else { Log.w("DynamiteModule", "Dynamite loader version < 2, falling back to loadModule2"); zze2 = zzrVar.zze(ObjectWrapper.wrap(applicationContext2), str, i11, ObjectWrapper.wrap(cursor)); } Context context2 = (Context) ObjectWrapper.unwrap(zze2); if (context2 == null) { throw new LoadingException("Failed to get module context", null); } dynamiteModule = new DynamiteModule(context2); } else { Log.i("DynamiteModule", "Selected remote version of " + str + ", version >= " + i11); zzq zzg2 = zzg(context); if (zzg2 == null) { throw new LoadingException("Failed to create IDynamiteLoader.", null); } int zze3 = zzg2.zze(); if (zze3 >= 3) { zzn zznVar4 = (zzn) threadLocal.get(); if (zznVar4 == null) { throw new LoadingException("No cached result cursor holder", null); } zzh2 = zzg2.zzi(ObjectWrapper.wrap(context), str, i11, ObjectWrapper.wrap(zznVar4.zza)); } else if (zze3 == 2) { Log.w("DynamiteModule", "IDynamite loader version = 2"); zzh2 = zzg2.zzj(ObjectWrapper.wrap(context), str, i11); } else { Log.w("DynamiteModule", "Dynamite loader version < 2, falling back to createModuleContext"); zzh2 = zzg2.zzh(ObjectWrapper.wrap(context), str, i11); } Object unwrap = ObjectWrapper.unwrap(zzh2); if (unwrap == null) { throw new LoadingException("Failed to load remote module.", null); } dynamiteModule = new DynamiteModule((Context) unwrap); } zzc2 = dynamiteModule; } catch (RemoteException e10) { throw new LoadingException("Failed to load remote module.", e10, null); } catch (LoadingException e11) { throw e11; } catch (Throwable th) { CrashUtils.addDynamiteErrorToDropBox(context, th); throw new LoadingException("Failed to load remote module.", th, null); } } catch (LoadingException e12) { Log.w("DynamiteModule", "Failed to load remote module: " + e12.getMessage()); int i12 = selectModule.localVersion; if (i12 == 0 || versionPolicy.selectModule(context, str, new zzo(i12, 0)).selection != -1) { throw new LoadingException("Remote load failed. No local fallback found.", e12, null); } zzc2 = zzc(applicationContext, str); } } if (longValue == 0) { zzh.remove(); } else { zzh.set(Long.valueOf(longValue)); } Cursor cursor2 = zznVar2.zza; if (cursor2 != null) { cursor2.close(); } zzg.set(zznVar); return zzc2; } } throw new LoadingException("No acceptable module " + str + " found. Local version is " + selectModule.localVersion + " and remote version is " + selectModule.remoteVersion + ".", null); } catch (Throwable th2) { if (longValue == 0) { zzh.remove(); } else { zzh.set(Long.valueOf(longValue)); } Cursor cursor3 = zznVar2.zza; if (cursor3 != null) { cursor3.close(); } zzg.set(zznVar); throw th2; } } /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:48:0x01b3 -> B:24:0x01b8). Please report as a decompilation issue!!! */ /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:49:0x01b5 -> B:24:0x01b8). Please report as a decompilation issue!!! */ public static int zza(Context context, String str, boolean z10) { Field declaredField; Throwable th; RemoteException e10; Cursor cursor; try { synchronized (DynamiteModule.class) { Boolean bool = zzb; int i10 = 0; if (bool == null) { try { declaredField = context.getApplicationContext().getClassLoader().loadClass(DynamiteLoaderClassLoader.class.getName()).getDeclaredField("sClassLoader"); } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e11) { Log.w("DynamiteModule", "Failed to load module via V2: " + e11.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 { zzd(classLoader); } catch (LoadingException unused) { } bool = Boolean.TRUE; } else { if (!zzf(context)) { return 0; } if (!zzd) { Boolean bool2 = Boolean.TRUE; if (!bool2.equals(null)) { try { int zzb2 = zzb(context, str, z10, true); String str2 = zzc; if (str2 != null && !str2.isEmpty()) { ClassLoader zza2 = zzb.zza(); if (zza2 == null) { if (Build.VERSION.SDK_INT >= 29) { b.a(); String str3 = zzc; Preconditions.checkNotNull(str3); zza2 = a.a(str3, ClassLoader.getSystemClassLoader()); } else { String str4 = zzc; Preconditions.checkNotNull(str4); zza2 = new zzc(str4, ClassLoader.getSystemClassLoader()); } } zzd(zza2); declaredField.set(null, zza2); zzb = bool2; return zzb2; } return zzb2; } catch (LoadingException unused2) { declaredField.set(null, ClassLoader.getSystemClassLoader()); bool = Boolean.FALSE; } } } declaredField.set(null, ClassLoader.getSystemClassLoader()); bool = Boolean.FALSE; } zzb = bool; } } if (bool.booleanValue()) { try { return zzb(context, str, z10, false); } catch (LoadingException e12) { Log.w("DynamiteModule", "Failed to retrieve remote module version: " + e12.getMessage()); return 0; } } zzq zzg2 = zzg(context); try { if (zzg2 != null) { try { int zze2 = zzg2.zze(); if (zze2 >= 3) { zzn zznVar = (zzn) zzg.get(); if (zznVar == null || (cursor = zznVar.zza) == null) { Cursor cursor2 = (Cursor) ObjectWrapper.unwrap(zzg2.zzk(ObjectWrapper.wrap(context), str, z10, ((Long) zzh.get()).longValue())); if (cursor2 != null) { try { if (cursor2.moveToFirst()) { int i11 = cursor2.getInt(0); r2 = (i11 <= 0 || !zze(cursor2)) ? cursor2 : null; if (r2 != null) { r2.close(); } i10 = i11; } } catch (RemoteException e13) { e10 = e13; r2 = cursor2; Log.w("DynamiteModule", "Failed to retrieve remote module version: " + e10.getMessage()); if (r2 != null) { r2.close(); } return i10; } catch (Throwable th2) { th = th2; r2 = cursor2; if (r2 != null) { r2.close(); } throw th; } } Log.w("DynamiteModule", "Failed to retrieve remote module version."); if (cursor2 != null) { cursor2.close(); } } else { i10 = cursor.getInt(0); } } else if (zze2 == 2) { Log.w("DynamiteModule", "IDynamite loader version = 2, no high precision latency measurement."); i10 = zzg2.zzg(ObjectWrapper.wrap(context), str, z10); } else { Log.w("DynamiteModule", "IDynamite loader version < 2, falling back to getModuleVersion2"); i10 = zzg2.zzf(ObjectWrapper.wrap(context), str, z10); } } catch (RemoteException e14) { e10 = e14; } } return i10; } catch (Throwable th3) { th = th3; } } } catch (Throwable th4) { CrashUtils.addDynamiteErrorToDropBox(context, th4); throw th4; } } /* JADX WARN: Code restructure failed: missing block: B:44:0x009f, code lost: r8.close(); */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Removed duplicated region for block: B:56:0x00dc */ /* JADX WARN: Type inference failed for: r0v0 */ /* JADX WARN: Type inference failed for: r0v1, types: [android.database.Cursor] */ /* JADX WARN: Type inference failed for: r0v2 */ /* JADX WARN: Type inference failed for: r0v3 */ /* JADX WARN: Type inference failed for: r0v4 */ /* JADX WARN: Type inference failed for: r0v5 */ /* JADX WARN: Type inference failed for: r0v6 */ /* JADX WARN: Type inference failed for: r0v7 */ /* JADX WARN: Type inference failed for: r0v8 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private static int zzb(android.content.Context r8, java.lang.String r9, boolean r10, boolean r11) { /* Method dump skipped, instructions count: 224 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: com.google.android.gms.dynamite.DynamiteModule.zzb(android.content.Context, java.lang.String, boolean, boolean):int"); } private static DynamiteModule zzc(Context context, String str) { Log.i("DynamiteModule", "Selected local version of ".concat(String.valueOf(str))); return new DynamiteModule(context); } private static void zzd(ClassLoader classLoader) { zzr zzrVar; zzp zzpVar = null; try { IBinder iBinder = (IBinder) classLoader.loadClass("com.google.android.gms.dynamiteloader.DynamiteLoaderV2").getConstructor(new Class[0]).newInstance(new Object[0]); if (iBinder == null) { zzrVar = null; } else { IInterface queryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.dynamite.IDynamiteLoaderV2"); zzrVar = queryLocalInterface instanceof zzr ? (zzr) queryLocalInterface : new zzr(iBinder); } zzl = zzrVar; } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e10) { throw new LoadingException("Failed to instantiate dynamite loader", e10, zzpVar); } } private static boolean zze(Cursor cursor) { zzn zznVar = (zzn) zzg.get(); if (zznVar == null || zznVar.zza != null) { return false; } zznVar.zza = cursor; return true; } private static boolean zzf(Context context) { ApplicationInfo applicationInfo; Boolean bool = Boolean.TRUE; if (bool.equals(null) || bool.equals(zzf)) { return true; } boolean z10 = false; if (zzf == null) { ProviderInfo resolveContentProvider = context.getPackageManager().resolveContentProvider("com.google.android.gms.chimera", 0); if (GoogleApiAvailabilityLight.getInstance().isGooglePlayServicesAvailable(context, 10000000) == 0 && resolveContentProvider != null && "com.google.android.gms".equals(resolveContentProvider.packageName)) { z10 = true; } Boolean valueOf = Boolean.valueOf(z10); zzf = valueOf; z10 = valueOf.booleanValue(); if (z10 && (applicationInfo = resolveContentProvider.applicationInfo) != null && (applicationInfo.flags & 129) == 0) { Log.i("DynamiteModule", "Non-system-image GmsCore APK, forcing V1"); zzd = true; } } if (!z10) { Log.e("DynamiteModule", "Invalid GmsCore APK, remote loading disabled."); } return z10; } private static zzq zzg(Context context) { zzq zzqVar; synchronized (DynamiteModule.class) { zzq zzqVar2 = zzk; if (zzqVar2 != null) { return zzqVar2; } try { IBinder iBinder = (IBinder) context.createPackageContext("com.google.android.gms", 3).getClassLoader().loadClass("com.google.android.gms.chimera.container.DynamiteLoaderImpl").newInstance(); if (iBinder == null) { zzqVar = null; } else { IInterface queryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.dynamite.IDynamiteLoader"); zzqVar = queryLocalInterface instanceof zzq ? (zzq) queryLocalInterface : new zzq(iBinder); } if (zzqVar != null) { zzk = zzqVar; return zzqVar; } } catch (Exception e10) { Log.e("DynamiteModule", "Failed to load IDynamiteLoader from GmsCore: " + e10.getMessage()); } return null; } } @ResultIgnorabilityUnspecified @KeepForSdk public Context getModuleContext() { return this.zzj; } @KeepForSdk public IBinder instantiate(String str) { try { return (IBinder) this.zzj.getClassLoader().loadClass(str).newInstance(); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e10) { throw new LoadingException("Failed to instantiate module class: ".concat(String.valueOf(str)), e10, null); } } }