package com.iBookStar.utils; import android.app.Activity; import android.app.ActivityManager; import android.app.Application; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Proxy; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Process; import android.text.format.Time; import android.util.Base64; import android.util.TypedValue; import com.bytedance.sdk.openadsdk.downloadnew.core.TTDownloadField; import com.iBookStar.b.a; import com.iBookStar.d.c; import com.kuaishou.weapon.p0.b; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.net.URLDecoder; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.TimeZone; import java.util.zip.GZIPOutputStream; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; public class k { public static Integer a; static char[] b = "哈哈哈哈,总算给你找到了,很难找吧,赚几个钱不容易吧,可惜这里还不是全部,再接再厉,继续找找!".toCharArray(); static int c = 20; private static Boolean d = null; private static b e = new b("yyyy-MM-dd HH:mm:ss"); static { new b("yyyyMMdd"); } public static int a() { Integer num = a; if (num != null) { return num.intValue(); } Integer valueOf = Integer.valueOf(c()); a = valueOf; return valueOf.intValue(); } public static int a(float f) { return Math.round(TypedValue.applyDimension(1, f, a.k().getResources().getDisplayMetrics())); } public static int a(int i, String str, String str2) { return a.q ? i : a.k().getResources().getIdentifier(str, str2, a.k().getPackageName()); } public static int a(Context context, float f) { return Math.round(TypedValue.applyDimension(1, f, context.getResources().getDisplayMetrics())); } public static Application a(Context context) { if (context instanceof Application) { return (Application) context; } if (context instanceof Activity) { return ((Activity) context).getApplication(); } try { Application application = (Application) Class.forName("android.app.ActivityThread").getDeclaredMethod("currentApplication", new Class[0]).invoke(null, new Object[0]); if (application != null) { PrintStream printStream = System.out; printStream.println("???????????????, ActivityThread currentApplication = " + application.toString()); return application; } } catch (Throwable th) { th.printStackTrace(); } return null; } /* JADX WARNING: Missing exception handler attribute for start block: B:13:0x0048 */ public static Bitmap a(String str, int i, int i2) { int i3; BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; options.inSampleSize = 1; if (i <= 0 || i2 <= 0) { options.inJustDecodeBounds = false; } i3 = 0; while (true) { int i4 = i3 + 1; if (i3 >= 3) { return null; } try { if (options.inJustDecodeBounds) { BitmapFactory.decodeFile(str, options); options.inSampleSize = Math.max(Math.max((int) Math.ceil((double) (((float) options.outWidth) / ((float) i))), (int) Math.ceil((double) (((float) options.outHeight) / ((float) i2)))), 1); options.inJustDecodeBounds = false; } return BitmapFactory.decodeFile(str, options); } catch (OutOfMemoryError unknown) { System.gc(); try { Thread.sleep(100); } catch (Exception e2) { e2.printStackTrace(); } i3 = i4; } catch (Exception unused) { return null; } i3 = i4; } } public static Drawable a(Drawable drawable, int i) { try { drawable.mutate().setColorFilter(i, PorterDuff.Mode.SRC_IN); return drawable; } catch (Exception e2) { e2.printStackTrace(); return null; } } public static String a(Uri uri) { try { StringBuilder sb = new StringBuilder(); sb.append(uri.getScheme()); sb.append("://"); sb.append(uri.getEncodedAuthority()); sb.append(uri.getEncodedPath()); Bundle b2 = b(uri.getEncodedQuery()); if (!b2.isEmpty()) { sb.append("?"); for (String str : b2.keySet()) { sb.append(str); sb.append("="); sb.append(URLEncoder.encode(b2.getString(str))); sb.append("&"); } sb.deleteCharAt(sb.length() - 1); } if (s.c(uri.getFragment())) { sb.append("#"); sb.append(uri.getEncodedFragment()); } return sb.toString(); } catch (Exception e2) { e2.printStackTrace(); return null; } } public static String a(String str, String str2) { byte[] a2; if (s.a(str) || s.a(str2) || (a2 = a(e(str), str2)) == null) { return null; } return new String(a2); } public static void a(Activity activity, int i) { try { r.b(activity, i, Build.VERSION.SDK_INT >= 23 ? 0 : 50); if (a(i)) { r.b(activity); } else { r.a(activity); } } catch (Exception unused) { } } public static void a(String str) { if (Build.VERSION.SDK_INT >= 11) { ((ClipboardManager) a.k().getSystemService("clipboard")).setPrimaryClip(ClipData.newPlainText(null, str)); } else { ((android.text.ClipboardManager) a.k().getSystemService("clipboard")).setText(str); } } public static boolean a(int i) { return 1.0d - ((((((double) Color.red(i)) * 0.299d) + (((double) Color.green(i)) * 0.587d)) + (((double) Color.blue(i)) * 0.114d)) / 255.0d) < 0.5d; } public static boolean a(long j) { Time time = new Time(); time.set(j); Time time2 = new Time(); time2.setToNow(); return time.monthDay == time2.monthDay && time.month == time2.month && time.year == time2.year; } private static byte[] a(byte[] bArr, String str) { try { byte[] bytes = str.getBytes("utf-8"); int i = 16; byte[] bArr2 = new byte[16]; if (bytes.length <= 16) { i = bytes.length; } System.arraycopy(bytes, 0, bArr2, 0, i); Cipher instance = Cipher.getInstance("AES/ECB/PKCS5Padding"); instance.init(2, new SecretKeySpec(bArr2, b.b)); return instance.doFinal(bArr); } catch (Throwable th) { th.printStackTrace(); return null; } } /* JADX WARNING: Can't wrap try/catch for region: R(6:12|13|14|15|16|21) */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:14:0x0035 */ public static Bundle b(String str) { Bundle bundle = new Bundle(); if (str != null) { for (String str2 : str.split("&")) { String[] split = str2.split("="); if (split != null && split.length == 2) { String str3 = split[0]; String str4 = split[1]; if (s.c(str3) && s.c(str4)) { str3 = URLDecoder.decode(str3); str4 = URLDecoder.decode(str4); bundle.putString(str3, str4); } } } } return bundle; } public static String b() { if (Build.VERSION.SDK_INT >= 11) { ClipboardManager clipboardManager = (ClipboardManager) a.k().getSystemService("clipboard"); if (clipboardManager != null && clipboardManager.hasPrimaryClip() && clipboardManager.getPrimaryClip().getItemCount() > 0) { for (int i = 0; i < clipboardManager.getPrimaryClip().getItemCount(); i++) { if (clipboardManager.getPrimaryClip().getItemAt(i).getText() != null) { String valueOf = String.valueOf(clipboardManager.getPrimaryClip().getItemAt(i).getText()); if (s.c(valueOf)) { return valueOf; } } } } return ""; } android.text.ClipboardManager clipboardManager2 = (android.text.ClipboardManager) a.k().getSystemService("clipboard"); return clipboardManager2.getText() != null ? String.valueOf(clipboardManager2.getText()) : ""; } /* JADX WARNING: Removed duplicated region for block: B:12:0x003e A[SYNTHETIC, Splitter:B:12:0x003e] */ /* JADX WARNING: Removed duplicated region for block: B:26:? A[RETURN, SYNTHETIC] */ public static String b(Context context) { String str; Throwable th; try { str = (String) Class.forName("android.app.ActivityThread").getDeclaredMethod("currentProcessName", new Class[0]).invoke(null, new Object[0]); try { System.out.println("???????????????, ActivityThread currentProcessName = " + str); } catch (Throwable th2) { th = th2; } } catch (Throwable th3) { str = null; th = th3; th.printStackTrace(); if (s.a(str)) { } } if (s.a(str)) { return str; } try { int myPid = Process.myPid(); List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) context.getApplicationContext().getSystemService(TTDownloadField.TT_ACTIVITY)).getRunningAppProcesses(); if (runningAppProcesses == null) { return str; } for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) { if (runningAppProcessInfo.pid == myPid) { return runningAppProcessInfo.processName; } } return str; } catch (Throwable th4) { th4.printStackTrace(); return str; } } /* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */ public static int c() { NetworkInfo activeNetworkInfo; try { ConnectivityManager connectivityManager = (ConnectivityManager) a.k().getSystemService("connectivity"); if (!(connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null)) { if (activeNetworkInfo.isAvailable()) { int type = activeNetworkInfo.getType(); if (type == 0) { switch (activeNetworkInfo.getSubtype()) { case 1: case 2: case 4: case 7: case 11: case 16: return 2; case 3: case 5: case 6: case 8: case 9: case 10: case 12: case 14: case 15: case 17: return 3; case 13: case 18: case 19: return 4; case 20: return 5; default: String subtypeName = activeNetworkInfo.getSubtypeName(); if (subtypeName.equalsIgnoreCase("TD-SCDMA") || subtypeName.equalsIgnoreCase("WCDMA") || subtypeName.equalsIgnoreCase("CDMA2000")) { return 3; } break; } } else if (type == 1) { return 1; } return 0; } } return 0; } catch (Exception e2) { e2.printStackTrace(); } } public static int c(Context context) { return context.getApplicationContext().getResources().getDisplayMetrics().heightPixels; } public static String c(String str) { try { String host = Uri.parse(str).getHost(); String[] split = host.split("\\."); if (split.length <= 2) { return host; } return split[1] + "." + split[2]; } catch (Exception e2) { e2.printStackTrace(); return null; } } public static int d(Context context) { return context.getApplicationContext().getResources().getDisplayMetrics().widthPixels; } /* JADX WARNING: Removed duplicated region for block: B:20:0x0039 A[SYNTHETIC, Splitter:B:20:0x0039] */ public static String d(String str) { Throwable th; GZIPOutputStream gZIPOutputStream; if (s.a(str)) { return null; } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream); try { gZIPOutputStream.write(str.getBytes("utf-8")); gZIPOutputStream.finish(); String encodeToString = Base64.encodeToString(byteArrayOutputStream.toByteArray(), 2); try { gZIPOutputStream.close(); } catch (Throwable th2) { th2.printStackTrace(); } return encodeToString; } catch (Throwable th3) { th = th3; try { th.printStackTrace(); if (gZIPOutputStream != null) { try { gZIPOutputStream.close(); } catch (Throwable th4) { th4.printStackTrace(); } } return null; } catch (Throwable th5) { th5.printStackTrace(); } } } catch (Throwable th6) { th = th6; gZIPOutputStream = null; th.printStackTrace(); if (gZIPOutputStream != null) { } return null; } throw th; } public static void d() { if (Build.VERSION.SDK_INT >= 11) { ClipboardManager clipboardManager = (ClipboardManager) a.k().getSystemService("clipboard"); if (clipboardManager != null) { try { if (Build.VERSION.SDK_INT >= 28) { clipboardManager.clearPrimaryClip(); } else { clipboardManager.setPrimaryClip(ClipData.newPlainText(null, null)); } } catch (Exception e2) { e2.printStackTrace(); } } } else { ((android.text.ClipboardManager) a.k().getSystemService("clipboard")).setText(null); } } public static int e(Context context) { try { Class<?> cls = Class.forName("com.android.internal.R$dimen"); return context.getResources().getDimensionPixelSize(Integer.parseInt(cls.getField("status_bar_height").get(cls.newInstance()).toString())); } catch (Exception e2) { e2.printStackTrace(); return a(20.0f); } } public static String e() { return e.a(Calendar.getInstance().getTime()); } private static byte[] e(String str) { if (str.length() < 1) { return null; } byte[] bArr = new byte[(str.length() / 2)]; for (int i = 0; i < str.length() / 2; i++) { int i2 = i * 2; int i3 = i2 + 1; bArr[i] = (byte) ((Integer.parseInt(str.substring(i2, i3), 16) * 16) + Integer.parseInt(str.substring(i3, i2 + 2), 16)); } return bArr; } public static String f() { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); String format = simpleDateFormat.format(new Date()); int intValue = Integer.valueOf(format.substring(6, 8)).intValue(); StringBuilder sb = new StringBuilder(); int i = c + intValue; char[] cArr = b; int i2 = 0; if (i > cArr.length) { int length = i - cArr.length; while (i2 < length) { sb.append(b[i2]); i2++; } while (true) { char[] cArr2 = b; if (intValue >= cArr2.length) { break; } sb.append(cArr2[intValue]); intValue++; } } else { while (i2 < c) { sb.append(b[(intValue - 1) + i2]); i2++; } } return c.a(sb.toString() + format); } public static boolean f(Context context) { Boolean bool = d; if (bool != null) { return bool.booleanValue(); } try { Boolean valueOf = Boolean.valueOf((context.getApplicationInfo().flags & 2) != 0); d = valueOf; return valueOf.booleanValue(); } catch (Throwable unused) { return false; } } public static boolean g() { return f(a.k()); } public static boolean g(Context context) { String str; int i; try { if (Build.VERSION.SDK_INT >= 14) { str = System.getProperty("http.proxyHost"); String property = System.getProperty("http.proxyPort"); if (!s.c(property)) { property = "-1"; } i = Integer.parseInt(property); } else { String host = Proxy.getHost(context); i = Proxy.getPort(context); str = host; } return s.c(str) && i != -1; } catch (Exception unused) { return false; } } }