From 5ac293f0406cc48cafb17a7f17eb0bfb50b3b2af Mon Sep 17 00:00:00 2001 From: sqian Date: Wed, 17 Oct 2018 16:31:31 -0700 Subject: [PATCH] Introduce Emergency number functions APIs - getCurrentEmergencyNumberList - getCurrentEmergencyNumberList (per categories) - isCurrentEmergencyNumber Note: the implementaion from PhoneInterfaceManager is empty, but the names of the APIs need to be finalized so that the usages and test plan are not blocked. Bug: 112657134 Test: Treehugger Change-Id: I1e310941aea6d5288fd6c99071be6b46a8d98197 Merged-In: I854db34f4378f35f99c3d8133bf35f3d0b3aad2b Merged-In: Ic0a22dd9c2023362bbb65b80cb78990ace7caac4 --- api/current.txt | 4 + .../android/telephony/PhoneStateListener.java | 8 ++ .../android/telephony/TelephonyManager.java | 115 ++++++++++++++++++ .../internal/telephony/ITelephony.aidl | 11 ++ 4 files changed, 138 insertions(+) diff --git a/api/current.txt b/api/current.txt index f1700f25121e9..6d0c5a69081d6 100755 --- a/api/current.txt +++ b/api/current.txt @@ -42494,6 +42494,7 @@ package android.telephony { field public static final int LISTEN_CELL_LOCATION = 16; // 0x10 field public static final int LISTEN_DATA_ACTIVITY = 128; // 0x80 field public static final int LISTEN_DATA_CONNECTION_STATE = 64; // 0x40 + field public static final int LISTEN_EMERGENCY_NUMBER_LIST = 16777216; // 0x1000000 field public static final int LISTEN_MESSAGE_WAITING_INDICATOR = 4; // 0x4 field public static final int LISTEN_NONE = 0; // 0x0 field public static final int LISTEN_SERVICE_STATE = 1; // 0x1 @@ -42805,6 +42806,8 @@ package android.telephony { method public int getCallState(); method public android.os.PersistableBundle getCarrierConfig(); method public deprecated android.telephony.CellLocation getCellLocation(); + method public java.util.Map> getCurrentEmergencyNumberList(); + method public java.util.Map> getCurrentEmergencyNumberList(int); method public int getDataActivity(); method public int getDataNetworkType(); method public int getDataState(); @@ -42858,6 +42861,7 @@ package android.telephony { method public java.lang.String iccTransmitApduBasicChannel(int, int, int, int, int, java.lang.String); method public java.lang.String iccTransmitApduLogicalChannel(int, int, int, int, int, int, java.lang.String); method public boolean isConcurrentVoiceAndDataSupported(); + method public boolean isCurrentEmergencyNumber(java.lang.String); method public boolean isDataEnabled(); method public boolean isDataRoamingEnabled(); method public boolean isHearingAidCompatibilitySupported(); diff --git a/telephony/java/android/telephony/PhoneStateListener.java b/telephony/java/android/telephony/PhoneStateListener.java index 0ec85360908be..2abf98c73944e 100644 --- a/telephony/java/android/telephony/PhoneStateListener.java +++ b/telephony/java/android/telephony/PhoneStateListener.java @@ -301,6 +301,14 @@ public class PhoneStateListener { @SystemApi public static final int LISTEN_RADIO_POWER_STATE_CHANGED = 0x00800000; + /** + * Listen for changes to emergency number list based on all active subscriptions. + * + *

Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling + * app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}). + */ + public static final int LISTEN_EMERGENCY_NUMBER_LIST = 0x01000000; + /* * Subscription used to listen to the phone state changes * @hide diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index e4f766f28d01c..9f697e9c6e93c 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -22,6 +22,7 @@ import static com.android.internal.util.Preconditions.checkNotNull; import android.Manifest; import android.annotation.IntDef; +import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; @@ -57,6 +58,8 @@ import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telephony.VisualVoicemailService.VisualVoicemailTask; +import android.telephony.emergency.EmergencyNumber; +import android.telephony.emergency.EmergencyNumber.EmergencyServiceCategories; import android.telephony.ims.aidl.IImsConfig; import android.telephony.ims.aidl.IImsMmTelFeature; import android.telephony.ims.aidl.IImsRcsFeature; @@ -86,6 +89,7 @@ import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.concurrent.Executor; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -9047,4 +9051,115 @@ public class TelephonyManager { } } + /** + * Get the emergency number list based on current locale, sim, default, modem and network. + * + *

The emergency number {@link EmergencyNumber} with higher display priority is located at + * the smaller index in the returned list. + * + *

The subscriptions which the returned list would be based on, are all the active + * subscriptions, no matter which subscription could be used to create TelephonyManager. + * + *

Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling + * app has carrier privileges (see {@link #hasCarrierPrivileges}). + * + * @return Map including the key as the active subscription ID (Note: if there is no active + * subscription, the key is {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID}) and the value + * as the list of {@link EmergencyNumber}; null if this information is not available. + */ + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) + @Nullable + public Map> getCurrentEmergencyNumberList() { + try { + ITelephony telephony = getITelephony(); + if (telephony == null) { + return null; + } + return telephony.getCurrentEmergencyNumberList(mContext.getOpPackageName()); + } catch (RemoteException ex) { + Log.e(TAG, "getCurrentEmergencyNumberList RemoteException", ex); + } + return null; + } + + /** + * Get the per-category emergency number list based on current locale, sim, default, modem + * and network. + * + *

The emergency number {@link EmergencyNumber} with higher display priority is located at + * the smaller index in the returned list. + * + *

The subscriptions which the returned list would be based on, are all the active + * subscriptions, no matter which subscription could be used to create TelephonyManager. + * + *

Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling + * app has carrier privileges (see {@link #hasCarrierPrivileges}). + * + * @param categories the emergency service categories which are the bitwise-OR combination of + * the following constants: + *

    + *
  1. {@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED}
  2. + *
  3. {@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_POLICE}
  4. + *
  5. {@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_AMBULANCE}
  6. + *
  7. {@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_FIRE_BRIGADE}
  8. + *
  9. {@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MARINE_GUARD}
  10. + *
  11. {@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MOUNTAIN_RESCUE}
  12. + *
  13. {@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MIEC}
  14. + *
  15. {@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_AIEC}
  16. + *
+ * @return Map including the key as the active subscription ID (Note: if there is no active + * subscription, the key is {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID}) and the value + * as the list of {@link EmergencyNumber}; null if this information is not available. + */ + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) + @Nullable + public Map> getCurrentEmergencyNumberList( + @EmergencyServiceCategories int categories) { + try { + ITelephony telephony = getITelephony(); + if (telephony == null) { + return null; + } + Map> numberMap = telephony + .getCurrentEmergencyNumberList(mContext.getOpPackageName()); + if (numberMap != null) { + for (Integer subscriptionId : numberMap.keySet()) { + List numberList = numberMap.get(subscriptionId); + for (EmergencyNumber number : numberList) { + if (!number.isInEmergencyServiceCategories(categories)) { + numberList.remove(number); + } + } + } + } + return numberMap; + } catch (RemoteException ex) { + Log.e(TAG, "getCurrentEmergencyNumberList with Categories RemoteException", ex); + } + return null; + } + + /** + * Checks if the supplied number is an emergency number based on current locale, sim, default, + * modem and network. + * + *

The subscriptions which the identification would be based on, are all the active + * subscriptions, no matter which subscription could be used to create TelephonyManager. + * + * @param number - the number to look up + * @return {@code true} if the given number is an emergency number based on current locale, + * sim, modem and network; {@code false} otherwise. + */ + public boolean isCurrentEmergencyNumber(@NonNull String number) { + try { + ITelephony telephony = getITelephony(); + if (telephony == null) { + return false; + } + return telephony.isCurrentEmergencyNumber(number); + } catch (RemoteException ex) { + Log.e(TAG, "isCurrentEmergencyNumber RemoteException", ex); + } + return false; + } } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 4b9b0fb84f16a..01c45545dc9de 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -49,6 +49,7 @@ import com.android.internal.telephony.CellNetworkScanResult; import com.android.internal.telephony.OperatorInfo; import java.util.List; +import java.util.Map; import android.telephony.UiccSlotInfo; @@ -1618,6 +1619,16 @@ interface ITelephony { */ boolean isTtyOverVolteEnabled(int subId); + /** + * Return the emergency number list from all the active subscriptions. + */ + Map getCurrentEmergencyNumberList(String callingPackage); + + /** + * Identify if the number is emergency number, based on all the active subscriptions. + */ + boolean isCurrentEmergencyNumber(String number); + /** * Return a list of certs in hex string from loaded carrier privileges access rules. */