From f4a7659967062197248b0a3fd21eab9a297133bc Mon Sep 17 00:00:00 2001 From: fionaxu Date: Mon, 27 Nov 2017 22:53:42 -0800 Subject: [PATCH] new carrier id APIs 1. New telephony APIs to getCurrentCarrierId and getCurrentCarrierName 2. New broadcast intent to notify carrier id changed Bug: 64131637 Test: Build Change-Id: I9a240ba7df313ad701f98bb3982f29c3d5317da8 (cherry picked from commit fff6f59a63304be50e7a251fb4fca38ae0090fc4) Merged-in: I9a240ba7df313ad701f98bb3982f29c3d5317da8 --- api/current.txt | 7 ++ .../android/telephony/TelephonyManager.java | 107 ++++++++++++++++++ .../internal/telephony/ITelephony.aidl | 28 +++++ 3 files changed, 142 insertions(+) diff --git a/api/current.txt b/api/current.txt index 878531baf1ba5..f8ade974d6c2d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -40769,6 +40769,8 @@ package android.telephony { method public int getSimState(); method public int getSimState(int); method public java.lang.String getSubscriberId(); + method public int getSubscriptionCarrierId(); + method public java.lang.String getSubscriptionCarrierName(); method public java.lang.String getVisualVoicemailPackageName(); method public java.lang.String getVoiceMailAlphaTag(); method public java.lang.String getVoiceMailNumber(); @@ -40813,6 +40815,7 @@ package android.telephony { field public static final java.lang.String ACTION_PHONE_STATE_CHANGED = "android.intent.action.PHONE_STATE"; field public static final java.lang.String ACTION_RESPOND_VIA_MESSAGE = "android.intent.action.RESPOND_VIA_MESSAGE"; field public static final java.lang.String ACTION_SHOW_VOICEMAIL_NOTIFICATION = "android.telephony.action.SHOW_VOICEMAIL_NOTIFICATION"; + field public static final java.lang.String ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED = "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED"; field public static final int APPTYPE_CSIM = 4; // 0x4 field public static final int APPTYPE_ISIM = 5; // 0x5 field public static final int APPTYPE_RUIM = 3; // 0x3 @@ -40833,6 +40836,8 @@ package android.telephony { field public static final int DATA_DISCONNECTED = 0; // 0x0 field public static final int DATA_SUSPENDED = 3; // 0x3 field public static final java.lang.String EXTRA_CALL_VOICEMAIL_INTENT = "android.telephony.extra.CALL_VOICEMAIL_INTENT"; + field public static final java.lang.String EXTRA_CARRIER_ID = "android.telephony.extra.CARRIER_ID"; + field public static final java.lang.String EXTRA_CARRIER_NAME = "android.telephony.extra.CARRIER_NAME"; field public static final java.lang.String EXTRA_HIDE_PUBLIC_SETTINGS = "android.telephony.extra.HIDE_PUBLIC_SETTINGS"; field public static final java.lang.String EXTRA_INCOMING_NUMBER = "incoming_number"; field public static final java.lang.String EXTRA_IS_REFRESH = "android.telephony.extra.IS_REFRESH"; @@ -40843,6 +40848,7 @@ package android.telephony { field public static final java.lang.String EXTRA_STATE_IDLE; field public static final java.lang.String EXTRA_STATE_OFFHOOK; field public static final java.lang.String EXTRA_STATE_RINGING; + field public static final java.lang.String EXTRA_SUBSCRIPTION_ID = "android.telephony.extra.SUBSCRIPTION_ID"; field public static final java.lang.String EXTRA_VOICEMAIL_NUMBER = "android.telephony.extra.VOICEMAIL_NUMBER"; field public static final java.lang.String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU = "android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU"; field public static final int NETWORK_TYPE_1xRTT = 7; // 0x7 @@ -40878,6 +40884,7 @@ package android.telephony { field public static final int SIM_STATE_PUK_REQUIRED = 3; // 0x3 field public static final int SIM_STATE_READY = 5; // 0x5 field public static final int SIM_STATE_UNKNOWN = 0; // 0x0 + field public static final int UNKNOWN_CARRIER_ID = -1; // 0xffffffff field public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; // 0xfffffffe field public static final int USSD_RETURN_FAILURE = -1; // 0xffffffff field public static final java.lang.String VVM_TYPE_CVVM = "vvm_type_cvvm"; diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index f278d7c22e759..805fae3533b68 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -957,6 +957,64 @@ public class TelephonyManager { */ public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; + /** + * An unknown carrier id. It could either be subscription unavailable or the subscription + * carrier cannot be recognized. Unrecognized carriers here means + * {@link #getSimOperator() MCC+MNC} cannot be identified. + */ + public static final int UNKNOWN_CARRIER_ID = -1; + + /** + * Broadcast Action: The subscription carrier identity has changed. + * This intent could be sent on the following events: + * + * The intent will have the following extra values: + * + *

This is a protected intent that can only be sent by the system. + */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED = + "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED"; + + /** + * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which indicates + * the updated carrier id {@link TelephonyManager#getSubscriptionCarrierId()} of the current + * subscription. + *

Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or + * the carrier cannot be identified. + */ + public static final String EXTRA_CARRIER_ID = "android.telephony.extra.CARRIER_ID"; + + /** + * An string extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which + * indicates the updated carrier name of the current subscription. + * {@see TelephonyManager#getSubscriptionCarrierName()} + *

Carrier name is a user-facing name of the carrier id {@link #EXTRA_CARRIER_ID}, + * usually the brand name of the subsidiary (e.g. T-Mobile). + */ + public static final String EXTRA_CARRIER_NAME = "android.telephony.extra.CARRIER_NAME"; + + /** + * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} to indicate the + * subscription which has changed. + */ + public static final String EXTRA_SUBSCRIPTION_ID = "android.telephony.extra.SUBSCRIPTION_ID"; + + // // // Device Info @@ -6547,6 +6605,55 @@ public class TelephonyManager { } } + /** + * Returns carrier id of the current subscription. + *

To recognize a carrier (including MVNO) as a first class identity, assign each carrier + * with a canonical integer a.k.a carrier id. + * + * @return Carrier id of the current subscription. Return {@link #UNKNOWN_CARRIER_ID} if the + * subscription is unavailable or the carrier cannot be identified. + * @throws IllegalStateException if telephony service is unavailable. + */ + public int getSubscriptionCarrierId() { + try { + ITelephony service = getITelephony(); + return service.getSubscriptionCarrierId(getSubId()); + } catch (RemoteException ex) { + // This could happen if binder process crashes. + ex.rethrowAsRuntimeException(); + } catch (NullPointerException ex) { + // This could happen before phone restarts due to crashing. + throw new IllegalStateException("Telephony service unavailable"); + } + return UNKNOWN_CARRIER_ID; + } + + /** + * Returns carrier name of the current subscription. + *

Carrier name is a user-facing name of carrier id {@link #getSubscriptionCarrierId()}, + * usually the brand name of the subsidiary (e.g. T-Mobile). Each carrier could configure + * multiple {@link #getSimOperatorName() SPN} but should have a single carrier name. + * Carrier name is not a canonical identity, use {@link #getSubscriptionCarrierId()} instead. + *

The returned carrier name is unlocalized. + * + * @return Carrier name of the current subscription. Return {@code null} if the subscription is + * unavailable or the carrier cannot be identified. + * @throws IllegalStateException if telephony service is unavailable. + */ + public String getSubscriptionCarrierName() { + try { + ITelephony service = getITelephony(); + return service.getSubscriptionCarrierName(getSubId()); + } catch (RemoteException ex) { + // This could happen if binder process crashes. + ex.rethrowAsRuntimeException(); + } catch (NullPointerException ex) { + // This could happen before phone restarts due to crashing. + throw new IllegalStateException("Telephony service unavailable"); + } + return null; + } + /** * Return the application ID for the app type like {@link APPTYPE_CSIM}. * diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index b0af9a84553bf..416146fcb98ec 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -1317,6 +1317,34 @@ interface ITelephony { */ List getAllowedCarriers(int slotIndex); + /** + * Returns carrier id of the given subscription. + *

To recognize carrier as a first class identity, assign each carrier with a canonical + * integer a.k.a carrier id. + * + * @param subId The subscription id + * @return Carrier id of given subscription id. return {@link #UNKNOWN_CARRIER_ID} if + * subscription is unavailable or carrier cannot be identified. + * @throws IllegalStateException if telephony service is unavailable. + * @hide + */ + int getSubscriptionCarrierId(int subId); + + /** + * Returns carrier name of the given subscription. + *

Carrier name is a user-facing name of carrier id {@link #getSubscriptionCarrierId(int)}, + * usually the brand name of the subsidiary (e.g. T-Mobile). Each carrier could configure + * multiple {@link #getSimOperatorName() SPN} but should have a single carrier name. + * Carrier name is not canonical identity, use {@link #getSubscriptionCarrierId(int)} instead. + *

Returned carrier name is unlocalized. + * + * @return Carrier name of given subscription id. return {@code null} if subscription is + * unavailable or carrier cannot be identified. + * @throws IllegalStateException if telephony service is unavailable. + * @hide + */ + String getSubscriptionCarrierName(int subId); + /** * Action set from carrier signalling broadcast receivers to enable/disable metered apns * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required