package androidx.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.activity.result.ActivityResultRegistry;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import p037.p038.InterfaceC1455;
import p037.p038.p039.C1461;
import p037.p038.p039.InterfaceC1458;
import p037.p038.p039.InterfaceC1460;
import p037.p038.p039.p040.AbstractC1463;
import p037.p065.p067.ActivityC1841;
import p037.p065.p067.C1830;
import p037.p065.p067.C1834;
import p037.p099.AbstractC2210;
import p037.p099.C2221;
import p037.p099.C2242;
import p037.p099.C2251;
import p037.p099.FragmentC2237;
import p037.p099.InterfaceC2209;
import p037.p099.InterfaceC2217;
import p037.p099.InterfaceC2219;
import p037.p099.InterfaceC2247;
import p037.p099.InterfaceC2252;
import p037.p099.p100.C2253;
import p037.p099.p101.C2254;
import p037.p112.C2429;
import p037.p112.C2430;
import p037.p112.C2433;
import p037.p112.InterfaceC2434;

/* JADX INFO: loaded from: classes.dex */
public class ComponentActivity extends ActivityC1841 implements InterfaceC2219, InterfaceC2252, InterfaceC2209, InterfaceC2434, InterfaceC1455, InterfaceC1460 {
    public InterfaceC2247 mDefaultFactory;
    public C2251 mViewModelStore;
    public final C2221 mLifecycleRegistry = new C2221(this);
    public final C2433 mSavedStateRegistryController = new C2433(this);
    public final OnBackPressedDispatcher mOnBackPressedDispatcher = new OnBackPressedDispatcher(new RunnableC0020());
    public final AtomicInteger mNextLocalRequestCode = new AtomicInteger();
    public ActivityResultRegistry mActivityResultRegistry = new C0021();

    /* JADX INFO: renamed from: androidx.activity.ComponentActivity$֏, reason: contains not printable characters */
    public class RunnableC0020 implements Runnable {
        public RunnableC0020() {
        }

        @Override // java.lang.Runnable
        public void run() {
            try {
                ComponentActivity.super.onBackPressed();
            } catch (IllegalStateException e) {
                if (!TextUtils.equals(e.getMessage(), "Can not perform this action after onSaveInstanceState")) {
                    throw e;
                }
            }
        }
    }

    /* JADX INFO: renamed from: androidx.activity.ComponentActivity$ؠ, reason: contains not printable characters */
    public class C0021 extends ActivityResultRegistry {

        /* JADX INFO: renamed from: androidx.activity.ComponentActivity$ؠ$֏, reason: contains not printable characters */
        public class RunnableC0022 implements Runnable {

            /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
            public final /* synthetic */ int f80;

            /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
            public final /* synthetic */ AbstractC1463.C1464 f81;

            public RunnableC0022(int i, AbstractC1463.C1464 c1464) {
                this.f80 = i;
                this.f81 = c1464;
            }

            @Override // java.lang.Runnable
            public void run() {
                ActivityResultRegistry.C0028<?> c0028;
                InterfaceC1458<?> interfaceC1458;
                C0021 c0021 = C0021.this;
                int i = this.f80;
                Object obj = this.f81.f4652;
                String str = c0021.f101.get(Integer.valueOf(i));
                if (str == null || (c0028 = c0021.f103.get(str)) == null || (interfaceC1458 = c0028.f118) == null) {
                    return;
                }
                interfaceC1458.mo2070(obj);
            }
        }

        /* JADX INFO: renamed from: androidx.activity.ComponentActivity$ؠ$ؠ, reason: contains not printable characters */
        public class RunnableC0023 implements Runnable {

            /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
            public final /* synthetic */ int f83;

            /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
            public final /* synthetic */ IntentSender.SendIntentException f84;

            public RunnableC0023(int i, IntentSender.SendIntentException sendIntentException) {
                this.f83 = i;
                this.f84 = sendIntentException;
            }

            @Override // java.lang.Runnable
            public void run() {
                C0021.this.m93(this.f83, 0, new Intent().setAction("androidx.activity.result.contract.action.INTENT_SENDER_REQUEST").putExtra("androidx.activity.result.contract.extra.SEND_INTENT_EXCEPTION", this.f84));
            }
        }

