diff --git a/services/core/java/com/android/server/MmsServiceBroker.java b/services/core/java/com/android/server/MmsServiceBroker.java
index d6f1348a6f3d5a4e36f06b283167874387fedec1..ced7773eff56cbfd1b4d0222a4184c57835f421d 100644
--- a/services/core/java/com/android/server/MmsServiceBroker.java
+++ b/services/core/java/com/android/server/MmsServiceBroker.java
@@ -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);
diff --git a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
index 29a952a5d6d12cee780a9ac5c69ca0673e1d95b9..250c3a54c92862b5e006748b01ff8e7aa6114860 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.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);
         }
diff --git a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
index 9a8c9655375d2394bc249b950c4271618e01af88..aed8fb8c4503aa7fd72cba00c83d02e8bf84f7b0 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 @@ 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
+}
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 29149b95e47141ad4c5e0ce94e7d184bd3d8810b..fa5fd875a024f46c950b87fb7f56243575f5c194 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -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