package g.h.a;

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.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import androidx.core.app.a;
import androidx.lifecycle.e;
import androidx.lifecycle.s;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import okhttp3.internal.http2.Settings;

/* JADX INFO: compiled from: FragmentActivity.java */
/* JADX INFO: loaded from: classes.dex */
public class d extends androidx.core.app.d implements s {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private androidx.lifecycle.r f541g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    boolean f542h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    boolean f543i;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    boolean f545k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    boolean f546l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    int f547m;
    g.c.h<String> n;
    final Handler e = new a();
    final f f = f.b(new b());

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    boolean f544j = true;

    /* JADX INFO: compiled from: FragmentActivity.java */
    class a extends Handler {
        a() {
        }

        @Override // android.os.Handler
        public void handleMessage(Message message) {
            if (message.what != 2) {
                super.handleMessage(message);
            } else {
                d.this.p();
                d.this.f.s();
            }
        }
    }

    /* JADX INFO: compiled from: FragmentActivity.java */
    class b extends g<d> {
        public b() {
            super(d.this);
        }

        @Override // g.h.a.e
        public View b(int i2) {
            return d.this.findViewById(i2);
        }

        @Override // g.h.a.e
        public boolean c() {
            Window window = d.this.getWindow();
            return (window == null || window.peekDecorView() == null) ? false : true;
        }

        @Override // g.h.a.g
        public void h(g.h.a.c cVar) {
            d.this.n(cVar);
        }

        @Override // g.h.a.g
        public void i(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
            d.this.dump(str, fileDescriptor, printWriter, strArr);
        }

        @Override // g.h.a.g
        public LayoutInflater j() {
            return d.this.getLayoutInflater().cloneInContext(d.this);
        }

        @Override // g.h.a.g
        public int k() {
            Window window = d.this.getWindow();
            if (window == null) {
                return 0;
            }
            return window.getAttributes().windowAnimations;
        }

        @Override // g.h.a.g
        public boolean l() {
            return d.this.getWindow() != null;
        }

        @Override // g.h.a.g
        public boolean m(g.h.a.c cVar) {
            return !d.this.isFinishing();
        }

        @Override // g.h.a.g
        public void n() {
            d.this.r();
        }
    }

    /* JADX INFO: compiled from: FragmentActivity.java */
    static final class c {
        androidx.lifecycle.r a;
        j b;

        c() {
        }
    }

    static void i(int i2) {
        if ((i2 & (-65536)) != 0) {
            throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
        }
    }

    private void l() {
        while (m(k(), e.b.CREATED)) {
        }
    }

    private static boolean m(h hVar, e.b bVar) {
        boolean zM = false;
        for (g.h.a.c cVar : hVar.b()) {
            if (cVar != null) {
                if (cVar.b().b().isAtLeast(e.b.STARTED)) {
                    cVar.U.k(bVar);
                    zM = true;
                }
                h hVarX0 = cVar.X0();
                if (hVarX0 != null) {
                    zM |= m(hVarX0, bVar);
                }
            }
        }
        return zM;
    }

