package com.android.billingclient.api;

import I2.C0327k;
import I2.C0328l;
import I2.T;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.os.ResultReceiver;
import com.google.android.apps.common.proguard.UsedByReflection;
import com.google.android.gms.internal.play_billing.zzc;
import com.google.android.gms.internal.play_billing.zzie;
import com.google.android.gms.internal.play_billing.zzil;
import com.revenuecat.purchases.google.history.BillingConstants;

/* JADX INFO: loaded from: classes.dex */
@UsedByReflection("PlatformActivityProxy")
public class ProxyBillingActivity extends Activity {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public ResultReceiver f13550a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f13551b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f13552c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f13553d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public long f13554e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f13555f;

    public final Intent a(zzie zzieVar, long j4) {
        Intent intentB = b();
        intentB.putExtra(BillingConstants.RESPONSE_CODE, 6);
        intentB.putExtra("DEBUG_MESSAGE", "An internal error occurred.");
        C0327k c0327kA = C0328l.a();
        c0327kA.f2633a = 6;
        c0327kA.f2635c = "An internal error occurred.";
        C0328l c0328lD = c0327kA.d();
        int i6 = T.f2535a;
        intentB.putExtra("FAILURE_LOGGING_PAYLOAD", T.b(zzieVar, 2, c0328lD, null, zzil.BROADCAST_ACTION_UNSPECIFIED).zzM());
        intentB.putExtra("INTENT_SOURCE", "LAUNCH_BILLING_FLOW");
        intentB.putExtra("billingClientTransactionId", j4);
        intentB.putExtra("wasServiceAutoReconnected", this.f13555f);
        return intentB;
    }

