Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29745b36 authored by Hunter Knepshield's avatar Hunter Knepshield
Browse files

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
parent f393f17f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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);
+52 −0
Original line number Diff line number Diff line
@@ -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() {