Loading services/core/java/com/android/server/MmsServiceBroker.java +2 −4 Original line number Diff line number Diff line Loading @@ -343,10 +343,8 @@ public class MmsServiceBroker extends SystemService { // Check if user is associated with the subscription if (!TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId, Binder.getCallingUserHandle())) { if (TelephonyUtils.isUidForeground(mContext, Binder.getCallingUid())) { TelephonyUtils.showErrorIfSubscriptionAssociatedWithManagedProfile(mContext, subId); } TelephonyUtils.showSwitchToManagedProfileDialogIfAppropriate(mContext, subId, Binder.getCallingUid(), callingPkg); return; } Loading telephony/common/com/android/internal/telephony/util/TelephonyUtils.java +34 −19 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.telephony.Annotation.DataState; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.role.RoleManager; import android.content.Context; import android.content.pm.ComponentInfo; import android.content.pm.PackageManager; Loading Loading @@ -256,14 +257,25 @@ public final class TelephonyUtils { * * @param context Context object * @param subId subscription id * @param callingUid uid for the calling app * @param callingPackage package name of the calling app */ public static void showErrorIfSubscriptionAssociatedWithManagedProfile(Context context, int subId) { public static void showSwitchToManagedProfileDialogIfAppropriate(Context context, int subId, int callingUid, String callingPackage) { if (!isSwitchToManagedProfileDialogFlagEnabled()) { return; } final long token = Binder.clearCallingIdentity(); try { UserHandle callingUserHandle = UserHandle.getUserHandleForUid(callingUid); // We only want to show this dialog, while user actually trying to send the message from // a messaging app, in other cases this dialog don't make sense. if (!TelephonyUtils.isUidForeground(context, callingUid) || !TelephonyUtils.isPackageSMSRoleHolderForUser(context, callingPackage, callingUserHandle)) { return; } SubscriptionManager subscriptionManager = context.getSystemService( SubscriptionManager.class); UserHandle associatedUserHandle = subscriptionManager.getSubscriptionUserHandle(subId); Loading Loading @@ -295,22 +307,25 @@ public final class TelephonyUtils { "enable_switch_to_managed_profile_dialog", false); } /** * Check if the process with given uid is foreground. * * @param context context * @param uid the caller uid * @return true if the process with uid is foreground, false otherwise. */ public static boolean isUidForeground(Context context, int uid) { final long token = Binder.clearCallingIdentity(); try { private static boolean isUidForeground(Context context, int uid) { ActivityManager am = context.getSystemService(ActivityManager.class); boolean result = am != null && am.getUidImportance(uid) == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; return result; } finally { Binder.restoreCallingIdentity(token); } private static boolean isPackageSMSRoleHolderForUser(Context context, String callingPackage, UserHandle user) { RoleManager roleManager = context.getSystemService(RoleManager.class); final List<String> smsRoleHolder = roleManager.getRoleHoldersAsUser( RoleManager.ROLE_SMS, user); // ROLE_SMS is an exclusive role per user, so there would just be one entry in the // retuned list if not empty if (!smsRoleHolder.isEmpty() && callingPackage.equals(smsRoleHolder.get(0))) { return true; } return false; } } No newline at end of file Loading
services/core/java/com/android/server/MmsServiceBroker.java +2 −4 Original line number Diff line number Diff line Loading @@ -343,10 +343,8 @@ public class MmsServiceBroker extends SystemService { // Check if user is associated with the subscription if (!TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId, Binder.getCallingUserHandle())) { if (TelephonyUtils.isUidForeground(mContext, Binder.getCallingUid())) { TelephonyUtils.showErrorIfSubscriptionAssociatedWithManagedProfile(mContext, subId); } TelephonyUtils.showSwitchToManagedProfileDialogIfAppropriate(mContext, subId, Binder.getCallingUid(), callingPkg); return; } Loading
telephony/common/com/android/internal/telephony/util/TelephonyUtils.java +34 −19 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.telephony.Annotation.DataState; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.role.RoleManager; import android.content.Context; import android.content.pm.ComponentInfo; import android.content.pm.PackageManager; Loading Loading @@ -256,14 +257,25 @@ public final class TelephonyUtils { * * @param context Context object * @param subId subscription id * @param callingUid uid for the calling app * @param callingPackage package name of the calling app */ public static void showErrorIfSubscriptionAssociatedWithManagedProfile(Context context, int subId) { public static void showSwitchToManagedProfileDialogIfAppropriate(Context context, int subId, int callingUid, String callingPackage) { if (!isSwitchToManagedProfileDialogFlagEnabled()) { return; } final long token = Binder.clearCallingIdentity(); try { UserHandle callingUserHandle = UserHandle.getUserHandleForUid(callingUid); // We only want to show this dialog, while user actually trying to send the message from // a messaging app, in other cases this dialog don't make sense. if (!TelephonyUtils.isUidForeground(context, callingUid) || !TelephonyUtils.isPackageSMSRoleHolderForUser(context, callingPackage, callingUserHandle)) { return; } SubscriptionManager subscriptionManager = context.getSystemService( SubscriptionManager.class); UserHandle associatedUserHandle = subscriptionManager.getSubscriptionUserHandle(subId); Loading Loading @@ -295,22 +307,25 @@ public final class TelephonyUtils { "enable_switch_to_managed_profile_dialog", false); } /** * Check if the process with given uid is foreground. * * @param context context * @param uid the caller uid * @return true if the process with uid is foreground, false otherwise. */ public static boolean isUidForeground(Context context, int uid) { final long token = Binder.clearCallingIdentity(); try { private static boolean isUidForeground(Context context, int uid) { ActivityManager am = context.getSystemService(ActivityManager.class); boolean result = am != null && am.getUidImportance(uid) == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; return result; } finally { Binder.restoreCallingIdentity(token); } private static boolean isPackageSMSRoleHolderForUser(Context context, String callingPackage, UserHandle user) { RoleManager roleManager = context.getSystemService(RoleManager.class); final List<String> smsRoleHolder = roleManager.getRoleHoldersAsUser( RoleManager.ROLE_SMS, user); // ROLE_SMS is an exclusive role per user, so there would just be one entry in the // retuned list if not empty if (!smsRoleHolder.isEmpty() && callingPackage.equals(smsRoleHolder.get(0))) { return true; } return false; } } No newline at end of file