package com.bytedance.sdk.openadsdk.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.text.TextUtils;
import android.webkit.WebView;
import io.flutter.embedding.android.FlutterActivity;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicReference;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class wu {
    private static final AtomicReference<Boolean> fm = new AtomicReference<>(null);
    private static final AtomicReference<String> ro = new AtomicReference<>(null);

    public static PackageInfo ajl(Context context) {
        try {
            if (Build.VERSION.SDK_INT >= 26) {
                return WebView.getCurrentWebViewPackage();
            }
            PackageInfo packageInfo = (PackageInfo) Class.forName("android.webkit.WebViewFactory").getMethod("getLoadedPackageInfo", new Class[0]).invoke(null, new Object[0]);
            return packageInfo != null ? packageInfo : ku(context);
        } catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) {
            return null;
        }
    }

    private static boolean ef(Context context) {
        try {
            int i10 = FlutterActivity.f27835e;
            return true;
        } catch (ClassNotFoundException unused) {
            if (context == null) {
                return false;
            }
            try {
                return new File(context.getApplicationInfo().nativeLibraryDir + "/libflutter.so").exists();
            } catch (Throwable unused2) {
                return false;
            }
        }
    }

    public static void fm(Context context) {
        if (context == null) {
            return;
        }
        try {
            if (ro()) {
                com.bytedance.sdk.openadsdk.core.lb lbVarFm = com.bytedance.sdk.openadsdk.core.lb.fm();
                lbVarFm.fm("w_ver", jnr(context));
                lbVarFm.fm("bp", ro(context));
                lbVarFm.fm("is_fold", wsy(context) ? 1 : 0);
                lbVarFm.fm("abi", fm());
                lbVarFm.fm("t_ver", lb(context));
                lbVarFm.fm("aab", yz(context));
            }
        } catch (Throwable unused) {
        }
    }

    public static String jnr(Context context) {
        try {
            AtomicReference<String> atomicReference = ro;
            String str = atomicReference.get();
            if (str != null) {
                return str;
            }
            PackageInfo packageInfoAjl = ajl(context);
            String str2 = packageInfoAjl != null ? packageInfoAjl.versionName : "";
            while (!atomicReference.compareAndSet(null, str2) && atomicReference.get() == null) {
            }
            return str2;
        } catch (Throwable unused) {
            AtomicReference<String> atomicReference2 = ro;
            while (!atomicReference2.compareAndSet(null, "") && atomicReference2.get() == null) {
            }
            return "";
        }
    }

    private static PackageInfo ku(Context context) {
        try {
            String str = (String) Class.forName("android.webkit.WebViewUpdateService").getMethod("getCurrentWebViewPackageName", new Class[0]).invoke(null, new Object[0]);
            if (str == null) {
                return null;
            }
            return context.getPackageManager().getPackageInfo(str, 0);
        } catch (Throwable unused) {
            return null;
        }
    }

    public static String lb(Context context) {
        try {
            return String.valueOf(context.getApplicationInfo().targetSdkVersion);
        } catch (Throwable unused) {
            return "";
        }
    }

    public static int ro(Context context) {
        if (wu(context)) {
            return 1;
        }
        if (ef(context)) {
            return 2;
        }
        return vt(context) ? 3 : 4;
    }

    private static boolean vt(Context context) {
        try {
            Class.forName("com.facebook.react.ReactActivity");
            return true;
        } catch (ClassNotFoundException unused) {
            if (context == null) {
                return false;
            }
            try {
                return new File(context.getApplicationInfo().nativeLibraryDir + "/libreactnativejni.so").exists();
            } catch (Throwable unused2) {
                return false;
            }
        }
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:42:0x007f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static boolean wsy(Context context) {
        boolean zYz;
        boolean z10;
        byte b10;
        try {
            AtomicReference<Boolean> atomicReference = fm;
            Boolean bool = atomicReference.get();
            if (bool != null) {
                return bool.booleanValue();
            }
            String lowerCase = Build.BRAND;
            if (!TextUtils.isEmpty(lowerCase)) {
                lowerCase = lowerCase.toLowerCase();
            }
            String lowerCase2 = Build.MANUFACTURER;
            if (!TextUtils.isEmpty(lowerCase2)) {
                lowerCase2 = lowerCase2.toLowerCase();
            }
            if (TextUtils.isEmpty(lowerCase) && TextUtils.isEmpty(lowerCase2)) {
                Boolean bool2 = Boolean.FALSE;
                while (!atomicReference.compareAndSet(null, bool2) && atomicReference.get() == null) {
                }
                return false;
            }
            byte b11 = -1;
            if (TextUtils.isEmpty(lowerCase)) {
                zYz = false;
                z10 = false;
            } else {
                switch (lowerCase.hashCode()) {
                    case -759499589:
                        b10 = !lowerCase.equals("xiaomi") ? (byte) -1 : (byte) 2;
                        break;
                    case 3418016:
                        if (lowerCase.equals("oppo")) {
                            b10 = 0;
                            break;
                        }
                        break;
                    case 3620012:
                        if (lowerCase.equals("vivo")) {
                            b10 = 1;
                            break;
                        }
                        break;
                    case 1864941562:
                        if (lowerCase.equals("samsung")) {
                            b10 = 3;
                            break;
                        }
                        break;
                    default:
                        break;
                }
                if (b10 == 0) {
                    zYz = ef();
                } else if (b10 == 1) {
                    zYz = ajl();
                } else if (b10 == 2) {
                    zYz = jnr();
                } else if (b10 != 3) {
                    zYz = false;
                    z10 = true;
                } else {
                    zYz = yz();
                }
                z10 = false;
            }
            if (z10 && !TextUtils.isEmpty(lowerCase2)) {
                switch (lowerCase2.hashCode()) {
                    case -759499589:
                        if (lowerCase2.equals("xiaomi")) {
                            b11 = 2;
                        }
                        break;
                    case 3418016:
                        if (lowerCase2.equals("oppo")) {
                            b11 = 0;
                        }
                        break;
                    case 3620012:
                        if (lowerCase2.equals("vivo")) {
                            b11 = 1;
                        }
                        break;
                    case 1864941562:
                        if (lowerCase2.equals("samsung")) {
                            b11 = 3;
                        }
                        break;
                }
                zYz = b11 != 0 ? b11 != 1 ? b11 != 2 ? b11 != 3 ? false : yz() : jnr() : ajl() : ef();
            }
            Boolean boolValueOf = Boolean.valueOf(zYz);
            while (!atomicReference.compareAndSet(null, boolValueOf) && atomicReference.get() == null) {
            }
            return zYz;
        } catch (Throwable unused) {
            AtomicReference<Boolean> atomicReference2 = fm;
            Boolean bool3 = Boolean.FALSE;
            while (!atomicReference2.compareAndSet(null, bool3) && atomicReference2.get() == null) {
            }
            return false;
        }
    }

    private static boolean wu(Context context) {
        try {
            Class.forName("com.unity3d.player.UnityPlayerActivity");
            return true;
        } catch (ClassNotFoundException unused) {
            if (context == null) {
                return false;
            }
            try {
                return new File(context.getApplicationInfo().nativeLibraryDir + "/libunity.so").exists();
            } catch (Throwable unused2) {
                return false;
            }
        }
    }

    public static int yz(Context context) {
        try {
            Class.forName("com.google.android.play.core.splitinstall.SplitInstallManager");
            return 1;
        } catch (ClassNotFoundException unused) {
            return 0;
        }
    }

    private static boolean yz() {
        if (ku()) {
            return true;
        }
        String[] strArr = {"sm-f9000", "sm-f9160", "sm-f9260", "sm-f9360", "sm-f9460", "sm-f9560", "sm-f7000", "sm-f7070", "sm-f7110", "sm-f7210", "sm-f7310", "sm-f7410"};
        String[] strArr2 = {"winner", "f2q", "q2q", "q4q", "q5q", "q6q", "bloomq", "bloomxq", "b2q", "b4q", "b5q", "b6q"};
        try {
            String lowerCase = Build.DEVICE.toLowerCase();
            if (!TextUtils.isEmpty(lowerCase)) {
                for (int i10 = 0; i10 < 12; i10++) {
                    if (lowerCase.contains(strArr2[i10])) {
                        return true;
                    }
                }
            }
            String lowerCase2 = Build.MODEL.toLowerCase();
            if (TextUtils.isEmpty(lowerCase2)) {
                return false;
            }
            for (int i11 = 0; i11 < 12; i11++) {
                if (lowerCase2.contains(strArr[i11])) {
                    return true;
                }
            }
            if (ro()) {
                String strFm = com.bytedance.sdk.openadsdk.hlt.jnr.fm("fold_config", "fold_samung", "");
                if (TextUtils.isEmpty(strFm)) {
                    return false;
                }
                for (String str : strFm.split(",")) {
                    if (lowerCase2.contains(str)) {
                        return true;
                    }
                }
            }
        } catch (Throwable unused) {
        }
        return false;
    }

    public static String lb() {
        return com.bytedance.sdk.openadsdk.hlt.jnr.fm("fold_config", "fold_default", "");
    }

    private static boolean ef() {
        if (vt()) {
            return true;
        }
        String[] strArr = {"CPH2439", "CPH2437", "CPH2499", "CPH2519", "PEUM00", "PGU110", "PGT110", "PHN110", "PHT110"};
        try {
            String lowerCase = Build.MODEL.toLowerCase();
            if (!TextUtils.isEmpty(lowerCase)) {
                for (int i10 = 0; i10 < 9; i10++) {
                    if (lowerCase.contains(strArr[i10].toLowerCase())) {
                        return true;
                    }
                }
                if (ro()) {
                    String strLb = lb();
                    if (TextUtils.isEmpty(strLb)) {
                        return false;
                    }
                    for (String str : strLb.split(",")) {
                        if (lowerCase.contains(str.toLowerCase())) {
                            return true;
                        }
                    }
                }
            }
        } catch (Throwable unused) {
        }
        return false;
    }

    public static void ro(JSONObject jSONObject, Context context) {
        try {
            if (ro()) {
                String strRo = com.bytedance.sdk.openadsdk.core.lb.fm().ro("w_ver", jnr(context));
                if (TextUtils.isEmpty(strRo)) {
                    return;
                }
                jSONObject.put("w_ver", strRo);
            }
        } catch (Throwable unused) {
        }
    }

    private static boolean vt() {
        try {
            Class<?> cls = Class.forName("com.oplus.content.OplusFeatureConfigManager");
            Object objInvoke = cls.getDeclaredMethod("hasFeature", String.class).invoke(cls.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]), "oplus.hardware.type.fold");
            if (objInvoke instanceof Boolean) {
                return ((Boolean) objInvoke).booleanValue();
            }
            return false;
        } catch (ClassNotFoundException e10) {
            e = e10;
            com.bytedance.sdk.component.utils.wey.lb("BED", "get oppo fold properties error, msg: " + e.getMessage());
            return false;
        } catch (IllegalAccessException e11) {
            e = e11;
            com.bytedance.sdk.component.utils.wey.lb("BED", "get oppo fold properties error, msg: " + e.getMessage());
            return false;
        } catch (NoSuchMethodException e12) {
            e = e12;
            com.bytedance.sdk.component.utils.wey.lb("BED", "get oppo fold properties error, msg: " + e.getMessage());
            return false;
        } catch (InvocationTargetException e13) {
            e = e13;
            com.bytedance.sdk.component.utils.wey.lb("BED", "get oppo fold properties error, msg: " + e.getMessage());
            return false;
        } catch (Throwable unused) {
            return false;
        }
    }

    private static boolean wu() {
        try {
            return ((Integer) Class.forName("android.os.SystemProperties").getMethod("getInt", String.class, Integer.TYPE).invoke(null, "persist.sys.muiltdisplay_type", 0)).intValue() == 2;
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("BED", "isXiaomiFold return false " + th.getMessage());
            return false;
        }
    }

    private static boolean ajl() {
        if (wsy()) {
            return true;
        }
        String[] strArr = {"V2330", "V2178A", "V2229A", "V2303A", "V2337A", "V2256A", "V2266A"};
        try {
            String lowerCase = Build.MODEL.toLowerCase();
            if (!TextUtils.isEmpty(lowerCase)) {
                for (int i10 = 0; i10 < 7; i10++) {
                    if (lowerCase.contains(strArr[i10].toLowerCase())) {
                        return true;
                    }
                }
                if (ro()) {
                    String strLb = lb();
                    if (TextUtils.isEmpty(strLb)) {
                        return false;
                    }
                    for (String str : strLb.split(",")) {
                        if (lowerCase.contains(str.toLowerCase())) {
                            return true;
                        }
                    }
                }
            }
        } catch (Throwable unused) {
        }
        return false;
    }

    private static boolean jnr() {
        if (wu()) {
            return true;
        }
        String[] strArr = {"M2011J18C", "22061218C", "2308CPXD0C", "24072PX77C", "2405CPX3DC", "2405CPX3DG"};
        try {
            String lowerCase = Build.MODEL.toLowerCase();
            if (!TextUtils.isEmpty(lowerCase)) {
                for (int i10 = 0; i10 < 6; i10++) {
                    if (lowerCase.contains(strArr[i10])) {
                        return true;
                    }
                }
                if (ro()) {
                    String strLb = lb();
                    if (TextUtils.isEmpty(strLb)) {
                        return false;
                    }
                    for (String str : strLb.split(",")) {
                        if (lowerCase.contains(str)) {
                            return true;
                        }
                    }
                }
            }
        } catch (Throwable unused) {
        }
        return false;
    }

    private static boolean ku() {
        try {
            Class<?> cls = Class.forName("com.samsung.android.feature.SemFloatingFeature");
            Object objInvoke = cls.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
            Method declaredMethod = cls.getDeclaredMethod("getString", String.class);
            if ("TRUE".equalsIgnoreCase((String) declaredMethod.invoke(objInvoke, "SEC_FLOATING_FEATURE_FRAMEWORK_SUPPORT_FOLDABLE_TYPE_FOLD"))) {
                return true;
            }
            return "TRUE".equalsIgnoreCase((String) declaredMethod.invoke(objInvoke, "SEC_FLOATING_FEATURE_FRAMEWORK_SUPPORT_FOLDABLE_TYPE_FLIP"));
        } catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e10) {
            com.bytedance.sdk.component.utils.wey.lb("PAG_BANNER", "get ss fold device error: " + e10.getMessage());
            return false;
        }
    }

    public static boolean ro() {
        return com.bytedance.sdk.openadsdk.hlt.jnr.fm("fold_config", "enable", 0) == 1;
    }

    public static String fm() {
        try {
            return Build.SUPPORTED_ABIS[0];
        } catch (Exception unused) {
            return "";
        }
    }

    public static void fm(JSONObject jSONObject, Context context) {
        if (context == null) {
            return;
        }
        try {
            if (ro()) {
                com.bytedance.sdk.openadsdk.core.lb lbVarFm = com.bytedance.sdk.openadsdk.core.lb.fm();
                String strRo = lbVarFm.ro("md", com.bytedance.sdk.openadsdk.core.vt.ro().wsy());
                if (!TextUtils.isEmpty(strRo)) {
                    jSONObject.put("md", strRo);
                }
                int iRo = lbVarFm.ro("bp", ro(context));
                if (iRo != 4) {
                    jSONObject.put("bp", iRo);
                }
                String strRo2 = lbVarFm.ro("t_ver", lb(context));
                if (!TextUtils.isEmpty(strRo2)) {
                    jSONObject.put("t_ver", strRo2);
                }
                jSONObject.put("is_fold", lbVarFm.ro("is_fold", wsy(context) ? 1 : 0));
                jSONObject.put("aab", lbVarFm.ro("aab", yz(context)));
                String strRo3 = lbVarFm.ro("abi", fm());
                if (TextUtils.isEmpty(strRo3)) {
                    return;
                }
                jSONObject.put("abi", strRo3);
            }
        } catch (Throwable unused) {
        }
    }

    private static boolean wsy() {
        try {
            return "foldable".equals(Class.forName("android.util.FtDeviceInfo").getMethod("getDeviceType", new Class[0]).invoke(null, new Object[0]));
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("BED", "isVIVOFoldDevice return false " + th.getMessage());
            return false;
        }
    }
}
