package com.bytedance.sdk.openadsdk.yz;

import android.app.ActivityManager;
import android.os.Build;
import com.bytedance.sdk.component.utils.wey;
import java.lang.reflect.Method;
import java.util.List;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class wu {
    private static Method fm = null;
    private static boolean jnr = false;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private static Method f7683lb;
    private static Class<?> ro;
    private static Method yz;

    static {
        ro();
    }

    public static JSONObject fm() {
        JSONObject jSONObject;
        Method method;
        List list;
        Method method2;
        Method method3;
        int i10 = Build.VERSION.SDK_INT;
        JSONObject jSONObject2 = null;
        if (i10 < 35 || !lb()) {
            return null;
        }
        ro();
        try {
            jSONObject = new JSONObject();
        } catch (Throwable th) {
            th = th;
        }
        try {
            ActivityManager activityManager = (ActivityManager) com.bytedance.sdk.openadsdk.core.gof.fm().getSystemService(ActivityManager.class);
            if (activityManager != null && (method = fm) != null && (list = (List) method.invoke(activityManager, 1)) != null && !list.isEmpty()) {
                Object obj = list.get(0);
                if (i10 >= 36 && obj != null && (method3 = f7683lb) != null) {
                    jSONObject.put("start_component", ((Integer) method3.invoke(obj, new Object[0])).intValue());
                }
                if (obj != null && (method2 = yz) != null) {
                    jSONObject.put("start_reason", ((Integer) method2.invoke(obj, new Object[0])).intValue());
                }
            }
            return jSONObject;
        } catch (Throwable th2) {
            th = th2;
            jSONObject2 = jSONObject;
            wey.lb(th.getMessage(), new Object[0]);
            return jSONObject2;
        }
    }

    private static boolean lb() {
        return com.bytedance.sdk.openadsdk.hlt.jnr.fm("s_i_e", 0) == 1;
    }

    private static void ro() {
        int i10;
        if (jnr || (i10 = Build.VERSION.SDK_INT) < 35) {
            return;
        }
        try {
            if (lb()) {
                fm = ActivityManager.class.getMethod("getHistoricalProcessStartReasons", Integer.TYPE);
                Class<?> cls = Class.forName("android.app.ApplicationStartInfo");
                ro = cls;
                yz = cls.getMethod("getReason", new Class[0]);
                if (i10 >= 36) {
                    f7683lb = ro.getMethod("getStartComponent", new Class[0]);
                }
                jnr = true;
            }
        } catch (Throwable th) {
            wey.lb(th.getMessage(), new Object[0]);
        }
    }
}
