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

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 defpackage.b2b;
import defpackage.mza;
import defpackage.qza;
import defpackage.rq6;
import defpackage.sma;
import defpackage.sxa;
import defpackage.t1b;
import defpackage.vya;
import defpackage.wxa;
import defpackage.yza;
import java.util.ArrayList;

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

    @rq6
    @sma
    final sxa a;
    private final t1b b;
    private final String c;
    private final Context d;
    private final at e;
    private final k f;

    public aj(Context context, t1b t1bVar, at atVar, k kVar) {
        t1b t1bVar2;
        this.c = context.getPackageName();
        this.b = t1bVar;
        this.e = atVar;
        this.f = kVar;
        this.d = context;
        t1b t1bVar3 = wxa.a;
        try {
            if (context.getPackageManager().getApplicationInfo("com.android.vending", 0).enabled) {
                try {
                    if (wxa.b(context.getPackageManager().getPackageInfo("com.android.vending", 64).signatures)) {
                        this.a = new sxa(context, t1bVar, "IntegrityService", ak.a, new b2b() { // from class: com.google.android.play.core.integrity.ae
                            @Override // defpackage.b2b
                            public final Object a(IBinder iBinder) {
                                int i = qza.w;
                                if (iBinder == null) {
                                    return null;
                                }
                                IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.play.core.integrity.protocol.IIntegrityService");
                                return iInterfaceQueryLocalInterface instanceof yza ? (yza) iInterfaceQueryLocalInterface : new mza(iBinder, "com.google.android.play.core.integrity.protocol.IIntegrityService");
                            }
                        });
                        return;
                    }
                } catch (PackageManager.NameNotFoundException unused) {
                    t1bVar2 = t1bVar;
                    t1bVar3.c("Play Store package is not found.", new Object[0]);
                }
            } else {
                t1bVar3.c("Play Store package is disabled.", new Object[0]);
            }
            t1bVar2 = t1bVar;
        } catch (PackageManager.NameNotFoundException unused2) {
            t1bVar2 = t1bVar;
            t1bVar3.c("Play Store package is not found.", new Object[0]);
        }
        Object[] objArr = new Object[0];
        if (Log.isLoggable("PlayCore", 6)) {
            Log.e("PlayCore", t1b.d(t1bVar2.a, "Phonesky is not installed.", objArr));
        } else {
            t1bVar2.getClass();
        }
        this.a = null;
    }

    public static /* bridge */ /* synthetic */ Bundle a(aj ajVar, byte[] bArr, Long l, Parcelable parcelable) {
        Bundle bundle = new Bundle();
        bundle.putString("package.name", ajVar.c);
        bundle.putByteArray("nonce", bArr);
        bundle.putInt("playcore.integrity.version.major", 1);
        bundle.putInt("playcore.integrity.version.minor", 4);
        bundle.putInt("playcore.integrity.version.patch", 0);
        if (l != null) {
            bundle.putLong("cloud.prj", l.longValue());
        }
        if (parcelable != null) {
            bundle.putParcelable("network", parcelable);
        }
        ArrayList arrayList = new ArrayList();
        vya.b(3, arrayList);
        bundle.putParcelableArrayList("event_timestamps", new ArrayList<>(vya.a(arrayList)));
        return bundle;
    }

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

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