Merge "[MMS] Don't show error for non sms app" into udc-dev am: 5c84e498a9
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22119409 Change-Id: I115cf3675230923b744369c36987c6e6b7bb8c22 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -343,10 +343,8 @@ public class MmsServiceBroker extends SystemService {
|
|||||||
// Check if user is associated with the subscription
|
// Check if user is associated with the subscription
|
||||||
if (!TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId,
|
if (!TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId,
|
||||||
Binder.getCallingUserHandle())) {
|
Binder.getCallingUserHandle())) {
|
||||||
if (TelephonyUtils.isUidForeground(mContext, Binder.getCallingUid())) {
|
TelephonyUtils.showSwitchToManagedProfileDialogIfAppropriate(mContext,
|
||||||
TelephonyUtils.showErrorIfSubscriptionAssociatedWithManagedProfile(mContext,
|
subId, Binder.getCallingUid(), callingPkg);
|
||||||
subId);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static android.telephony.Annotation.DataState;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
|
import android.app.role.RoleManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ComponentInfo;
|
import android.content.pm.ComponentInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -255,15 +256,26 @@ public final class TelephonyUtils {
|
|||||||
* Show switch to managed profile dialog if subscription is associated with managed profile.
|
* Show switch to managed profile dialog if subscription is associated with managed profile.
|
||||||
*
|
*
|
||||||
* @param context Context object
|
* @param context Context object
|
||||||
* @param subId subscription id
|
* @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,
|
public static void showSwitchToManagedProfileDialogIfAppropriate(Context context,
|
||||||
int subId) {
|
int subId, int callingUid, String callingPackage) {
|
||||||
if (!isSwitchToManagedProfileDialogFlagEnabled()) {
|
if (!isSwitchToManagedProfileDialogFlagEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
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 subscriptionManager = context.getSystemService(
|
||||||
SubscriptionManager.class);
|
SubscriptionManager.class);
|
||||||
UserHandle associatedUserHandle = subscriptionManager.getSubscriptionUserHandle(subId);
|
UserHandle associatedUserHandle = subscriptionManager.getSubscriptionUserHandle(subId);
|
||||||
@@ -295,22 +307,25 @@ public final class TelephonyUtils {
|
|||||||
"enable_switch_to_managed_profile_dialog", false);
|
"enable_switch_to_managed_profile_dialog", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static boolean isUidForeground(Context context, int uid) {
|
||||||
* Check if the process with given uid is foreground.
|
ActivityManager am = context.getSystemService(ActivityManager.class);
|
||||||
*
|
boolean result = am != null && am.getUidImportance(uid)
|
||||||
* @param context context
|
== ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
|
||||||
* @param uid the caller uid
|
return result;
|
||||||
* @return true if the process with uid is foreground, false otherwise.
|
}
|
||||||
*/
|
|
||||||
public static boolean isUidForeground(Context context, int uid) {
|
private static boolean isPackageSMSRoleHolderForUser(Context context, String callingPackage,
|
||||||
final long token = Binder.clearCallingIdentity();
|
UserHandle user) {
|
||||||
try {
|
RoleManager roleManager = context.getSystemService(RoleManager.class);
|
||||||
ActivityManager am = context.getSystemService(ActivityManager.class);
|
final List<String> smsRoleHolder = roleManager.getRoleHoldersAsUser(
|
||||||
boolean result = am != null && am.getUidImportance(uid)
|
RoleManager.ROLE_SMS, user);
|
||||||
== ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
|
|
||||||
return result;
|
// ROLE_SMS is an exclusive role per user, so there would just be one entry in the
|
||||||
} finally {
|
// retuned list if not empty
|
||||||
Binder.restoreCallingIdentity(token);
|
if (!smsRoleHolder.isEmpty() && callingPackage.equals(smsRoleHolder.get(0))) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user