package com.glu.plugins.gluanalytics.util; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import java.net.UnknownHostException; import java.util.concurrent.Callable; /* loaded from: classes2.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 UnknownHostException unknownHostCause(Throwable th) { while (th != null) { if (!(th instanceof UnknownHostException)) { th = th.getCause(); } else { return (UnknownHostException) th; } } return null; } public static String emptyToNull(String str) { if (str == null || str.length() > 0) { return str; } return null; } public static String printBytes(byte[] bArr, int i, int i2) { StringBuilder sb = new StringBuilder(); while (i < i2) { sb.append(String.format("%02x", Byte.valueOf(bArr[i]))); i++; } return sb.toString(); } public static Looper createLooper() { return createLooper("looper"); } public static Looper createLooper(String str) { HandlerThread handlerThread = new HandlerThread(str); handlerThread.start(); return handlerThread.getLooper(); } public static T call(Callable callable) { try { return callable.call(); } catch (Exception e) { throw propagate(e); } } public static long packageVersionCode(Context context) { long longVersionCode; try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); if (Build.VERSION.SDK_INT >= 28) { longVersionCode = packageInfo.getLongVersionCode(); return longVersionCode; } return packageInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } } 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"); } } }