Loading services/core/java/com/android/server/MmsServiceBroker.java +6 −2 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import android.util.Slog; import com.android.internal.telephony.IMms; import com.android.internal.telephony.TelephonyPermissions; import com.android.internal.telephony.util.TelephonyUtils; import com.android.server.uri.NeededUriGrants; import com.android.server.uri.UriGrantsManagerInternal; Loading Loading @@ -342,7 +343,10 @@ public class MmsServiceBroker extends SystemService { // Check if user is associated with the subscription if (!TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId, Binder.getCallingUserHandle())) { // TODO(b/258629881): Display error dialog. if (TelephonyUtils.isUidForeground(mContext, Binder.getCallingUid())) { TelephonyUtils.showErrorIfSubscriptionAssociatedWithManagedProfile(mContext, subId); } return; } Loading telephony/common/com/android/internal/telephony/util/TelephonyUtils.java +64 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static android.telephony.Annotation.DataState; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.content.Context; import android.content.pm.ComponentInfo; import android.content.pm.PackageManager; Loading @@ -26,10 +27,16 @@ import android.content.pm.ResolveInfo; import android.os.Binder; import android.os.Bundle; import android.os.PersistableBundle; import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyFrameworkInitializer; import android.telephony.TelephonyManager; import android.util.Log; import com.android.internal.telephony.ITelephony; import java.io.PrintWriter; import java.util.Collections; Loading @@ -43,6 +50,8 @@ import java.util.function.Supplier; * This class provides various util functions */ public final class TelephonyUtils { private static final String LOG_TAG = "TelephonyUtils"; public static boolean IS_USER = "user".equals(android.os.Build.TYPE); public static boolean IS_DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0) == 1; Loading Loading @@ -240,4 +249,59 @@ public final class TelephonyUtils { } return userHandle; } /** * Show switch to managed profile dialog if subscription is associated with managed profile. * * @param context Context object * @param subId subscription id */ public static void showErrorIfSubscriptionAssociatedWithManagedProfile(Context context, int subId) { final long token = Binder.clearCallingIdentity(); try { SubscriptionManager subscriptionManager = context.getSystemService( SubscriptionManager.class); UserHandle associatedUserHandle = subscriptionManager.getSubscriptionUserHandle(subId); UserManager um = context.getSystemService(UserManager.class); if (associatedUserHandle != null && um.isManagedProfile( associatedUserHandle.getIdentifier())) { ITelephony iTelephony = ITelephony.Stub.asInterface( TelephonyFrameworkInitializer .getTelephonyServiceManager() .getTelephonyServiceRegisterer() .get()); if (iTelephony != null) { try { iTelephony.showSwitchToManagedProfileDialog(); } catch (RemoteException e) { Log.e(LOG_TAG, "Failed to launch switch to managed profile dialog."); } } } } finally { Binder.restoreCallingIdentity(token); } } /** * 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 { ActivityManager am = context.getSystemService(ActivityManager.class); boolean result = am != null && am.getUidImportance(uid) == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; return result; } finally { Binder.restoreCallingIdentity(token); } } } No newline at end of file telephony/java/com/android/internal/telephony/ITelephony.aidl +5 −0 Original line number Diff line number Diff line Loading @@ -2208,6 +2208,11 @@ interface ITelephony { oneway void enqueueSmsPickResult(String callingPackage, String callingAttributeTag, IIntegerConsumer subIdResult); /** * Show error dialog to switch to managed profile. */ oneway void showSwitchToManagedProfileDialog(); /** * Returns the MMS user agent. */ Loading Loading
services/core/java/com/android/server/MmsServiceBroker.java +6 −2 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import android.util.Slog; import com.android.internal.telephony.IMms; import com.android.internal.telephony.TelephonyPermissions; import com.android.internal.telephony.util.TelephonyUtils; import com.android.server.uri.NeededUriGrants; import com.android.server.uri.UriGrantsManagerInternal; Loading Loading @@ -342,7 +343,10 @@ public class MmsServiceBroker extends SystemService { // Check if user is associated with the subscription if (!TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId, Binder.getCallingUserHandle())) { // TODO(b/258629881): Display error dialog. if (TelephonyUtils.isUidForeground(mContext, Binder.getCallingUid())) { TelephonyUtils.showErrorIfSubscriptionAssociatedWithManagedProfile(mContext, subId); } return; } Loading
telephony/common/com/android/internal/telephony/util/TelephonyUtils.java +64 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static android.telephony.Annotation.DataState; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.content.Context; import android.content.pm.ComponentInfo; import android.content.pm.PackageManager; Loading @@ -26,10 +27,16 @@ import android.content.pm.ResolveInfo; import android.os.Binder; import android.os.Bundle; import android.os.PersistableBundle; import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyFrameworkInitializer; import android.telephony.TelephonyManager; import android.util.Log; import com.android.internal.telephony.ITelephony; import java.io.PrintWriter; import java.util.Collections; Loading @@ -43,6 +50,8 @@ import java.util.function.Supplier; * This class provides various util functions */ public final class TelephonyUtils { private static final String LOG_TAG = "TelephonyUtils"; public static boolean IS_USER = "user".equals(android.os.Build.TYPE); public static boolean IS_DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0) == 1; Loading Loading @@ -240,4 +249,59 @@ public final class TelephonyUtils { } return userHandle; } /** * Show switch to managed profile dialog if subscription is associated with managed profile. * * @param context Context object * @param subId subscription id */ public static void showErrorIfSubscriptionAssociatedWithManagedProfile(Context context, int subId) { final long token = Binder.clearCallingIdentity(); try { SubscriptionManager subscriptionManager = context.getSystemService( SubscriptionManager.class); UserHandle associatedUserHandle = subscriptionManager.getSubscriptionUserHandle(subId); UserManager um = context.getSystemService(UserManager.class); if (associatedUserHandle != null && um.isManagedProfile( associatedUserHandle.getIdentifier())) { ITelephony iTelephony = ITelephony.Stub.asInterface( TelephonyFrameworkInitializer .getTelephonyServiceManager() .getTelephonyServiceRegisterer() .get()); if (iTelephony != null) { try { iTelephony.showSwitchToManagedProfileDialog(); } catch (RemoteException e) { Log.e(LOG_TAG, "Failed to launch switch to managed profile dialog."); } } } } finally { Binder.restoreCallingIdentity(token); } } /** * 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 { ActivityManager am = context.getSystemService(ActivityManager.class); boolean result = am != null && am.getUidImportance(uid) == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; return result; } finally { Binder.restoreCallingIdentity(token); } } } No newline at end of file
telephony/java/com/android/internal/telephony/ITelephony.aidl +5 −0 Original line number Diff line number Diff line Loading @@ -2208,6 +2208,11 @@ interface ITelephony { oneway void enqueueSmsPickResult(String callingPackage, String callingAttributeTag, IIntegerConsumer subIdResult); /** * Show error dialog to switch to managed profile. */ oneway void showSwitchToManagedProfileDialog(); /** * Returns the MMS user agent. */ Loading