From 6fdfb791b04755a926b5907a48c9ecc96d6fa13b Mon Sep 17 00:00:00 2001 From: jinjeong Date: Fri, 15 Nov 2024 08:06:58 +0000 Subject: New System Api: getCarrierId using carrierIdentifier Bug: b/378778278 FLAG: com.android.internal.telephony.flags.carrier_id_from_carrier_identifier Test: atest Change-Id: I763fff823aecbe26c000c12cf6edb01371cbf52f --- core/api/system-current.txt | 1 + .../java/android/telephony/TelephonyManager.java | 33 ++++++++++++++++++++++ .../com/android/internal/telephony/ITelephony.aidl | 11 ++++++++ 3 files changed, 45 insertions(+) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 61f9b892c4dd..29b069313743 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -15925,6 +15925,7 @@ package android.telephony { method @Nullable @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public android.content.ComponentName getAndUpdateDefaultRespondViaMessageApplication(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getCallForwarding(int, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CallForwardingInfoCallback); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public void getCallWaitingStatus(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer); + method @FlaggedApi("com.android.internal.telephony.flags.carrier_id_from_carrier_identifier") @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) @WorkerThread public int getCarrierIdFromCarrierIdentifier(@NonNull android.service.carrier.CarrierIdentifier); method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public android.telephony.ImsiEncryptionInfo getCarrierInfoForImsiEncryption(int); method public java.util.List getCarrierPackageNamesForIntent(android.content.Intent); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.List getCarrierPackageNamesForIntentAndPhone(android.content.Intent, int); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 6f2c8623fd71..883a9ef3eb50 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -19594,4 +19594,37 @@ public class TelephonyManager { throw ex.rethrowAsRuntimeException(); } } + + /** + * Returns carrier id maps to the passing CarrierIdentifier. + * To recognize a carrier (including MVNO) as a first-class identity, + * Android assigns each carrier with a canonical integer a.k.a. carrier id. + * The carrier ID is an Android platform-wide identifier for a carrier. + * AOSP maintains carrier ID assignments in + * here + * + * @param carrierIdentifier {@link CarrierIdentifier} + * + * @return Carrier id. Return {@link #UNKNOWN_CARRIER_ID} if the carrier cannot be identified. + * @throws UnsupportedOperationException If the device does not have + * {@link PackageManager#FEATURE_TELEPHONY_SUBSCRIPTION}. + * + * @hide + */ + @FlaggedApi(Flags.FLAG_CARRIER_ID_FROM_CARRIER_IDENTIFIER) + @SystemApi + @WorkerThread + @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + public int getCarrierIdFromCarrierIdentifier(@NonNull CarrierIdentifier carrierIdentifier) { + try { + ITelephony service = getITelephony(); + if (service != null) { + return service.getCarrierIdFromIdentifier(carrierIdentifier); + } + } catch (RemoteException ex) { + // This could happen if binder process crashes. + } + return UNKNOWN_CARRIER_ID; + } } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index a58427318b55..a8bcf7a7264f 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -3508,4 +3508,15 @@ interface ITelephony { * @hide */ void setNtnSmsSupported(boolean ntnSmsSupported); + + /** + * Returns carrier id maps to the passing {@link CarrierIdentifier}. + * + * @param {@link CarrierIdentifier}. + * + * @return carrier id from passing {@link CarrierIdentifier} or {@link #UNKNOWN_CARRIER_ID} + * if the carrier cannot be identified + * @hide + */ + int getCarrierIdFromIdentifier(in CarrierIdentifier carrierIdentifier); } -- cgit v1.2.3-59-g8ed1b