package com.baidu.sec.a.d; import android.app.ActivityManager; import android.content.Context; import android.os.Build; import android.os.PowerManager; import android.text.TextUtils; import com.baidu.sec.a.b.a; import com.bytedance.sdk.openadsdk.downloadnew.core.TTDownloadField; import com.kuaishou.weapon.p0.h; import java.lang.reflect.Method; import java.util.Arrays; /* compiled from: CommonUtils */ public class b { private static boolean a = false; private static boolean b = false; private static long c = 0; private static boolean d = false; public static void a(Throwable th) { } public static boolean a(Context context) { try { long currentTimeMillis = System.currentTimeMillis(); if (currentTimeMillis - c < 1000) { return d; } d = b(context) && c(context); c = currentTimeMillis; return d; } catch (Throwable th) { a(th); } } public static boolean b(Context context) { try { return ((PowerManager) context.getSystemService("power")).isScreenOn(); } catch (Throwable th) { a(th); return false; } } public static boolean c(Context context) { try { if (Build.VERSION.SDK_INT < 21) { return e(context); } if (context == null) { return false; } for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : ((ActivityManager) context.getSystemService(TTDownloadField.TT_ACTIVITY)).getRunningAppProcesses()) { if (runningAppProcessInfo.importance == 100 && runningAppProcessInfo.importanceReasonCode == 0 && runningAppProcessInfo.pkgList != null && runningAppProcessInfo.pkgList.length != 0 && Arrays.asList(runningAppProcessInfo.pkgList).contains(context.getPackageName())) { return true; } } return false; } catch (Throwable th) { a(th); return false; } } private static boolean e(Context context) { ActivityManager.RunningTaskInfo runningTaskInfo; try { if (!c.a(context, new String[]{h.e})) { return true; } ActivityManager activityManager = (ActivityManager) context.getSystemService(TTDownloadField.TT_ACTIVITY); if (activityManager.getRunningTasks(1) == null || (runningTaskInfo = activityManager.getRunningTasks(1).get(0)) == null) { return false; } return context.getPackageName().equals(runningTaskInfo.topActivity.getPackageName()); } catch (Throwable th) { a(th); return false; } } public static boolean d(Context context) { try { if (a) { return b; } int a2 = a(f(context), "3.5.5.0"); boolean z = true; a = true; if (a2 < 0) { z = false; } b = z; return z; } catch (Throwable th) { a(th); return false; } } private static String f(Context context) { String str; try { if ("sofire".equals(a.a)) { str = "com.baidu.sofire.ac.FH"; } else if ("techain".equals(a.a)) { str = "com.baidu.techain.ac.TH"; } else if ("puying".equals(a.a)) { str = "com.baidu.puying.ac.HH"; } else if ("xenv".equals(a.a)) { str = "com.baidu.xenv.ac.XEH"; } else if ("liantian".equals(a.a)) { str = "com.baidu.liantian.ac.LH"; } else if ("xshield".equals(a.a)) { str = "com.baidu.xshield.ac.XH"; } else if ("xsecurity".equals(a.a)) { str = "com.baidu.xsecurity.ac.XSH"; } else if ("haotian".equals(a.a)) { str = "com.baidu.haotian.ac.HTH"; } else if ("tvshield".equals(a.a)) { str = "com.baidu.tvshield.ac.TVH"; } else if ("enan".equals(a.a)) { str = "com.baidu.enan.ac.FH"; } else if ("xface".equals(a.a)) { str = "com.baidu.xface.ac.LH"; } else { str = "mshield".equals(a.a) ? "com.baidu.mshield.ac.MH" : ""; } Method method = Class.forName(str).getMethod("getVersion", Context.class); if (method != null) { method.setAccessible(true); String str2 = (String) method.invoke(null, context); if (!TextUtils.isEmpty(str2)) { return str2; } } } catch (Throwable th) { a(th); } return ""; } private static int a(String str, String str2) { try { String[] split = str.split("\\."); String[] split2 = str2.split("\\."); int i = 0; while (true) { if (i >= split.length && i >= split2.length) { break; } int parseInt = i < split.length ? Integer.parseInt(split[i]) : 0; int parseInt2 = i < split2.length ? Integer.parseInt(split2[i]) : 0; if (parseInt > parseInt2) { return 1; } if (parseInt < parseInt2) { return -1; } i++; } } catch (Throwable th) { a(th); } return 0; } }