diff options
author | Sooraj Sasindran <sasindran@google.com> | 2019-11-27 08:02:15 -0800 |
---|---|---|
committer | Sooraj Sasindran <sasindran@google.com> | 2020-01-27 22:03:47 -0800 |
commit | 7998fbc67eae129a469b422a9e2325e3781210ec (patch) | |
tree | 6f1f83e81c6cf379cc742a3e1780f7d402cfbe20 | |
parent | b1c57994da213cefbc101a5a8a030e978b650d4e (diff) |
Do not use hidden withCleanCallingIdentity
Do not use hidden withCleanCallingIdentity
Bug: 140908357
Test: Build
Merged-In: Ic6cbd587c009df973d4602ff21e5b8a9c27293ff
Change-Id: Ic6cbd587c009df973d4602ff21e5b8a9c27293ff
7 files changed, 117 insertions, 37 deletions
diff --git a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java index 0498d7c31406..2abcc76fdccc 100644 --- a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java +++ b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java @@ -28,6 +28,7 @@ import android.os.RemoteException; import android.os.SystemProperties; import java.io.PrintWriter; +import java.util.function.Supplier; /** * This class provides various util functions @@ -75,6 +76,42 @@ public final class TelephonyUtils { } /** + * Convenience method for running the provided action enclosed in + * {@link Binder#clearCallingIdentity}/{@link Binder#restoreCallingIdentity} + * + * Any exception thrown by the given action will need to be handled by caller. + * + */ + public static void runWithCleanCallingIdentity( + @NonNull Runnable action) { + long callingIdentity = Binder.clearCallingIdentity(); + try { + action.run(); + } finally { + Binder.restoreCallingIdentity(callingIdentity); + } + } + + + /** + * Convenience method for running the provided action enclosed in + * {@link Binder#clearCallingIdentity}/{@link Binder#restoreCallingIdentity} and return + * the result. + * + * Any exception thrown by the given action will need to be handled by caller. + * + */ + public static <T> T runWithCleanCallingIdentity( + @NonNull Supplier<T> action) { + long callingIdentity = Binder.clearCallingIdentity(); + try { + return action.get(); + } finally { + Binder.restoreCallingIdentity(callingIdentity); + } + } + + /** * Filter values in bundle to only basic types. */ public static Bundle filterValues(Bundle bundle) { diff --git a/telephony/java/android/telephony/ims/ImsMmTelManager.java b/telephony/java/android/telephony/ims/ImsMmTelManager.java index ba8e90ff539b..494009f35dba 100644 --- a/telephony/java/android/telephony/ims/ImsMmTelManager.java +++ b/telephony/java/android/telephony/ims/ImsMmTelManager.java @@ -163,9 +163,13 @@ public class ImsMmTelManager implements RegistrationManager { public void onCapabilitiesStatusChanged(int config) { if (mLocalCallback == null) return; - Binder.withCleanCallingIdentity(() -> - mExecutor.execute(() -> mLocalCallback.onCapabilitiesStatusChanged( - new MmTelFeature.MmTelCapabilities(config)))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + mExecutor.execute(() -> mLocalCallback.onCapabilitiesStatusChanged( + new MmTelFeature.MmTelCapabilities(config))); + } finally { + restoreCallingIdentity(callingIdentity); + } } @Override diff --git a/telephony/java/android/telephony/ims/ImsRcsManager.java b/telephony/java/android/telephony/ims/ImsRcsManager.java index 5aa37bba7efe..917f91fcf232 100644 --- a/telephony/java/android/telephony/ims/ImsRcsManager.java +++ b/telephony/java/android/telephony/ims/ImsRcsManager.java @@ -75,9 +75,13 @@ public class ImsRcsManager implements RegistrationManager { public void onCapabilitiesStatusChanged(int config) { if (mLocalCallback == null) return; - Binder.withCleanCallingIdentity(() -> - mExecutor.execute(() -> mLocalCallback.onAvailabilityChanged( - new RcsFeature.RcsImsCapabilities(config)))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + mExecutor.execute(() -> mLocalCallback.onAvailabilityChanged( + new RcsFeature.RcsImsCapabilities(config))); + } finally { + restoreCallingIdentity(callingIdentity); + } } @Override diff --git a/telephony/java/android/telephony/ims/ProvisioningManager.java b/telephony/java/android/telephony/ims/ProvisioningManager.java index aa4f77d09212..6125001850db 100644 --- a/telephony/java/android/telephony/ims/ProvisioningManager.java +++ b/telephony/java/android/telephony/ims/ProvisioningManager.java @@ -791,17 +791,24 @@ public class ProvisioningManager { @Override public final void onIntConfigChanged(int item, int value) { - Binder.withCleanCallingIdentity(() -> - mExecutor.execute(() -> - mLocalConfigurationCallback.onProvisioningIntChanged(item, value))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + mExecutor.execute(() -> + mLocalConfigurationCallback.onProvisioningIntChanged(item, value)); + } finally { + restoreCallingIdentity(callingIdentity); + } } @Override public final void onStringConfigChanged(int item, String value) { - Binder.withCleanCallingIdentity(() -> - mExecutor.execute(() -> - mLocalConfigurationCallback.onProvisioningStringChanged(item, - value))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + mExecutor.execute(() -> + mLocalConfigurationCallback.onProvisioningStringChanged(item, value)); + } finally { + restoreCallingIdentity(callingIdentity); + } } private void setExecutor(Executor executor) { diff --git a/telephony/java/android/telephony/ims/RcsUceAdapter.java b/telephony/java/android/telephony/ims/RcsUceAdapter.java index d3f393ae11a2..5e3847f1359a 100644 --- a/telephony/java/android/telephony/ims/RcsUceAdapter.java +++ b/telephony/java/android/telephony/ims/RcsUceAdapter.java @@ -251,15 +251,22 @@ public class RcsUceAdapter { IRcsUceControllerCallback internalCallback = new IRcsUceControllerCallback.Stub() { @Override public void onCapabilitiesReceived(List<RcsContactUceCapability> contactCapabilities) { - Binder.withCleanCallingIdentity(() -> - executor.execute(() -> - c.onCapabilitiesReceived(contactCapabilities))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> + c.onCapabilitiesReceived(contactCapabilities)); + } finally { + restoreCallingIdentity(callingIdentity); + } } @Override public void onError(int errorCode) { - Binder.withCleanCallingIdentity(() -> - executor.execute(() -> - c.onError(errorCode))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + executor.execute(() -> c.onError(errorCode)); + } finally { + restoreCallingIdentity(callingIdentity); + } } }; diff --git a/telephony/java/android/telephony/ims/RegistrationManager.java b/telephony/java/android/telephony/ims/RegistrationManager.java index a1f6b78ba7c5..5c86ba732701 100644 --- a/telephony/java/android/telephony/ims/RegistrationManager.java +++ b/telephony/java/android/telephony/ims/RegistrationManager.java @@ -105,41 +105,62 @@ public interface RegistrationManager { public void onRegistered(int imsRadioTech) { if (mLocalCallback == null) return; - Binder.withCleanCallingIdentity(() -> mExecutor.execute(() -> - mLocalCallback.onRegistered(getAccessType(imsRadioTech)))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + mExecutor.execute(() -> + mLocalCallback.onRegistered(getAccessType(imsRadioTech))); + } finally { + restoreCallingIdentity(callingIdentity); + } } @Override public void onRegistering(int imsRadioTech) { if (mLocalCallback == null) return; - Binder.withCleanCallingIdentity(() -> mExecutor.execute(() -> - mLocalCallback.onRegistering(getAccessType(imsRadioTech)))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + mExecutor.execute(() -> + mLocalCallback.onRegistering(getAccessType(imsRadioTech))); + } finally { + restoreCallingIdentity(callingIdentity); + } } @Override public void onDeregistered(ImsReasonInfo info) { if (mLocalCallback == null) return; - Binder.withCleanCallingIdentity(() -> - mExecutor.execute(() -> mLocalCallback.onUnregistered(info))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + mExecutor.execute(() -> mLocalCallback.onUnregistered(info)); + } finally { + restoreCallingIdentity(callingIdentity); + } } @Override public void onTechnologyChangeFailed(int imsRadioTech, ImsReasonInfo info) { if (mLocalCallback == null) return; - Binder.withCleanCallingIdentity(() -> - mExecutor.execute(() -> mLocalCallback.onTechnologyChangeFailed( - getAccessType(imsRadioTech), info))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + mExecutor.execute(() -> mLocalCallback.onTechnologyChangeFailed( + getAccessType(imsRadioTech), info)); + } finally { + restoreCallingIdentity(callingIdentity); + } } public void onSubscriberAssociatedUriChanged(Uri[] uris) { if (mLocalCallback == null) return; - Binder.withCleanCallingIdentity(() -> - mExecutor.execute(() -> - mLocalCallback.onSubscriberAssociatedUriChanged(uris))); + long callingIdentity = Binder.clearCallingIdentity(); + try { + mExecutor.execute(() -> mLocalCallback.onSubscriberAssociatedUriChanged(uris)); + } finally { + restoreCallingIdentity(callingIdentity); + } } private void setExecutor(Executor executor) { diff --git a/telephony/java/android/telephony/ims/feature/RcsFeature.java b/telephony/java/android/telephony/ims/feature/RcsFeature.java index e4efc20437bb..8e67621b2ea3 100644 --- a/telephony/java/android/telephony/ims/feature/RcsFeature.java +++ b/telephony/java/android/telephony/ims/feature/RcsFeature.java @@ -22,7 +22,6 @@ import android.annotation.NonNull; import android.annotation.SystemApi; import android.annotation.TestApi; import android.net.Uri; -import android.os.Binder; import android.os.RemoteException; import android.telephony.ims.RcsContactUceCapability; import android.telephony.ims.aidl.IImsCapabilityCallback; @@ -33,7 +32,7 @@ import android.telephony.ims.stub.RcsPresenceExchangeImplBase; import android.telephony.ims.stub.RcsSipOptionsImplBase; import android.util.Log; -import com.android.internal.util.FunctionalUtils; +import com.android.internal.telephony.util.TelephonyUtils; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -43,6 +42,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; +import java.util.function.Supplier; /** * Base implementation of the RcsFeature APIs. Any ImsService wishing to support RCS should extend @@ -150,13 +150,13 @@ public class RcsFeature extends ImsFeature { // Call the methods with a clean calling identity on the executor and wait indefinitely for // the future to return. - private void executeMethodAsync(FunctionalUtils.ThrowingRunnable r, String errorLogName) + private void executeMethodAsync(Runnable r, String errorLogName) throws RemoteException { // call with a clean calling identity on the executor and wait indefinitely for the // future to return. try { CompletableFuture.runAsync( - () -> Binder.withCleanCallingIdentity(r), mExecutor).join(); + () -> TelephonyUtils.runWithCleanCallingIdentity(r), mExecutor).join(); } catch (CancellationException | CompletionException e) { Log.w(LOG_TAG, "RcsFeatureBinder - " + errorLogName + " exception: " + e.getMessage()); @@ -164,12 +164,12 @@ public class RcsFeature extends ImsFeature { } } - private <T> T executeMethodAsyncForResult(FunctionalUtils.ThrowingSupplier<T> r, + private <T> T executeMethodAsyncForResult(Supplier<T> r, String errorLogName) throws RemoteException { // call with a clean calling identity on the executor and wait indefinitely for the // future to return. CompletableFuture<T> future = CompletableFuture.supplyAsync( - () -> Binder.withCleanCallingIdentity(r), mExecutor); + () -> TelephonyUtils.runWithCleanCallingIdentity(r), mExecutor); try { return future.get(); } catch (ExecutionException | InterruptedException e) { |