package ῲ.ᨨ.K;

import android.app.Activity;
import android.app.Application;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

/* renamed from: ῲ.ᨨ.K.ῲ  reason: contains not printable characters */
/* compiled from: ActivityRecreator */
public final class C1821 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public static final Field f6201;

    /* renamed from: ඓ  reason: contains not printable characters */
    public static final Method f6202;

    /* renamed from: ῲ  reason: contains not printable characters */
    public static final Field f6203;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static final Handler f6204 = new Handler(Looper.getMainLooper());

    /* renamed from: K  reason: contains not printable characters */
    public static final Class<?> f6205;

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final Method f6206;

    /* renamed from: 㸾  reason: contains not printable characters */
    public static final Method f6207;

    /* renamed from: ῲ.ᨨ.K.ῲ$ʬ  reason: contains not printable characters */
    /* compiled from: ActivityRecreator */
    public class RunnableC1822 implements Runnable {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final /* synthetic */ Object f6208;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ Object f6209;

        public RunnableC1822(Object obj, Object obj2) {
            this.f6209 = obj;
            this.f6208 = obj2;
        }

        public void run() {
            try {
                if (C1821.f6207 != null) {
                    C1821.f6207.invoke(this.f6209, this.f6208, false, "AppCompat recreation");
                    return;
                }
                C1821.f6202.invoke(this.f6209, this.f6208, false);
            } catch (RuntimeException e) {
                if (e.getClass() == RuntimeException.class && e.getMessage() != null && e.getMessage().startsWith("Unable to stop")) {
                    throw e;
                }
            } catch (Throwable th) {
                Log.e("ActivityRecreator", "Exception while invoking performStopActivity", th);
            }
        }
    }

    /* renamed from: ῲ.ᨨ.K.ῲ$ῲ  reason: contains not printable characters */
    /* compiled from: ActivityRecreator */
    public class RunnableC1823 implements Runnable {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final /* synthetic */ C1825 f6210;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ Application f6211;

        public RunnableC1823(Application application, C1825 r2) {
            this.f6211 = application;
            this.f6210 = r2;
        }

        public void run() {
            this.f6211.unregisterActivityLifecycleCallbacks(this.f6210);
        }
    }

    /* renamed from: ῲ.ᨨ.K.ῲ$K  reason: contains not printable characters */
    /* compiled from: ActivityRecreator */
    public class RunnableC1824 implements Runnable {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final /* synthetic */ Object f6212;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ C1825 f6213;

        public RunnableC1824(C1825 r1, Object obj) {
            this.f6213 = r1;
            this.f6212 = obj;
        }

        public void run() {
            this.f6213.f6217 = this.f6212;
        }
    }

    /* renamed from: ῲ.ᨨ.K.ῲ$㸾  reason: contains not printable characters */
    /* compiled from: ActivityRecreator */
    public static final class C1825 implements Application.ActivityLifecycleCallbacks {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final int f6214;

        /* renamed from: ඓ  reason: contains not printable characters */
        public boolean f6215 = false;

        /* renamed from: ῲ  reason: contains not printable characters */
        public Activity f6216;

        /* renamed from: K  reason: contains not printable characters */
        public Object f6217;

        /* renamed from: 㴹  reason: contains not printable characters */
        public boolean f6218 = false;

        /* renamed from: 㸾  reason: contains not printable characters */
        public boolean f6219 = false;

        public C1825(Activity activity) {
            this.f6216 = activity;
            this.f6214 = this.f6216.hashCode();
        }

        public void onActivityCreated(Activity activity, Bundle bundle) {
        }

        public void onActivityDestroyed(Activity activity) {
            if (this.f6216 == activity) {
                this.f6216 = null;
                this.f6215 = true;
            }
        }

        public void onActivityPaused(Activity activity) {
            if (this.f6215 && !this.f6218 && !this.f6219 && C1821.m4713(this.f6217, this.f6214, activity)) {
                this.f6218 = true;
                this.f6217 = null;
            }
        }

        public void onActivityResumed(Activity activity) {
        }

        public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
        }

        public void onActivityStarted(Activity activity) {
            if (this.f6216 == activity) {
                this.f6219 = true;
            }
        }

        public void onActivityStopped(Activity activity) {
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:25:0x005d A[SYNTHETIC, Splitter:B:25:0x005d] */
    static {
        Class<?> cls;
        Field field;
        Field field2;
        Method method;
        Class<?> cls2;
        Method method2;
        Class<?> cls3;
        Method method3 = null;
        try {
            cls = Class.forName("android.app.ActivityThread");
        } catch (Throwable unused) {
            cls = null;
        }
        f6205 = cls;
        try {
            field = Activity.class.getDeclaredField("mMainThread");
            field.setAccessible(true);
        } catch (Throwable unused2) {
            field = null;
        }
        f6203 = field;
        try {
            field2 = Activity.class.getDeclaredField("mToken");
            field2.setAccessible(true);
        } catch (Throwable unused3) {
            field2 = null;
        }
        f6201 = field2;
        Class<?> cls4 = f6205;
        if (cls4 != null) {
            try {
                method = cls4.getDeclaredMethod("performStopActivity", IBinder.class, Boolean.TYPE, String.class);
                method.setAccessible(true);
            } catch (Throwable unused4) {
            }
            f6207 = method;
            cls2 = f6205;
            if (cls2 != null) {
                try {
                    method2 = cls2.getDeclaredMethod("performStopActivity", IBinder.class, Boolean.TYPE);
                    method2.setAccessible(true);
                } catch (Throwable unused5) {
                }
                f6202 = method2;
                cls3 = f6205;
                if (m4711() && cls3 != null) {
                    Method declaredMethod = cls3.getDeclaredMethod("requestRelaunchActivity", IBinder.class, List.class, List.class, Integer.TYPE, Boolean.TYPE, Configuration.class, Configuration.class, Boolean.TYPE, Boolean.TYPE);
                    declaredMethod.setAccessible(true);
                    method3 = declaredMethod;
                }
                f6206 = method3;
            }
            method2 = null;
            f6202 = method2;
            cls3 = f6205;
            Method declaredMethod2 = cls3.getDeclaredMethod("requestRelaunchActivity", IBinder.class, List.class, List.class, Integer.TYPE, Boolean.TYPE, Configuration.class, Configuration.class, Boolean.TYPE, Boolean.TYPE);
            declaredMethod2.setAccessible(true);
            method3 = declaredMethod2;
            f6206 = method3;
        }
        method = null;
        f6207 = method;
        cls2 = f6205;
        if (cls2 != null) {
        }
        method2 = null;
        f6202 = method2;
        cls3 = f6205;
        try {
            Method declaredMethod22 = cls3.getDeclaredMethod("requestRelaunchActivity", IBinder.class, List.class, List.class, Integer.TYPE, Boolean.TYPE, Configuration.class, Configuration.class, Boolean.TYPE, Boolean.TYPE);
            declaredMethod22.setAccessible(true);
            method3 = declaredMethod22;
        } catch (Throwable unused6) {
        }
        f6206 = method3;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m4712(Activity activity) {
        Object obj;
        if (Build.VERSION.SDK_INT >= 28) {
            activity.recreate();
            return true;
        } else if (m4711() && f6206 == null) {
            return false;
        } else {
            if (f6202 == null && f6207 == null) {
                return false;
            }
            try {
                Object obj2 = f6201.get(activity);
                if (obj2 == null || (obj = f6203.get(activity)) == null) {
                    return false;
                }
                Application application = activity.getApplication();
                C1825 r5 = new C1825(activity);
                application.registerActivityLifecycleCallbacks(r5);
                f6204.post(new RunnableC1824(r5, obj2));
                try {
                    if (m4711()) {
                        f6206.invoke(obj, obj2, null, null, 0, false, null, null, false, false);
                    } else {
                        activity.recreate();
                    }
                    return true;
                } finally {
                    f6204.post(new RunnableC1823(application, r5));
                }
            } catch (Throwable unused) {
                return false;
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m4713(Object obj, int i, Activity activity) {
        try {
            Object obj2 = f6201.get(activity);
            if (obj2 == obj) {
                if (activity.hashCode() == i) {
                    f6204.postAtFrontOfQueue(new RunnableC1822(f6203.get(activity), obj2));
                    return true;
                }
            }
            return false;
        } catch (Throwable th) {
            Log.e("ActivityRecreator", "Exception while fetching field values", th);
            return false;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m4711() {
        int i = Build.VERSION.SDK_INT;
        return i == 26 || i == 27;
    }
}
