check telephony feature before validating telephony intents

Bug: 73490653
Test: cts protectedBroadcastTest
Change-Id: I3a5d9a1c5bc5deb0a86c1083f3e27388eb96b09a
(cherry picked from commit 0c4e871135ed5af167c4d26d7c6ae0059c9a650c)
(cherry picked from commit 71619ce98f78dd82999824d982b73b1c216976fc)
diff --git a/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java b/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java
index 37b9461..1b1e669 100644
--- a/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java
+++ b/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java
@@ -17,6 +17,7 @@
 package android.permission2.cts;
 
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.test.AndroidTestCase;
 
 /**
@@ -47,21 +48,7 @@
         Intent.ACTION_SHUTDOWN,
         Intent.ACTION_DEVICE_STORAGE_LOW,
         Intent.ACTION_DEVICE_STORAGE_OK,
-        Intent.ACTION_NEW_OUTGOING_CALL,
         Intent.ACTION_REBOOT,
-        "android.intent.action.SERVICE_STATE",
-        "android.intent.action.RADIO_TECHNOLOGY",
-        "android.intent.action.EMERGENCY_CALLBACK_MODE_CHANGED",
-        "android.intent.action.SIG_STR",
-        "android.intent.action.ANY_DATA_STATE",
-        "android.intent.action.DATA_CONNECTION_FAILED",
-        "android.intent.action.SIM_STATE_CHANGED",
-        "android.intent.action.NETWORK_SET_TIME",
-        "android.intent.action.NETWORK_SET_TIMEZONE",
-        "com.android.internal.intent.action.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS",
-        "android.intent.action.ACTION_MDN_STATE_CHANGED",
-        "android.provider.Telephony.SPN_STRINGS_UPDATED",
-        "android.intent.action.ANY_DATA_STATE",
         "com.android.server.WifiManager.action.START_SCAN",
         "com.android.server.WifiManager.action.DELAYED_DRIVER_STOP",
         "android.net.wifi.WIFI_STATE_CHANGED",
@@ -85,6 +72,23 @@
         "com.android.server.InputMethodManagerService.SHOW_INPUT_METHOD_PICKER"
     };
 
+    private static final String BROADCASTS_TELEPHONY[] = new String[] {
+        Intent.ACTION_NEW_OUTGOING_CALL,
+        "android.intent.action.SERVICE_STATE",
+        "android.intent.action.SIG_STR",
+        "android.intent.action.RADIO_TECHNOLOGY",
+        "android.intent.action.ANY_DATA_STATE",
+        "android.intent.action.ACTION_MDN_STATE_CHANGED",
+        "android.provider.Telephony.SPN_STRINGS_UPDATED",
+        "android.intent.action.EMERGENCY_CALLBACK_MODE_CHANGED",
+        "android.intent.action.SIM_STATE_CHANGED",
+        "android.intent.action.DATA_CONNECTION_FAILED",
+        "android.intent.action.NETWORK_SET_TIME",
+        "android.intent.action.NETWORK_SET_TIMEZONE",
+        "com.android.internal.intent.action.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS",
+        "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED",
+    };
+
     /**
      * Verify that protected broadcast actions can't be sent.
      */
@@ -99,4 +103,19 @@
             }
         }
     }
+
+    public void testSendProtectedTelephonyBroadcasts() {
+        if (!getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+            return;
+        }
+        for (String action : BROADCASTS_TELEPHONY) {
+            try {
+                Intent intent = new Intent(action);
+                getContext().sendBroadcast(intent);
+                fail("expected security exception broadcasting telephony action: " + action);
+            } catch (SecurityException expected) {
+                assertNotNull("security exception's error message.", expected.getMessage());
+            }
+        }
+    }
 }