package com.google.android.play.core.assetpacks; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Parcelable; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import com.google.android.gms.tasks.Tasks; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; /* loaded from: classes2.dex */ final class s implements t3 { /* renamed from: g, reason: collision with root package name */ private static final r3.h0 f5036g = new r3.h0("AssetPackServiceImpl"); /* renamed from: h, reason: collision with root package name */ private static final Intent f5037h = new Intent("com.google.android.play.core.assetmoduleservice.BIND_ASSET_MODULE_SERVICE").setPackage("com.android.vending"); /* renamed from: a, reason: collision with root package name */ private final String f5038a; /* renamed from: b, reason: collision with root package name */ private final h1 f5039b; /* renamed from: c, reason: collision with root package name */ private final p2 f5040c; /* renamed from: d, reason: collision with root package name */ private r3.s0 f5041d; /* renamed from: e, reason: collision with root package name */ private r3.s0 f5042e; /* renamed from: f, reason: collision with root package name */ private final AtomicBoolean f5043f = new AtomicBoolean(); /* JADX WARN: Type inference failed for: r10v2, types: [q3.b] */ /* JADX WARN: Type inference failed for: r5v0, types: [q3.b] */ s(Context context, h1 h1Var, p2 p2Var) { this.f5038a = context.getPackageName(); this.f5039b = h1Var; this.f5040c = p2Var; if (r3.h.b(context)) { Context a10 = r3.f.a(context); r3.h0 h0Var = f5036g; Intent intent = f5037h; this.f5041d = new r3.s0(a10, h0Var, "AssetPackService", intent, new Object() { // from class: q3.b }, null); this.f5042e = new r3.s0(r3.f.a(context), h0Var, "AssetPackService-keepAlive", intent, new Object() { // from class: q3.b }, null); } f5036g.a("AssetPackService initiated.", new Object[0]); } /* JADX INFO: Access modifiers changed from: private */ public static Bundle g() { Bundle bundle = new Bundle(); bundle.putInt("playcore_version_code", 20202); ArrayList arrayList = new ArrayList<>(); arrayList.add(0); arrayList.add(1); bundle.putIntegerArrayList("supported_compression_formats", arrayList); ArrayList arrayList2 = new ArrayList<>(); arrayList2.add(1); arrayList2.add(2); bundle.putIntegerArrayList("supported_patch_formats", arrayList2); return bundle; } /* JADX INFO: Access modifiers changed from: private */ public static Bundle h(int i10) { Bundle bundle = new Bundle(); bundle.putInt("session_id", i10); return bundle; } private static Task i() { f5036g.b("onError(%d)", -11); return Tasks.forException(new a(-11)); } /* JADX INFO: Access modifiers changed from: private */ public final void j(int i10, String str, int i11) { if (this.f5041d == null) { throw new d1("The Play Store app is not installed or is an unofficial version.", i10); } f5036g.d("notifyModuleCompleted", new Object[0]); TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.f5041d.s(new g(this, taskCompletionSource, i10, str, taskCompletionSource, i11), taskCompletionSource); } static /* bridge */ /* synthetic */ Bundle k(int i10, String str, String str2, int i11) { Bundle x10 = x(i10, str); x10.putString("slice_id", str2); x10.putInt("chunk_number", i11); return x10; } static /* bridge */ /* synthetic */ Bundle n(Map map) { Bundle g10 = g(); ArrayList arrayList = new ArrayList<>(); for (Map.Entry entry : map.entrySet()) { Bundle bundle = new Bundle(); bundle.putString("installed_asset_module_name", (String) entry.getKey()); bundle.putLong("installed_asset_module_version", ((Long) entry.getValue()).longValue()); arrayList.add(bundle); } g10.putParcelableArrayList("installed_asset_module", arrayList); return g10; } static /* bridge */ /* synthetic */ ArrayList t(Collection collection) { ArrayList arrayList = new ArrayList(collection.size()); Iterator it = collection.iterator(); while (it.hasNext()) { String str = (String) it.next(); Bundle bundle = new Bundle(); bundle.putString("module_name", str); arrayList.add(bundle); } return arrayList; } static /* bridge */ /* synthetic */ List u(s sVar, List list) { ArrayList arrayList = new ArrayList(); Iterator it = list.iterator(); while (it.hasNext()) { AssetPackState assetPackState = (AssetPackState) c.a((Bundle) it.next(), sVar.f5039b, sVar.f5040c).c().values().iterator().next(); if (assetPackState == null) { f5036g.b("onGetSessionStates: Bundle contained no pack.", new Object[0]); } if (d0.a(assetPackState.h())) { arrayList.add(assetPackState.g()); } } return arrayList; } /* JADX INFO: Access modifiers changed from: private */ public static Bundle x(int i10, String str) { Bundle h10 = h(i10); h10.putString("module_name", str); return h10; } @Override // com.google.android.play.core.assetpacks.t3 public final void a(int i10) { if (this.f5041d == null) { throw new d1("The Play Store app is not installed or is an unofficial version.", i10); } f5036g.d("notifySessionFailed", new Object[0]); TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.f5041d.s(new h(this, taskCompletionSource, i10, taskCompletionSource), taskCompletionSource); } @Override // com.google.android.play.core.assetpacks.t3 public final void b(int i10, String str) { j(i10, str, 10); } @Override // com.google.android.play.core.assetpacks.t3 public final void c(List list) { if (this.f5041d == null) { return; } f5036g.d("cancelDownloads(%s)", list); TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.f5041d.s(new d(this, taskCompletionSource, list, taskCompletionSource), taskCompletionSource); } @Override // com.google.android.play.core.assetpacks.t3 public final Task d(Map map) { if (this.f5041d == null) { return i(); } f5036g.d("syncPacks", new Object[0]); TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.f5041d.s(new e(this, taskCompletionSource, map, taskCompletionSource), taskCompletionSource); return taskCompletionSource.getTask(); } @Override // com.google.android.play.core.assetpacks.t3 public final void e(int i10, String str, String str2, int i11) { if (this.f5041d == null) { throw new d1("The Play Store app is not installed or is an unofficial version.", i10); } f5036g.d("notifyChunkTransferred", new Object[0]); TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.f5041d.s(new f(this, taskCompletionSource, i10, str, str2, i11, taskCompletionSource), taskCompletionSource); } @Override // com.google.android.play.core.assetpacks.t3 public final Task f(int i10, String str, String str2, int i11) { if (this.f5041d == null) { return i(); } f5036g.d("getChunkFileDescriptor(%s, %s, %d, session=%d)", str, str2, Integer.valueOf(i11), Integer.valueOf(i10)); TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.f5041d.s(new i(this, taskCompletionSource, i10, str, str2, i11, taskCompletionSource), taskCompletionSource); return taskCompletionSource.getTask(); } @Override // com.google.android.play.core.assetpacks.t3 public final synchronized void f() { if (this.f5042e == null) { f5036g.e("Keep alive connection manager is not initialized.", new Object[0]); return; } r3.h0 h0Var = f5036g; h0Var.d("keepAlive", new Object[0]); if (!this.f5043f.compareAndSet(false, true)) { h0Var.d("Service is already kept alive.", new Object[0]); } else { TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.f5042e.s(new j(this, taskCompletionSource, taskCompletionSource), taskCompletionSource); } } }