package com.ss.android.ugc.aweme.utils;

import X.3GY;
import X.AnonymousClass7iX;
import X.C22428Zd;
import X.C22438Ze;
import X.C25518ec;
import X.C42869Ft;
import X.C42909Fx;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.Pair;
import com.bytedance.covode.number.Covode;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class PreventServerSideCrashes implements C22438Ze {
    public static Activity LIZ;
    public static Field LIZIZ;
    public static Object LIZJ;
    public static Object LIZLLL;
    public static boolean LJ;
    public static CopyOnWriteArrayList<AnonymousClass7iX> LJFF = new CopyOnWriteArrayList<>();

    public static Object LIZ(Method method, Object obj, Object[] objArr) {
        3GY.LIZ(110000);
        Method method2 = method;
        Pair LIZ2 = 3GY.LIZ((Object) null, method2, new Object[]{obj, objArr}, 110000, "java.lang.Object", true, -743082703, 2);
        return ((Boolean) LIZ2.first).booleanValue() ? LIZ2.second : method2.invoke(obj, objArr);
    }

    public boolean meetTrigger() {
        return true;
    }

    public String prefix() {
        return "task_";
    }

    public boolean serialExecute() {
        return false;
    }

    public int targetProcess() {
        return 1048575;
    }

    public List triggerOtherLegoComponents() {
        return null;
    }

    public C42869Ft triggerType() {
        return C22428Zd.LIZ(this);
    }

    public C42909Fx scenesType() {
        return C42909Fx.DEFAULT;
    }

    public C25518ec type() {
        return C25518ec.BACKGROUND;
    }

    static {
        Covode.recordClassIndex(122060);
    }

    public String key() {
        return getClass().getSimpleName();
    }

    /* JADX WARNING: Code restructure failed: missing block: B:54:?, code lost:
        com.bytedance.frameworks.apm.trace.MethodCollector.o(3778);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:56:0x00c1, code lost:
        return;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:58:?, code lost:
        com.bytedance.frameworks.apm.trace.MethodCollector.o(3778);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:60:0x00c6, code lost:
        return;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:62:?, code lost:
        com.bytedance.frameworks.apm.trace.MethodCollector.o(3778);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:64:0x00cb, code lost:
        return;
     */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    /* JADX WARNING: Missing exception handler attribute for start block: B:21:0x003d */
    /* JADX WARNING: Missing exception handler attribute for start block: B:53:0x00bd */
    /* JADX WARNING: Missing exception handler attribute for start block: B:57:0x00c2 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:61:0x00c7 */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static synchronized void LIZ() {
        /*
            java.lang.Class<com.ss.android.ugc.aweme.utils.PreventServerSideCrashes> r7 = com.ss.android.ugc.aweme.utils.PreventServerSideCrashes.class
            monitor-enter(r7)
            r6 = 3778(0xec2, float:5.294E-42)
            com.bytedance.frameworks.apm.trace.MethodCollector.i(r6)     // Catch:{ all -> 0x00cc }
            boolean r0 = LJ     // Catch:{ all -> 0x00cc }
            if (r0 == 0) goto L_0x0011
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r6)     // Catch:{ all -> 0x00cc }
            monitor-exit(r7)
            return
        L_0x0011:
            r5 = 1
            LJ = r5     // Catch:{ all -> 0x00cc }
            boolean r0 = X.C04117fo.LIZ     // Catch:{ all -> 0x00cc }
            r2 = 0
            if (r0 != 0) goto L_0x003f
            java.lang.Class<X.7iY> r3 = X.AnonymousClass7iY.class
            java.lang.String r1 = "classLoader"
            java.lang.String r0 = "target object must not be null"
            X.C04117fo.LIZ(r3, (java.lang.String) r0)     // Catch:{ Exception -> 0x003d }
            java.lang.Class r0 = r3.getClass()     // Catch:{ Exception -> 0x003d }
            java.lang.reflect.Field r1 = X.C04117fo.LIZ((java.lang.Class<?>) r0, (java.lang.String) r1)     // Catch:{ Exception -> 0x003d }
            if (r1 == 0) goto L_0x003d
            java.lang.String r0 = "The field must not be null"
            X.C04117fo.LIZ(r1, (java.lang.String) r0)     // Catch:{ Exception -> 0x003d }
            boolean r0 = r1.isAccessible()     // Catch:{ Exception -> 0x003d }
            if (r0 != 0) goto L_0x003a
            r1.setAccessible(r5)     // Catch:{ Exception -> 0x003d }
        L_0x003a:
            r1.set(r3, r2)     // Catch:{ Exception -> 0x003d }
        L_0x003d:
            X.C04117fo.LIZ = r5     // Catch:{ all -> 0x00cc }
        L_0x003f:
            int r1 = android.os.Build.VERSION.SDK_INT     // Catch:{ all -> 0x00cc }
            r0 = 28
            if (r1 <= r0) goto L_0x004a
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r6)     // Catch:{ all -> 0x00cc }
            monitor-exit(r7)
            return
        L_0x004a:
            int r1 = android.os.Build.VERSION.SDK_INT     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            r0 = 26
            if (r1 >= r0) goto L_0x007f
            java.lang.String r0 = "android.app.ActivityManagerNative"
            java.lang.Class r1 = java.lang.Class.forName(r0)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.String r0 = "gDefault"
            java.lang.reflect.Field r0 = r1.getDeclaredField(r0)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
        L_0x005c:
            r0.setAccessible(r5)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.Object r0 = r0.get(r2)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            LIZJ = r0     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.String r0 = "android.util.Singleton"
            java.lang.Class r1 = java.lang.Class.forName(r0)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.String r0 = "mInstance"
            java.lang.reflect.Field r0 = r1.getDeclaredField(r0)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            LIZIZ = r0     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            r0.setAccessible(r5)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.reflect.Field r1 = LIZIZ     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.Object r0 = LIZJ     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.Object r4 = r1.get(r0)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            goto L_0x008c
        L_0x007f:
            java.lang.String r0 = "android.app.ActivityManager"
            java.lang.Class r1 = java.lang.Class.forName(r0)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.String r0 = "IActivityManagerSingleton"
            java.lang.reflect.Field r0 = r1.getDeclaredField(r0)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            goto L_0x005c
        L_0x008c:
            if (r4 != 0) goto L_0x0093
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r6)     // Catch:{ all -> 0x00cc }
            monitor-exit(r7)
            return
        L_0x0093:
            java.lang.String r0 = "android.app.IActivityManager"
            java.lang.Class r3 = java.lang.Class.forName(r0)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            if (r3 != 0) goto L_0x00a0
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r6)     // Catch:{ all -> 0x00cc }
            monitor-exit(r7)
            return
        L_0x00a0:
            java.lang.Thread r0 = java.lang.Thread.currentThread()     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.ClassLoader r2 = r0.getContextClassLoader()     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.Class[] r1 = new java.lang.Class[r5]     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            r0 = 0
            r1[r0] = r3     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            X.7iW r0 = new X.7iW     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            r0.<init>(r4)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            java.lang.Object r0 = java.lang.reflect.Proxy.newProxyInstance(r2, r1, r0)     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            LIZLLL = r0     // Catch:{ ClassNotFoundException -> 0x00c7, NoSuchFieldException -> 0x00c2, IllegalAccessException -> 0x00bd }
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r6)     // Catch:{ all -> 0x00cc }
            monitor-exit(r7)
            return
        L_0x00bd:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r6)     // Catch:{ all -> 0x00cc }
            monitor-exit(r7)
            return
        L_0x00c2:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r6)     // Catch:{ all -> 0x00cc }
            monitor-exit(r7)
            return
        L_0x00c7:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r6)     // Catch:{ all -> 0x00cc }
            monitor-exit(r7)
            return
        L_0x00cc:
            r0 = move-exception
            monitor-exit(r7)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.utils.PreventServerSideCrashes.LIZ():void");
    }

    public void run(Context context) {
        if (Build.VERSION.SDK_INT <= 28) {
            LIZ();
        }
    }

    public static Throwable LIZ(Throwable th) {
        RuntimeException runtimeException;
        try {
            StackTraceElement[] stackTrace = th.getStackTrace();
            if (th instanceof InvocationTargetException) {
                InvocationTargetException invocationTargetException = (InvocationTargetException) th;
                if (invocationTargetException.getTargetException() != null) {
                    th = invocationTargetException.getTargetException();
                    stackTrace = th.getStackTrace();
                } else {
                    runtimeException = new RuntimeException();
                    th = runtimeException;
                }
            } else if (th instanceof UndeclaredThrowableException) {
                UndeclaredThrowableException undeclaredThrowableException = (UndeclaredThrowableException) th;
                if (undeclaredThrowableException.getUndeclaredThrowable() != null) {
                    th = undeclaredThrowableException.getUndeclaredThrowable();
                    stackTrace = th.getStackTrace();
                } else {
                    runtimeException = new RuntimeException();
                    th = runtimeException;
                }
            }
            ArrayList arrayList = new ArrayList();
            for (StackTraceElement stackTraceElement : stackTrace) {
                if (stackTraceElement != null) {
                    String className = stackTraceElement.getClassName();
                    if (TextUtils.isEmpty(className) || (!className.contains("com.ss.android.ugc.aweme.utils.PreventServerSideCrashes") && !className.equals(Proxy.class.getName()) && !className.equals(Method.class.getName()))) {
                        arrayList.add(stackTraceElement);
                    }
                }
            }
            if (arrayList.isEmpty()) {
                return th;
            }
            int size = arrayList.size();
            StackTraceElement[] stackTraceElementArr = new StackTraceElement[size];
            for (int i = 0; i < size; i++) {
                stackTraceElementArr[i] = (StackTraceElement) arrayList.get(i);
            }
            th.setStackTrace(stackTraceElementArr);
            return th;
        } catch (Throwable unused) {
        }
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:31:0x005f */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static final /* synthetic */ java.lang.Object LIZ(java.lang.Object r4, java.lang.reflect.Method r5, java.lang.Object[] r6) {
        /*
            java.lang.String r1 = r5.getName()
            java.lang.String r0 = "reportSizeConfigurations"
            boolean r0 = r1.contains(r0)
            r3 = 0
            r2 = 24
            if (r0 == 0) goto L_0x0022
            int r0 = android.os.Build.VERSION.SDK_INT
            if (r0 < r2) goto L_0x0022
            java.lang.Object r0 = LIZ((java.lang.reflect.Method) r5, (java.lang.Object) r4, (java.lang.Object[]) r6)     // Catch:{ InvocationTargetException -> 0x0018 }
            return r0
        L_0x0018:
            r0 = move-exception
            java.lang.Throwable r0 = r0.getTargetException()
            boolean r0 = r0 instanceof java.lang.IllegalArgumentException
            if (r0 == 0) goto L_0x0022
            return r3
        L_0x0022:
            java.lang.String r1 = r5.getName()
            java.lang.String r0 = "isTopOfTask"
            boolean r0 = r1.contains(r0)
            if (r0 == 0) goto L_0x0046
            int r0 = android.os.Build.VERSION.SDK_INT
            if (r0 < r2) goto L_0x0046
            java.lang.Object r0 = LIZ((java.lang.reflect.Method) r5, (java.lang.Object) r4, (java.lang.Object[]) r6)     // Catch:{ InvocationTargetException -> 0x0037 }
            return r0
        L_0x0037:
            r0 = move-exception
            java.lang.Throwable r0 = r0.getTargetException()
            boolean r0 = r0 instanceof java.lang.IllegalArgumentException
            if (r0 == 0) goto L_0x0046
            r0 = 0
            java.lang.Boolean r0 = java.lang.Boolean.valueOf(r0)
            return r0
        L_0x0046:
            java.lang.String r1 = r5.getName()
            java.lang.String r0 = "willActivityBeVisible"
            boolean r0 = r1.contains(r0)
            if (r0 == 0) goto L_0x005f
            android.app.Activity r0 = LIZ     // Catch:{ IllegalArgumentException -> 0x0058, all -> 0x005f }
            r0.isImmersive()     // Catch:{ IllegalArgumentException -> 0x0058, all -> 0x005f }
            goto L_0x005f
        L_0x0058:
            android.app.Activity r0 = LIZ
            if (r0 == 0) goto L_0x005f
            r0.finish()
        L_0x005f:
            java.lang.Object r0 = LIZ((java.lang.reflect.Method) r5, (java.lang.Object) r4, (java.lang.Object[]) r6)     // Catch:{ all -> 0x0064 }
            return r0
        L_0x0064:
            r2 = move-exception
            java.util.concurrent.CopyOnWriteArrayList<X.7iX> r0 = LJFF
            java.util.Iterator r1 = r0.iterator()
        L_0x006b:
            boolean r0 = r1.hasNext()
            if (r0 == 0) goto L_0x007e
            java.lang.Object r0 = r1.next()
            X.7iX r0 = (X.AnonymousClass7iX) r0
            boolean r0 = r0.LIZ()
            if (r0 == 0) goto L_0x006b
            return r3
        L_0x007e:
            java.lang.Throwable r0 = LIZ(r2)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.utils.PreventServerSideCrashes.LIZ(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]):java.lang.Object");
    }
}
