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: classes3.dex */
final class s implements t3 {

    /* renamed from: g, reason: collision with root package name */
    private static final rj.h0 f14058g = new rj.h0("AssetPackServiceImpl");

    /* renamed from: h, reason: collision with root package name */
    private static final Intent f14059h = 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 f14060a;

    /* renamed from: b, reason: collision with root package name */
    private final h1 f14061b;

    /* renamed from: c, reason: collision with root package name */
    private final p2 f14062c;

    /* renamed from: d, reason: collision with root package name */
    private rj.s0 f14063d;

    /* renamed from: e, reason: collision with root package name */
    private rj.s0 f14064e;

    /* renamed from: f, reason: collision with root package name */
    private final AtomicBoolean f14065f = new AtomicBoolean();

    /* JADX INFO: Access modifiers changed from: package-private */
    /* JADX WARN: Type inference failed for: r10v3, types: [qj.b] */
    /* JADX WARN: Type inference failed for: r5v0, types: [qj.b] */
    public s(Context context, h1 h1Var, p2 p2Var) {
        this.f14060a = context.getPackageName();
        this.f14061b = h1Var;
        this.f14062c = p2Var;
        if (rj.h.b(context)) {
            Context a10 = rj.f.a(context);
            rj.h0 h0Var = f14058g;
            Intent intent = f14059h;
            this.f14063d = new rj.s0(a10, h0Var, "AssetPackService", intent, new Object() { // from class: qj.b
            }, null);
            this.f14064e = new rj.s0(rj.f.a(context), h0Var, "AssetPackService-keepAlive", intent, new Object() { // from class: qj.b
            }, null);
        }
        f14058g.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<Integer> arrayList = new ArrayList<>();
        arrayList.add(0);
        arrayList.add(1);
        bundle.putIntegerArrayList("supported_compression_formats", arrayList);
        ArrayList<Integer> 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() {
        f14058g.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.f14063d == null) {
            throw new d1("The Play Store app is not installed or is an unofficial version.", i10);
        }
        f14058g.d("notifyModuleCompleted", new Object[0]);
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        this.f14063d.s(new g(this, taskCompletionSource, i10, str, taskCompletionSource, i11), taskCompletionSource);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public 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;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static /* bridge */ /* synthetic */ Bundle n(Map map) {
        Bundle g10 = g();
        ArrayList<? extends Parcelable> 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;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public 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;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public 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.f14061b, sVar.f14062c).c().values().iterator().next();
            if (assetPackState == null) {
                f14058g.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.f14063d == null) {
            throw new d1("The Play Store app is not installed or is an unofficial version.", i10);
        }
        f14058g.d("notifySessionFailed", new Object[0]);
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        this.f14063d.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.f14063d == null) {
            return;
        }
        f14058g.d("cancelDownloads(%s)", list);
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        this.f14063d.s(new d(this, taskCompletionSource, list, taskCompletionSource), taskCompletionSource);
    }

    @Override // com.google.android.play.core.assetpacks.t3
    public final Task d(Map map) {
        if (this.f14063d == null) {
            return i();
        }
        f14058g.d("syncPacks", new Object[0]);
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        this.f14063d.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.f14063d == null) {
            throw new d1("The Play Store app is not installed or is an unofficial version.", i10);
        }
        f14058g.d("notifyChunkTransferred", new Object[0]);
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        this.f14063d.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.f14063d == null) {
            return i();
        }
        f14058g.d("getChunkFileDescriptor(%s, %s, %d, session=%d)", str, str2, Integer.valueOf(i11), Integer.valueOf(i10));
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        this.f14063d.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.f14064e == null) {
            f14058g.e("Keep alive connection manager is not initialized.", new Object[0]);
            return;
        }
        rj.h0 h0Var = f14058g;
        h0Var.d("keepAlive", new Object[0]);
        if (!this.f14065f.compareAndSet(false, true)) {
            h0Var.d("Service is already kept alive.", new Object[0]);
        } else {
            TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
            this.f14064e.s(new j(this, taskCompletionSource, taskCompletionSource), taskCompletionSource);
        }
    }
}