        public C0021() {
        }

        @Override // androidx.activity.result.ActivityResultRegistry
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public <I, O> void mo88(int i, AbstractC1463<I, O> abstractC1463, I i2, C1834 c1834) {
            ComponentActivity componentActivity = ComponentActivity.this;
            AbstractC1463.C1464<O> c1464Mo2802 = abstractC1463.mo2802(componentActivity, i2);
            if (c1464Mo2802 != null) {
                new Handler(Looper.getMainLooper()).post(new RunnableC0022(i, c1464Mo2802));
                return;
            }
            Intent intentMo2800 = abstractC1463.mo2800(componentActivity, i2);
            if (!"androidx.activity.result.contract.action.REQUEST_PERMISSIONS".equals(intentMo2800.getAction())) {
                Bundle bundleMo3636 = null;
                if ("androidx.activity.result.contract.action.INTENT_SENDER_REQUEST".equals(intentMo2800.getAction())) {
                    C1461 c1461 = (C1461) intentMo2800.getParcelableExtra("androidx.activity.result.contract.extra.INTENT_SENDER_REQUEST");
                    try {
                        C1830.m3632(componentActivity, c1461.f4648, i, c1461.f4649, c1461.f4650, c1461.f4651, 0, c1834 != null ? c1834.mo3636() : null);
                        return;
                    } catch (IntentSender.SendIntentException e) {
                        new Handler(Looper.getMainLooper()).post(new RunnableC0023(i, e));
                        return;
                    }
                }
                if (intentMo2800.hasExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE")) {
                    bundleMo3636 = intentMo2800.getBundleExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE");
                } else if (c1834 != null) {
                    bundleMo3636 = c1834.mo3636();
                }
                C1830.m3631(componentActivity, intentMo2800, i, bundleMo3636);
                return;
            }
            String[] stringArrayExtra = intentMo2800.getStringArrayExtra("androidx.activity.result.contract.extra.PERMISSIONS");
            if (stringArrayExtra == null) {
                return;
            }
            ArrayList arrayList = new ArrayList();
            for (String str : stringArrayExtra) {
                if (ComponentActivity.this.checkPermission(str, Process.myPid(), Process.myUid()) != 0) {
                    arrayList.add(str);
                }
            }
            if (arrayList.isEmpty()) {
                return;
            }
            C1830.m3633(componentActivity, (String[]) arrayList.toArray(new String[0]), i);
        }
    }

