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

import C3.A;
import C3.C0129e;
import C3.E;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcelable;
import android.util.Base64;
import android.util.Log;
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;

/* JADX INFO: loaded from: classes3.dex */
final class aj {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    final C0129e f13601a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final A f13602b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final String f13603c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final at f13604d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final k f13605e;

    public aj(Context context, A a6, at atVar, k kVar) {
        this.f13603c = context.getPackageName();
        this.f13602b = a6;
        this.f13604d = atVar;
        this.f13605e = kVar;
        A a7 = C3.g.f729a;
        try {
            if (context.getPackageManager().getApplicationInfo("com.android.vending", 0).enabled) {
                if (C3.g.a(context.getPackageManager().getPackageInfo("com.android.vending", 64).signatures)) {
                    this.f13601a = new C0129e(context, a6, "IntegrityService", ak.f13606a, new E() { // from class: com.google.android.play.core.integrity.ae
                        @Override // C3.E
                        public final Object a(IBinder iBinder) {
                            int i6 = C3.u.f738i;
                            if (iBinder == null) {
                                return null;
                            }
                            IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.play.core.integrity.protocol.IIntegrityService");
                            return iInterfaceQueryLocalInterface instanceof C3.v ? (C3.v) iInterfaceQueryLocalInterface : new C3.t(iBinder, "com.google.android.play.core.integrity.protocol.IIntegrityService");
                        }
                    });
                    return;
                }
            }
        } catch (PackageManager.NameNotFoundException unused) {
        }
        Object[] objArr = new Object[0];
        a6.getClass();
        if (Log.isLoggable("PlayCore", 6)) {
            Log.e("PlayCore", A.c(a6.f702a, "Phonesky is not installed.", objArr));
        }
        this.f13601a = null;
    }

    public static Bundle a(aj ajVar, byte[] bArr, Long l, Parcelable parcelable) {
        Bundle bundle = new Bundle();
        bundle.putString("package.name", ajVar.f13603c);
        bundle.putByteArray("nonce", bArr);
        bundle.putInt("playcore.integrity.version.major", 1);
        bundle.putInt("playcore.integrity.version.minor", 3);
        bundle.putInt("playcore.integrity.version.patch", 0);
        if (l != null) {
            bundle.putLong("cloud.prj", l.longValue());
        }
        ArrayList arrayList = new ArrayList();
        arrayList.add(new C3.n(3, System.currentTimeMillis()));
        bundle.putParcelableArrayList("event_timestamps", new ArrayList<>(A4.g.d(arrayList)));
        return bundle;
    }

    public final Task b(Activity activity, Bundle bundle) {
        if (this.f13601a == null) {
            return Tasks.forException(new IntegrityServiceException(-2, null));
        }
        int i6 = bundle.getInt("dialog.intent.type");
        this.f13602b.b("requestAndShowDialog(%s, %s)", this.f13603c, Integer.valueOf(i6));
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        this.f13601a.c(new ag(this, taskCompletionSource, bundle, activity, taskCompletionSource, i6), taskCompletionSource);
        return taskCompletionSource.getTask();
    }

    public final Task c(IntegrityTokenRequest integrityTokenRequest) {
        if (this.f13601a == null) {
            return Tasks.forException(new IntegrityServiceException(-2, null));
        }
        try {
            byte[] bArrDecode = Base64.decode(integrityTokenRequest.nonce(), 10);
            Long lCloudProjectNumber = integrityTokenRequest.cloudProjectNumber();
            if (integrityTokenRequest instanceof ao) {
            }
            this.f13602b.b("requestIntegrityToken(%s)", integrityTokenRequest);
            TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
            this.f13601a.c(new af(this, taskCompletionSource, bArrDecode, lCloudProjectNumber, null, taskCompletionSource, integrityTokenRequest), taskCompletionSource);
            return taskCompletionSource.getTask();
        } catch (IllegalArgumentException e6) {
            return Tasks.forException(new IntegrityServiceException(-13, e6));
        }
    }
}
