package com.bytedance.sdk.openadsdk.activity.single;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.window.OnBackInvokedCallback;
import androidx.annotation.Nullable;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.utils.gzf;
import com.bytedance.sdk.openadsdk.utils.hi;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;

/* JADX INFO: loaded from: classes2.dex */
public class TTBaseActivity extends Activity {
    private OnBackInvokedCallback fm;
    protected String hxv;
    protected boolean pkk = false;

    public static class fm implements OnBackInvokedCallback {
        private final WeakReference<TTBaseActivity> fm;

        public fm(TTBaseActivity tTBaseActivity) {
            this.fm = new WeakReference<>(tTBaseActivity);
        }

        public void onBackInvoked() {
            TTBaseActivity tTBaseActivity = this.fm.get();
            if (tTBaseActivity != null) {
                tTBaseActivity.onz();
            }
        }
    }

    @Override // android.app.Activity
    public void finish() {
        try {
            super.finish();
        } catch (Exception unused) {
        }
    }

    public void gof() {
        try {
            if (!gzf.ro() || Build.VERSION.SDK_INT < 29) {
                return;
            }
            getWindow().getDecorView().setForceDarkAllowed(false);
        } catch (Throwable unused) {
        }
    }

    public void lb(boolean z10) {
        this.pkk = z10;
    }

    @Override // android.app.Activity
    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        if (yz() && hi.fm()) {
            this.fm = new fm(this);
            getOnBackInvokedDispatcher().registerOnBackInvokedCallback(0, this.fm);
        }
    }

    @Override // android.app.Activity
    public void onDestroy() {
        super.onDestroy();
        if (!hi.fm() || this.fm == null) {
            return;
        }
        getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(this.fm);
        this.fm = null;
    }

    @Override // android.app.Activity
    public void onPause() {
        if (Build.VERSION.SDK_INT < 33) {
            super.onPause();
            return;
        }
        try {
            try {
                super.onPause();
            } catch (Exception unused) {
            }
        } catch (IllegalArgumentException unused2) {
            Field declaredField = Activity.class.getDeclaredField("mCalled");
            declaredField.setAccessible(true);
            declaredField.set(this, Boolean.TRUE);
        }
    }

    @Override // android.app.Activity
    public void onResume() {
        if (Build.VERSION.SDK_INT > 28) {
            super.onResume();
            return;
        }
        try {
            super.onResume();
        } catch (IllegalArgumentException e10) {
            wey.fm("TTBaseActivity", "super.onResume() run fail", e10);
            try {
                Field declaredField = Activity.class.getDeclaredField("mCalled");
                declaredField.setAccessible(true);
                declaredField.set(this, Boolean.TRUE);
            } catch (Exception e11) {
                wey.fm("TTBaseActivity", "onResume set mCalled fail", e11);
            }
        }
    }

    public void onz() {
        onBackPressed();
    }

    public boolean yz() {
        return false;
    }
}
