package com.bytedance.sdk.openadsdk.utils;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Environment;
import android.os.Looper;
import android.os.StatFs;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.webkit.WebBackForwardList;
import android.webkit.WebHistoryItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import androidx.recyclerview.widget.j2;
import com.bytedance.sdk.component.ef.wsy;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.google.android.gms.measurement.internal.u1;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
import org.json.JSONException;
import org.json.JSONObject;
import v5.b;

/* JADX INFO: loaded from: classes2.dex */
public class bx {
    private static final byte[] dsz;
    private static final byte[] duv;
    private static String fhx;
    public static Integer fm;
    private static final HashSet<String> ku;
    private static String onz;
    private static final ExecutorService ro = Executors.newSingleThreadExecutor();

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private static volatile boolean f7534lb = false;
    private static final AtomicInteger yz = new AtomicInteger(0);
    private static volatile String jnr = "";
    private static final ReentrantLock ajl = new ReentrantLock();
    private static String wsy = null;
    private static String wu = null;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private static String f7533ef = null;
    private static final HashSet<String> vt = new HashSet<>(Arrays.asList("Asia/Shanghai", "Asia/Urumqi", "Asia/Chongqing", "Asia/Harbin", "Asia/Kashgar"));

    /* JADX INFO: renamed from: com.bytedance.sdk.openadsdk.utils.bx$2, reason: invalid class name */
    public static class AnonymousClass2 implements Runnable {
        @Override // java.lang.Runnable
        public void run() {
            try {
                if (TextUtils.isEmpty(bx.jnr)) {
                    com.bytedance.sdk.component.ef.wsy wsyVar = new com.bytedance.sdk.component.ef.wsy(com.bytedance.sdk.openadsdk.core.gof.fm(), wsy.lb.USER_AGENT);
                    wsyVar.setWebViewClient(new wsy.fm());
                    String unused = bx.jnr = wsyVar.getUserAgentString();
                    com.bytedance.sdk.component.utils.gzf.fm(wsyVar);
                }
            } catch (Exception e10) {
                com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "", e10);
            } catch (NoClassDefFoundError e11) {
                com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "", e11);
            }
        }
    }

    public static class fm implements Callable<String> {
        private final int fm;

        public fm(int i10) {
            this.fm = i10;
        }

        private synchronized String lb() {
            final String[] strArr;
            strArr = new String[]{"unKnow"};
            final CountDownLatch countDownLatch = new CountDownLatch(1);
            xgn.fm(new Runnable() { // from class: com.bytedance.sdk.openadsdk.utils.bx.fm.1
                @Override // java.lang.Runnable
                public void run() {
                    strArr[0] = bx.hxv();
                    String str = strArr[0];
                    countDownLatch.countDown();
                }
            });
            try {
                countDownLatch.await(2L, TimeUnit.SECONDS);
            } catch (InterruptedException e10) {
                com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", e10.getMessage());
            }
            return strArr[0];
        }

        private String ro() {
            String property;
            Throwable th;
            try {
                property = System.getProperty("http.agent");
                if (property != null) {
                    try {
                        if (!"unKnow".equals(property)) {
                            com.bytedance.sdk.openadsdk.core.lb.fm().fm("android_system_ua", property);
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        com.bytedance.sdk.component.utils.wey.lb("getUA", "e:" + th.getMessage());
                    }
                }
            } catch (Throwable th3) {
                property = "unKnow";
                th = th3;
            }
            return property;
        }

        @Override // java.util.concurrent.Callable
        /* JADX INFO: renamed from: fm, reason: merged with bridge method [inline-methods] */
        public synchronized String call() throws Exception {
            String strRo;
            try {
                strRo = "unKnow";
                int i10 = this.fm;
                if (i10 == 1) {
                    strRo = lb();
                } else if (i10 == 2) {
                    strRo = ro();
                }
            } catch (Throwable th) {
                throw th;
            }
            return strRo;
        }
    }

    public static class lb {
        private static final int fm;

        static {
            com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "init hasBindingAdapterPositionMethod start status = 0");
            int i10 = 2;
            try {
                int i11 = j2.f3741a;
                if (j2.class.getDeclaredMethod("getBindingAdapterPosition", new Class[0]) != null) {
                    i10 = 0;
                }
            } catch (ClassNotFoundException unused) {
                i10 = 1;
            } catch (NoSuchMethodException unused2) {
            }
            fm = i10;
            com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "init hasBindingAdapterPositionMethod end status = ".concat(String.valueOf(i10)));
        }
    }

    public static class ro {
        public final ComponentName fm;
        public final int ro;

        public ro(ComponentName componentName, int i10) {
            this.fm = componentName;
            this.ro = i10;
        }
    }

    static {
        HashSet<String> hashSet = new HashSet<>();
        ku = hashSet;
        hashSet.addAll(Arrays.asList("America/Eirunepe", "America/Rio_Branco", "America/Boa_Vista", "America/Campo_Grande", "America/Cuiaba", "America/Manaus", "America/Porto_Velho", "America/Araguaina", "America/Bahia", "America/Belem", "America/Fortaleza", "America/Maceio", "America/Recife", "America/Santarem", "America/Sao_Paulo", "America/Noronha"));
        fm = null;
        duv = new byte[]{108, 111, 97, 100, 105, 110, 103};
        dsz = new byte[]{97, 114, 98, 105, 116, 114, 97, 103, 101};
    }

    public static String ai() {
        String str = onz;
        if (!TextUtils.isEmpty(str)) {
            return str;
        }
        String str2 = new String(duv);
        onz = str2;
        return str2;
    }

    public static boolean ajl(int i10) {
        return i10 == 6;
    }

    public static long duv() {
        try {
            StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
            return statFs.getBlockCountLong() * statFs.getBlockSizeLong();
        } catch (Throwable unused) {
            return 0L;
        }
    }

    public static String ef() {
        try {
            ActivityManager activityManager = (ActivityManager) com.bytedance.sdk.openadsdk.core.gof.fm().getSystemService("activity");
            ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
            activityManager.getMemoryInfo(memoryInfo);
            long j10 = memoryInfo.totalMem;
            if (j10 > 0) {
                return String.valueOf(j10 / 1024);
            }
            return null;
        } catch (Throwable unused) {
            return null;
        }
    }

    public static long fhx() {
        try {
            if (!gc()) {
                return 0L;
            }
            StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
            return ((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize());
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", th.getMessage());
            return 0L;
        }
    }

    public static String fm(int i10) {
        if (i10 == 1) {
            return "embeded_ad";
        }
        if (i10 == 2) {
            return "banner_ad";
        }
        if (i10 == 3) {
            return "interaction";
        }
        if (i10 == 4) {
            return "open_ad";
        }
        if (i10 == 5) {
            return "fullscreen_interstitial_ad";
        }
        if (i10 != 7) {
            return null;
        }
        return "rewarded_video";
    }

    private static boolean gc() {
        try {
            return "mounted".equals(Environment.getExternalStorageState());
        } catch (Throwable unused) {
            return false;
        }
    }

    public static String gof() {
        String strMon = com.bytedance.sdk.openadsdk.core.gof.yz().mon();
        return TextUtils.isEmpty(strMon) ? lse.fm() : strMon;
    }

    public static String gqi() {
        String strQph = com.bytedance.sdk.openadsdk.core.gof.yz().qph();
        if (!TextUtils.isEmpty(strQph)) {
            return strQph;
        }
        String strFm = lse.fm();
        return !TextUtils.isEmpty(strFm) ? u1.k("https://", strFm, "/service/2/dual_events/") : strQph;
    }

    public static boolean gzf() {
        return yz.get() == 1;
    }

    public static int hi() {
        try {
            String id2 = TimeZone.getDefault().getID();
            if (vt.contains(id2)) {
                return 2;
            }
            if (id2 != null && id2.startsWith("Asia/")) {
                return 2;
            }
            if (id2 != null && id2.startsWith("Europe/")) {
                return 4;
            }
            if (id2 != null && id2.startsWith("America/")) {
                if (!ku.contains(id2)) {
                    return 5;
                }
            }
            return 3;
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", th.toString());
            return 0;
        }
    }

    public static String hlt() {
        try {
            return TimeZone.getDefault().getID();
        } catch (Exception e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", e10.toString());
            return "";
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static String hxv() {
        try {
            WebView webView = new WebView(com.bytedance.sdk.openadsdk.core.gof.fm());
            webView.setWebViewClient(new wsy.fm());
            String userAgentString = webView.getSettings().getUserAgentString();
            if (userAgentString != null && !"unKnow".equals(userAgentString)) {
                com.bytedance.sdk.openadsdk.core.lb.fm().fm("webview_ua", userAgentString);
            }
            return userAgentString;
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("getUA", "e:" + th.getMessage());
            return "unKnow";
        }
    }

    public static int irt() {
        return com.bytedance.sdk.openadsdk.core.lb.fm().ro("is_root", -1);
    }

    public static boolean jnr(int i10) {
        return i10 == 5;
    }

    public static String ku() {
        return lb("MemTotal");
    }

    public static String lb(int i10) {
        return i10 != 1 ? i10 != 2 ? (i10 == 3 || i10 == 4) ? "open_ad" : i10 != 7 ? i10 != 8 ? "embeded_ad" : "fullscreen_interstitial_ad" : "rewarded_video" : "interaction" : "banner_ad";
    }

    public static String lse() {
        return "https://lf-static.tiktokpangle-cdn-us.com/obj/ad-pattern-tx/renderer/package_tx.json";
    }

    public static String maa() {
        return String.format("https://%s", "log.byteoversea.com/service/2/app_log_test/");
    }

    public static String mq() {
        int i10 = -nt();
        return i10 >= 0 ? "Etc/GMT+".concat(String.valueOf(i10)) : "Etc/GMT".concat(String.valueOf(i10));
    }

    public static int nt() {
        int rawOffset = TimeZone.getDefault().getRawOffset() / 3600000;
        if (rawOffset < -12) {
            rawOffset = -12;
        }
        if (rawOffset > 12) {
            return 12;
        }
        return rawOffset;
    }

    public static String ol() {
        String str = fhx;
        if (!TextUtils.isEmpty(str)) {
            return str;
        }
        String str2 = new String(dsz);
        fhx = str2;
        return str2;
    }

    public static long onz() {
        return com.bytedance.sdk.openadsdk.core.lb.fm().ro("total_sdcard_storage", 0L).longValue();
    }

    public static boolean qhl() {
        try {
            if (!new File("/system/bin/su").exists()) {
                if (!new File("/system/xbin/su").exists()) {
                    return false;
                }
            }
            return true;
        } catch (Throwable unused) {
            return false;
        }
    }

    public static String ro(int i10) {
        return i10 != 1 ? i10 != 2 ? i10 != 3 ? i10 != 4 ? i10 != 5 ? i10 != 7 ? "unknow" : "rewarded_video_landingpage" : "fullscreen_interstitial_ad" : "splash_ad_landingpage" : "interaction_landingpage" : "banner_ad_landingpage" : "embeded_ad_landingpage";
    }

    public static String sds() {
        String strEx = com.bytedance.sdk.openadsdk.core.settings.ku.ex();
        if (!TextUtils.isEmpty(strEx)) {
            return strEx;
        }
        String strBx = com.bytedance.sdk.openadsdk.core.gof.yz().bx();
        return TextUtils.isEmpty(strBx) ? lse.fm() : strBx;
    }

    public static String vt() {
        return com.bytedance.sdk.openadsdk.core.lb.fm().ro("total_memory", SessionDescription.SUPPORTED_SDP_VERSION);
    }

    public static int wbw() {
        return lb.fm;
    }

    public static List<String> wey() {
        ArrayList arrayList = new ArrayList();
        Set<String> setCpu = com.bytedance.sdk.openadsdk.core.gof.yz().cpu();
        if (setCpu != null && !setCpu.isEmpty()) {
            for (String str : setCpu) {
                if (!TextUtils.isEmpty(str)) {
                    arrayList.add(str);
                }
            }
        }
        return arrayList;
    }

    public static int wsy(int i10) {
        if (i10 == 1) {
            return 0;
        }
        if (i10 == 4) {
            return 1;
        }
        if (i10 == 5) {
            return 4;
        }
        if (i10 != 6) {
            return i10;
        }
        return 5;
    }

    public static synchronized String wu() {
        try {
            if (TextUtils.isEmpty(f7533ef) && com.bytedance.sdk.openadsdk.core.gof.fm() != null) {
                try {
                    PackageInfo packageInfo = com.bytedance.sdk.openadsdk.core.gof.fm().getPackageManager().getPackageInfo(ajl(), 0);
                    wu = String.valueOf(packageInfo.versionCode);
                    f7533ef = packageInfo.versionName;
                } catch (Throwable th) {
                    com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "ToolUtils getVersionName throws exception :", th);
                }
            }
        } catch (Throwable th2) {
            throw th2;
        }
        return f7533ef;
    }

    public static boolean yz(int i10) {
        return i10 == 4;
    }

    public static synchronized String ajl() {
        Context contextFm;
        try {
            if (TextUtils.isEmpty(wsy) && (contextFm = com.bytedance.sdk.openadsdk.core.gof.fm()) != null) {
                try {
                    wsy = contextFm.getPackageName();
                } catch (Throwable th) {
                    com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "ToolUtils getPackageName throws exception :", th);
                }
            }
        } catch (Throwable th2) {
            throw th2;
        }
        return wsy;
    }

    public static long dsz() {
        return com.bytedance.sdk.openadsdk.core.lb.fm().ro("free_internal_storage", 0L).longValue();
    }

    public static void fm(@NonNull com.bytedance.sdk.openadsdk.core.model.lse lseVar, @NonNull View view) {
    }

    public static String jnr() {
        return mq.fm();
    }

    public static boolean ku(String str) {
        if (com.bytedance.sdk.openadsdk.core.fhx.jnr()) {
            return true;
        }
        com.bytedance.sdk.component.utils.wey.lb(u1.k("You must use method '", str, "' after initialization, please check."), new Object[0]);
        return false;
    }

    public static void lb() {
        com.bytedance.sdk.openadsdk.irt.yz.fm("recycle_version_not_valid", false, new com.bytedance.sdk.openadsdk.irt.ro() { // from class: com.bytedance.sdk.openadsdk.utils.bx.1
            @Override // com.bytedance.sdk.openadsdk.irt.ro
            public com.bytedance.sdk.openadsdk.irt.fm.lb fm() throws Exception {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("method_exist", bx.wbw());
                return com.bytedance.sdk.openadsdk.irt.fm.yz.ro().fm("recycle_version_not_valid").ro(jSONObject.toString());
            }
        });
    }

    private static String onz(String str) {
        try {
            return Uri.parse(str).buildUpon().appendQueryParameter("aid", "1371").appendQueryParameter("device_platform", "android").appendQueryParameter("version_code", wsy()).toString();
        } catch (Exception e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", e10.getMessage());
            return str;
        }
    }

    public static boolean ro(Context context, String str) {
        if (context != null && !TextUtils.isEmpty(str)) {
            try {
                Intent intent = new Intent("android.intent.action.DIAL", Uri.parse("tel:" + Uri.encode(str)));
                if (!(context instanceof Activity)) {
                    intent.setFlags(268435456);
                }
                com.bytedance.sdk.component.utils.ro.fm(context, intent, null);
                return true;
            } catch (Exception unused) {
            }
        }
        return false;
    }

    public static long vt(String str) {
        if (TextUtils.isEmpty(str)) {
            return 0L;
        }
        try {
            String[] strArrSplit = str.split("\\.");
            if (strArrSplit.length == 0) {
                return 0L;
            }
            StringBuilder sb = new StringBuilder();
            sb.append(strArrSplit[0]);
            for (int i10 = 1; i10 < strArrSplit.length; i10++) {
                String str2 = strArrSplit[i10];
                if (!wu(str2)) {
                    return 0L;
                }
                if (str2.length() == 1) {
                    sb.append(SessionDescription.SUPPORTED_SDP_VERSION);
                    sb.append(str2);
                } else {
                    sb.append(str2);
                }
                if (sb.length() > 18) {
                    return 0L;
                }
            }
            String string = sb.toString();
            if (TextUtils.isEmpty(string)) {
                return 0L;
            }
            return Long.parseLong(string);
        } catch (Exception e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", e10.getMessage());
            return 0L;
        }
    }

    public static synchronized String wsy() {
        try {
            if (TextUtils.isEmpty(wu) && com.bytedance.sdk.openadsdk.core.gof.fm() != null) {
                try {
                    PackageInfo packageInfo = com.bytedance.sdk.openadsdk.core.gof.fm().getPackageManager().getPackageInfo(ajl(), 0);
                    wu = String.valueOf(packageInfo.versionCode);
                    f7533ef = packageInfo.versionName;
                } catch (Throwable th) {
                    com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "ToolUtils getVersionCode throws exception :", th);
                }
            }
        } catch (Throwable th2) {
            throw th2;
        }
        return wu;
    }

    public static boolean yz(Context context) {
        return false;
    }

    public static Intent fm(Context context, String str) {
        Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage(str);
        if (launchIntentForPackage == null) {
            return null;
        }
        if (!launchIntentForPackage.hasCategory("android.intent.category.LAUNCHER")) {
            launchIntentForPackage.addCategory("android.intent.category.LAUNCHER");
        }
        launchIntentForPackage.setPackage(null);
        launchIntentForPackage.addFlags(2097152);
        launchIntentForPackage.addFlags(268435456);
        return launchIntentForPackage;
    }

    public static String jnr(String str) {
        if (TextUtils.isEmpty(str)) {
            str = com.bytedance.sdk.openadsdk.core.gof.yz().zan();
        }
        return TextUtils.isEmpty(str) ? "https://api16-access-ttp.tiktokpangle.us/service/2/app_log/" : !str.startsWith("http") ? "https://".concat(str) : str;
    }

    public static String lb(String str) {
        FileReader fileReader;
        BufferedReader bufferedReader;
        String line;
        try {
            fileReader = new FileReader("/proc/meminfo");
            try {
                bufferedReader = new BufferedReader(fileReader, 4096);
                do {
                    try {
                        line = bufferedReader.readLine();
                        if (line == null) {
                            break;
                        }
                    } catch (Throwable th) {
                        th = th;
                        try {
                            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", th.getMessage());
                            if (bufferedReader != null) {
                                try {
                                    bufferedReader.close();
                                } catch (Exception unused) {
                                }
                            }
                            if (fileReader != null) {
                                try {
                                    fileReader.close();
                                } catch (Exception unused2) {
                                }
                            }
                            return null;
                        } finally {
                        }
                    }
                } while (!line.contains(str));
                if (line == null) {
                    try {
                        bufferedReader.close();
                    } catch (Exception unused3) {
                    }
                    try {
                        fileReader.close();
                    } catch (Exception unused4) {
                    }
                    return null;
                }
                String str2 = line.split("\\s+")[1];
                try {
                    bufferedReader.close();
                } catch (Exception unused5) {
                }
                try {
                    fileReader.close();
                } catch (Exception unused6) {
                }
                return str2;
            } catch (Throwable th2) {
                th = th2;
                bufferedReader = null;
            }
        } catch (Throwable th3) {
            th = th3;
            fileReader = null;
            bufferedReader = null;
        }
    }

    public static String yz() {
        if (!TextUtils.isEmpty(jnr)) {
            return jnr;
        }
        com.bytedance.sdk.openadsdk.gqi.fm.fm(com.bytedance.sdk.openadsdk.core.gof.fm());
        String strFm = com.bytedance.sdk.openadsdk.core.vt.fm("sdk_local_web_ua", 86400000L);
        jnr = strFm;
        if (TextUtils.isEmpty(strFm)) {
            ReentrantLock reentrantLock = ajl;
            try {
                if (reentrantLock.tryLock()) {
                    try {
                        if (TextUtils.isEmpty(jnr)) {
                            jnr = WebSettings.getDefaultUserAgent(com.bytedance.sdk.openadsdk.core.gof.fm());
                        }
                        com.bytedance.sdk.openadsdk.core.vt.fm("sdk_local_web_ua", jnr);
                        reentrantLock.unlock();
                    } catch (Exception e10) {
                        com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "", e10);
                        ajl.unlock();
                    } catch (NoClassDefFoundError e11) {
                        com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "", e11);
                        ajl.unlock();
                    }
                }
            } catch (Throwable th) {
                ajl.unlock();
                throw th;
            }
        }
        return jnr;
    }

    public static void duv(String str) {
        if (Looper.myLooper() != Looper.getMainLooper()) {
            return;
        }
        com.bytedance.sdk.component.utils.wey.lb(u1.k("You should use method '", str, "' on the asynchronous thread,it may cause anr, please check."), new Object[0]);
    }

    public static String ef(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        if (str.contains("KLLK")) {
            return str.replace("KLLK", "OPPO");
        }
        return str.contains("kllk") ? str.replace("kllk", "oppo") : "";
    }

    public static String ajl(String str) {
        return TextUtils.isEmpty(str) ? "" : !str.startsWith("http") ? "https://".concat(str) : str;
    }

    public static boolean jnr(Context context) {
        if (context == null) {
            return false;
        }
        return (context.getApplicationInfo().flags & 2) != 0;
    }

    public static int ro(com.bytedance.sdk.openadsdk.core.model.lse lseVar) {
        if (lseVar == null) {
            return -1;
        }
        int iIe = lseVar.ie();
        int i10 = 1;
        if (iIe == 1) {
            return 2;
        }
        if (iIe == 3) {
            return 4;
        }
        if (iIe != 5) {
            i10 = 7;
            if (iIe != 7) {
                return iIe != 8 ? -1 : 5;
            }
        }
        return i10;
    }

    @NonNull
    public static ro fm(Context context, Intent intent) {
        return new ro(null, 0);
    }

    public static String ro() {
        String str = "unKnow";
        com.bytedance.sdk.openadsdk.gqi.fm.fm(com.bytedance.sdk.openadsdk.core.gof.fm());
        try {
            String strRo = com.bytedance.sdk.openadsdk.core.lb.fm().ro("android_system_ua", "unKnow");
            if (strRo != null && !"unKnow".equals(strRo)) {
                return strRo;
            }
            FutureTask futureTask = new FutureTask(new fm(2));
            ro.execute(futureTask);
            str = (String) futureTask.get(500L, TimeUnit.MILLISECONDS);
        } catch (Exception unused) {
        }
        com.bytedance.sdk.component.utils.wey.lb("getUA", " getAndroidSystemUA userAgent".concat(String.valueOf(str)));
        return str;
    }

    public static int ajl(Context context) {
        try {
            return context.getApplicationInfo().targetSdkVersion;
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", th.getMessage());
            return -1;
        }
    }

    public static boolean fm() {
        return (com.bytedance.sdk.openadsdk.core.irt.fm() == null || com.bytedance.sdk.openadsdk.core.irt.fm().yz()) ? false : true;
    }

    public static boolean wu(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return Pattern.compile("^[+-]?([0-9]|([1-9][0-9]*))(\\.[0-9]+)?").matcher(str).matches();
    }

    public static void ef(Context context) {
        try {
            AtomicInteger atomicInteger = yz;
            if (atomicInteger.get() != 0) {
                return;
            }
            AccessibilityManager accessibilityManager = (AccessibilityManager) context.getSystemService("accessibility");
            boolean zIsEnabled = accessibilityManager.isEnabled();
            boolean zIsTouchExplorationEnabled = accessibilityManager.isTouchExplorationEnabled();
            if (zIsEnabled && zIsTouchExplorationEnabled) {
                atomicInteger.set(1);
                com.bytedance.sdk.openadsdk.irt.yz.fm().lb();
            } else {
                atomicInteger.set(2);
            }
        } catch (Exception unused) {
            yz.set(2);
        }
    }

    public static String fm(com.bytedance.sdk.openadsdk.core.model.lse lseVar) {
        if (lseVar == null) {
            return null;
        }
        try {
            return lb(lseVar.ie());
        } catch (Throwable unused) {
            return null;
        }
    }

    public static boolean wsy(String str) {
        try {
            return Pattern.compile("[一-龥]").matcher(str).find();
        } catch (Throwable unused) {
            return false;
        }
    }

    public static int fm(String str) {
        if (TextUtils.isEmpty(str)) {
            return 1;
        }
        str.getClass();
        switch (str) {
        }
        return 1;
    }

    public static int wu(Context context) {
        return wsy(com.bytedance.sdk.component.utils.nt.fm(context, 0L));
    }

    public static long wsy(Context context) {
        int i10;
        try {
            i10 = context.getApplicationInfo().minSdkVersion;
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", th.getMessage());
            i10 = -1;
        }
        return i10;
    }

    public static String fm(Context context) {
        String strRo = com.bytedance.sdk.openadsdk.core.lb.fm().ro("total_memory", (String) null);
        if (strRo == null || ro(strRo) <= 0) {
            strRo = lb("MemTotal");
            if (ro(strRo) <= 0) {
                strRo = ef();
            }
            com.bytedance.sdk.openadsdk.core.lb.fm().fm("total_memory", strRo);
        }
        return strRo;
    }

    public static boolean wu(int i10) {
        if (i10 <= 0) {
            return false;
        }
        return i10 >= 100 || new Random(System.currentTimeMillis()).nextInt(100) + 1 <= i10;
    }

    public static String yz(String str) {
        return fm(str, false, false);
    }

    public static long ro(String str) {
        try {
            return Long.parseLong(str);
        } catch (Throwable unused) {
            return 0L;
        }
    }

    public static boolean yz(com.bytedance.sdk.openadsdk.core.model.lse lseVar) {
        return lseVar != null && lseVar.oy() == 3 && lseVar.ug() && (lseVar.bp() == 4 || lseVar.bp() == 5);
    }

    public static long ro(Context context) {
        return com.bytedance.sdk.openadsdk.core.lb.fm().ro("total_internal_storage", 0L).longValue();
    }

    public static int vt(Context context) {
        List<ResolveInfo> listQueryIntentActivities;
        Integer num = fm;
        if (num != null) {
            return num.intValue();
        }
        if (context == null || (listQueryIntentActivities = context.getPackageManager().queryIntentActivities(new Intent("android.intent.action.VIEW", Uri.parse("https://www.example.com")), 0)) == null) {
            return 0;
        }
        Integer numValueOf = Integer.valueOf(listQueryIntentActivities.size());
        fm = numValueOf;
        return numValueOf.intValue();
    }

    public static String lb(@NonNull Context context) {
        try {
            return context.getResources().getConfiguration().getLocales().get(0).getLanguage();
        } catch (Exception e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", e10.toString());
            return "";
        }
    }

    public static String fm(@NonNull String str, boolean z10, boolean z11) {
        String strGof;
        if (str != null && !str.startsWith("/")) {
            str = "/".concat(str);
        }
        if (z11) {
            strGof = sds();
        } else {
            strGof = gof();
        }
        if (TextUtils.isEmpty(strGof)) {
            strGof = "api16-access-ttp.tiktokpangle.us";
        }
        String strK = u1.k("https://", strGof, str);
        if (!TextUtils.isEmpty(str) && (str.equals("/api/ad/union/sdk/compliance_status/") || str.equals("/api/ad/union/sdk/register_status/"))) {
            return strK;
        }
        if (gc.fm() && !z10) {
            strK = gc.fm(strK);
        }
        return z10 ? onz(strK) : strK;
    }

    public static boolean lb(com.bytedance.sdk.openadsdk.core.model.lse lseVar) {
        if (lseVar == null) {
            return true;
        }
        int iRo = com.bytedance.sdk.openadsdk.core.gof.yz().ro(lseVar.pg());
        int iLb = com.bytedance.sdk.component.utils.gof.lb(com.bytedance.sdk.openadsdk.core.gof.fm());
        if (iRo == 1) {
            return yz(iLb);
        }
        if (iRo == 2) {
            return jnr(iLb) || yz(iLb) || ajl(iLb);
        }
        if (iRo != 3) {
            return iRo != 5 || yz(iLb) || ajl(iLb);
        }
        return false;
    }

    public static List<String> fm(@NonNull String str, boolean z10) {
        if (!TextUtils.isEmpty(str) && !str.startsWith("/")) {
            str = "/".concat(str);
        }
        ArrayList arrayList = new ArrayList();
        Set<String> setVod = com.bytedance.sdk.openadsdk.core.gof.yz().vod();
        if (setVod != null && !setVod.isEmpty()) {
            for (String str2 : setVod) {
                if (!TextUtils.isEmpty(str2)) {
                    String strK = u1.k("https://", str2, str);
                    if (gc.fm() && !z10) {
                        strK = gc.fm(strK);
                    }
                    if (z10) {
                        strK = onz(strK);
                    }
                    arrayList.add(strK);
                }
            }
        }
        return arrayList;
    }

    public static JSONObject fm(com.bytedance.sdk.openadsdk.core.model.lse lseVar, long j10, b bVar) {
        if (lseVar == null) {
            return new JSONObject();
        }
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("creative_id", lseVar.eo());
            jSONObject.put("buffers_time", j10);
            com.bykv.vk.openvk.fm.fm.fm.lb.b bVarEx = lseVar.ex();
            if (bVarEx != null) {
                jSONObject.put("video_size", bVarEx.f5923c);
                jSONObject.put("video_resolution", bVarEx.f5925e);
            }
            fm(jSONObject, bVar);
        } catch (JSONException e10) {
            com.bytedance.sdk.component.utils.wey.fm("TTAD.ToolUtils", "getVideoAction json error", e10);
        }
        return jSONObject;
    }

    private static void fm(JSONObject jSONObject, b bVar) {
        if (jSONObject.has("video_resolution") || bVar == null) {
            return;
        }
        try {
            jSONObject.put("video_resolution", String.format(Locale.getDefault(), "%d×%d", Integer.valueOf(bVar.yz()), Integer.valueOf(bVar.jnr())));
        } catch (Throwable unused) {
        }
    }

    public static void fm(String str, String str2, Context context) {
        int i10;
        if (TextUtils.isEmpty(str2) || !jnr(context)) {
            return;
        }
        int length = str2.length();
        int i11 = 1;
        if (length % 3572 == 0) {
            i10 = length / 3572;
        } else {
            i10 = (length / 3572) + 1;
        }
        int i12 = 3572;
        int i13 = 0;
        while (i11 <= i10) {
            if (i12 < length) {
                str2.substring(i13, i12);
                i11++;
                i13 = i12;
                i12 += 3572;
            } else {
                str2.substring(i13);
                return;
            }
        }
    }

    public static void fm(StringBuilder sb, String str, String str2) {
        int iIndexOf;
        if (sb == null || TextUtils.isEmpty(str) || (iIndexOf = sb.indexOf(str)) <= 0) {
            return;
        }
        sb.replace(iIndexOf, str.length() + iIndexOf, str2);
    }

    public static com.bytedance.sdk.openadsdk.common.jnr fm(com.bytedance.sdk.openadsdk.core.model.lse lseVar, com.bytedance.sdk.component.ef.wsy wsyVar, Context context, String str) {
        int iBp = lseVar.bp();
        if (!lseVar.ug() || (iBp != 1 && iBp != 3)) {
            return null;
        }
        wsyVar.fm(true, (View) new com.bytedance.sdk.openadsdk.common.yz(context));
        return new com.bytedance.sdk.openadsdk.common.jnr(lseVar, wsyVar, str, false);
    }

    public static void fm(JSONObject jSONObject) {
        int iIntValue;
        try {
            Pair<String, Long> pairYz = com.bytedance.sdk.openadsdk.core.vt.yz("oem_store");
            int i10 = -1;
            if (pairYz != null && ((iIntValue = Integer.valueOf((String) pairYz.first).intValue()) != -2 || System.currentTimeMillis() - ((Long) pairYz.second).longValue() < com.bytedance.sdk.openadsdk.hlt.jnr.fm("oem_store_state_time", 259200000))) {
                i10 = iIntValue;
            }
            jSONObject.put("oem_store", i10);
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", th.getMessage());
        }
    }

    public static void fm(com.bytedance.sdk.openadsdk.core.model.lse lseVar, com.bytedance.sdk.component.ef.wsy wsyVar) {
        fm(lseVar, wsyVar, false);
    }

    public static void fm(com.bytedance.sdk.openadsdk.core.model.lse lseVar, com.bytedance.sdk.component.ef.wsy wsyVar, boolean z10) {
        com.bytedance.sdk.openadsdk.core.model.wu wuVarHi;
        List<Integer> list;
        if (lseVar == null || wsyVar == null) {
            return;
        }
        int iBp = lseVar.bp();
        if (lseVar.ug() && ((iBp == 2 || iBp == 3 || iBp == 5) && (wuVarHi = lseVar.hi()) != null)) {
            List<Integer> listAjl = wuVarHi.ajl();
            ArrayList arrayList = new ArrayList();
            if (z10) {
                for (int i10 = 0; i10 < listAjl.size(); i10++) {
                    arrayList.add(Integer.valueOf(listAjl.get(i10).intValue() - 1));
                }
                list = arrayList;
            } else {
                list = listAjl;
            }
            wsyVar.fm(true, wuVarHi.yz(), wuVarHi.jnr(), list, wuVarHi.wsy(), wuVarHi.lb());
        }
        int iVrv = lseVar.vrv();
        long jHfj = lseVar.hfj();
        if ((iVrv == 1 || iVrv == 2) && jHfj > 0) {
            wsyVar.fm(iVrv, jHfj);
        }
    }

    public static int fm(WebView webView) {
        if (webView == null) {
            return -1;
        }
        try {
            WebBackForwardList webBackForwardListCopyBackForwardList = webView.copyBackForwardList();
            int size = webBackForwardListCopyBackForwardList.getSize();
            ArrayList arrayList = new ArrayList();
            for (int i10 = 0; i10 < size; i10++) {
                WebHistoryItem itemAtIndex = webBackForwardListCopyBackForwardList.getItemAtIndex(i10);
                if (itemAtIndex != null) {
                    String url = itemAtIndex.getUrl();
                    if (!arrayList.contains(url)) {
                        arrayList.add(url);
                    }
                }
            }
            return arrayList.indexOf(webView.getUrl()) + 1;
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.ToolUtils", th.toString());
            return -1;
        }
    }

    public static JSONObject fm(AdSlot adSlot) {
        JSONObject jSONObject = new JSONObject();
        if (adSlot != null) {
            try {
                jSONObject.put("is_sb", !TextUtils.isEmpty(adSlot.getBidAdm()));
            } catch (Throwable unused) {
            }
        }
        return jSONObject;
    }
}
