package a4; import android.content.Context; import android.content.SharedPreferences; import android.text.TextUtils; import com.google.android.gms.common.internal.Preconditions; import com.google.android.gms.common.logging.Logger; import com.google.android.gms.internal.p002firebaseauthapi.zzadu; import com.google.android.gms.internal.p002firebaseauthapi.zzwk; import com.unity3d.ads.metadata.MediationMetaData; import java.util.List; import org.json.JSONArray; import org.json.JSONObject; /* loaded from: classes2.dex */ public final class h0 { /* renamed from: a, reason: collision with root package name */ private final Context f85a; /* renamed from: b, reason: collision with root package name */ private final String f86b; /* renamed from: c, reason: collision with root package name */ private final SharedPreferences f87c; /* renamed from: d, reason: collision with root package name */ private final Logger f88d; public h0(Context context, String str) { Preconditions.checkNotNull(context); String checkNotEmpty = Preconditions.checkNotEmpty(str); this.f86b = checkNotEmpty; Context applicationContext = context.getApplicationContext(); this.f85a = applicationContext; this.f87c = applicationContext.getSharedPreferences(String.format("com.google.firebase.auth.api.Store.%s", checkNotEmpty), 0); this.f88d = new Logger("StorageHelpers", new String[0]); } /* JADX WARN: Removed duplicated region for block: B:31:0x00d0 A[Catch: zzwk -> 0x017e, IllegalArgumentException -> 0x0180, ArrayIndexOutOfBoundsException -> 0x0182, JSONException -> 0x0184, TRY_ENTER, TryCatch #0 {JSONException -> 0x0184, blocks: (B:3:0x0007, B:6:0x0024, B:10:0x003a, B:13:0x0078, B:16:0x007f, B:17:0x008b, B:20:0x008c, B:22:0x009b, B:24:0x00a4, B:25:0x00a7, B:27:0x00b0, B:31:0x00d0, B:36:0x00d3, B:38:0x00d9, B:40:0x00df, B:41:0x00e5, B:43:0x00eb, B:46:0x0106, B:48:0x010e, B:50:0x0163, B:52:0x0125, B:53:0x012c, B:57:0x0133, B:62:0x013c, B:64:0x0144, B:66:0x0150, B:69:0x016a, B:70:0x0171, B:72:0x0172, B:73:0x0179, B:75:0x017a), top: B:2:0x0007 }] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private final a4.e1 f(org.json.JSONObject r27) { /* Method dump skipped, instructions count: 397 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: a4.h0.f(org.json.JSONObject):a4.e1"); } public final com.google.firebase.auth.t a() { String string = this.f87c.getString("com.google.firebase.auth.FIREBASE_USER", null); if (TextUtils.isEmpty(string)) { return null; } try { JSONObject jSONObject = new JSONObject(string); if (jSONObject.has("type") && "com.google.firebase.auth.internal.DefaultFirebaseUser".equalsIgnoreCase(jSONObject.optString("type"))) { return f(jSONObject); } } catch (Exception unused) { } return null; } public final zzadu b(com.google.firebase.auth.t tVar) { Preconditions.checkNotNull(tVar); String string = this.f87c.getString(String.format("com.google.firebase.auth.GET_TOKEN_RESPONSE.%s", tVar.Y()), null); if (string != null) { return zzadu.zzd(string); } return null; } public final void c(String str) { this.f87c.edit().remove(str).apply(); } public final void d(com.google.firebase.auth.t tVar) { Preconditions.checkNotNull(tVar); JSONObject jSONObject = new JSONObject(); String str = null; if (e1.class.isAssignableFrom(tVar.getClass())) { e1 e1Var = (e1) tVar; try { jSONObject.put("cachedTokenState", e1Var.zzf()); jSONObject.put("applicationName", e1Var.u0().n()); jSONObject.put("type", "com.google.firebase.auth.internal.DefaultFirebaseUser"); if (e1Var.F0() != null) { JSONArray jSONArray = new JSONArray(); List F0 = e1Var.F0(); int size = F0.size(); if (F0.size() > 30) { this.f88d.w("Provider user info list size larger than max size, truncating list to %d. Actual list size: %d", 30, Integer.valueOf(F0.size())); size = 30; } boolean z10 = false; for (int i10 = 0; i10 < size; i10++) { a1 a1Var = (a1) F0.get(i10); z10 |= a1Var.I().equals("firebase"); if (i10 == size - 1 && !z10) { break; } jSONArray.put(a1Var.zzb()); } if (!z10) { for (int i11 = size - 1; i11 < F0.size(); i11++) { a1 a1Var2 = (a1) F0.get(i11); if (a1Var2.I().equals("firebase")) { jSONArray.put(a1Var2.zzb()); } } this.f88d.w("Malformed user object! No Firebase Auth provider id found.", new Object[0]); } jSONObject.put("userInfos", jSONArray); } jSONObject.put("anonymous", e1Var.a0()); jSONObject.put(MediationMetaData.KEY_VERSION, "2"); if (e1Var.r0() != null) { jSONObject.put("userMetadata", ((g1) e1Var.r0()).a()); } List a10 = new c(e1Var).a(); if (!a10.isEmpty()) { JSONArray jSONArray2 = new JSONArray(); for (int i12 = 0; i12 < a10.size(); i12++) { jSONArray2.put(((com.google.firebase.auth.b0) a10.get(i12)).toJson()); } jSONObject.put("userMultiFactorInfo", jSONArray2); } str = jSONObject.toString(); } catch (Exception e10) { this.f88d.wtf("Failed to turn object into JSON", e10, new Object[0]); throw new zzwk(e10); } } if (TextUtils.isEmpty(str)) { return; } this.f87c.edit().putString("com.google.firebase.auth.FIREBASE_USER", str).apply(); } public final void e(com.google.firebase.auth.t tVar, zzadu zzaduVar) { Preconditions.checkNotNull(tVar); Preconditions.checkNotNull(zzaduVar); this.f87c.edit().putString(String.format("com.google.firebase.auth.GET_TOKEN_RESPONSE.%s", tVar.Y()), zzaduVar.zzh()).apply(); } }