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.e;
import androidx.activity.result.f;
import androidx.activity.result.g.a;
import androidx.core.app.d;
import androidx.lifecycle.ReportFragment;
import androidx.lifecycle.a0;
import androidx.lifecycle.b0;
import androidx.lifecycle.f;
import androidx.lifecycle.j;
import androidx.lifecycle.l;
import androidx.lifecycle.m;
import androidx.lifecycle.u;
import androidx.lifecycle.x;
import androidx.lifecycle.y;
import androidx.lifecycle.z;
import androidx.savedstate.SavedStateRegistry;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public class ComponentActivity extends d implements l, z, androidx.savedstate.c, androidx.activity.c, e {

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private y f6i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private x.b f7j;
    private int l;
    private androidx.activity.result.d m;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    final androidx.activity.d.a f3f = new androidx.activity.d.a();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final m f4g = new m(this);

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    final androidx.savedstate.b f5h = androidx.savedstate.b.a(this);

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private final OnBackPressedDispatcher f8k = new OnBackPressedDispatcher(new a());

    class a implements Runnable {
        a() {
        }

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

    class b extends androidx.activity.result.d {

        class a implements Runnable {

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            final /* synthetic */ int f14b;

            /* JADX INFO: renamed from: f, reason: collision with root package name */
            final /* synthetic */ a.C0002a f15f;

            a(int i2, a.C0002a c0002a) {
                this.f14b = i2;
                this.f15f = c0002a;
            }

            @Override // java.lang.Runnable
            public void run() {
                b.this.c(this.f14b, this.f15f.a());
            }
        }

        /* JADX INFO: renamed from: androidx.activity.ComponentActivity$b$b, reason: collision with other inner class name */
        class RunnableC0000b implements Runnable {

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            final /* synthetic */ int f17b;

            /* JADX INFO: renamed from: f, reason: collision with root package name */
            final /* synthetic */ IntentSender.SendIntentException f18f;

            RunnableC0000b(int i2, IntentSender.SendIntentException sendIntentException) {
                this.f17b = i2;
                this.f18f = sendIntentException;
            }

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

        b() {
        }

        @Override // androidx.activity.result.d
        public <I, O> void f(int i2, androidx.activity.result.g.a<I, O> aVar, I i3, androidx.core.app.b bVar) {
            ComponentActivity componentActivity = ComponentActivity.this;
            a.C0002a<O> c0002aB = aVar.b(componentActivity, i3);
            if (c0002aB != null) {
                new Handler(Looper.getMainLooper()).post(new a(i2, c0002aB));
                return;
            }
            Intent intentA = aVar.a(componentActivity, i3);
            Bundle bundleA = null;
            if (intentA.hasExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE")) {
                bundleA = intentA.getBundleExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE");
                intentA.removeExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE");
            } else if (bVar != null) {
                bundleA = bVar.a();
            }
            Bundle bundle = bundleA;
            if (!"androidx.activity.result.contract.action.REQUEST_PERMISSIONS".equals(intentA.getAction())) {
                if (!"androidx.activity.result.contract.action.INTENT_SENDER_REQUEST".equals(intentA.getAction())) {
                    androidx.core.app.a.i(componentActivity, intentA, i2, bundle);
                    return;
                }
                f fVar = (f) intentA.getParcelableExtra("androidx.activity.result.contract.extra.INTENT_SENDER_REQUEST");
                try {
                    androidx.core.app.a.j(componentActivity, fVar.d(), i2, fVar.a(), fVar.b(), fVar.c(), 0, bundle);
                    return;
                } catch (IntentSender.SendIntentException e2) {
                    new Handler(Looper.getMainLooper()).post(new RunnableC0000b(i2, e2));
                    return;
                }
            }
            String[] stringArrayExtra = intentA.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;
            }
            androidx.core.app.a.h(componentActivity, (String[]) arrayList.toArray(new String[0]), i2);
        }
    }

    static final class c {
        Object a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        y f20b;

        c() {
        }
    }

    public ComponentActivity() {
        new AtomicInteger();
        this.m = new b();
        if (a() == 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.");
        }
        if (Build.VERSION.SDK_INT >= 19) {
            a().a(new j() { // from class: androidx.activity.ComponentActivity.3
                @Override // androidx.lifecycle.j
                public void d(l lVar, f.b bVar) {
                    if (bVar == f.b.ON_STOP) {
                        Window window = ComponentActivity.this.getWindow();
                        View viewPeekDecorView = window != null ? window.peekDecorView() : null;
                        if (viewPeekDecorView != null) {
                            viewPeekDecorView.cancelPendingInputEvents();
                        }
                    }
                }
            });
        }
        a().a(new j() { // from class: androidx.activity.ComponentActivity.4
            @Override // androidx.lifecycle.j
            public void d(l lVar, f.b bVar) {
                if (bVar == f.b.ON_DESTROY) {
                    ComponentActivity.this.f3f.b();
                    if (ComponentActivity.this.isChangingConfigurations()) {
                        return;
                    }
                    ComponentActivity.this.j().a();
                }
            }
        });
        a().a(new j() { // from class: androidx.activity.ComponentActivity.5
            @Override // androidx.lifecycle.j
            public void d(l lVar, f.b bVar) {
                ComponentActivity.this.n();
                ComponentActivity.this.a().c(this);
            }
        });
        int i2 = Build.VERSION.SDK_INT;
        if (19 > i2 || i2 > 23) {
            return;
        }
        a().a(new ImmLeaksCleaner(this));
    }

    private void p() {
        a0.a(getWindow().getDecorView(), this);
        b0.a(getWindow().getDecorView(), this);
        androidx.savedstate.d.a(getWindow().getDecorView(), this);
    }

    @Override // androidx.lifecycle.l
    public androidx.lifecycle.f a() {
        return this.f4g;
    }

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

    @Override // androidx.activity.c
    public final OnBackPressedDispatcher c() {
        return this.f8k;
    }

    @Override // androidx.savedstate.c
    public final SavedStateRegistry d() {
        return this.f5h.b();
    }

    @Override // androidx.activity.result.e
    public final androidx.activity.result.d h() {
        return this.m;
    }

    @Override // androidx.lifecycle.z
    public y j() {
        if (getApplication() == null) {
            throw new IllegalStateException("Your activity is not yet attached to the Application instance. You can't request ViewModel before onCreate call.");
        }
        n();
        return this.f6i;
    }

    public final void m(androidx.activity.d.b bVar) {
        this.f3f.a(bVar);
    }

    void n() {
        if (this.f6i == null) {
            c cVar = (c) getLastNonConfigurationInstance();
            if (cVar != null) {
                this.f6i = cVar.f20b;
            }
            if (this.f6i == null) {
                this.f6i = new y();
            }
        }
    }

    public x.b o() {
        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.f7j == null) {
            this.f7j = new u(getApplication(), this, getIntent() != null ? getIntent().getExtras() : null);
        }
        return this.f7j;
    }

    @Override // android.app.Activity
    @Deprecated
    protected void onActivityResult(int i2, int i3, Intent intent) {
        if (this.m.b(i2, i3, intent)) {
            return;
        }
        super.onActivityResult(i2, i3, intent);
    }

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

    @Override // androidx.core.app.d, android.app.Activity
    protected void onCreate(Bundle bundle) {
        this.f5h.c(bundle);
        this.f3f.c(this);
        super.onCreate(bundle);
        this.m.g(bundle);
        ReportFragment.f(this);
        int i2 = this.l;
        if (i2 != 0) {
            setContentView(i2);
        }
    }

    @Override // android.app.Activity
    @Deprecated
    public void onRequestPermissionsResult(int i2, String[] strArr, int[] iArr) {
        if (this.m.b(i2, -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(i2, strArr, iArr);
    }

    @Override // android.app.Activity
    public final Object onRetainNonConfigurationInstance() {
        c cVar;
        Object objQ = q();
        y yVar = this.f6i;
        if (yVar == null && (cVar = (c) getLastNonConfigurationInstance()) != null) {
            yVar = cVar.f20b;
        }
        if (yVar == null && objQ == null) {
            return null;
        }
        c cVar2 = new c();
        cVar2.a = objQ;
        cVar2.f20b = yVar;
        return cVar2;
    }

    @Override // androidx.core.app.d, android.app.Activity
    protected void onSaveInstanceState(Bundle bundle) {
        androidx.lifecycle.f fVarA = a();
        if (fVarA instanceof m) {
            ((m) fVarA).o(f.c.CREATED);
        }
        super.onSaveInstanceState(bundle);
        this.f5h.d(bundle);
        this.m.h(bundle);
    }

    @Deprecated
    public Object q() {
        return null;
    }

    @Override // android.app.Activity
    public void reportFullyDrawn() {
        try {
            if (c.m.a.d()) {
                c.m.a.a("reportFullyDrawn() for " + getComponentName());
            }
            if (Build.VERSION.SDK_INT > 19) {
                super.reportFullyDrawn();
            } else if (Build.VERSION.SDK_INT == 19 && c.f.d.a.a(this, "android.permission.UPDATE_DEVICE_STATS") == 0) {
                super.reportFullyDrawn();
            }
        } finally {
            c.m.a.b();
        }
    }

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

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

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

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

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

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

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