package com.bytedance.sdk.openadsdk.core;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.LocaleList;
import android.os.SystemClock;
import android.text.TextUtils;
import androidx.annotation.RequiresPermission;
import com.bytedance.sdk.component.pglcrypt.PglCryptUtils;
import java.util.Locale;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class dsz {
    private static String fm;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private static String f7020lb;
    private static String ro;
    private static boolean yz;

    private static void ajl(Context context) {
        if (yz(context) == null) {
            return;
        }
        String strRo = lb.fm().ro("abcd", (String) null);
        if (TextUtils.isEmpty(strRo)) {
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject(strRo);
            int iOptInt = jSONObject.optInt("cypher", -1);
            String strOptString = jSONObject.optString(PglCryptUtils.KEY_MESSAGE);
            if (iOptInt == 3) {
                String strLb = com.bytedance.sdk.component.utils.fm.lb(strOptString);
                if (TextUtils.isEmpty(strLb)) {
                    return;
                }
                fm = new JSONObject(strLb).optString("abcd");
                fm();
            }
        } catch (Throwable unused) {
        }
    }

    public static String fm(Context context) {
        if (!TextUtils.isEmpty(fm)) {
            return fm;
        }
        ajl(context);
        return fm;
    }

    @RequiresPermission(anyOf = {"android.permission.ACCESS_WIFI_STATE"})
    @SuppressLint({"HardwareIds"})
    private static void jnr(Context context) {
        if (yz || yz(context) == null) {
            return;
        }
        ro = String.valueOf(Build.TIME);
        f7020lb = lb.fm().ro("uuid", (String) null);
        yz = true;
    }

    public static String ro(Context context) {
        if (ro == null && !yz) {
            synchronized (dsz.class) {
                try {
                    if (!yz) {
                        jnr(context);
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        return ro;
    }

    private static Context yz(Context context) {
        return context == null ? gof.fm() : context;
    }

    public static String lb(Context context) {
        if (TextUtils.isEmpty(f7020lb) && !yz) {
            synchronized (dsz.class) {
                try {
                    if (!yz) {
                        jnr(context);
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        return f7020lb;
    }

    public static void fm(String str) {
        if (!TextUtils.isEmpty(str)) {
            if (!str.equals(fm)) {
                fm = str;
            }
            fm();
        }
        if (TextUtils.isEmpty(fm)) {
            return;
        }
        com.bytedance.sdk.openadsdk.core.duv.lb.ro(fm);
        duv.fm(fm);
    }

    public static String ro() {
        try {
            Locale locale = LocaleList.getDefault().get(0);
            String language = locale != null ? locale.getLanguage() : "";
            if (locale == null || !"zh".equals(language)) {
                return language;
            }
            String string = locale.toString();
            if (locale.toString().length() >= 5) {
                string = string.substring(0, 5);
            }
            return Locale.SIMPLIFIED_CHINESE.toString().equals(string) ? "zh" : "zh-Hant";
        } catch (Throwable unused) {
            return "";
        }
    }

    public static void fm() {
        if (TextUtils.isEmpty(fm)) {
            return;
        }
        com.bytedance.sdk.openadsdk.utils.xgn.lb((Runnable) new com.bytedance.sdk.component.wu.ro.lb("update_did") { // from class: com.bytedance.sdk.openadsdk.core.dsz.1
            @Override // java.lang.Runnable
            public void run() {
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("time", SystemClock.elapsedRealtime());
                    jSONObject.put("abcd", dsz.fm);
                    lb.fm().fm("abcd", com.bytedance.sdk.component.utils.fm.fm(jSONObject).toString());
                } catch (Throwable unused) {
                }
            }
        });
    }
}