    @Override // androidx.lifecycle.s
    public androidx.lifecycle.r A() {
        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.f541g == null) {
            c cVar = (c) getLastNonConfigurationInstance();
            if (cVar != null) {
                this.f541g = cVar.a;
            }
            if (this.f541g == null) {
                this.f541g = new androidx.lifecycle.r();
            }
        }
        return this.f541g;
    }

    @Override // androidx.core.app.d, androidx.lifecycle.g
    public androidx.lifecycle.e b() {
        return super.b();
    }

    @Override // android.app.Activity
    public void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
        super.dump(str, fileDescriptor, printWriter, strArr);
        printWriter.print(str);
        printWriter.print("Local FragmentActivity ");
        printWriter.print(Integer.toHexString(System.identityHashCode(this)));
        printWriter.println(" State:");
        String str2 = str + "  ";
        printWriter.print(str2);
        printWriter.print("mCreated=");
        printWriter.print(this.f542h);
        printWriter.print(" mResumed=");
        printWriter.print(this.f543i);
        printWriter.print(" mStopped=");
        printWriter.print(this.f544j);
        if (getApplication() != null) {
            g.j.a.a.b(this).a(str2, fileDescriptor, printWriter, strArr);
        }
        this.f.u().a(str, fileDescriptor, printWriter, strArr);
    }

    final View j(View view, String str, Context context, AttributeSet attributeSet) {
        return this.f.w(view, str, context, attributeSet);
    }

    public h k() {
        return this.f.u();
    }

    public void n(g.h.a.c cVar) {
    }

    protected boolean o(View view, Menu menu) {
        return super.onPreparePanel(0, view, menu);
    }

    @Override // android.app.Activity
    protected void onActivityResult(int i2, int i3, Intent intent) {
        this.f.v();
        int i4 = i2 >> 16;
        if (i4 == 0) {
            a.InterfaceC0006a interfaceC0006aF = androidx.core.app.a.f();
            if (interfaceC0006aF == null || !interfaceC0006aF.a(this, i2, i3, intent)) {
                super.onActivityResult(i2, i3, intent);
                return;
            }
            return;
        }
        int i5 = i4 - 1;
        String strF = this.n.f(i5);
        this.n.j(i5);
        if (strF == null) {
            Log.w("FragmentActivity", "Activity result delivered for unknown Fragment.");
            return;
        }
        g.h.a.c cVarT = this.f.t(strF);
        if (cVarT != null) {
            cVarT.s0(i2 & Settings.DEFAULT_INITIAL_WINDOW_SIZE, i3, intent);
            return;
        }
        Log.w("FragmentActivity", "Activity result no fragment exists for who: " + strF);
    }

    @Override // android.app.Activity
    public void onBackPressed() {
        h hVarU = this.f.u();
        boolean zC = hVarU.c();
        if (!zC || Build.VERSION.SDK_INT > 25) {
            if (zC || !hVarU.d()) {
                super.onBackPressed();
            }
        }
    }

    @Override // android.app.Activity, android.content.ComponentCallbacks
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        this.f.v();
        this.f.d(configuration);
    }

    @Override // androidx.core.app.d, android.app.Activity
    protected void onCreate(Bundle bundle) {
        androidx.lifecycle.r rVar;
        this.f.a(null);
        super.onCreate(bundle);
        c cVar = (c) getLastNonConfigurationInstance();
        if (cVar != null && (rVar = cVar.a) != null && this.f541g == null) {
            this.f541g = rVar;
        }
        if (bundle != null) {
            this.f.x(bundle.getParcelable("android:support:fragments"), cVar != null ? cVar.b : null);
            if (bundle.containsKey("android:support:next_request_index")) {
                this.f547m = bundle.getInt("android:support:next_request_index");
                int[] intArray = bundle.getIntArray("android:support:request_indicies");
                String[] stringArray = bundle.getStringArray("android:support:request_fragment_who");
                if (intArray == null || stringArray == null || intArray.length != stringArray.length) {
                    Log.w("FragmentActivity", "Invalid requestCode mapping in savedInstanceState.");
                } else {
                    this.n = new g.c.h<>(intArray.length);
                    for (int i2 = 0; i2 < intArray.length; i2++) {
                        this.n.i(intArray[i2], stringArray[i2]);
                    }
                }
            }
        }
        if (this.n == null) {
            this.n = new g.c.h<>();
            this.f547m = 0;
        }
        this.f.f();
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean onCreatePanelMenu(int i2, Menu menu) {
        return i2 == 0 ? super.onCreatePanelMenu(i2, menu) | this.f.g(menu, getMenuInflater()) : super.onCreatePanelMenu(i2, menu);
    }

    @Override // android.app.Activity, android.view.LayoutInflater.Factory2
    public View onCreateView(View view, String str, Context context, AttributeSet attributeSet) {
        View viewJ = j(view, str, context, attributeSet);
        return viewJ == null ? super.onCreateView(view, str, context, attributeSet) : viewJ;
    }

    @Override // android.app.Activity
    protected void onDestroy() {
        super.onDestroy();
        if (this.f541g != null && !isChangingConfigurations()) {
            this.f541g.a();
        }
        this.f.h();
    }

    @Override // android.app.Activity, android.content.ComponentCallbacks
    public void onLowMemory() {
        super.onLowMemory();
        this.f.i();
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean onMenuItemSelected(int i2, MenuItem menuItem) {
        if (super.onMenuItemSelected(i2, menuItem)) {
            return true;
        }
        if (i2 == 0) {
            return this.f.k(menuItem);
        }
        if (i2 != 6) {
            return false;
        }
        return this.f.e(menuItem);
    }

    @Override // android.app.Activity
    public void onMultiWindowModeChanged(boolean z) {
        this.f.j(z);
    }

    @Override // android.app.Activity
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        this.f.v();
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public void onPanelClosed(int i2, Menu menu) {
        if (i2 == 0) {
            this.f.l(menu);
        }
        super.onPanelClosed(i2, menu);
    }

    @Override // android.app.Activity
    protected void onPause() {
        super.onPause();
        this.f543i = false;
        if (this.e.hasMessages(2)) {
            this.e.removeMessages(2);
            p();
        }
        this.f.m();
    }

    @Override // android.app.Activity
    public void onPictureInPictureModeChanged(boolean z) {
        this.f.n(z);
    }

    @Override // android.app.Activity
    protected void onPostResume() {
        super.onPostResume();
        this.e.removeMessages(2);
        p();
        this.f.s();
    }

    @Override // android.app.Activity, android.view.Window.Callback
    public boolean onPreparePanel(int i2, View view, Menu menu) {
        return (i2 != 0 || menu == null) ? super.onPreparePanel(i2, view, menu) : o(view, menu) | this.f.o(menu);
    }

    @Override // android.app.Activity
    public void onRequestPermissionsResult(int i2, String[] strArr, int[] iArr) {
        this.f.v();
        int i3 = (i2 >> 16) & Settings.DEFAULT_INITIAL_WINDOW_SIZE;
        if (i3 != 0) {
            int i4 = i3 - 1;
            String strF = this.n.f(i4);
            this.n.j(i4);
            if (strF == null) {
                Log.w("FragmentActivity", "Activity result delivered for unknown Fragment.");
                return;
            }
            g.h.a.c cVarT = this.f.t(strF);
            if (cVarT != null) {
                cVarT.Q0(i2 & Settings.DEFAULT_INITIAL_WINDOW_SIZE, strArr, iArr);
                return;
            }
            Log.w("FragmentActivity", "Activity result no fragment exists for who: " + strF);
        }
    }

    @Override // android.app.Activity
    protected void onResume() {
        super.onResume();
        this.e.sendEmptyMessage(2);
        this.f543i = true;
        this.f.s();
    }

    @Override // android.app.Activity
    public final Object onRetainNonConfigurationInstance() {
        Object objQ = q();
        j jVarY = this.f.y();
        if (jVarY == null && this.f541g == null && objQ == null) {
            return null;
        }
        c cVar = new c();
        cVar.a = this.f541g;
        cVar.b = jVarY;
        return cVar;
    }

    @Override // androidx.core.app.d, android.app.Activity
    protected void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        l();
        Parcelable parcelableZ = this.f.z();
        if (parcelableZ != null) {
            bundle.putParcelable("android:support:fragments", parcelableZ);
        }
        if (this.n.k() > 0) {
            bundle.putInt("android:support:next_request_index", this.f547m);
            int[] iArr = new int[this.n.k()];
            String[] strArr = new String[this.n.k()];
            for (int i2 = 0; i2 < this.n.k(); i2++) {
                iArr[i2] = this.n.h(i2);
                strArr[i2] = this.n.l(i2);
            }
            bundle.putIntArray("android:support:request_indicies", iArr);
            bundle.putStringArray("android:support:request_fragment_who", strArr);
        }
    }

    @Override // android.app.Activity
    protected void onStart() {
        super.onStart();
        this.f544j = false;
        if (!this.f542h) {
            this.f542h = true;
            this.f.c();
        }
        this.f.v();
        this.f.s();
        this.f.q();
    }

    @Override // android.app.Activity
    public void onStateNotSaved() {
        this.f.v();
    }

    @Override // android.app.Activity
    protected void onStop() {
        super.onStop();
        this.f544j = true;
        l();
        this.f.r();
    }

    protected void p() {
        this.f.p();
    }

    public Object q() {
        return null;
    }

    @Deprecated
    public void r() {
        invalidateOptionsMenu();
    }

    @Override // android.app.Activity
    public void startActivityForResult(Intent intent, int i2) {
        if (!this.f546l && i2 != -1) {
            i(i2);
        }
        super.startActivityForResult(intent, i2);
    }

    @Override // android.app.Activity
    public void startIntentSenderForResult(IntentSender intentSender, int i2, Intent intent, int i3, int i4, int i5) throws IntentSender.SendIntentException {
        if (!this.f545k && i2 != -1) {
            i(i2);
        }
        super.startIntentSenderForResult(intentSender, i2, intent, i3, i4, i5);
    }

    @Override // android.app.Activity, android.view.LayoutInflater.Factory
    public View onCreateView(String str, Context context, AttributeSet attributeSet) {
        View viewJ = j(null, str, context, attributeSet);
        return viewJ == null ? super.onCreateView(str, context, attributeSet) : viewJ;
    }

    @Override // android.app.Activity
    public void startActivityForResult(Intent intent, int i2, Bundle bundle) {
        if (!this.f546l && i2 != -1) {
            i(i2);
        }
        super.startActivityForResult(intent, i2, bundle);
    }

    @Override // android.app.Activity
    public void startIntentSenderForResult(IntentSender intentSender, int i2, Intent intent, int i3, int i4, int i5, Bundle bundle) throws IntentSender.SendIntentException {
        if (!this.f545k && i2 != -1) {
            i(i2);
        }
        super.startIntentSenderForResult(intentSender, i2, intent, i3, i4, i5, bundle);
    }
}
