1
0
mirror of https://github.com/yurisieucuti/treble_evolution.git synced 2024-11-24 12:06:19 +00:00
treble_evolution/patches/trebledroid/platform_frameworks_base/0035-Add-runWithCleanCallingIdentity-variant-with-both-ex.patch
2024-03-10 06:48:11 +00:00

73 lines
2.6 KiB
Diff

From bdfdfb6bc34b555f4f53dd8f9c9b6058767caba9 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 35/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 | 32 ++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
index 9a8c9655375d..454080144d35 100644
--- a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
+++ b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
@@ -42,7 +42,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;
@@ -151,6 +153,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.
*/
@@ -319,4 +349,4 @@ public final class TelephonyUtils {
return false;
}
-}
\ No newline at end of file
+}
--
2.25.1