package com.google.android.gms.internal.measurement; import android.content.Context; import android.content.SharedPreferences; import android.os.StrictMode; import androidx.annotation.GuardedBy; import androidx.annotation.Nullable; import androidx.collection.ArrayMap; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; /* loaded from: classes3.dex */ public final class zzhj implements zzgo { @GuardedBy("SharedPreferencesLoader.class") private static final Map zza = new ArrayMap(); private final SharedPreferences zzb; private final Runnable zzc; private final SharedPreferences.OnSharedPreferenceChangeListener zzd; private final Object zze; private volatile Map zzf; @GuardedBy("this") private final List zzg; private static SharedPreferences zza(Context context, String str) { StrictMode.ThreadPolicy allowThreadDiskReads = StrictMode.allowThreadDiskReads(); try { if (!str.startsWith("direct_boot:")) { SharedPreferences sharedPreferences = context.getSharedPreferences(str, 0); StrictMode.setThreadPolicy(allowThreadDiskReads); return sharedPreferences; } if (zzgf.zza()) { context = context.createDeviceProtectedStorageContext(); } SharedPreferences sharedPreferences2 = context.getSharedPreferences(str.substring(12), 0); StrictMode.setThreadPolicy(allowThreadDiskReads); return sharedPreferences2; } catch (Throwable th) { StrictMode.setThreadPolicy(allowThreadDiskReads); throw th; } } @Nullable public static zzhj zza(Context context, String str, Runnable runnable) { zzhj zzhjVar; if (zzgf.zza() && !str.startsWith("direct_boot:") && !zzgf.zzb(context)) { return null; } synchronized (zzhj.class) { try { Map map = zza; zzhjVar = map.get(str); if (zzhjVar == null) { zzhjVar = new zzhj(zza(context, str), runnable); map.put(str, zzhjVar); } } catch (Throwable th) { throw th; } } return zzhjVar; } @Override // com.google.android.gms.internal.measurement.zzgo @Nullable public final Object zza(String str) { Map map = this.zzf; if (map == null) { synchronized (this.zze) { try { map = this.zzf; if (map == null) { StrictMode.ThreadPolicy allowThreadDiskReads = StrictMode.allowThreadDiskReads(); try { Map all = this.zzb.getAll(); this.zzf = all; StrictMode.setThreadPolicy(allowThreadDiskReads); map = all; } catch (Throwable th) { StrictMode.setThreadPolicy(allowThreadDiskReads); throw th; } } } finally { } } } if (map != null) { return map.get(str); } return null; } private zzhj(SharedPreferences sharedPreferences, Runnable runnable) { SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() { // from class: com.google.android.gms.internal.measurement.zzhi @Override // android.content.SharedPreferences.OnSharedPreferenceChangeListener public final void onSharedPreferenceChanged(SharedPreferences sharedPreferences2, String str) { zzhj.this.zza(sharedPreferences2, str); } }; this.zzd = onSharedPreferenceChangeListener; this.zze = new Object(); this.zzg = new ArrayList(); this.zzb = sharedPreferences; this.zzc = runnable; sharedPreferences.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener); } public static synchronized void zza() { synchronized (zzhj.class) { try { for (zzhj zzhjVar : zza.values()) { zzhjVar.zzb.unregisterOnSharedPreferenceChangeListener(zzhjVar.zzd); } zza.clear(); } catch (Throwable th) { throw th; } } } public final /* synthetic */ void zza(SharedPreferences sharedPreferences, String str) { synchronized (this.zze) { this.zzf = null; this.zzc.run(); } synchronized (this) { try { Iterator it = this.zzg.iterator(); while (it.hasNext()) { it.next().zza(); } } catch (Throwable th) { throw th; } } } }