package oj;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
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.HashMap;
import java.util.HashSet;
import java.util.Map;

/* loaded from: classes3.dex */
final class u {

    /* renamed from: e, reason: collision with root package name */
    private static final pj.p f31528e = new pj.p("AppUpdateService");

    /* renamed from: f, reason: collision with root package name */
    private static final Intent f31529f = new Intent("com.google.android.play.core.install.BIND_UPDATE_SERVICE").setPackage("com.android.vending");

    /* renamed from: a, reason: collision with root package name */
    pj.a0 f31530a;

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

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

    /* renamed from: d, reason: collision with root package name */
    private final w f31533d;

    /* JADX INFO: Access modifiers changed from: package-private */
    public u(Context context, w wVar) {
        this.f31531b = context.getPackageName();
        this.f31532c = context;
        this.f31533d = wVar;
        if (pj.c.a(context)) {
            this.f31530a = new pj.a0(pj.c0.a(context), f31528e, "AppUpdateService", f31529f, q.f31519a, null);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static /* bridge */ /* synthetic */ Bundle b(u uVar, String str) {
        Integer num;
        Bundle bundle = new Bundle();
        bundle.putAll(g());
        bundle.putString("package.name", str);
        try {
            num = Integer.valueOf(uVar.f31532c.getPackageManager().getPackageInfo(uVar.f31532c.getPackageName(), 0).versionCode);
        } catch (PackageManager.NameNotFoundException unused) {
            f31528e.a("The current version of the app could not be retrieved", new Object[0]);
            num = null;
        }
        if (num != null) {
            bundle.putInt("app.version.code", num.intValue());
        }
        return bundle;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static /* bridge */ /* synthetic */ a d(u uVar, Bundle bundle, String str) {
        int i10 = bundle.getInt("version.code", -1);
        int i11 = bundle.getInt("update.availability");
        int i12 = bundle.getInt("install.status", 0);
        Integer valueOf = bundle.getInt("client.version.staleness", -1) == -1 ? null : Integer.valueOf(bundle.getInt("client.version.staleness"));
        int i13 = bundle.getInt("in.app.update.priority", 0);
        long j10 = bundle.getLong("bytes.downloaded");
        long j11 = bundle.getLong("total.bytes.to.download");
        long j12 = bundle.getLong("additional.size.required");
        long a10 = uVar.f31533d.a();
        PendingIntent pendingIntent = (PendingIntent) bundle.getParcelable("blocking.intent");
        PendingIntent pendingIntent2 = (PendingIntent) bundle.getParcelable("nonblocking.intent");
        PendingIntent pendingIntent3 = (PendingIntent) bundle.getParcelable("blocking.destructive.intent");
        PendingIntent pendingIntent4 = (PendingIntent) bundle.getParcelable("nonblocking.destructive.intent");
        HashMap hashMap = new HashMap();
        hashMap.put("blocking.destructive.intent", i(bundle.getIntegerArrayList("update.precondition.failures:blocking.destructive.intent")));
        hashMap.put("nonblocking.destructive.intent", i(bundle.getIntegerArrayList("update.precondition.failures:nonblocking.destructive.intent")));
        hashMap.put("blocking.intent", i(bundle.getIntegerArrayList("update.precondition.failures:blocking.intent")));
        hashMap.put("nonblocking.intent", i(bundle.getIntegerArrayList("update.precondition.failures:nonblocking.intent")));
        return a.e(str, i10, i11, i12, valueOf, i13, j10, j11, j12, a10, pendingIntent, pendingIntent2, pendingIntent3, pendingIntent4, hashMap);
    }

    private static Bundle g() {
        Bundle bundle = new Bundle();
        Bundle bundle2 = new Bundle();
        Map a10 = pj.n.a("app_update");
        bundle2.putInt("playcore_version_code", ((Integer) a10.get("java")).intValue());
        if (a10.containsKey("native")) {
            bundle2.putInt("playcore_native_version", ((Integer) a10.get("native")).intValue());
        }
        if (a10.containsKey("unity")) {
            bundle2.putInt("playcore_unity_version", ((Integer) a10.get("unity")).intValue());
        }
        bundle.putAll(bundle2);
        bundle.putInt("playcore.version.code", 11004);
        return bundle;
    }

    private static Task h() {
        f31528e.a("onError(%d)", -9);
        return Tasks.forException(new uj.a(-9));
    }

    private static HashSet i(ArrayList arrayList) {
        HashSet hashSet = new HashSet();
        if (arrayList != null) {
            hashSet.addAll(arrayList);
        }
        return hashSet;
    }

    public final Task c(String str) {
        if (this.f31530a == null) {
            return h();
        }
        f31528e.c("requestUpdateInfo(%s)", str);
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        this.f31530a.s(new r(this, taskCompletionSource, str, taskCompletionSource), taskCompletionSource);
        return taskCompletionSource.getTask();
    }
}
