package com.google.android.gms.auth.api.signin.internal;

import X.1hK;
import X.AnonymousClass9AD;
import X.C26528gF;
import X.C407897t;
import X.C413699z;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.accessibility.AccessibilityEvent;
import com.bytedance.covode.number.Covode;
import com.bytedance.sysoptimizer.BadParcelableCrashOptimizer;
import com.bytedance.sysoptimizer.EnterTransitionCrashOptimizer;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.SignInAccount;
import com.google.android.gms.common.api.Status;

public class SignInHubActivity extends 1hK {
    public static boolean LIZJ;
    public int LIZ;
    public Intent LIZIZ;
    public boolean LIZLLL;
    public SignInConfiguration LJ;
    public boolean LJFF;

    static {
        Covode.recordClassIndex(42517);
    }

    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        return true;
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [X.1hK, com.google.android.gms.auth.api.signin.internal.SignInHubActivity, android.app.Activity] */
    public void onDestroy() {
        C26528gF.LJ(this);
        SignInHubActivity.super.onDestroy();
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [X.1hK, com.google.android.gms.auth.api.signin.internal.SignInHubActivity, android.app.Activity] */
    public void onPause() {
        C26528gF.LIZJ(this);
        SignInHubActivity.super.onPause();
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [X.1hK, com.google.android.gms.auth.api.signin.internal.SignInHubActivity, android.app.Activity] */
    public void onResume() {
        C26528gF.LIZIZ(this);
        SignInHubActivity.super.onResume();
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [X.1hK, com.google.android.gms.auth.api.signin.internal.SignInHubActivity, android.app.Activity] */
    public void onStart() {
        C26528gF.LIZ(this);
        SignInHubActivity.super.onStart();
    }

    private final void LIZ() {
        getSupportLoaderManager().LIZ(0, (Bundle) null, new C413699z(this, (byte) 0));
        LIZJ = false;
    }

    /* JADX WARNING: type inference failed for: r1v0, types: [X.1hK, com.google.android.gms.auth.api.signin.internal.SignInHubActivity, android.app.Activity] */
    public void onStop() {
        C26528gF.LIZLLL(this);
        SignInHubActivity.super.onStop();
        if (EnterTransitionCrashOptimizer.getContext() != null) {
            try {
                getWindow().getDecorView().getViewTreeObserver().dispatchOnPreDraw();
            } catch (Throwable unused) {
            }
        }
        try {
            getWindow().getDecorView().getViewTreeObserver().dispatchOnPreDraw();
        } catch (Throwable unused2) {
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        SignInHubActivity.super.onSaveInstanceState(bundle);
        bundle.putBoolean("signingInGoogleApiClients", this.LJFF);
        if (this.LJFF) {
            bundle.putInt("signInResultCode", this.LIZ);
            bundle.putParcelable("signInResultData", this.LIZIZ);
        }
    }

    private final void LIZ(int i) {
        Status status = new Status(i);
        Intent intent = new Intent();
        intent.putExtra("googleSignInStatus", status);
        setResult(0, intent);
        finish();
        LIZJ = false;
    }

    /* JADX WARNING: type inference failed for: r6v0, types: [X.1hK, com.google.android.gms.auth.api.signin.internal.SignInHubActivity, android.app.Activity] */
    public void onCreate(Bundle bundle) {
        C26528gF.LIZ((Activity) this, bundle);
        SignInHubActivity.super.onCreate(bundle);
        Intent intent = getIntent();
        String action = intent.getAction();
        AnonymousClass9AD.LIZ(action);
        if ("com.google.android.gms.auth.NO_IMPL".equals(action)) {
            LIZ(12500);
        } else if (action.equals("com.google.android.gms.auth.GOOGLE_SIGN_IN") || action.equals("com.google.android.gms.auth.APPAUTH_SIGN_IN")) {
            Bundle bundleExtra = intent.getBundleExtra("config");
            Context context = BadParcelableCrashOptimizer.getContext();
            if (!(bundleExtra == null || context == null)) {
                bundleExtra.setClassLoader(context.getClassLoader());
            }
            AnonymousClass9AD.LIZ(bundleExtra);
            SignInConfiguration signInConfiguration = (SignInConfiguration) bundleExtra.getParcelable("config");
            if (signInConfiguration == null) {
                setResult(0);
                finish();
                return;
            }
            this.LJ = signInConfiguration;
            if (bundle != null) {
                boolean z = bundle.getBoolean("signingInGoogleApiClients");
                this.LJFF = z;
                if (z) {
                    this.LIZ = bundle.getInt("signInResultCode");
                    Intent intent2 = (Intent) bundle.getParcelable("signInResultData");
                    AnonymousClass9AD.LIZ(intent2);
                    this.LIZIZ = intent2;
                    LIZ();
                }
            } else if (LIZJ) {
                setResult(0);
                LIZ(12502);
            } else {
                LIZJ = true;
                Intent intent3 = new Intent(action);
                if (action.equals("com.google.android.gms.auth.GOOGLE_SIGN_IN")) {
                    intent3.setPackage("com.google.android.gms");
                } else {
                    intent3.setPackage(getPackageName());
                }
                intent3.putExtra("config", this.LJ);
                try {
                    startActivityForResult(intent3, 40962);
                } catch (ActivityNotFoundException unused) {
                    this.LIZLLL = true;
                    LIZ(17);
                }
            }
        } else {
            String valueOf = String.valueOf(intent.getAction());
            if (valueOf.length() != 0) {
                "Unknown action: ".concat(valueOf);
            } else {
                new String("Unknown action: ");
            }
            finish();
        }
    }

    /* JADX WARNING: type inference failed for: r4v0, types: [android.content.Context, com.google.android.gms.auth.api.signin.internal.SignInHubActivity] */
    public void onActivityResult(int i, int i2, Intent intent) {
        if (!this.LIZLLL) {
            setResult(0);
            if (i == 40962) {
                if (intent != null) {
                    SignInAccount signInAccount = (SignInAccount) intent.getParcelableExtra("signInAccount");
                    if (signInAccount != null && signInAccount.LIZ != null) {
                        GoogleSignInAccount googleSignInAccount = signInAccount.LIZ;
                        C407897t LIZ2 = C407897t.LIZ(this);
                        GoogleSignInOptions googleSignInOptions = this.LJ.LIZ;
                        AnonymousClass9AD.LIZ(googleSignInAccount);
                        LIZ2.LIZ(googleSignInOptions, googleSignInAccount);
                        intent.removeExtra("signInAccount");
                        intent.putExtra("googleSignInAccount", googleSignInAccount);
                        this.LJFF = true;
                        this.LIZ = i2;
                        this.LIZIZ = intent;
                        LIZ();
                        return;
                    } else if (intent.hasExtra("errorCode")) {
                        int intExtra = intent.getIntExtra("errorCode", 8);
                        if (intExtra == 13) {
                            intExtra = 12501;
                        }
                        LIZ(intExtra);
                        return;
                    }
                }
                LIZ(8);
            }
        }
    }
}
