package com.bytedance.sdk.openadsdk.utils;

import android.os.Build;
import android.text.TextUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import u.a;

/* JADX INFO: loaded from: classes2.dex */
public class gzf {
    private static int ajl = Integer.MAX_VALUE;
    public static boolean fm = false;
    private static String jnr = null;
    public static boolean ro = false;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private static final CharSequence f7542lb = "amigo";
    private static final CharSequence yz = "funtouch";
    private static final ConcurrentHashMap<String, String> wsy = new ConcurrentHashMap<>();

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

        public fm(String str) {
            this.fm = str;
        }

        @Override // java.util.concurrent.Callable
        /* JADX INFO: renamed from: fm, reason: merged with bridge method [inline-methods] */
        public String call() throws Exception {
            String str = (String) gzf.wsy.get(this.fm);
            if (str != null) {
                return str;
            }
            System.currentTimeMillis();
            String strLb = gzf.lb(this.fm);
            System.currentTimeMillis();
            if (strLb != null) {
                gzf.wsy.put(this.fm, strLb);
            }
            return strLb;
        }
    }

    public static boolean ajl() {
        if (!ro) {
            try {
                Class.forName("miui.os.Build");
                fm = true;
                ro = true;
                return true;
            } catch (Exception unused) {
                ro = true;
            }
        }
        return fm;
    }

    public static String dsz() {
        if (!ajl()) {
            return "";
        }
        return "miui_" + yz("ro.miui.ui.version.name") + "_" + Build.VERSION.INCREMENTAL;
    }

    public static boolean duv() {
        return !TextUtils.isEmpty(yz("ro.letv.release.version"));
    }

    public static boolean ef() {
        String str = Build.DISPLAY;
        return !TextUtils.isEmpty(str) && str.toLowerCase().contains(f7542lb);
    }

    public static String fhx() {
        return yz("ro.build.version.emui");
    }

    public static String fm() {
        if (!TextUtils.isEmpty(jnr)) {
            return jnr;
        }
        String strFm = com.bytedance.sdk.openadsdk.core.vt.fm("sdk_local_rom_info", 604800000L);
        jnr = strFm;
        if (TextUtils.isEmpty(strFm)) {
            String strLse = lse();
            jnr = strLse;
            com.bytedance.sdk.openadsdk.core.vt.fm("sdk_local_rom_info", strLse);
        }
        return jnr;
    }

    public static String gof() {
        String str = Build.DISPLAY;
        return (str == null || !str.toLowerCase().contains("flyme")) ? "" : str;
    }

    public static boolean gqi() {
        if (ajl == Integer.MAX_VALUE) {
            String str = Build.MANUFACTURER;
            String strEf = bx.ef("kllk");
            if (TextUtils.isEmpty(str) || !str.toLowerCase().contains(strEf)) {
                ajl = 0;
            } else {
                ajl = 1;
            }
        }
        return ajl == 1;
    }

    public static boolean irt() {
        return "smartisan".equalsIgnoreCase(Build.MANUFACTURER) || "smartisan".equalsIgnoreCase(Build.BRAND);
    }

    public static boolean jnr() {
        String str = Build.MANUFACTURER + Build.BRAND;
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        String lowerCase = str.toLowerCase();
        return lowerCase.contains("360") || lowerCase.contains("qiku");
    }

    public static String ku() {
        if (!duv()) {
            return "";
        }
        return "eui_" + yz("ro.letv.release.version") + "_" + Build.DISPLAY;
    }

    public static boolean lb() {
        return Build.DISPLAY.contains("Flyme") || Build.USER.equals("flyme");
    }

    private static String lse() {
        if (irt()) {
            return qhl();
        }
        if (ajl()) {
            return dsz();
        }
        if (lb()) {
            return gof();
        }
        if (gqi()) {
            return wey();
        }
        String strOnz = onz();
        if (!TextUtils.isEmpty(strOnz)) {
            return strOnz;
        }
        if (wu()) {
            return wsy();
        }
        if (ef()) {
            return vt();
        }
        if (jnr()) {
            return yz();
        }
        String strKu = ku();
        return !TextUtils.isEmpty(strKu) ? strKu : Build.DISPLAY;
    }

    public static String onz() {
        String strFhx = fhx();
        if (strFhx == null || !strFhx.toLowerCase().contains("emotionui")) {
            return "";
        }
        StringBuilder sbD = a.d(strFhx, "_");
        sbD.append(Build.DISPLAY);
        return sbD.toString();
    }

    public static String qhl() {
        if (irt()) {
            try {
                return "smartisan_".concat(String.valueOf(yz("ro.smartisan.version")));
            } catch (Throwable unused) {
            }
        }
        return Build.DISPLAY;
    }

    public static boolean sds() {
        try {
            String str = Build.BRAND;
            if (TextUtils.isEmpty(str) || !str.toLowerCase().startsWith("huawei")) {
                String str2 = Build.MANUFACTURER;
                if (TextUtils.isEmpty(str2)) {
                    return false;
                }
                if (!str2.toLowerCase().startsWith("huawei")) {
                    return false;
                }
            }
            return true;
        } catch (Throwable unused) {
            return false;
        }
    }

    public static String vt() {
        return Build.DISPLAY + "_" + yz("ro.gn.sv.version");
    }

    public static String wey() {
        if (!gqi()) {
            return "";
        }
        return "coloros_" + yz(bx.ef("ro.build.version.kllkrom")) + "_" + Build.DISPLAY;
    }

    public static String wsy() {
        return yz("ro.vivo.os.build.display.id") + "_" + yz("ro.vivo.product.version");
    }

    public static boolean wu() {
        String strYz = yz("ro.vivo.os.build.display.id");
        return !TextUtils.isEmpty(strYz) && strYz.toLowerCase().contains(yz);
    }

    public static String yz() {
        return yz("ro.build.uiversion") + "_" + Build.DISPLAY;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static String lb(String str) {
        BufferedReader bufferedReader;
        Throwable th;
        Process processExec;
        String line = "";
        Process process = null;
        try {
            try {
                try {
                    processExec = Runtime.getRuntime().exec("getprop ".concat(String.valueOf(str)));
                    try {
                        bufferedReader = new BufferedReader(new InputStreamReader(processExec.getInputStream()), 1024);
                    } catch (IllegalThreadStateException unused) {
                        bufferedReader = null;
                    }
                } catch (IOException e10) {
                    com.bytedance.sdk.component.utils.wey.fm("ToolUtils", "Exception while closing InputStream", e10);
                }
            } catch (Throwable th2) {
                bufferedReader = null;
                th = th2;
            }
        } catch (IllegalThreadStateException unused2) {
            bufferedReader = null;
        }
        try {
            line = bufferedReader.readLine();
            processExec.exitValue();
            bufferedReader.close();
        } catch (IllegalThreadStateException unused3) {
            process = processExec;
            try {
                process.destroy();
            } catch (Throwable unused4) {
            }
            if (bufferedReader != null) {
                bufferedReader.close();
            }
            return line;
        } catch (Throwable th3) {
            th = th3;
            try {
                com.bytedance.sdk.component.utils.wey.fm("ToolUtils", "Unable to read sysprop ".concat(String.valueOf(str)), th);
                return line;
            } finally {
                if (bufferedReader != null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException e11) {
                        com.bytedance.sdk.component.utils.wey.fm("ToolUtils", "Exception while closing InputStream", e11);
                    }
                }
            }
        }
        return line;
    }

    public static boolean ro() {
        try {
            String strFm = fm();
            if (TextUtils.isEmpty(strFm) || !strFm.startsWith("miui")) {
                return false;
            }
            String str = Build.VERSION.INCREMENTAL;
            if (TextUtils.isEmpty(str)) {
                return false;
            }
            return str.toLowerCase().startsWith("v12");
        } catch (Throwable unused) {
            return false;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    private static String yz(String str) {
        String str2;
        String str3 = wsy.get(str);
        if (str3 != null) {
            return str3;
        }
        if (TextUtils.isEmpty("")) {
            final com.bytedance.sdk.component.wu.ro.ro roVar = new com.bytedance.sdk.component.wu.ro.ro(new fm(str), 5, 2);
            xgn.lb((Runnable) new com.bytedance.sdk.component.wu.ro.lb("_getSystemPropertyTask") { // from class: com.bytedance.sdk.openadsdk.utils.gzf.1
                @Override // java.lang.Runnable
                public void run() {
                    roVar.run();
                }
            });
            str2 = (String) roVar.get(1L, TimeUnit.SECONDS);
        } else {
            str2 = "";
        }
        return str2 == null ? "" : str2;
    }

    public static boolean fm(String str) {
        if (TextUtils.isEmpty(str)) {
            str = fhx();
        }
        return (!TextUtils.isEmpty(str) && str.toLowerCase().startsWith("emotionui")) || sds();
    }
}
