package csdk.gluads.util; import android.content.Context; import android.content.SharedPreferences; import android.os.Handler; import android.os.Looper; import android.provider.Settings; import android.util.Base64; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.google.android.gms.ads.identifier.AdvertisingIdClient; import com.mbridge.msdk.foundation.tools.SameMD5; import java.math.BigInteger; import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.UUID; import java.util.concurrent.Callable; /* loaded from: classes4.dex */ public class Common { private static Handler mainHandler = new Handler(Looper.getMainLooper()); public static T or(T t, T t2) { return t != null ? t : t2; } public static void require(boolean z) { if (!z) { throw new IllegalArgumentException(); } } public static void require(boolean z, String str) { if (z) { return; } if (str != null) { throw new IllegalArgumentException(str); } throw new IllegalArgumentException(); } public static RuntimeException propagate(Throwable th) { if (th instanceof Error) { throw ((Error) th); } if (th instanceof RuntimeException) { throw ((RuntimeException) th); } throw new RuntimeException(th); } public static String emptyToNull(String str) { if (str == null || str.length() > 0) { return str; } return null; } public static T call(Callable callable) { try { return callable.call(); } catch (Exception e) { throw propagate(e); } } public static String uuid() { return UUID.randomUUID().toString(); } public static Map createMap() { return new HashMap(); } public static Map shallowClone(Map map) { if (map == null) { return null; } Map createMap = createMap(); createMap.putAll(map); return createMap; } public static V get(Map map, K k, V v) { if (map == null || k == null) { return v; } V v2 = map.get(k); return (v2 != null || map.containsKey(k)) ? v2 : v; } public static V get(Map map, K k) { return (V) get(map, k, null); } public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); } public static void runOnUIThread(Runnable runnable) { require(runnable != null, "runnable == null"); if (!mainHandler.post(runnable)) { throw new IllegalStateException("Failed to post runnable"); } } public static void runOnUIThreadDelayed(Runnable runnable, long j) { require(runnable != null, "runnable == null"); if (!mainHandler.postDelayed(runnable, j)) { throw new IllegalStateException("Failed to post runnable"); } } public static long msTimestamp() { return System.nanoTime() / 1000000; } public static String getGAID(Context context) { try { return AdvertisingIdClient.getAdvertisingIdInfo(context).getId(); } catch (Exception unused) { return ""; } } public static String getAdMobTestDeviceID(Context context) { return md5(Settings.Secure.getString(context.getContentResolver(), "android_id")).toUpperCase(Locale.US); } public static Map getMapFromUserID(String str) { try { return JsonUtil.parseJsonObject(new String(Base64.decode(str, 0), "UTF-8")); } catch (Exception unused) { return createMap(); } } public static String getUserIDFromMap(Map map) { return Base64.encodeToString(JsonUtil.toJson(map).getBytes(Charset.forName("UTF-8")), 10).trim(); } public static String removeRevIDAndSessionIDFromUserID(String str) { Map mapFromUserID = getMapFromUserID(str); mapFromUserID.remove("revId"); mapFromUserID.remove("sessionId"); return getUserIDFromMap(mapFromUserID); } private static String md5(String str) { try { return String.format("%032X", new BigInteger(1, MessageDigest.getInstance(SameMD5.TAG).digest(str.getBytes()))); } catch (NoSuchAlgorithmException unused) { return ""; } } public static Map loadMap(SharedPreferences sharedPreferences, String str) { try { return JsonUtil.parseJsonObject(sharedPreferences.getString(str, "")); } catch (Exception unused) { return new HashMap(); } } public static void saveMap(SharedPreferences sharedPreferences, String str, Map map) { SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putString(str, JsonUtil.toJson(map)); edit.apply(); } @NonNull public static Map mapSSFromConfig(@Nullable Map map) { Map createMap = createMap(); if (map != null) { for (Map.Entry entry : map.entrySet()) { createMap.put(entry.getKey(), (String) entry.getValue()); } } return createMap; } }