Add ability for CTS to set itself as carrier service package

This change introduces a Carrier Service Package override, requiring
MODIFY_PHONE_STATE, ensuring that CTS can export a CarrierService, and
set itself as the carrier service.

The requirement for the application to also be carrier-privileged still
stands, but omits the SIM-certificate-match requirement, instead
allowing carrierConfig based certificates + carrier service package
override as a sufficient gate (which critically need to both be doable
with the CTS Shell permission identity)

Bug: 266904760
Test: Manually tested with a demo CTS build, will be used for Core
      Networking CTS tests
Change-Id: I09f3107b860618d207a016964515eb1440e7beba
Merged-In: I09f3107b860618d207a016964515eb1440e7beba
(cherry picked from commit 810b869a628a290e6c4d794fb63daa5268ef0650)
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 8c668e3..e951f59 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -9562,6 +9562,34 @@
     }
 
     @Override
+    public void setCarrierServicePackageOverride(
+            int subId, String carrierServicePackage, String callingPackage) {
+        TelephonyPermissions.enforceShellOnly(
+                Binder.getCallingUid(), "setCarrierServicePackageOverride");
+
+        // Verify that the callingPackage belongs to the calling UID
+        mApp.getSystemService(AppOpsManager.class)
+                .checkPackage(Binder.getCallingUid(), callingPackage);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone == null || phone.getSubId() != subId) {
+                loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
+                throw new IllegalArgumentException("No phone for subid");
+            }
+            CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
+            if (cpt == null) {
+                loge("setCarrierServicePackageOverride failed with no CPT for phone");
+                throw new IllegalStateException("No CPT for phone");
+            }
+            cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    @Override
     public int getCarrierIdListVersion(int subId) {
         enforceReadPrivilegedPermission("getCarrierIdListVersion");