diff --git a/core/api/system-current.txt b/core/api/system-current.txt index da9a4c50d3cb..5261019a9b62 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -12025,6 +12025,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 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 6286390ba139..29ffcd12a181 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; @@ -9178,6 +9179,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. + * + *

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 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 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 getPackagesWithCarrierPrivileges() {