package com.facebook;

import X.8gF;
import X.C5549M4m;
import X.M12;
import X.M18;
import X.M19;
import X.M1A;
import X.M1D;
import X.M1E;
import X.M1N;
import X.M5M;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.bytedance.covode.number.Covode;
import com.bytedance.sysoptimizer.BadParcelableCrashOptimizer;
import com.bytedance.sysoptimizer.EnterTransitionCrashOptimizer;
import kotlin.h.b.n;

public final class CustomTabMainActivity extends Activity {
    public static final M19 LIZ = new M19((byte) 0);
    public static final String LIZIZ;
    public static final String LIZJ;
    public static final String LIZLLL;
    public static final String LJ;
    public static final String LJFF;
    public static final String LJI;
    public static final String LJII;
    public boolean LJIIIIZZ = true;
    public BroadcastReceiver LJIIIZ;

    public final void onDestroy() {
        8gF.LJ(this);
        super.onDestroy();
    }

    public final void onPause() {
        8gF.LIZJ(this);
        super.onPause();
    }

    public final void onStart() {
        8gF.LIZ(this);
        super.onStart();
    }

    public final void onResume() {
        8gF.LIZIZ(this);
        super.onResume();
        if (this.LJIIIIZZ) {
            LIZ(0, (Intent) null);
        }
        this.LJIIIIZZ = true;
    }

    public final void onStop() {
        8gF.LIZLLL(this);
        super.onStop();
        if (EnterTransitionCrashOptimizer.getContext() != null) {
            try {
                getWindow().getDecorView().getViewTreeObserver().dispatchOnPreDraw();
            } catch (Throwable unused) {
            }
        }
        try {
            getWindow().getDecorView().getViewTreeObserver().dispatchOnPreDraw();
        } catch (Throwable unused2) {
        }
    }

    static {
        Class<CustomTabMainActivity> cls = CustomTabMainActivity.class;
        Covode.recordClassIndex(40795);
        LIZIZ = n.LIZ(cls.getSimpleName(), ".extra_action");
        LIZJ = n.LIZ(cls.getSimpleName(), ".extra_params");
        LIZLLL = n.LIZ(cls.getSimpleName(), ".extra_chromePackage");
        LJ = n.LIZ(cls.getSimpleName(), ".extra_url");
        LJFF = n.LIZ(cls.getSimpleName(), ".extra_targetApp");
        LJI = n.LIZ(cls.getSimpleName(), ".action_refresh");
        LJII = n.LIZ(cls.getSimpleName(), ".no_activity_exception");
    }

    public final void onNewIntent(Intent intent) {
        M12.LIZ((Object) intent);
        super.onNewIntent(intent);
        if (n.LIZ(LJI, intent.getAction())) {
            LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(CustomTabActivity.LIZJ));
            LIZ(-1, intent);
        } else if (n.LIZ(CustomTabActivity.LIZIZ, intent.getAction())) {
            LIZ(-1, intent);
        }
    }

    public final void onCreate(Bundle bundle) {
        String LIZ2;
        M1N m1n;
        8gF.LIZ(this, bundle);
        super.onCreate(bundle);
        if (n.LIZ(CustomTabActivity.LIZIZ, getIntent().getAction())) {
            setResult(0);
            finish();
        } else if (bundle == null && (LIZ2 = LIZ(getIntent(), LIZIZ)) != null) {
            Bundle bundleExtra = getIntent().getBundleExtra(LIZJ);
            Context context = BadParcelableCrashOptimizer.getContext();
            if (!(bundleExtra == null || context == null)) {
                bundleExtra.setClassLoader(context.getClassLoader());
            }
            String LIZ3 = LIZ(getIntent(), LIZLLL);
            if (M1A.LIZ[M1D.Companion.LIZ(LIZ(getIntent(), LJFF)).ordinal()] == 1) {
                m1n = new M1E(LIZ2, bundleExtra);
            } else {
                m1n = new M1N(LIZ2, bundleExtra);
            }
            boolean LIZ4 = m1n.LIZ(this, LIZ3);
            this.LJIIIIZZ = false;
            if (!LIZ4) {
                setResult(0, getIntent().putExtra(LJII, true));
                finish();
                return;
            }
            M18 m18 = new M18(this);
            this.LJIIIZ = m18;
            LocalBroadcastManager.getInstance(this).registerReceiver(m18, new IntentFilter(CustomTabActivity.LIZIZ));
        }
    }

    public static String LIZ(Intent intent, String str) {
        try {
            return intent.getStringExtra(str);
        } catch (Exception unused) {
            return null;
        }
    }

    private final void LIZ(int i, Intent intent) {
        Bundle bundle;
        BroadcastReceiver broadcastReceiver = this.LJIIIZ;
        if (broadcastReceiver != null) {
            LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
        }
        if (intent != null) {
            String LIZ2 = LIZ(intent, LJ);
            if (LIZ2 != null) {
                bundle = LIZ.LIZ(LIZ2);
            } else {
                bundle = new Bundle();
            }
            Intent intent2 = getIntent();
            M12.LIZ((Object) intent2);
            Intent LIZ3 = C5549M4m.LIZ(intent2, bundle, (M5M) null);
            if (LIZ3 != null) {
                intent = LIZ3;
            }
            setResult(i, intent);
        } else {
            Intent intent3 = getIntent();
            M12.LIZ((Object) intent3);
            setResult(i, C5549M4m.LIZ(intent3, (Bundle) null, (M5M) null));
        }
        finish();
    }
}
