package androidx.browser.customtabs;

import android.app.PendingIntent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.customtabs.ICustomTabsCallback;
import android.support.customtabs.ICustomTabsService;
import android.support.customtabs.IEngagementSignalsCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public final class t extends ICustomTabsService.Stub {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ CustomTabsService f887a;

    public t(CustomTabsService customTabsService) {
        this.f887a = customTabsService;
    }

    @Nullable
    private PendingIntent getSessionIdFromBundle(@Nullable Bundle bundle) {
        if (bundle == null) {
            return null;
        }
        PendingIntent pendingIntent = (PendingIntent) bundle.getParcelable("android.support.customtabs.extra.SESSION_ID");
        bundle.remove("android.support.customtabs.extra.SESSION_ID");
        return pendingIntent;
    }

    @Nullable
    private Uri getTargetOriginFromBundle(@Nullable Bundle bundle) {
        if (bundle == null) {
            return null;
        }
        return Build.VERSION.SDK_INT >= 33 ? (Uri) a.getParcelable(bundle, "target_origin", Uri.class) : (Uri) bundle.getParcelable("target_origin");
    }

    private boolean newSessionInternal(@NonNull ICustomTabsCallback iCustomTabsCallback, @Nullable PendingIntent pendingIntent) {
        final b0 b0Var = new b0(iCustomTabsCallback, pendingIntent);
        try {
            IBinder.DeathRecipient deathRecipient = new IBinder.DeathRecipient() { // from class: androidx.browser.customtabs.s
                @Override // android.os.IBinder.DeathRecipient
                public final void binderDied() {
                    this.f885a.f887a.cleanUpSession(b0Var);
                }
            };
            synchronized (this.f887a.mDeathRecipientMap) {
                iCustomTabsCallback.asBinder().linkToDeath(deathRecipient, 0);
                this.f887a.mDeathRecipientMap.put(iCustomTabsCallback.asBinder(), deathRecipient);
            }
            return this.f887a.newSession(b0Var);
        } catch (RemoteException unused) {
            return false;
        }
    }

    @Override // android.support.customtabs.ICustomTabsService
    public Bundle extraCommand(@NonNull String str, @Nullable Bundle bundle) {
        return this.f887a.extraCommand(str, bundle);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public final boolean isEngagementSignalsApiAvailable(ICustomTabsCallback iCustomTabsCallback, Bundle bundle) {
        return this.f887a.isEngagementSignalsApiAvailable(new b0(iCustomTabsCallback, getSessionIdFromBundle(bundle)), bundle);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public boolean mayLaunchUrl(@Nullable ICustomTabsCallback iCustomTabsCallback, @Nullable Uri uri, @Nullable Bundle bundle, @Nullable List<Bundle> list) {
        return this.f887a.mayLaunchUrl(new b0(iCustomTabsCallback, getSessionIdFromBundle(bundle)), uri, bundle, list);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public final boolean newSession(ICustomTabsCallback iCustomTabsCallback) {
        return newSessionInternal(iCustomTabsCallback, null);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public boolean newSessionWithExtras(@NonNull ICustomTabsCallback iCustomTabsCallback, @Nullable Bundle bundle) {
        return newSessionInternal(iCustomTabsCallback, getSessionIdFromBundle(bundle));
    }

    @Override // android.support.customtabs.ICustomTabsService
    public int postMessage(@NonNull ICustomTabsCallback iCustomTabsCallback, @NonNull String str, @Nullable Bundle bundle) {
        return this.f887a.postMessage(new b0(iCustomTabsCallback, getSessionIdFromBundle(bundle)), str, bundle);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public boolean receiveFile(@NonNull ICustomTabsCallback iCustomTabsCallback, @NonNull Uri uri, int i10, @Nullable Bundle bundle) {
        return this.f887a.receiveFile(new b0(iCustomTabsCallback, getSessionIdFromBundle(bundle)), uri, i10, bundle);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public final boolean requestPostMessageChannel(ICustomTabsCallback iCustomTabsCallback, Uri uri) {
        return this.f887a.requestPostMessageChannel(new b0(iCustomTabsCallback, null), uri, null, new Bundle());
    }

    @Override // android.support.customtabs.ICustomTabsService
    public final boolean requestPostMessageChannelWithExtras(ICustomTabsCallback iCustomTabsCallback, Uri uri, Bundle bundle) {
        return this.f887a.requestPostMessageChannel(new b0(iCustomTabsCallback, getSessionIdFromBundle(bundle)), uri, getTargetOriginFromBundle(bundle), bundle);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public final boolean setEngagementSignalsCallback(ICustomTabsCallback iCustomTabsCallback, IBinder iBinder, Bundle bundle) {
        d0 d0Var = new d0(IEngagementSignalsCallback.Stub.asInterface(iBinder));
        return this.f887a.setEngagementSignalsCallback(new b0(iCustomTabsCallback, getSessionIdFromBundle(bundle)), d0Var, bundle);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public boolean updateVisuals(@NonNull ICustomTabsCallback iCustomTabsCallback, @Nullable Bundle bundle) {
        return this.f887a.updateVisuals(new b0(iCustomTabsCallback, getSessionIdFromBundle(bundle)), bundle);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public boolean validateRelationship(@NonNull ICustomTabsCallback iCustomTabsCallback, int i10, @NonNull Uri uri, @Nullable Bundle bundle) {
        return this.f887a.validateRelationship(new b0(iCustomTabsCallback, getSessionIdFromBundle(bundle)), i10, uri, bundle);
    }

    @Override // android.support.customtabs.ICustomTabsService
    public final boolean warmup(long j10) {
        return this.f887a.warmup(j10);
    }
}
