package com.google.android.play.core.assetpacks;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.google.android.play.core.b.au;
import com.google.android.play.core.b.b;
import com.google.android.play.core.b.ca;
import com.google.android.play.core.b.l;
import com.google.android.play.core.d.q;
import com.google.android.play.core.tasks.e;
import com.google.android.play.core.tasks.g;
import com.google.android.play.core.tasks.p;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

public final class r implements dk {
    public static final b LIZ = new b("AssetPackServiceImpl");
    public static final Intent LJI = new Intent("com.google.android.play.core.assetmoduleservice.BIND_ASSET_MODULE_SERVICE").setPackage("com.android.vending");
    public final String LIZIZ;
    public final ay LIZJ;
    public l<ca> LIZLLL;
    public l<ca> LJ;
    public final AtomicBoolean LJFF = new AtomicBoolean();

    static {
        Covode.recordClassIndex(44214);
    }

    public r(Context context, ay ayVar) {
        this.LIZIZ = context.getPackageName();
        this.LIZJ = ayVar;
        if (au.LIZ(context)) {
            Context LIZ2 = q.LIZ(context);
            b bVar = LIZ;
            Intent intent = LJI;
            this.LIZLLL = new l<>(LIZ2, bVar, "AssetPackService", intent, dl.LIZ);
            this.LJ = new l<>(q.LIZ(context), bVar, "AssetPackService-keepAlive", intent, dm.LIZ);
        }
        LIZ.LIZ("AssetPackService initiated.", new Object[0]);
    }

    public static Bundle LIZIZ() {
        Bundle bundle = new Bundle();
        bundle.putInt("playcore_version_code", 10900);
        ArrayList arrayList = new ArrayList();
        arrayList.add(0);
        arrayList.add(1);
        bundle.putIntegerArrayList("supported_compression_formats", arrayList);
        bundle.putIntegerArrayList("supported_patch_formats", new ArrayList());
        return bundle;
    }

    public static Bundle LIZIZ(int i) {
        Bundle bundle = new Bundle();
        bundle.putInt("session_id", i);
        return bundle;
    }

    public static Bundle LIZIZ(int i, String str) {
        Bundle LIZIZ2 = LIZIZ(i);
        LIZIZ2.putString("module_name", str);
        return LIZIZ2;
    }

    public static /* synthetic */ Bundle LIZJ(int i, String str, String str2, int i2) {
        Bundle LIZIZ2 = LIZIZ(i, str);
        LIZIZ2.putString("slice_id", str2);
        LIZIZ2.putInt("chunk_number", i2);
        return LIZIZ2;
    }

    public static <T> e<T> LIZJ() {
        LIZ.LIZIZ("onError(%d)", -11);
        return g.LIZ((Exception) new a(-11));
    }

    public final e<List<String>> LIZ(Map<String, Long> map) {
        if (this.LIZLLL == null) {
            return LIZJ();
        }
        LIZ.LIZJ("syncPacks", new Object[0]);
        p pVar = new p();
        this.LIZLLL.LIZ(new g(this, pVar, map, pVar));
        return pVar.LIZ;
    }

    public final synchronized void LIZ() {
        MethodCollector.i(11156);
        if (this.LJ == null) {
            LIZ.LIZLLL("Keep alive connection manager is not initialized.", new Object[0]);
            MethodCollector.o(11156);
            return;
        }
        b bVar = LIZ;
        bVar.LIZJ("keepAlive", new Object[0]);
        if (!this.LJFF.compareAndSet(false, true)) {
            bVar.LIZJ("Service is already kept alive.", new Object[0]);
            MethodCollector.o(11156);
            return;
        }
        p pVar = new p();
        this.LJ.LIZ(new l(this, pVar, pVar));
        MethodCollector.o(11156);
    }

    public final void LIZ(int i) {
        if (this.LIZLLL != null) {
            LIZ.LIZJ("notifySessionFailed", new Object[0]);
            p pVar = new p();
            this.LIZLLL.LIZ(new j(this, pVar, i, pVar));
            return;
        }
        throw new au("The Play Store app is not installed or is an unofficial version.", i);
    }

    public final void LIZ(int i, String str) {
        LIZ(i, str, 10);
    }

    public final void LIZ(int i, String str, int i2) {
        int i3 = i;
        if (this.LIZLLL != null) {
            LIZ.LIZJ("notifyModuleCompleted", new Object[0]);
            p pVar = new p();
            this.LIZLLL.LIZ(new i(this, pVar, i3, str, pVar, i2));
            return;
        }
        throw new au("The Play Store app is not installed or is an unofficial version.", i3);
    }

    public final void LIZ(int i, String str, String str2, int i2) {
        int i3 = i;
        if (this.LIZLLL != null) {
            LIZ.LIZJ("notifyChunkTransferred", new Object[0]);
            p pVar = new p();
            this.LIZLLL.LIZ(new h(this, pVar, i3, str, str2, i2, pVar));
            return;
        }
        throw new au("The Play Store app is not installed or is an unofficial version.", i3);
    }

    public final void LIZ(List<String> list) {
        if (this.LIZLLL != null) {
            LIZ.LIZJ("cancelDownloads(%s)", list);
            p pVar = new p();
            this.LIZLLL.LIZ(new f(this, pVar, list, pVar));
        }
    }

    public final e<ParcelFileDescriptor> LIZIZ(int i, String str, String str2, int i2) {
        if (this.LIZLLL == null) {
            return LIZJ();
        }
        String str3 = str;
        String str4 = str2;
        int i3 = i2;
        int i4 = i;
        LIZ.LIZJ("getChunkFileDescriptor(%s, %s, %d, session=%d)", str3, str4, Integer.valueOf(i3), Integer.valueOf(i4));
        p pVar = new p();
        this.LIZLLL.LIZ(new k(this, pVar, i4, str3, str4, i3, pVar));
        return pVar.LIZ;
    }
}
