package androidx.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.lifecycle.a0;
import androidx.lifecycle.c0;
import androidx.lifecycle.d0;
import androidx.lifecycle.e0;
import androidx.lifecycle.f0;
import androidx.lifecycle.g;
import androidx.lifecycle.k;
import androidx.lifecycle.l;
import androidx.lifecycle.t;
import androidx.lifecycle.w;
import g0.c;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public class ComponentActivity extends androidx.core.app.e implements d0, androidx.lifecycle.f, g0.e, h, androidx.activity.result.e {

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final androidx.core.view.i f25g = new androidx.core.view.i(new Runnable() { // from class: androidx.activity.d
        @Override // java.lang.Runnable
        public final void run() {
            this.f58e.r();
        }
    });

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private final l f26h = new l(this);

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    final g0.d f27i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private c0 f28j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private final OnBackPressedDispatcher f29k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private int f30l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private final androidx.activity.result.d f31m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private final CopyOnWriteArrayList<androidx.core.util.a<Configuration>> f32n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private final CopyOnWriteArrayList<androidx.core.util.a<Integer>> f33o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private final CopyOnWriteArrayList<androidx.core.util.a<Intent>> f34p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private final CopyOnWriteArrayList<androidx.core.util.a<androidx.core.app.f>> f35q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private final CopyOnWriteArrayList<androidx.core.util.a<androidx.core.app.h>> f36r;

    class a implements Runnable {
        a() {
        }

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

    class b extends androidx.activity.result.d {
        b(ComponentActivity componentActivity) {
        }
    }

    static class c {
        static void a(View view) {
            view.cancelPendingInputEvents();
        }
    }

    static final class d {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        Object f41a;

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

        d() {
        }
    }

    public ComponentActivity() {
        g0.d dVarA = g0.d.a(this);
        this.f27i = dVarA;
        this.f29k = new OnBackPressedDispatcher(new a());
        new AtomicInteger();
        this.f31m = new b(this);
        this.f32n = new CopyOnWriteArrayList<>();
        this.f33o = new CopyOnWriteArrayList<>();
        this.f34p = new CopyOnWriteArrayList<>();
        this.f35q = new CopyOnWriteArrayList<>();
        this.f36r = new CopyOnWriteArrayList<>();
        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.");
        }
        int i3 = Build.VERSION.SDK_INT;
        if (i3 >= 19) {
            a().a(new androidx.lifecycle.i() { // from class: androidx.activity.ComponentActivity.3
                @Override // androidx.lifecycle.i
                public void g(k kVar, g.b bVar) {
                    if (bVar == g.b.ON_STOP) {
                        Window window = ComponentActivity.this.getWindow();
                        View viewPeekDecorView = window != null ? window.peekDecorView() : null;
                        if (viewPeekDecorView != null) {
                            c.a(viewPeekDecorView);
                        }
                    }
                }
            });
        }
        a().a(new androidx.lifecycle.i() { // from class: androidx.activity.ComponentActivity.4
            @Override // androidx.lifecycle.i
            public void g(k kVar, g.b bVar) {
                if (bVar == g.b.ON_DESTROY) {
                    ComponentActivity.this.f24f.b();
                    if (ComponentActivity.this.isChangingConfigurations()) {
                        return;
                    }
                    ComponentActivity.this.i().a();
                }
            }
        });
        a().a(new androidx.lifecycle.i() { // from class: androidx.activity.ComponentActivity.5
            @Override // androidx.lifecycle.i
            public void g(k kVar, g.b bVar) {
                ComponentActivity.this.p();
                ComponentActivity.this.a().c(this);
            }
        });
        dVarA.c();
        w.a(this);
        if (19 <= i3 && i3 <= 23) {
            a().a(new ImmLeaksCleaner(this));
        }
        d().h("android:support:activity-result", new c.InterfaceC0065c() { // from class: androidx.activity.c
            @Override // g0.c.InterfaceC0065c
            public final Bundle a() {
                return this.f57a.s();
            }
        });
        o(new a.b() { // from class: androidx.activity.b
            @Override // a.b
            public final void a(Context context) {
                this.f56a.t(context);
            }
        });
    }

    private void q() {
        e0.a(getWindow().getDecorView(), this);
        f0.a(getWindow().getDecorView(), this);
        g0.f.a(getWindow().getDecorView(), this);
        j.a(getWindow().getDecorView(), this);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ Bundle s() {
        Bundle bundle = new Bundle();
        this.f31m.f(bundle);
        return bundle;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void t(Context context) {
        Bundle bundleB = d().b("android:support:activity-result");
        if (bundleB != null) {
            this.f31m.e(bundleB);
        }
    }

    @Override // androidx.lifecycle.k
    public androidx.lifecycle.g a() {
        return this.f26h;
    }

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

    @Override // androidx.lifecycle.f
    public d0.a b() {
        d0.d dVar = new d0.d();
        if (getApplication() != null) {
            dVar.b(a0.a.f2548b, getApplication());
        }
        dVar.b(w.f2589a, this);
        dVar.b(w.f2590b, this);
        if (getIntent() != null && getIntent().getExtras() != null) {
            dVar.b(w.f2591c, getIntent().getExtras());
        }
        return dVar;
    }

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

    @Override // g0.e
    public final g0.c d() {
        return this.f27i.b();
    }

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

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

    public final void o(a.b bVar) {
        this.f24f.a(bVar);
    }

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

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

    @Override // android.app.Activity, android.content.ComponentCallbacks
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        Iterator<androidx.core.util.a<Configuration>> it = this.f32n.iterator();
        while (it.hasNext()) {
            it.next().a(configuration);
        }
    }

    @Override // androidx.core.app.e, android.app.Activity
    protected void onCreate(Bundle bundle) {
        this.f27i.d(bundle);
        this.f24f.c(this);
        super.onCreate(bundle);
        t.g(this);
        int i3 = this.f30l;
        if (i3 != 0) {
            setContentView(i3);
        }
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean onCreatePanelMenu(int i3, Menu menu) {
        if (i3 != 0) {
            return true;
        }
        super.onCreatePanelMenu(i3, menu);
        this.f25g.a(menu, getMenuInflater());
        return true;
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean onMenuItemSelected(int i3, MenuItem menuItem) {
        if (super.onMenuItemSelected(i3, menuItem)) {
            return true;
        }
        if (i3 == 0) {
            return this.f25g.c(menuItem);
        }
        return false;
    }

    @Override // android.app.Activity
    public void onMultiWindowModeChanged(boolean z2) {
        Iterator<androidx.core.util.a<androidx.core.app.f>> it = this.f35q.iterator();
        while (it.hasNext()) {
            it.next().a(new androidx.core.app.f(z2));
        }
    }

    @Override // android.app.Activity
    protected void onNewIntent(@SuppressLint({"UnknownNullness", "MissingNullability"}) Intent intent) {
        super.onNewIntent(intent);
        Iterator<androidx.core.util.a<Intent>> it = this.f34p.iterator();
        while (it.hasNext()) {
            it.next().a(intent);
        }
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public void onPanelClosed(int i3, Menu menu) {
        this.f25g.b(menu);
        super.onPanelClosed(i3, menu);
    }

    @Override // android.app.Activity
    public void onPictureInPictureModeChanged(boolean z2) {
        Iterator<androidx.core.util.a<androidx.core.app.h>> it = this.f36r.iterator();
        while (it.hasNext()) {
            it.next().a(new androidx.core.app.h(z2));
        }
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean onPreparePanel(int i3, View view, Menu menu) {
        if (i3 != 0) {
            return true;
        }
        super.onPreparePanel(i3, view, menu);
        this.f25g.d(menu);
        return true;
    }

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

    @Override // android.app.Activity
    public final Object onRetainNonConfigurationInstance() {
        d dVar;
        Object objU = u();
        c0 c0Var = this.f28j;
        if (c0Var == null && (dVar = (d) getLastNonConfigurationInstance()) != null) {
            c0Var = dVar.f42b;
        }
        if (c0Var == null && objU == null) {
            return null;
        }
        d dVar2 = new d();
        dVar2.f41a = objU;
        dVar2.f42b = c0Var;
        return dVar2;
    }

    @Override // androidx.core.app.e, android.app.Activity
    protected void onSaveInstanceState(Bundle bundle) {
        androidx.lifecycle.g gVarA = a();
        if (gVarA instanceof l) {
            ((l) gVarA).o(g.c.CREATED);
        }
        super.onSaveInstanceState(bundle);
        this.f27i.e(bundle);
    }

    @Override // android.app.Activity, android.content.ComponentCallbacks2
    public void onTrimMemory(int i3) {
        super.onTrimMemory(i3);
        Iterator<androidx.core.util.a<Integer>> it = this.f33o.iterator();
        while (it.hasNext()) {
            it.next().a(Integer.valueOf(i3));
        }
    }

    void p() {
        if (this.f28j == null) {
            d dVar = (d) getLastNonConfigurationInstance();
            if (dVar != null) {
                this.f28j = dVar.f42b;
            }
            if (this.f28j == null) {
                this.f28j = new c0();
            }
        }
    }

    public void r() {
        invalidateOptionsMenu();
    }

    @Override // android.app.Activity
    public void reportFullyDrawn() {
        try {
            if (i0.a.d()) {
                i0.a.a("reportFullyDrawn() for ComponentActivity");
            }
            int i3 = Build.VERSION.SDK_INT;
            if (i3 > 19) {
                super.reportFullyDrawn();
            } else if (i3 == 19 && androidx.core.content.a.a(this, "android.permission.UPDATE_DEVICE_STATS") == 0) {
                super.reportFullyDrawn();
            }
        } finally {
            i0.a.b();
        }
    }

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

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

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

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

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

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

    @Override // android.app.Activity
    public void onMultiWindowModeChanged(boolean z2, Configuration configuration) {
        Iterator<androidx.core.util.a<androidx.core.app.f>> it = this.f35q.iterator();
        while (it.hasNext()) {
            it.next().a(new androidx.core.app.f(z2, configuration));
        }
    }

    @Override // android.app.Activity
    public void onPictureInPictureModeChanged(boolean z2, Configuration configuration) {
        Iterator<androidx.core.util.a<androidx.core.app.h>> it = this.f36r.iterator();
        while (it.hasNext()) {
            it.next().a(new androidx.core.app.h(z2, configuration));
        }
    }

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

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