From e6a2c0a4d301546ae2bb7a7c0546b52535ef38de Mon Sep 17 00:00:00 2001 From: Sooraj Sasindran Date: Tue, 26 Nov 2019 13:56:49 -0800 Subject: [PATCH 1/2] Do not use hidden withCleanCallingIdentity Do not use hidden withCleanCallingIdentity API Bug: 140908357 Test: make Merged-In: I131f7affd811eb7a848ea230b332b53654e6fd43 Change-Id: I131f7affd811eb7a848ea230b332b53654e6fd43 --- .../telephony/SubscriptionManager.java | 13 +- .../android/telephony/TelephonyManager.java | 118 +++++++++++++----- 2 files changed, 92 insertions(+), 39 deletions(-) diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 3e51ff6e75d2b..366ad100a6e30 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -51,12 +51,10 @@ import android.os.Build; import android.os.Handler; import android.os.HandlerExecutor; import android.os.Looper; -import android.os.Message; import android.os.ParcelUuid; import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; -import android.telephony.Annotation.NetworkType; import android.telephony.euicc.EuiccManager; import android.telephony.ims.ImsMmTelManager; import android.util.DisplayMetrics; @@ -2684,9 +2682,14 @@ public class SubscriptionManager { if (executor == null || callback == null) { return; } - Binder.withCleanCallingIdentity(() -> executor.execute(() -> { - callback.accept(result); - })); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> { + callback.accept(result); + }); + } finally { + Binder.restoreCallingIdentity(identity); + } } }; iSub.setPreferredDataSubscriptionId(subId, needValidation, callbackStub); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 1a5796bb810db..d7da5287b7628 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -5549,16 +5549,24 @@ public class TelephonyManager { new ICellInfoCallback.Stub() { @Override public void onCellInfo(List cellInfo) { - Binder.withCleanCallingIdentity(() -> - executor.execute(() -> callback.onCellInfo(cellInfo))); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> callback.onCellInfo(cellInfo)); + } finally { + Binder.restoreCallingIdentity(identity); + } } @Override public void onError(int errorCode, String exceptionName, String message) { - Binder.withCleanCallingIdentity(() -> - executor.execute(() -> callback.onError( - errorCode, - createThrowableByClassName(exceptionName, message)))); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> callback.onError( + errorCode, + createThrowableByClassName(exceptionName, message))); + } finally { + Binder.restoreCallingIdentity(identity); + } } }, getOpPackageName()); } catch (RemoteException ex) { @@ -5591,16 +5599,25 @@ public class TelephonyManager { new ICellInfoCallback.Stub() { @Override public void onCellInfo(List cellInfo) { - Binder.withCleanCallingIdentity(() -> - executor.execute(() -> callback.onCellInfo(cellInfo))); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> callback.onCellInfo(cellInfo)); + } finally { + Binder.restoreCallingIdentity(identity); + } + } @Override public void onError(int errorCode, String exceptionName, String message) { - Binder.withCleanCallingIdentity(() -> - executor.execute(() -> callback.onError( - errorCode, - createThrowableByClassName(exceptionName, message)))); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> callback.onError( + errorCode, + createThrowableByClassName(exceptionName, message))); + } finally { + Binder.restoreCallingIdentity(identity); + } } }, getOpPackageName(), workSource); } catch (RemoteException ex) { @@ -6465,16 +6482,24 @@ public class TelephonyManager { INumberVerificationCallback internalCallback = new INumberVerificationCallback.Stub() { @Override public void onCallReceived(String phoneNumber) { - Binder.withCleanCallingIdentity(() -> - executor.execute(() -> - callback.onCallReceived(phoneNumber))); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> + callback.onCallReceived(phoneNumber)); + } finally { + Binder.restoreCallingIdentity(identity); + } } @Override public void onVerificationFailed(int reason) { - Binder.withCleanCallingIdentity(() -> - executor.execute(() -> - callback.onVerificationFailed(reason))); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> + callback.onVerificationFailed(reason)); + } finally { + Binder.restoreCallingIdentity(identity); + } } }; @@ -11276,9 +11301,14 @@ public class TelephonyManager { if (executor == null || callback == null) { return; } - Binder.withCleanCallingIdentity(() -> executor.execute(() -> { - callback.accept(SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION); - })); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> { + callback.accept(SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION); + }); + } finally { + Binder.restoreCallingIdentity(identity); + } return; } ISetOpportunisticDataCallback callbackStub = new ISetOpportunisticDataCallback.Stub() { @@ -11287,9 +11317,14 @@ public class TelephonyManager { if (executor == null || callback == null) { return; } - Binder.withCleanCallingIdentity(() -> executor.execute(() -> { - callback.accept(result); - })); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> { + callback.accept(result); + }); + } finally { + Binder.restoreCallingIdentity(identity); + } } }; @@ -11361,14 +11396,24 @@ public class TelephonyManager { return; } if (iOpportunisticNetworkService == null) { - /* Todo passing unknown due to lack of good error codes */ - Binder.withCleanCallingIdentity(() -> executor.execute(() -> { - callback.accept(UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE); - })); + final long identity = Binder.clearCallingIdentity(); + try { + /* Todo passing unknown due to lack of good error codes */ + executor.execute(() -> { + callback.accept(UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE); + }); + } finally { + Binder.restoreCallingIdentity(identity); + } } else { - Binder.withCleanCallingIdentity(() -> executor.execute(() -> { - callback.accept(UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS); - })); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> { + callback.accept(UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS); + }); + } finally { + Binder.restoreCallingIdentity(identity); + } } return; } @@ -11379,9 +11424,14 @@ public class TelephonyManager { if (executor == null || callback == null) { return; } - Binder.withCleanCallingIdentity(() -> executor.execute(() -> { - callback.accept(result); - })); + final long identity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> { + callback.accept(result); + }); + } finally { + Binder.restoreCallingIdentity(identity); + } } }; iOpportunisticNetworkService.updateAvailableNetworks(availableNetworks, callbackStub, From e5ac4da10cb95c210b8d302a709b9a0a9a8a38ac Mon Sep 17 00:00:00 2001 From: Sooraj Sasindran Date: Thu, 7 Nov 2019 18:32:37 -0800 Subject: [PATCH 2/2] Make hidden subscription apis as system Make following APIs as system SubscriptionInfo;->isGroupDisabled TelephonyManager;->isModemEnabledForSlot TelephonyManager;->setOpportunisticNetworkState Add a new public API SubscriptionManager;->getActiveAndHiddenSubscriptionInfoList As they need to be accessed by system application to configure the opportunistic subscripion info Bug: 141122805 Test: verified that CBRS app is still working fine Merged-In: Idf1520911272ba4b7c1f15671d6221d99ba0ab37 Change-Id: Idf1520911272ba4b7c1f15671d6221d99ba0ab37 --- api/current.txt | 1 + api/system-current.txt | 4 +++ .../android/telephony/SubscriptionInfo.java | 1 + .../telephony/SubscriptionManager.java | 28 ++++++++++++++++--- .../android/telephony/TelephonyManager.java | 3 ++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/api/current.txt b/api/current.txt index ab0c57dfaaf26..cb85a93171f09 100644 --- a/api/current.txt +++ b/api/current.txt @@ -44964,6 +44964,7 @@ package android.telephony { method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.os.ParcelUuid createSubscriptionGroup(@NonNull java.util.List); method @Deprecated public static android.telephony.SubscriptionManager from(android.content.Context); method public java.util.List getAccessibleSubscriptionInfoList(); + method @Nullable public java.util.List getActiveAndHiddenSubscriptionInfoList(); method public static int getActiveDataSubscriptionId(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public android.telephony.SubscriptionInfo getActiveSubscriptionInfo(int); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public int getActiveSubscriptionInfoCount(); diff --git a/api/system-current.txt b/api/system-current.txt index 756b4f1d0351c..b1a31cd6fcf4e 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -8550,6 +8550,7 @@ package android.telephony { public class SubscriptionInfo implements android.os.Parcelable { method @Nullable public java.util.List getAccessRules(); method public int getProfileClass(); + method public boolean isGroupDisabled(); } public class SubscriptionManager { @@ -8665,7 +8666,9 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isEmergencyAssistanceEnabled(); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isIdle(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isInEmergencySmsMode(); + method public boolean isModemEnabledForSlot(int); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isOffhook(); + method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isOpportunisticNetworkEnabled(); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isPotentialEmergencyNumber(@NonNull String); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isRadioOn(); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isRinging(); @@ -8687,6 +8690,7 @@ package android.telephony { method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(int, boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataRoamingEnabled(boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMultiSimCarrierRestriction(boolean); + method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setOpportunisticNetworkState(boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setPreferredNetworkTypeBitmask(long); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setRadio(boolean); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setRadioPower(boolean); diff --git a/telephony/java/android/telephony/SubscriptionInfo.java b/telephony/java/android/telephony/SubscriptionInfo.java index 58f2858513758..ad840dec64647 100644 --- a/telephony/java/android/telephony/SubscriptionInfo.java +++ b/telephony/java/android/telephony/SubscriptionInfo.java @@ -653,6 +653,7 @@ public class SubscriptionInfo implements Parcelable { * Return whether the subscription's group is disabled. * @hide */ + @SystemApi public boolean isGroupDisabled() { return mIsGroupDisabled; } diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 366ad100a6e30..2c37ec33acb3a 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -1290,12 +1290,32 @@ public class SubscriptionManager { } /** - * This is similar to {@link #getActiveSubscriptionInfoList()}, but if userVisibleOnly - * is true, it will filter out the hidden subscriptions. + * Get both hidden and visible SubscriptionInfo(s) of the currently active SIM(s). + * The records will be sorted by {@link SubscriptionInfo#getSimSlotIndex} + * then by {@link SubscriptionInfo#getSubscriptionId}. + * + *

Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} + * or that the calling app has carrier privileges (see + * {@link TelephonyManager#hasCarrierPrivileges}). In the latter case, only records accessible + * to the calling app are returned. + * + * @return Sorted list of the currently available {@link SubscriptionInfo} + * records on the device. + * This is similar to {@link #getActiveSubscriptionInfoList} except that it will return + * both active and hidden SubscriptionInfos. * - * @hide */ - public List getActiveSubscriptionInfoList(boolean userVisibleOnly) { + public @Nullable List getActiveAndHiddenSubscriptionInfoList() { + return getActiveSubscriptionInfoList(/* userVisibleonly */false); + } + + /** + * This is similar to {@link #getActiveSubscriptionInfoList()}, but if userVisibleOnly + * is true, it will filter out the hidden subscriptions. + * + * @hide + */ + public @Nullable List getActiveSubscriptionInfoList(boolean userVisibleOnly) { List activeList = null; try { diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index d7da5287b7628..621cd848f9ed3 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -10713,6 +10713,7 @@ public class TelephonyManager { * @hide */ @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + @SystemApi public boolean setOpportunisticNetworkState(boolean enable) { String pkgForDebug = mContext != null ? mContext.getOpPackageName() : ""; boolean ret = false; @@ -10740,6 +10741,7 @@ public class TelephonyManager { * @hide */ @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + @SystemApi public boolean isOpportunisticNetworkEnabled() { String pkgForDebug = mContext != null ? mContext.getOpPackageName() : ""; boolean isEnabled = false; @@ -11477,6 +11479,7 @@ public class TelephonyManager { * @param slotIndex which slot it's checking. * @hide */ + @SystemApi public boolean isModemEnabledForSlot(int slotIndex) { try { ITelephony telephony = getITelephony();