package com.ironsource; import android.content.Context; import android.content.pm.ApplicationInfo; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes2.dex */ public class un { public static final String a = "com.google.market"; public static final String b = "com.android.vending"; public static final String c = "isInstalled"; private static final String d = "un"; private static final ArrayList e = new a(); public class a extends ArrayList { public a() { add(un.a); add("com.android.vending"); } } public class b extends JSONObject { final /* synthetic */ boolean a; public b(boolean z) throws JSONException { this.a = z; put("isInstalled", z); } } public enum c { GOOGLE_PLAY(2, new String[]{"com.android.vending"}), GOOGLE_MARKET(4, new String[]{un.a}), SAMSUNG(5, new String[]{"com.sec.android.app.samsungapps"}), AMAZON(6, new String[]{"com.amazon.venezia"}), HUAWEI(7, new String[]{"com.huawei.appmarket"}); private static final Map h = new HashMap(); private final int a; private final String[] b; static { for (c cVar : values()) { for (String str : cVar.d()) { h.put(str, cVar); } } } c(int i2, String[] strArr) { this.a = i2; this.b = strArr; } /* JADX INFO: Access modifiers changed from: private */ public static ArrayList b() { return new ArrayList<>(h.keySet()); } /* JADX INFO: Access modifiers changed from: private */ public int c() { return this.a; } /* JADX INFO: Access modifiers changed from: private */ public String[] d() { return this.b; } } private static JSONObject a(Context context) { return a(context, e); } private static JSONObject a(Context context, ArrayList arrayList) { JSONObject jSONObject = new JSONObject(); try { ArrayList b2 = b(context); Iterator it = arrayList.iterator(); while (it.hasNext()) { String next = it.next(); jSONObject.put(next, a(b2.contains(next.trim().toLowerCase(Locale.getDefault())))); } } catch (Exception e2) { i9.d().a(e2); } return jSONObject; } private static JSONObject a(boolean z) throws JSONException { return new b(z); } private static ArrayList b(Context context) { List o = el.N().f().o(context); ArrayList arrayList = new ArrayList<>(); for (ApplicationInfo applicationInfo : o) { if (applicationInfo != null) { arrayList.add(applicationInfo.packageName.toLowerCase(Locale.getDefault())); } } return arrayList; } public static Integer c(Context context) { JSONObject a2 = a(context, c.b()); int i = 0; for (c cVar : c.values()) { String[] d2 = cVar.d(); int length = d2.length; int i2 = 0; while (true) { if (i2 >= length) { break; } JSONObject optJSONObject = a2.optJSONObject(d2[i2]); if (optJSONObject != null && optJSONObject.optBoolean("isInstalled")) { i = (int) (i + Math.pow(2.0d, r5.c() - 1)); break; } i2++; } } return Integer.valueOf(i); } public static boolean d(Context context) { JSONObject a2 = a(context); Iterator keys = a2.keys(); while (keys.hasNext()) { JSONObject optJSONObject = a2.optJSONObject(keys.next()); if (optJSONObject != null && optJSONObject.optBoolean("isInstalled")) { return true; } } return false; } }