package com.bytedance.sdk.openadsdk.core;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.text.TextUtils;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bytedance.sdk.openadsdk.core.yz.wsy;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class vt {
    public static onz fm = null;
    private static boolean ku = false;
    public static final Set<String> ro = new HashSet<String>() { // from class: com.bytedance.sdk.openadsdk.core.vt.1
        {
            add("8025677");
            add("5001121");
        }
    };

    @NonNull
    private String ajl;
    private boolean dsz;
    private String duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private int f7288ef;
    private com.bytedance.sdk.openadsdk.core.fhx.lb.lb fhx;
    private volatile ConcurrentHashMap<String, wsy.fm> irt;
    private String jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private boolean f7289lb;
    private String onz;
    private int vt;
    private int wsy;

    @Nullable
    private String wu;

    @NonNull
    private String yz;

    public static class fm {
        private static final vt fm = new vt();
    }

    public static int ajl() {
        try {
            String strFm = fm("config_fail_times", Long.MAX_VALUE);
            if (TextUtils.isEmpty(strFm)) {
                return 0;
            }
            return Integer.valueOf(strFm).intValue();
        } catch (Throwable th) {
            th.getMessage();
            return 0;
        }
    }

    public static void fm(onz onzVar) {
        fm = onzVar;
    }

    @NonNull
    public static vt ro() {
        return fm.fm;
    }

    public static void sds() {
        if (Build.VERSION.SDK_INT == 26 && "MI 6".equals(Build.MODEL)) {
            ku = true;
        }
    }

    public static boolean wey() {
        return ku;
    }

    public com.bytedance.sdk.openadsdk.core.fhx.lb.lb dsz() {
        if (this.fhx == null) {
            this.fhx = new com.bytedance.sdk.openadsdk.core.fhx.lb.lb(10, 8);
        }
        return this.fhx;
    }

    @Nullable
    public String duv() {
        return this.wu;
    }

    public int ef() {
        return this.wsy;
    }

    public boolean fhx() {
        return ro.contains(this.yz);
    }

    public String gof() {
        if (!TextUtils.isEmpty(this.onz)) {
            return this.onz;
        }
        String strFm = com.bytedance.sdk.openadsdk.utils.duv.fm();
        this.onz = strFm;
        if (!TextUtils.isEmpty(strFm)) {
            return this.onz;
        }
        String strValueOf = String.valueOf(System.currentTimeMillis());
        com.bytedance.sdk.openadsdk.utils.duv.fm(strValueOf);
        this.onz = strValueOf;
        return strValueOf;
    }

    public void gqi() {
        try {
            if (this.irt == null || this.irt.size() != 0) {
                return;
            }
            this.irt = null;
        } catch (Throwable th) {
            th.getMessage();
        }
    }

    public boolean irt() {
        return "5001121".contains(this.yz);
    }

    public void jnr(int i10) {
        this.f7288ef = i10;
    }

    public boolean ku() {
        int i10 = this.vt;
        return i10 < -1 || i10 > 1;
    }

    public void lb(int i10) {
        this.wsy = i10;
    }

    public String maa() {
        return this.duv;
    }

    public boolean onz() {
        return true;
    }

    public boolean qhl() {
        return "com.union_test.internationad".equals(com.bytedance.sdk.openadsdk.utils.bx.ajl());
    }

    public int vt() {
        return this.vt;
    }

    public String wsy() {
        String str = this.jnr;
        if (str != null) {
            return str;
        }
        String strFm = fm("mediation_info", Long.MAX_VALUE);
        this.jnr = strFm;
        if (strFm == null) {
            this.jnr = "";
        }
        return this.jnr;
    }

    public void wu(String str) {
        this.duv = str;
    }

    public void yz(int i10) {
        this.vt = i10;
    }

    private vt() {
        this.f7289lb = false;
        this.f7288ef = 0;
        this.vt = -1;
        this.irt = null;
    }

    private static JSONObject duv(String str) {
        String strRo = com.bytedance.sdk.openadsdk.gqi.yz.fm.ro("sp_global_file", str, (String) null);
        if (TextUtils.isEmpty(strRo)) {
            return null;
        }
        try {
            return new JSONObject(strRo);
        } catch (JSONException e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.GlobalInfo", e10.getMessage());
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void ef(String str) {
        if (TextUtils.isEmpty(this.wu)) {
            this.wu = str;
            return;
        }
        try {
            HashMap map = new HashMap();
            JSONArray jSONArray = new JSONArray(this.wu);
            for (int i10 = 0; i10 < jSONArray.length(); i10++) {
                JSONObject jSONObjectOptJSONObject = jSONArray.optJSONObject(i10);
                if (jSONObjectOptJSONObject != null) {
                    String strOptString = jSONObjectOptJSONObject.optString("name");
                    if (!TextUtils.isEmpty(strOptString)) {
                        map.put(strOptString, jSONObjectOptJSONObject);
                    }
                }
            }
            JSONArray jSONArray2 = new JSONArray(str);
            for (int i11 = 0; i11 < jSONArray2.length(); i11++) {
                JSONObject jSONObjectOptJSONObject2 = jSONArray2.optJSONObject(i11);
                if (jSONObjectOptJSONObject2 != null) {
                    String strOptString2 = jSONObjectOptJSONObject2.optString("name");
                    String strOptString3 = jSONObjectOptJSONObject2.optString("value");
                    if (!TextUtils.isEmpty(strOptString2) && !TextUtils.isEmpty(strOptString3)) {
                        map.put(strOptString2, jSONObjectOptJSONObject2);
                    }
                }
            }
            Collection collectionValues = map.values();
            JSONArray jSONArray3 = new JSONArray();
            Iterator it = collectionValues.iterator();
            while (it.hasNext()) {
                jSONArray3.put((JSONObject) it.next());
            }
            this.wu = jSONArray3.toString();
        } catch (Throwable th) {
            th.getMessage();
        }
    }

    public static int jnr() {
        try {
            String strFm = fm("domain_index", Long.MAX_VALUE);
            if (TextUtils.isEmpty(strFm)) {
                return 0;
            }
            return Integer.valueOf(strFm).intValue();
        } catch (Throwable th) {
            th.getMessage();
            return 0;
        }
    }

    private static void ku(String str) {
        if (TextUtils.isEmpty(str) || str.length() <= 1000) {
            return;
        }
        onz onzVar = fm;
        if (onzVar != null) {
            onzVar.fm(4000, "Data is very long, the longest is 1000");
        }
        com.bytedance.sdk.component.utils.wey.lb("TTAD.GlobalInfo", "Data is very long, the longest is 1000");
    }

    private static void vt(String str) {
        onz onzVar;
        if (TextUtils.isEmpty(str) && (onzVar = fm) != null) {
            onzVar.fm(4000, "appid cannot be empty");
        }
        com.bytedance.sdk.component.utils.wey.lb("TTAD.GlobalInfo", "appid cannot be empty");
    }

    public static boolean wsy(String str) {
        return (TextUtils.isEmpty(str) || str.contains("sp_full_screen_video") || str.contains("sp_reward_video") || str.contains("tt_openad") || str.contains("pag_sp_bad_par")) ? false : true;
    }

    public void fm(boolean z10) {
        this.dsz = z10;
    }

    public void lb(boolean z10) {
        this.f7289lb = z10;
    }

    public void ro(boolean z10) {
        com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_global_file", "sdk_activate_init", Boolean.valueOf(z10));
    }

    @NonNull
    public String wu() {
        if (TextUtils.isEmpty(this.ajl)) {
            this.ajl = fm(gof.fm());
        }
        return this.ajl;
    }

    @Nullable
    public String yz() {
        if (TextUtils.isEmpty(this.yz)) {
            String strFm = fm("app_id", Long.MAX_VALUE);
            if (!TextUtils.isEmpty(strFm)) {
                this.yz = strFm;
            }
        }
        return this.yz;
    }

    public static void ro(int i10) {
        if (i10 >= 0) {
            fm("config_fail_times", String.valueOf(i10));
        }
    }

    public boolean fm() {
        return this.dsz;
    }

    public boolean lb() {
        return com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_global_file", "sdk_activate_init", true);
    }

    public void lb(@Nullable final String str) {
        ku(str);
        if (com.bytedance.sdk.openadsdk.utils.xgn.ajl()) {
            fhx.ro().post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.vt.2
                @Override // java.lang.Runnable
                public void run() {
                    vt.this.ef(str);
                }
            });
        } else {
            ef(str);
        }
    }

    public void ro(String str) {
        this.jnr = str;
        if (TextUtils.isEmpty(str)) {
            return;
        }
        fm("mediation_info", str);
    }

    public static void fm(int i10) {
        if (i10 >= 0) {
            fm("domain_index", String.valueOf(i10));
        }
    }

    public static Pair<String, Long> yz(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        try {
            JSONObject jSONObjectDuv = duv(str);
            if (jSONObjectDuv == null) {
                return null;
            }
            return new Pair<>(jSONObjectDuv.getString("value"), Long.valueOf(jSONObjectDuv.getLong("time")));
        } catch (JSONException e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.GlobalInfo", e10.getMessage());
            return null;
        }
    }

    public void ajl(String str) {
        try {
            if (TextUtils.isEmpty(str) || this.irt == null) {
                return;
            }
            this.irt.remove(str);
        } catch (Throwable unused) {
        }
    }

    public void fm(@NonNull String str) {
        vt(str);
        this.yz = str;
        if (TextUtils.isEmpty(str)) {
            return;
        }
        fm("app_id", str);
    }

    public wsy.fm jnr(String str) {
        try {
            if (this.irt == null || str == null) {
                return null;
            }
            return this.irt.get(str);
        } catch (Throwable unused) {
            return null;
        }
    }

    private String fm(Context context) {
        try {
            PackageManager packageManager = context.getApplicationContext().getPackageManager();
            return (String) packageManager.getApplicationLabel(packageManager.getApplicationInfo(context.getPackageName(), 128));
        } catch (Throwable unused) {
            return "";
        }
    }

    public static void fm(String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("value", str2);
            jSONObject.put("time", System.currentTimeMillis());
            com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_global_file", str, jSONObject.toString());
        } catch (JSONException e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.GlobalInfo", e10.getMessage());
        }
    }

    public static String fm(String str, long j10) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        try {
            JSONObject jSONObjectDuv = duv(str);
            if (jSONObjectDuv == null) {
                return null;
            }
            if (System.currentTimeMillis() - jSONObjectDuv.getLong("time") <= j10) {
                return jSONObjectDuv.getString("value");
            }
        } catch (JSONException e10) {
            com.bytedance.sdk.component.utils.wey.lb("TTAD.GlobalInfo", e10.getMessage());
        }
        return null;
    }

    public void fm(String str, wsy.fm fmVar) {
        try {
            if (TextUtils.isEmpty(str) || fmVar == null) {
                return;
            }
            if (this.irt == null) {
                synchronized (vt.class) {
                    try {
                        if (this.irt == null) {
                            this.irt = new ConcurrentHashMap<>();
                        }
                    } catch (Throwable th) {
                        throw th;
                    }
                }
            }
            if (this.irt != null) {
                this.irt.put(str, fmVar);
            }
        } catch (Throwable unused) {
        }
    }
}
