package wj;

import android.content.Context;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcelable;
import android.util.Base64;
import bk.e0;
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;

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

    /* renamed from: a, reason: collision with root package name */
    private final bk.x f49511a;

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

    /* renamed from: c, reason: collision with root package name */
    final bk.d f49513c;

    /* JADX INFO: Access modifiers changed from: package-private */
    public j(Context context, bk.x xVar) {
        this.f49512b = context.getPackageName();
        this.f49511a = xVar;
        if (bk.h.a(context)) {
            this.f49513c = new bk.d(context, xVar, "IntegrityService", k.f49514a, new e0() { // from class: wj.g
                @Override // bk.e0
                public final Object a(IBinder iBinder) {
                    return bk.t.V(iBinder);
                }
            }, null);
        } else {
            xVar.a("Phonesky is not installed.", new Object[0]);
            this.f49513c = null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static /* bridge */ /* synthetic */ Bundle a(j jVar, byte[] bArr, Long l10, Parcelable parcelable) {
        Bundle bundle = new Bundle();
        bundle.putString("package.name", jVar.f49512b);
        bundle.putByteArray("nonce", bArr);
        bundle.putInt("playcore.integrity.version.major", 1);
        bundle.putInt("playcore.integrity.version.minor", 2);
        bundle.putInt("playcore.integrity.version.patch", 0);
        if (l10 != null) {
            bundle.putLong("cloud.prj", l10.longValue());
        }
        ArrayList arrayList = new ArrayList();
        bk.p.b(3, arrayList);
        bundle.putParcelableArrayList("event_timestamps", new ArrayList<>(bk.p.a(arrayList)));
        return bundle;
    }

    public final Task b(d dVar) {
        if (this.f49513c == null) {
            return Tasks.forException(new c(-2, null));
        }
        try {
            byte[] decode = Base64.decode(dVar.d(), 10);
            Long c10 = dVar.c();
            dVar.a();
            this.f49511a.c("requestIntegrityToken(%s)", dVar);
            TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
            this.f49513c.t(new h(this, taskCompletionSource, decode, c10, null, taskCompletionSource, dVar), taskCompletionSource);
            return taskCompletionSource.getTask();
        } catch (IllegalArgumentException e10) {
            return Tasks.forException(new c(-13, e10));
        }
    }
}