    public final Intent b() {
        Intent intent = new Intent("com.android.vending.billing.LOCAL_BROADCAST_PURCHASES_UPDATED");
        intent.setPackage(getApplicationContext().getPackageName());
        return intent;
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0069  */
    /* JADX WARN: Removed duplicated region for block: B:30:0x00c4  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x0100  */
    @Override // android.app.Activity
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onActivityResult(int i6, int i7, Intent intent) {
        Intent intentA;
        super.onActivityResult(i6, i7, intent);
        if (i6 == 100 || i6 == 110) {
            int i8 = zzc.zzh(intent, "ProxyBillingActivity").f2636a;
            if (i7 != -1) {
                zzc.zzn("ProxyBillingActivity", "Activity finished with resultCode " + i7 + " and billing's responseCode: " + i8);
                if (intent == null) {
                    zzc.zzn("ProxyBillingActivity", "Got null data with resultCode " + i7 + "!");
                    intentA = a(i7 != -1 ? i7 != 0 ? i7 != 3 ? i7 != 4 ? i7 != 5 ? zzie.NULL_DATA_WITH_OTHER_RESULT_CODE_IN_PROXY_BILLING_ACTIVITY_RESULT : zzie.NULL_DATA_WITH_ON_CREATE_RUNTIME_EXCEPTION_RESULT_CODE : zzie.NULL_DATA_WITH_PLAY_CANCELED_WITHOUT_COMPLETE_ACTION_RESULT_CODE : zzie.NULL_DATA_WITH_PLAY_CANCELED_RESULT_CODE : zzie.NULL_DATA_WITH_CANCELLED_RESULT_CODE_IN_PROXY_BILLING_ACTIVITY_RESULT : zzie.NULL_DATA_WITH_OK_RESULT_CODE_IN_PROXY_BILLING_ACTIVITY_RESULT, this.f13554e);
                } else if (intent.getExtras() != null) {
                    String string = intent.getExtras().getString("ALTERNATIVE_BILLING_USER_CHOICE_DATA");
                    if (string != null) {
                        intentA = new Intent("com.android.vending.billing.ALTERNATIVE_BILLING");
                        intentA.setPackage(getApplicationContext().getPackageName());
                        intentA.putExtra("ALTERNATIVE_BILLING_USER_CHOICE_DATA", string);
                        intentA.putExtra("INTENT_SOURCE", "LAUNCH_BILLING_FLOW");
                    } else {
                        Intent intentB = b();
                        intentB.putExtras(intent.getExtras());
                        intentB.putExtra("INTENT_SOURCE", "LAUNCH_BILLING_FLOW");
                        intentA = intentB;
                    }
                    intentA.putExtra("billingClientTransactionId", this.f13554e);
                    intentA.putExtra("wasServiceAutoReconnected", this.f13555f);
                } else {
                    zzc.zzn("ProxyBillingActivity", "Got null bundle!");
                    intentA = a(zzie.NULL_BUNDLE_IN_ACTIVITY_RESULT, this.f13554e);
                }
                if (i6 == 110) {
                    intentA.putExtra("IS_FIRST_PARTY_PURCHASE", true);
                }
                sendBroadcast(intentA);
            } else if (i8 != 0) {
                i7 = -1;
                zzc.zzn("ProxyBillingActivity", "Activity finished with resultCode " + i7 + " and billing's responseCode: " + i8);
                if (intent == null) {
                }
                if (i6 == 110) {
                }
                sendBroadcast(intentA);
            } else {
                i7 = -1;
                if (intent == null) {
                }
                if (i6 == 110) {
                }
                sendBroadcast(intentA);
            }
        } else if (i6 == 101) {
            int iZza = zzc.zza(intent, "ProxyBillingActivity");
            ResultReceiver resultReceiver = this.f13550a;
            if (resultReceiver != null) {
                resultReceiver.send(iZza, intent == null ? null : intent.getExtras());
            }
        } else {
            zzc.zzn("ProxyBillingActivity", "Got onActivityResult with wrong requestCode: " + i6 + "; skipping...");
        }
        this.f13551b = false;
        finish();
    }

    @Override // android.app.Activity
    public final void onCreate(Bundle bundle) {
        PendingIntent pendingIntent;
        super.onCreate(bundle);
        if (bundle != null) {
            zzc.zzm("ProxyBillingActivity", "Launching Play Store billing flow from savedInstanceState");
            this.f13551b = bundle.getBoolean("send_cancelled_broadcast_if_finished", false);
            if (bundle.containsKey("in_app_message_result_receiver")) {
                this.f13550a = (ResultReceiver) bundle.getParcelable("in_app_message_result_receiver");
            }
            this.f13552c = bundle.getBoolean("IS_FLOW_FROM_FIRST_PARTY_CLIENT", false);
            this.f13553d = bundle.getInt("activity_code", 100);
            if (bundle.containsKey("billingClientTransactionId")) {
                this.f13554e = bundle.getLong("billingClientTransactionId");
            }
            if (bundle.containsKey("wasServiceAutoReconnected")) {
                this.f13555f = bundle.getBoolean("wasServiceAutoReconnected");
                return;
            }
            return;
        }
        zzc.zzm("ProxyBillingActivity", "Launching Play Store billing flow");
        this.f13553d = 100;
        if (getIntent().hasExtra("BUY_INTENT")) {
            pendingIntent = (PendingIntent) getIntent().getParcelableExtra("BUY_INTENT");
            if (getIntent().hasExtra("IS_FLOW_FROM_FIRST_PARTY_CLIENT") && getIntent().getBooleanExtra("IS_FLOW_FROM_FIRST_PARTY_CLIENT", false)) {
                this.f13552c = true;
                this.f13553d = 110;
            }
        } else if (getIntent().hasExtra("IN_APP_MESSAGE_INTENT")) {
            pendingIntent = (PendingIntent) getIntent().getParcelableExtra("IN_APP_MESSAGE_INTENT");
            this.f13550a = (ResultReceiver) getIntent().getParcelableExtra("in_app_message_result_receiver");
            this.f13553d = 101;
        } else {
            pendingIntent = null;
        }
        if (getIntent().hasExtra("billingClientTransactionId")) {
            this.f13554e = getIntent().getLongExtra("billingClientTransactionId", 0L);
        }
        if (getIntent().hasExtra("wasServiceAutoReconnected")) {
            this.f13555f = getIntent().getBooleanExtra("wasServiceAutoReconnected", false);
        }
        try {
            this.f13551b = true;
            startIntentSenderForResult(pendingIntent.getIntentSender(), this.f13553d, new Intent(), 0, 0, 0);
        } catch (IntentSender.SendIntentException e6) {
            zzc.zzo("ProxyBillingActivity", "Got exception while trying to start a purchase flow.", e6);
            ResultReceiver resultReceiver = this.f13550a;
            if (resultReceiver != null) {
                resultReceiver.send(0, null);
            } else {
                Intent intentA = a(zzie.INTENT_SENDER_EXCEPTION, this.f13554e);
                if (this.f13552c) {
                    intentA.putExtra("IS_FIRST_PARTY_PURCHASE", true);
                }
                sendBroadcast(intentA);
            }
            this.f13551b = false;
            finish();
        }
    }

    @Override // android.app.Activity
    public final void onDestroy() {
        super.onDestroy();
        if (isFinishing() && this.f13551b) {
            Intent intentB = b();
            intentB.putExtra(BillingConstants.RESPONSE_CODE, 1);
            intentB.putExtra("DEBUG_MESSAGE", "Billing dialog closed.");
            if (this.f13552c) {
                intentB.putExtra("IS_FIRST_PARTY_PURCHASE", true);
            }
            int i6 = this.f13553d;
            if (i6 == 110 || i6 == 100) {
                intentB.putExtra("INTENT_SOURCE", "LAUNCH_BILLING_FLOW");
                intentB.putExtra("billingClientTransactionId", this.f13554e);
            }
            sendBroadcast(intentB);
        }
    }

    @Override // android.app.Activity
    public final void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        ResultReceiver resultReceiver = this.f13550a;
        if (resultReceiver != null) {
            bundle.putParcelable("in_app_message_result_receiver", resultReceiver);
        }
        bundle.putBoolean("send_cancelled_broadcast_if_finished", this.f13551b);
        bundle.putBoolean("IS_FLOW_FROM_FIRST_PARTY_CLIENT", this.f13552c);
        bundle.putInt("activity_code", this.f13553d);
        bundle.putLong("billingClientTransactionId", this.f13554e);
        bundle.putBoolean("wasServiceAutoReconnected", this.f13555f);
    }
}