    /* JADX INFO: renamed from: androidx.activity.ComponentActivity$ހ, reason: contains not printable characters */
    public static final class C0024 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public C2251 f86;
    }

    public ComponentActivity() {
        C2221 c2221 = this.mLifecycleRegistry;
        if (c2221 == null) {
            throw new IllegalStateException("getLifecycle() returned null in ComponentActivity's constructor. Please make sure you are lazily constructing your Lifecycle in the first call to getLifecycle() rather than relying on field initialization.");
        }
        c2221.mo4273(new InterfaceC2217() { // from class: androidx.activity.ComponentActivity.3
            @Override // p037.p099.InterfaceC2217
            /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
            public void mo87(InterfaceC2219 interfaceC2219, AbstractC2210.EnumC2211 enumC2211) {
                if (enumC2211 == AbstractC2210.EnumC2211.ON_STOP) {
                    Window window = ComponentActivity.this.getWindow();
                    View viewPeekDecorView = window != null ? window.peekDecorView() : null;
                    if (viewPeekDecorView != null) {
                        viewPeekDecorView.cancelPendingInputEvents();
                    }
                }
            }
        });
        this.mLifecycleRegistry.mo4273(new InterfaceC2217() { // from class: androidx.activity.ComponentActivity.4
            @Override // p037.p099.InterfaceC2217
            /* JADX INFO: renamed from: ֏ */
            public void mo87(InterfaceC2219 interfaceC2219, AbstractC2210.EnumC2211 enumC2211) {
                if (enumC2211 != AbstractC2210.EnumC2211.ON_DESTROY || ComponentActivity.this.isChangingConfigurations()) {
                    return;
                }
                ComponentActivity.this.getViewModelStore().m4306();
            }
        });
        if (Build.VERSION.SDK_INT <= 23) {
            this.mLifecycleRegistry.mo4273(new ImmLeaksCleaner(this));
        }
    }

    @Override // android.app.Activity
    public void addContentView(@SuppressLint({"UnknownNullness", "MissingNullability"}) View view, @SuppressLint({"UnknownNullness", "MissingNullability"}) ViewGroup.LayoutParams layoutParams) {
        initViewTreeOwners();
        super.addContentView(view, layoutParams);
    }

    @Override // p037.p038.p039.InterfaceC1460
    public final ActivityResultRegistry getActivityResultRegistry() {
        return this.mActivityResultRegistry;
    }

    @Override // p037.p099.InterfaceC2209
    public InterfaceC2247 getDefaultViewModelProviderFactory() {
        if (getApplication() == null) {
            throw new IllegalStateException("Your activity is not yet attached to the Application instance. You can't request ViewModel before onCreate call.");
        }
        if (this.mDefaultFactory == null) {
            this.mDefaultFactory = new C2242(getApplication(), this, getIntent() != null ? getIntent().getExtras() : null);
        }
        return this.mDefaultFactory;
    }

    @Override // p037.p099.InterfaceC2219
    public AbstractC2210 getLifecycle() {
        return this.mLifecycleRegistry;
    }

    @Override // p037.p038.InterfaceC1455
    public final OnBackPressedDispatcher getOnBackPressedDispatcher() {
        return this.mOnBackPressedDispatcher;
    }

    @Override // p037.p112.InterfaceC2434
    public final C2430 getSavedStateRegistry() {
        return this.mSavedStateRegistryController.f7708;
    }

    @Override // p037.p099.InterfaceC2252
    public C2251 getViewModelStore() {
        if (getApplication() == null) {
            throw new IllegalStateException("Your activity is not yet attached to the Application instance. You can't request ViewModel before onCreate call.");
        }
        if (this.mViewModelStore == null) {
            C0024 c0024 = (C0024) getLastNonConfigurationInstance();
            if (c0024 != null) {
                this.mViewModelStore = c0024.f86;
            }
            if (this.mViewModelStore == null) {
                this.mViewModelStore = new C2251();
            }
        }
        return this.mViewModelStore;
    }

    public final void initViewTreeOwners() {
        getWindow().getDecorView().setTag(C2253.view_tree_lifecycle_owner, this);
        getWindow().getDecorView().setTag(C2254.view_tree_view_model_store_owner, this);
        getWindow().getDecorView().setTag(C2429.view_tree_saved_state_registry_owner, this);
    }

    @Override // android.app.Activity
    @Deprecated
    public void onActivityResult(int i, int i2, Intent intent) {
        if (this.mActivityResultRegistry.m93(i, i2, intent)) {
            return;
        }
        super.onActivityResult(i, i2, intent);
    }

    @Override // android.app.Activity
    public void onBackPressed() {
        this.mOnBackPressedDispatcher.m89();
    }

    @Override // p037.p065.p067.ActivityC1841, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.mSavedStateRegistryController.m4514(bundle);
        ActivityResultRegistry activityResultRegistry = this.mActivityResultRegistry;
        if (activityResultRegistry == null) {
            throw null;
        }
        if (bundle != null) {
            ArrayList<Integer> integerArrayList = bundle.getIntegerArrayList("KEY_COMPONENT_ACTIVITY_REGISTERED_RCS");
            ArrayList<String> stringArrayList = bundle.getStringArrayList("KEY_COMPONENT_ACTIVITY_REGISTERED_KEYS");
            if (stringArrayList != null && integerArrayList != null) {
                int size = stringArrayList.size();
                for (int i = 0; i < size; i++) {
                    int iIntValue = integerArrayList.get(i).intValue();
                    String str = stringArrayList.get(i);
                    activityResultRegistry.f101.put(Integer.valueOf(iIntValue), str);
                    activityResultRegistry.f102.put(str, Integer.valueOf(iIntValue));
                }
                activityResultRegistry.f100.set(size);
                activityResultRegistry.f104.putAll(bundle.getBundle("KEY_COMPONENT_ACTIVITY_PENDING_RESULT"));
            }
        }
        FragmentC2237.m4295(this);
    }

    @Override // android.app.Activity
    @Deprecated
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (this.mActivityResultRegistry.m93(i, -1, new Intent().putExtra("androidx.activity.result.contract.extra.PERMISSIONS", strArr).putExtra("androidx.activity.result.contract.extra.PERMISSION_GRANT_RESULTS", iArr)) || Build.VERSION.SDK_INT < 23) {
            return;
        }
        super.onRequestPermissionsResult(i, strArr, iArr);
    }

    @Override // android.app.Activity
    public final Object onRetainNonConfigurationInstance() {
        C0024 c0024;
        C2251 c2251 = this.mViewModelStore;
        if (c2251 == null && (c0024 = (C0024) getLastNonConfigurationInstance()) != null) {
            c2251 = c0024.f86;
        }
        if (c2251 == null) {
            return null;
        }
        C0024 c00242 = new C0024();
        c00242.f86 = c2251;
        return c00242;
    }

    @Override // p037.p065.p067.ActivityC1841, android.app.Activity
    public void onSaveInstanceState(Bundle bundle) {
        C2221 c2221 = this.mLifecycleRegistry;
        if (c2221 instanceof C2221) {
            c2221.m4281(AbstractC2210.EnumC2212.CREATED);
        }
        super.onSaveInstanceState(bundle);
        this.mSavedStateRegistryController.m4515(bundle);
        ActivityResultRegistry activityResultRegistry = this.mActivityResultRegistry;
        if (activityResultRegistry == null) {
            throw null;
        }
        bundle.putIntegerArrayList("KEY_COMPONENT_ACTIVITY_REGISTERED_RCS", new ArrayList<>(activityResultRegistry.f101.keySet()));
        bundle.putStringArrayList("KEY_COMPONENT_ACTIVITY_REGISTERED_KEYS", new ArrayList<>(activityResultRegistry.f101.values()));
        bundle.putBundle("KEY_COMPONENT_ACTIVITY_PENDING_RESULT", activityResultRegistry.f104);
    }

    @Override // android.app.Activity
    public void setContentView(int i) {
        initViewTreeOwners();
        super.setContentView(i);
    }

    @Override // android.app.Activity
    public void setContentView(@SuppressLint({"UnknownNullness", "MissingNullability"}) View view) {
        initViewTreeOwners();
        super.setContentView(view);
    }

    @Override // android.app.Activity
    public void setContentView(@SuppressLint({"UnknownNullness", "MissingNullability"}) View view, @SuppressLint({"UnknownNullness", "MissingNullability"}) ViewGroup.LayoutParams layoutParams) {
        initViewTreeOwners();
        super.setContentView(view, layoutParams);
    }

    @Override // android.app.Activity
    @Deprecated
    public void startActivityForResult(@SuppressLint({"UnknownNullness"}) Intent intent, int i) {
        super.startActivityForResult(intent, i);
    }

    @Override // android.app.Activity
    @Deprecated
    public void startActivityForResult(@SuppressLint({"UnknownNullness"}) Intent intent, int i, Bundle bundle) {
        super.startActivityForResult(intent, i, bundle);
    }

    @Override // android.app.Activity
    @Deprecated
    public void startIntentSenderForResult(@SuppressLint({"UnknownNullness"}) IntentSender intentSender, int i, Intent intent, int i2, int i3, int i4) throws IntentSender.SendIntentException {
        super.startIntentSenderForResult(intentSender, i, intent, i2, i3, i4);
    }

    @Override // android.app.Activity
    @Deprecated
    public void startIntentSenderForResult(@SuppressLint({"UnknownNullness"}) IntentSender intentSender, int i, Intent intent, int i2, int i3, int i4, Bundle bundle) throws IntentSender.SendIntentException {
        super.startIntentSenderForResult(intentSender, i, intent, i2, i3, i4, bundle);
    }
}
