package com.google.android.play.core.assetpacks; import android.content.Intent; import android.os.Bundle; import com.google.android.gms.ads.RequestConfiguration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.locks.ReentrantLock; /* loaded from: classes2.dex */ final class w1 { /* renamed from: g, reason: collision with root package name */ private static final r3.h0 f5120g = new r3.h0("ExtractorSessionStoreView"); /* renamed from: a, reason: collision with root package name */ private final e0 f5121a; /* renamed from: b, reason: collision with root package name */ private final h1 f5122b; /* renamed from: c, reason: collision with root package name */ private final Map f5123c = new HashMap(); /* renamed from: d, reason: collision with root package name */ private final ReentrantLock f5124d = new ReentrantLock(); /* renamed from: e, reason: collision with root package name */ private final r3.o f5125e; /* renamed from: f, reason: collision with root package name */ private final r3.o f5126f; w1(e0 e0Var, r3.o oVar, h1 h1Var, r3.o oVar2) { this.f5121a = e0Var; this.f5125e = oVar; this.f5122b = h1Var; this.f5126f = oVar2; } private final t1 o(int i10) { Map map = this.f5123c; Integer valueOf = Integer.valueOf(i10); t1 t1Var = (t1) map.get(valueOf); if (t1Var != null) { return t1Var; } throw new d1(String.format("Could not find session %d while trying to get it", valueOf), i10); } private final Object p(v1 v1Var) { try { this.f5124d.lock(); return v1Var.a(); } finally { this.f5124d.unlock(); } } private static String q(Bundle bundle) { ArrayList stringArrayList = bundle.getStringArrayList("pack_names"); if (stringArrayList == null || stringArrayList.isEmpty()) { throw new d1("Session without pack received."); } return stringArrayList.get(0); } private static List r(List list) { return list == null ? Collections.emptyList() : list; } private final Map s(final List list) { return (Map) p(new v1() { // from class: com.google.android.play.core.assetpacks.n1 @Override // com.google.android.play.core.assetpacks.v1 public final Object a() { return w1.this.g(list); } }); } final /* synthetic */ Boolean a(Bundle bundle) { int i10 = bundle.getInt("session_id"); if (i10 == 0) { return Boolean.TRUE; } Map map = this.f5123c; Integer valueOf = Integer.valueOf(i10); if (!map.containsKey(valueOf)) { return Boolean.TRUE; } if (((t1) this.f5123c.get(valueOf)).f5058c.f5048d == 6) { return Boolean.FALSE; } return Boolean.valueOf(!d0.c(r0.f5058c.f5048d, bundle.getInt(s3.b.a("status", q(bundle))))); } final /* synthetic */ Boolean b(Bundle bundle) { int i10 = bundle.getInt("session_id"); if (i10 == 0) { return Boolean.FALSE; } Map map = this.f5123c; Integer valueOf = Integer.valueOf(i10); boolean z10 = true; if (map.containsKey(valueOf)) { t1 o10 = o(i10); int i11 = bundle.getInt(s3.b.a("status", o10.f5058c.f5045a)); s1 s1Var = o10.f5058c; int i12 = s1Var.f5048d; if (d0.c(i12, i11)) { f5120g.a("Found stale update for session %s with status %d.", valueOf, Integer.valueOf(i12)); s1 s1Var2 = o10.f5058c; int i13 = s1Var2.f5048d; String str = s1Var2.f5045a; if (i13 == 4) { ((t3) this.f5125e.a()).b(i10, str); } else if (i13 == 5) { ((t3) this.f5125e.a()).a(i10); } else if (i13 == 6) { ((t3) this.f5125e.a()).c(Arrays.asList(str)); } } else { s1Var.f5048d = i11; if (d0.d(i11)) { l(i10); this.f5122b.c(o10.f5058c.f5045a); } else { for (u1 u1Var : s1Var.f5050f) { ArrayList parcelableArrayList = bundle.getParcelableArrayList(s3.b.b("chunk_intents", o10.f5058c.f5045a, u1Var.f5073a)); if (parcelableArrayList != null) { for (int i14 = 0; i14 < parcelableArrayList.size(); i14++) { if (parcelableArrayList.get(i14) != null && ((Intent) parcelableArrayList.get(i14)).getData() != null) { ((q1) u1Var.f5076d.get(i14)).f5026a = true; } } } } } } } else { String q10 = q(bundle); long j10 = bundle.getLong(s3.b.a("pack_version", q10)); String string = bundle.getString(s3.b.a("pack_version_tag", q10), RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); int i15 = bundle.getInt(s3.b.a("status", q10)); long j11 = bundle.getLong(s3.b.a("total_bytes_to_download", q10)); ArrayList stringArrayList = bundle.getStringArrayList(s3.b.a("slice_ids", q10)); ArrayList arrayList = new ArrayList(); for (String str2 : r(stringArrayList)) { ArrayList parcelableArrayList2 = bundle.getParcelableArrayList(s3.b.b("chunk_intents", q10, str2)); ArrayList arrayList2 = new ArrayList(); Iterator it = r(parcelableArrayList2).iterator(); while (it.hasNext()) { if (((Intent) it.next()) == null) { z10 = false; } arrayList2.add(new q1(z10)); z10 = true; } String string2 = bundle.getString(s3.b.b("uncompressed_hash_sha256", q10, str2)); long j12 = bundle.getLong(s3.b.b("uncompressed_size", q10, str2)); int i16 = bundle.getInt(s3.b.b("patch_format", q10, str2), 0); arrayList.add(i16 != 0 ? new u1(str2, string2, j12, arrayList2, 0, i16) : new u1(str2, string2, j12, arrayList2, bundle.getInt(s3.b.b("compression_format", q10, str2), 0), 0)); z10 = true; } this.f5123c.put(Integer.valueOf(i10), new t1(i10, bundle.getInt("app_version_code"), new s1(q10, j10, i15, j11, arrayList, string))); } return Boolean.TRUE; } final /* synthetic */ Object c(String str, int i10, long j10) { t1 t1Var = (t1) s(Arrays.asList(str)).get(str); if (t1Var == null || d0.d(t1Var.f5058c.f5048d)) { f5120g.b(String.format("Could not find pack %s while trying to complete it", str), new Object[0]); } this.f5121a.d(str, i10, j10); t1Var.f5058c.f5048d = 4; return null; } final /* synthetic */ Object d(int i10, int i11) { o(i10).f5058c.f5048d = 5; return null; } final /* synthetic */ Object e(int i10) { t1 o10 = o(i10); s1 s1Var = o10.f5058c; if (!d0.d(s1Var.f5048d)) { throw new d1(String.format("Could not safely delete session %d because it is not in a terminal state.", Integer.valueOf(i10)), i10); } this.f5121a.d(s1Var.f5045a, o10.f5057b, s1Var.f5046b); s1 s1Var2 = o10.f5058c; int i11 = s1Var2.f5048d; if (i11 != 5 && i11 != 6) { return null; } this.f5121a.e(s1Var2.f5045a, o10.f5057b, s1Var2.f5046b); return null; } final Map f() { return this.f5123c; } final /* synthetic */ Map g(List list) { HashMap hashMap = new HashMap(); for (t1 t1Var : this.f5123c.values()) { String str = t1Var.f5058c.f5045a; if (list.contains(str)) { t1 t1Var2 = (t1) hashMap.get(str); if ((t1Var2 == null ? -1 : t1Var2.f5056a) < t1Var.f5056a) { hashMap.put(str, t1Var); } } } return hashMap; } final void h() { this.f5124d.lock(); } final void i(final String str, final int i10, final long j10) { p(new v1() { // from class: com.google.android.play.core.assetpacks.l1 @Override // com.google.android.play.core.assetpacks.v1 public final Object a() { w1.this.c(str, i10, j10); return null; } }); } final void j() { this.f5124d.unlock(); } final void k(final int i10, int i11) { final int i12 = 5; p(new v1(i10, i12) { // from class: com.google.android.play.core.assetpacks.m1 /* renamed from: b, reason: collision with root package name */ public final /* synthetic */ int f4983b; @Override // com.google.android.play.core.assetpacks.v1 public final Object a() { w1.this.d(this.f4983b, 5); return null; } }); } final void l(final int i10) { p(new v1() { // from class: com.google.android.play.core.assetpacks.k1 @Override // com.google.android.play.core.assetpacks.v1 public final Object a() { w1.this.e(i10); return null; } }); } final boolean m(final Bundle bundle) { return ((Boolean) p(new v1() { // from class: com.google.android.play.core.assetpacks.p1 @Override // com.google.android.play.core.assetpacks.v1 public final Object a() { return w1.this.a(bundle); } })).booleanValue(); } final boolean n(final Bundle bundle) { return ((Boolean) p(new v1() { // from class: com.google.android.play.core.assetpacks.o1 @Override // com.google.android.play.core.assetpacks.v1 public final Object a() { return w1.this.b(bundle); } })).booleanValue(); } }