1
0
mirror of https://github.com/ponces/treble_aosp.git synced 2024-11-24 21:26:23 +00:00
treble_aosp/patches/trebledroid/platform_frameworks_base/0035-Add-runWithCleanCallingIdentity-variant-with-both-ex.patch
2024-07-21 01:50:08 +01:00

66 lines
2.5 KiB
Diff

From 4f23f2917496b0683fac7275c9a5498b33589259 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/54] 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 a63db88cb614..1d5a36885307 100644
--- a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
+++ b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java
@@ -44,7 +44,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;
@@ -153,6 +155,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.34.1