Skip to content
Snippets Groups Projects
Commit 1f2ea352 authored by Ling Ma's avatar Ling Ma
Browse files

Deny SIM-profile association for non-existent SIM

Previously, for a SIM Id that we have no records of, we return true for
its accessibility check for any profiles. After this change, we throw
IAE/convert the IAE to false to better define the API behavior.

Bug: 294125411
Test: Manually sending/receiving SMS/MMS,
    atest com.android.providers.telephony.SmsProviderTest,
    atest com.android.providers.telephony.MmsProviderTest,
    atest com.android.providers.telephony.ProviderUtilTest,
    atest CtsTelephonyProviderTestCases,
    atest CtsTelephonyTestCases
Change-Id: If5a66e186273ab0e5439df1e76107431bbb8d8e1
parent 84c5a997
No related branches found
No related tags found
No related merge requests found
......@@ -342,7 +342,10 @@ public class MmsServiceBroker extends SystemService {
// 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 @@ public class MmsServiceBroker extends SystemService {
}
}
/** @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);
......
......@@ -35,6 +35,8 @@ import android.telephony.TelephonyManager;
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 @@ public final class TelephonyPermissions {
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 final class TelephonyPermissions {
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 @@ public final class TelephonyPermissions {
* @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 @@ public final class TelephonyPermissions {
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);
}
......
......@@ -274,6 +274,10 @@ public final class TelephonyUtils {
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 @@ public final class TelephonyUtils {
return false;
}
}
\ No newline at end of file
}
......@@ -4348,7 +4348,7 @@ public class SubscriptionManager {
* {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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment