diff options
| author | 2016-11-10 22:02:17 +0000 | |
|---|---|---|
| committer | 2016-11-10 22:02:17 +0000 | |
| commit | 969a6eb2b8ae2b6f77c16f7c0a106b8eff260467 (patch) | |
| tree | 91f37080d4ef50d611ee5ba0f2af761b70271358 | |
| parent | 861e99e815000078f5214748b9b5db946d803da7 (diff) | |
| parent | 0a3b6b70dde6925c75552ad404201a9ec384ee0a (diff) | |
Merge "Add createForPhoneAccountHandle() and getServicetate() Respect TelephonyManager's subId when listening to phone state"
am: 0a3b6b70dd
Change-Id: I512e68bccda115ad7c58ec1f1fbfbb2c69c86578
| -rw-r--r-- | api/current.txt | 2 | ||||
| -rw-r--r-- | api/system-current.txt | 2 | ||||
| -rw-r--r-- | api/test-current.txt | 2 | ||||
| -rw-r--r-- | telephony/java/android/telephony/PhoneStateListener.java | 10 | ||||
| -rw-r--r-- | telephony/java/android/telephony/TelephonyManager.java | 45 |
5 files changed, 56 insertions, 5 deletions
diff --git a/api/current.txt b/api/current.txt index 0b5b6414cd87..db1820fb268e 100644 --- a/api/current.txt +++ b/api/current.txt @@ -37369,6 +37369,7 @@ package android.telephony { public class TelephonyManager { method public boolean canChangeDtmfToneLength(); + method public android.telephony.TelephonyManager createForPhoneAccountHandle(android.telecom.PhoneAccountHandle); method public android.telephony.TelephonyManager createForSubscriptionId(int); method public java.util.List<android.telephony.CellInfo> getAllCellInfo(); method public int getCallState(); @@ -37391,6 +37392,7 @@ package android.telephony { method public int getNetworkType(); method public int getPhoneCount(); method public int getPhoneType(); + method public android.telephony.ServiceState getServiceState(); method public java.lang.String getSimCountryIso(); method public java.lang.String getSimOperator(); method public java.lang.String getSimOperatorName(); diff --git a/api/system-current.txt b/api/system-current.txt index 92cac0cfa776..838f395a2f8b 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -40482,6 +40482,7 @@ package android.telephony { method public boolean canChangeDtmfToneLength(); method public int checkCarrierPrivilegesForPackage(java.lang.String); method public int checkCarrierPrivilegesForPackageAnyPhone(java.lang.String); + method public android.telephony.TelephonyManager createForPhoneAccountHandle(android.telecom.PhoneAccountHandle); method public android.telephony.TelephonyManager createForSubscriptionId(int); method public void dial(java.lang.String); method public boolean disableDataConnectivity(); @@ -40519,6 +40520,7 @@ package android.telephony { method public int getNetworkType(); method public int getPhoneCount(); method public int getPhoneType(); + method public android.telephony.ServiceState getServiceState(); method public java.lang.String getSimCountryIso(); method public java.lang.String getSimOperator(); method public java.lang.String getSimOperatorName(); diff --git a/api/test-current.txt b/api/test-current.txt index 81e924067acd..e59e88cdcf76 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -37451,6 +37451,7 @@ package android.telephony { public class TelephonyManager { method public boolean canChangeDtmfToneLength(); + method public android.telephony.TelephonyManager createForPhoneAccountHandle(android.telecom.PhoneAccountHandle); method public android.telephony.TelephonyManager createForSubscriptionId(int); method public java.util.List<android.telephony.CellInfo> getAllCellInfo(); method public int getCallState(); @@ -37473,6 +37474,7 @@ package android.telephony { method public int getNetworkType(); method public int getPhoneCount(); method public int getPhoneType(); + method public android.telephony.ServiceState getServiceState(); method public java.lang.String getSimCountryIso(); method public java.lang.String getSimOperator(); method public java.lang.String getSimOperatorName(); diff --git a/telephony/java/android/telephony/PhoneStateListener.java b/telephony/java/android/telephony/PhoneStateListener.java index bb2b4478433d..32f487bb5dbe 100644 --- a/telephony/java/android/telephony/PhoneStateListener.java +++ b/telephony/java/android/telephony/PhoneStateListener.java @@ -233,7 +233,7 @@ public class PhoneStateListener { * @hide */ /** @hide */ - protected int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; + protected Integer mSubId; private final Handler mHandler; @@ -242,7 +242,7 @@ public class PhoneStateListener { * This class requires Looper.myLooper() not return null. */ public PhoneStateListener() { - this(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, Looper.myLooper()); + this(null, Looper.myLooper()); } /** @@ -251,7 +251,7 @@ public class PhoneStateListener { * @hide */ public PhoneStateListener(Looper looper) { - this(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, looper); + this(null, looper); } /** @@ -260,7 +260,7 @@ public class PhoneStateListener { * own non-null Looper use PhoneStateListener(int subId, Looper looper) below. * @hide */ - public PhoneStateListener(int subId) { + public PhoneStateListener(Integer subId) { this(subId, Looper.myLooper()); } @@ -269,7 +269,7 @@ public class PhoneStateListener { * and non-null Looper. * @hide */ - public PhoneStateListener(int subId, Looper looper) { + public PhoneStateListener(Integer subId, Looper looper) { if (DBG) log("ctor: subId=" + subId + " looper=" + looper); mSubId = subId; mHandler = new Handler(looper) { diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index cb74ad47a350..f4eb7e9f8226 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -258,6 +258,22 @@ public class TelephonyManager { return new TelephonyManager(mContext, subId); } + /** + * Create a new TelephonyManager object pinned to the subscription ID associated with the given + * phone account. + * + * @return a TelephonyManager that uses the given phone account for all calls, or {@code null} + * if the phone account does not correspond to a valid subscription ID. + */ + @Nullable + public TelephonyManager createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { + int subId = getSubIdForPhoneAccountHandle(phoneAccountHandle); + if (!SubscriptionManager.isValidSubscriptionId(subId)) { + return null; + } + return new TelephonyManager(mContext, subId); + } + /** {@hide} */ public boolean isMultiSimEnabled() { return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || @@ -2991,6 +3007,12 @@ public class TelephonyManager { if (mContext == null) return; try { Boolean notifyNow = (getITelephony() != null); + // If the listener has not explicitly set the subId (for example, created with the + // default constructor), replace the subId so it will listen to the account the + // telephony manager is created with. + if (listener.mSubId == null) { + listener.mSubId = mSubId; + } sRegistry.listenForSubscriber(listener.mSubId, getOpPackageName(), listener.callback, events, notifyNow); } catch (RemoteException ex) { @@ -5354,6 +5376,19 @@ public class TelephonyManager { return retval; } + private int getSubIdForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { + int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; + try { + ITelecomService service = getTelecomService(); + if (service != null) { + retval = getSubIdForPhoneAccount(service.getPhoneAccount(phoneAccountHandle)); + } + } catch (RemoteException e) { + } + + return retval; + } + /** * Resets telephony manager settings back to factory defaults. * @@ -5403,6 +5438,16 @@ public class TelephonyManager { } /** + * Returns the current {@link ServiceState} information. + * + * <p>Requires Permission: + * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} + */ + public ServiceState getServiceState() { + return getServiceStateForSubscriber(getSubId()); + } + + /** * Returns the service state information on specified subscription. Callers require * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. * @hide |