From e6a2c0a4d301546ae2bb7a7c0546b52535ef38de Mon Sep 17 00:00:00 2001 From: Sooraj Sasindran Date: Tue, 26 Nov 2019 13:56:49 -0800 Subject: [PATCH] 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,