mirror of
https://github.com/ponces/treble_aosp.git
synced 2025-04-20 02:20:21 +00:00
66 lines
2.5 KiB
Diff
66 lines
2.5 KiB
Diff
From 978f8b79130512d7f4c3b29e50f7cd3cbbaf0dcc Mon Sep 17 00:00:00 2001
|
|
From: Andy CrossGate Yan <GeForce8800Ultra@gmail.com>
|
|
Date: Sat, 12 Aug 2023 20:11:17 +0800
|
|
Subject: [PATCH 34/56] Add runWithCleanCallingIdentity variant with both
|
|
executor and return value
|
|
|
|
This complements the fixup to ImsPhoneCallTracker (in fw/o/t) for U
|
|
|
|
Change-Id: If444290787025e130dce4bdeaf92372ae32793fe
|
|
---
|
|
.../telephony/util/TelephonyUtils.java | 30 +++++++++++++++++++
|
|
1 file changed, 30 insertions(+)
|
|
|
|
diff --git a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
|
|
index 4224338918f4..3bbecf0f2065 100644
|
|
--- a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
|
|
+++ b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
|
|
@@ -47,7 +47,9 @@ import com.android.internal.telephony.ITelephony;
|
|
import java.io.PrintWriter;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
+import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.CountDownLatch;
|
|
+import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.function.Supplier;
|
|
@@ -159,6 +161,34 @@ public final class TelephonyUtils {
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
+ * Convenience method for running the provided action in the provided
|
|
+ * executor 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, @NonNull Executor executor) {
|
|
+ if (action != null) {
|
|
+ if (executor != null) {
|
|
+ try {
|
|
+ return CompletableFuture.supplyAsync(
|
|
+ () -> runWithCleanCallingIdentity(action), executor).get();
|
|
+ } catch (ExecutionException | InterruptedException e) {
|
|
+ Log.w(LOG_TAG, "TelephonyUtils : runWithCleanCallingIdentity exception: "
|
|
+ + e.getMessage());
|
|
+ return null;
|
|
+ }
|
|
+ } else {
|
|
+ return runWithCleanCallingIdentity(action);
|
|
+ }
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+
|
|
/**
|
|
* Filter values in bundle to only basic types.
|
|
*/
|
|
--
|
|
2.43.0
|
|
|