diff options
| author | 2021-11-24 15:23:05 -0800 | |
|---|---|---|
| committer | 2021-12-03 18:21:11 -0800 | |
| commit | 29745b36f125b0370561fa97379c8094bb1e3de7 (patch) | |
| tree | c88245a3caff8ecc21fcf3c5b81c75e2cac2a646 | |
| parent | f393f17f55255ab990572b58a6acac4dda419209 (diff) | |
Create a convenience method to get the CarrierService package.
Currently, this just redirects to the existing Intent resolution APIs to
find the first carrier privileged package that declares a CarrierService
implementation for the specified SIM.
Follow-up work will make this a proper API that reaches all the way down
to CarrierPrivilegesTracker, which is slated to become the source of
truth for all carrier privilege related checks. Doing so will also
provide a free caching layer for this API, which should result in
appreciable performance increases.
Bug: 205736323
Test: make
CTS-Coverage-Bug: 205995169
Change-Id: I949de81f2c5b284b14c56b5d8d3ed0b60cb97847
| -rw-r--r-- | core/api/system-current.txt | 2 | ||||
| -rw-r--r-- | telephony/java/android/telephony/TelephonyManager.java | 52 |
2 files changed, 54 insertions, 0 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 84a4a44c5cf0..5ed5ffa703c3 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -12016,6 +12016,8 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getCarrierPrivilegeStatus(int); method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.List<java.lang.String> getCarrierPrivilegedPackagesForAllActiveSubscriptions(); method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public android.telephony.CarrierRestrictionRules getCarrierRestrictionRules(); + method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getCarrierServicePackageName(); + method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getCarrierServicePackageNameForLogicalSlot(int); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getCdmaEnhancedRoamingIndicatorDisplayNumber(); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public String getCdmaMdn(); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public String getCdmaMdn(int); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index a1d68b215ba5..034d9dbb59ac 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -70,6 +70,7 @@ import android.os.SystemProperties; import android.os.WorkSource; import android.provider.Settings.SettingNotFoundException; import android.service.carrier.CarrierIdentifier; +import android.service.carrier.CarrierService; import android.sysprop.TelephonyProperties; import android.telecom.CallScreeningService; import android.telecom.InCallService; @@ -9190,6 +9191,57 @@ public class TelephonyManager { return null; } + /** + * Returns the package name that provides the {@link CarrierService} implementation for the + * current subscription, or {@code null} if no package with carrier privileges declares one. + * + * <p>If this object has been created with {@link #createForSubscriptionId}, then the provided + * subscription ID is used. Otherwise, the default subscription ID will be used. + * + * @return The system-selected package that provides the {@link CarrierService} implementation + * for the current subscription, or {@code null} if none is resolved + * + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + public @Nullable String getCarrierServicePackageName() { + // TODO(b/205736323) plumb this through to CarrierPrivilegesTracker, which will cache the + // value instead of re-querying every time. + List<String> carrierServicePackages = + getCarrierPackageNamesForIntent( + new Intent(CarrierService.CARRIER_SERVICE_INTERFACE)); + if (carrierServicePackages != null && !carrierServicePackages.isEmpty()) { + return carrierServicePackages.get(0); + } + return null; + } + + /** + * Returns the package name that provides the {@link CarrierService} implementation for the + * specified {@code logicalSlotIndex}, or {@code null} if no package with carrier privileges + * declares one. + * + * @param logicalSlotIndex The slot index to fetch the {@link CarrierService} package for + * @return The system-selected package that provides the {@link CarrierService} implementation + * for the slot, or {@code null} if none is resolved + * + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { + // TODO(b/205736323) plumb this through to CarrierPrivilegesTracker, which will cache the + // value instead of re-querying every time. + List<String> carrierServicePackages = + getCarrierPackageNamesForIntentAndPhone( + new Intent(CarrierService.CARRIER_SERVICE_INTERFACE), logicalSlotIndex); + if (carrierServicePackages != null && !carrierServicePackages.isEmpty()) { + return carrierServicePackages.get(0); + } + return null; + } + /** @hide */ @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public List<String> getPackagesWithCarrierPrivileges() { |