summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorOlivier Gaillard <gaillard@google.com>2018-08-16 14:01:58 +0100
committerOlivier Gaillard <gaillard@google.com>2018-10-23 14:27:34 +0100
commite4ff397f0859dd707b7e1ad40176d84f05f689a5 (patch)
tree9c021a222604eff55831cd3d9692914e27a6df45 /core/java/android
parentef5741f9767d243b3f4496d7975548b0ae4a1c98 (diff)
Add WorkSource support to Binder.java.
Test: unit test Change-Id: I6f3507b51a89c35943cc34299d7e364aab337e98
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/os/Binder.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java
index f947b5ef9f5b..8b6194c29707 100644
--- a/core/java/android/os/Binder.java
+++ b/core/java/android/os/Binder.java
@@ -28,6 +28,8 @@ import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FunctionalUtils.ThrowingRunnable;
import com.android.internal.util.FunctionalUtils.ThrowingSupplier;
+import dalvik.annotation.optimization.CriticalNative;
+
import libcore.io.IoUtils;
import libcore.util.NativeAllocationRegistry;
@@ -373,6 +375,54 @@ public class Binder implements IBinder {
public static final native int getThreadStrictModePolicy();
/**
+ * Sets the work source for this thread.
+ *
+ * <p>All the following binder calls on this thread will use the provided work source.
+ *
+ * <p>The concept of worksource is similar to {@link WorkSource}. However, for performance
+ * reasons, we only support one UID. This UID represents the original user responsible for the
+ * binder calls.
+ *
+ * <p>A typical use case would be
+ * <pre>
+ * Binder.setThreadWorkSource(uid);
+ * try {
+ * // Call an API.
+ * } finally {
+ * Binder.clearThreadWorkSource();
+ * }
+ * </pre>
+ *
+ * @param workSource The original UID responsible for the binder call.
+ * @return The previously set work source.
+ * @hide
+ **/
+ @CriticalNative
+ public static final native int setThreadWorkSource(int workSource);
+
+ /**
+ * Returns the work source set by the caller.
+ *
+ * Unlike {@link Binder#getCallingUid()}, this result of this method cannot be trusted. The
+ * caller can set the value to whatever he wants. Only use this value if you trust the calling
+ * uid.
+ *
+ * @return The original UID responsible for the binder transaction.
+ * @hide
+ */
+ @CriticalNative
+ public static final native int getThreadWorkSource();
+
+ /**
+ * Clears the work source on this thread.
+ *
+ * @return The previously set work source.
+ * @hide
+ **/
+ @CriticalNative
+ public static final native int clearThreadWorkSource();
+
+ /**
* Flush any Binder commands pending in the current thread to the kernel
* driver. This can be
* useful to call before performing an operation that may block for a long