summaryrefslogtreecommitdiff
path: root/telephony/common
diff options
context:
space:
mode:
authorSooraj Sasindran <sasindran@google.com>2019-11-27 08:02:15 -0800
committerSooraj Sasindran <sasindran@google.com>2020-01-27 22:03:47 -0800
commit7998fbc67eae129a469b422a9e2325e3781210ec (patch)
tree6f1f83e81c6cf379cc742a3e1780f7d402cfbe20 /telephony/common
parentb1c57994da213cefbc101a5a8a030e978b650d4e (diff)
Do not use hidden withCleanCallingIdentity
Do not use hidden withCleanCallingIdentity Bug: 140908357 Test: Build Merged-In: Ic6cbd587c009df973d4602ff21e5b8a9c27293ff Change-Id: Ic6cbd587c009df973d4602ff21e5b8a9c27293ff
Diffstat (limited to 'telephony/common')
-rw-r--r--telephony/common/com/android/internal/telephony/util/TelephonyUtils.java37
1 files changed, 37 insertions, 0 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) {