Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1acb8c1b authored by Ling Ma's avatar Ling Ma Committed by Android (Google) Code Review
Browse files

Merge "Deny SIM-profile association for non-existent SIM" into main

parents e52df630 1f2ea352
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -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);
+17 −7
Original line number Diff line number Diff line
@@ -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);
        }
+5 −1
Original line number Diff line number Diff line
@@ -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);

+1 −1
Original line number Diff line number Diff line
@@ -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