Merge "Deny SIM-profile association for non-existent SIM" into main
diff --git a/services/core/java/com/android/server/MmsServiceBroker.java b/services/core/java/com/android/server/MmsServiceBroker.java
index d6f1348..ced7773 100644
--- a/services/core/java/com/android/server/MmsServiceBroker.java
+++ b/services/core/java/com/android/server/MmsServiceBroker.java
@@ -342,7 +342,10 @@
// Check if user is associated with the subscription
if (!TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId,
- Binder.getCallingUserHandle())) {
+ Binder.getCallingUserHandle())
+ // For inactive sub, fall through to MMS service to have it recorded in metrics.
+ && isActiveSubId(subId)) {
+ // Try remind user to use another profile to send.
TelephonyUtils.showSwitchToManagedProfileDialogIfAppropriate(mContext,
subId, Binder.getCallingUid(), callingPkg);
return;
@@ -550,6 +553,17 @@
}
}
+ /** @return true if the subId is active. */
+ private boolean isActiveSubId(int subId) {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ SubscriptionManager subManager = mContext.getSystemService(SubscriptionManager.class);
+ return subManager != null && subManager.isActiveSubscriptionId(subId);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
private int getPhoneIdFromSubId(int subId) {
SubscriptionManager subManager = (SubscriptionManager)
mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
diff --git a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
index 29a952a..250c3a5 100644
--- a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
+++ b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
@@ -35,6 +35,8 @@
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.telephony.flags.FeatureFlags;
+import com.android.internal.telephony.flags.FeatureFlagsImpl;
import java.util.HashMap;
import java.util.HashSet;
@@ -46,7 +48,8 @@
private static final String LOG_TAG = "TelephonyPermissions";
private static final boolean DBG = false;
-
+ /** Feature flags */
+ private static final FeatureFlags sFeatureFlag = new FeatureFlagsImpl();
/**
* Whether to disable the new device identifier access restrictions.
*/
@@ -854,7 +857,8 @@
public static boolean checkSubscriptionAssociatedWithUser(@NonNull Context context, int subId,
@NonNull UserHandle callerUserHandle, @NonNull String destAddr) {
// Skip subscription-user association check for emergency numbers
- TelephonyManager tm = context.getSystemService(TelephonyManager.class);
+ TelephonyManager tm = (TelephonyManager) context.getSystemService(
+ Context.TELEPHONY_SERVICE);
final long token = Binder.clearCallingIdentity();
try {
if (tm != null && tm.isEmergencyNumber(destAddr)) {
@@ -876,16 +880,19 @@
* @param context Context
* @param subId subscription ID
* @param callerUserHandle caller user handle
- * @return false if user is not associated with the subscription.
+ * @return false if user is not associated with the subscription, or no record found of this
+ * subscription.
*/
public static boolean checkSubscriptionAssociatedWithUser(@NonNull Context context, int subId,
@NonNull UserHandle callerUserHandle) {
- if (!SubscriptionManager.isValidSubscriptionId(subId)) {
- // No subscription on device, return true.
+ if (!sFeatureFlag.rejectBadSubIdInteraction()
+ && !SubscriptionManager.isValidSubscriptionId(subId)) {
+ // Return true for invalid sub Id.
return true;
}
- SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class);
+ SubscriptionManager subManager = (SubscriptionManager) context.getSystemService(
+ Context.TELEPHONY_SUBSCRIPTION_SERVICE);
final long token = Binder.clearCallingIdentity();
try {
if ((subManager != null) &&
@@ -894,8 +901,11 @@
Log.e(LOG_TAG, "User[User ID:" + callerUserHandle.getIdentifier()
+ "] is not associated with Subscription ID:" + subId);
return false;
-
}
+ } catch (IllegalArgumentException e) {
+ // Found no record of this sub Id.
+ Log.e(LOG_TAG, "Subscription[Subscription ID:" + subId + "] has no records on device");
+ return !sFeatureFlag.rejectBadSubIdInteraction();
} finally {
Binder.restoreCallingIdentity(token);
}
diff --git a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
index 9a8c965..aed8fb8 100644
--- a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
+++ b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
@@ -274,6 +274,10 @@
SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class);
+ if (!subscriptionManager.isActiveSubscriptionId(subId)) {
+ Log.e(LOG_TAG, "Tried to send message with an inactive subscription " + subId);
+ return;
+ }
UserHandle associatedUserHandle = subscriptionManager.getSubscriptionUserHandle(subId);
UserManager um = context.getSystemService(UserManager.class);
@@ -319,4 +323,4 @@
return false;
}
-}
\ No newline at end of file
+}
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 29149b9..fa5fd87 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -4348,7 +4348,7 @@
* {code true} if there are no subscriptions on device
* else {@code false} if subscription is not associated with user.
*
- * @throws IllegalArgumentException if subscription is invalid.
+ * @throws IllegalArgumentException if subscription doesn't exist.
* @throws SecurityException if the caller doesn't have permissions required.
*
* @hide