package com.huawei.hms.utils; import android.app.Activity; import android.app.ActivityManager; import android.app.KeyguardManager; import android.content.Context; import android.content.Intent; import android.os.Process; import android.text.TextUtils; import com.huawei.hms.support.api.entity.common.CommonConstant; import com.huawei.hms.support.common.ActivityMgr; import com.huawei.hms.support.log.HMSLog; import java.util.List; /* loaded from: classes2.dex */ public class UIUtil { private static int a(Context context) { if (context == null) { return 0; } return context.getResources().getIdentifier("androidhwext:style/Theme.Emui", null, null); } public static Activity getActiveActivity(Activity activity, Context context) { if (isBackground(context)) { StringBuilder sb = new StringBuilder("isBackground"); sb.append(isBackground(context)); HMSLog.i("UIUtil", sb.toString()); return null; } if (activity == null) { HMSLog.i("UIUtil", "activity is null"); return ActivityMgr.INST.getCurrentActivity(); } if (!activity.isFinishing()) { return activity; } StringBuilder sb2 = new StringBuilder("activity isFinishing is "); sb2.append(activity.isFinishing()); HMSLog.i("UIUtil", sb2.toString()); return ActivityMgr.INST.getCurrentActivity(); } public static int getDialogThemeId(Activity activity) { if (a(activity) != 0) { return 0; } return (activity != null && (activity.getResources().getConfiguration().uiMode & 48) == 32) ? 2 : 3; } public static boolean isActivityFullscreen(Activity activity) { if (activity != null) { return (activity.getWindow().getAttributes().flags & 1024) == 1024; } HMSLog.w("UIUtil", "activity is null"); return false; } public static boolean isBackground(Context context) { List runningAppProcesses; if (context == null) { return true; } ActivityManager activityManager = (ActivityManager) context.getSystemService("activity"); KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService("keyguard"); if (activityManager == null || keyguardManager == null || (runningAppProcesses = activityManager.getRunningAppProcesses()) == null) { return true; } String processName = getProcessName(context, Process.myPid()); for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) { if (TextUtils.equals(runningAppProcessInfo.processName, processName)) { StringBuilder sb = new StringBuilder("appProcess.importance is "); sb.append(runningAppProcessInfo.importance); HMSLog.i("UIUtil", sb.toString()); boolean z = runningAppProcessInfo.importance == 100; boolean isKeyguardLocked = keyguardManager.isKeyguardLocked(); StringBuilder sb2 = new StringBuilder("isForground is "); sb2.append(z); sb2.append("*** isLockedState is "); sb2.append(isKeyguardLocked); HMSLog.i("UIUtil", sb2.toString()); return !z || isKeyguardLocked; } } return true; } public static Intent modifyIntentBehaviorsSafe(Intent intent) { if (intent == null) { return null; } String action = intent.getAction(); if ("android.intent.action.SEND".equals(action) || "android.intent.action.SEND_MULTIPLE".equals(action) || "android.media.action.IMAGE_CAPTURE".equals(action) || "android.media.action.IMAGE_CAPTURE_SECURE".equals(action) || "android.media.action.VIDEO_CAPTURE".equals(action)) { intent.setAction(CommonConstant.ACTION.HWID_SCHEME_URL); } intent.setFlags(intent.getFlags() & (-196)); return intent; } public static String getProcessName(Context context, int i) { ActivityManager activityManager; List runningAppProcesses; if (context != null && (activityManager = (ActivityManager) context.getSystemService("activity")) != null && (runningAppProcesses = activityManager.getRunningAppProcesses()) != null) { for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) { if (runningAppProcessInfo.pid == i) { return runningAppProcessInfo.processName; } } } return ""; } }