summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/os/Binder.java50
-rw-r--r--core/java/android/view/TouchDelegate.java6
-rw-r--r--core/jni/android_util_Binder.cpp21
-rw-r--r--core/res/AndroidManifest.xml12
-rw-r--r--core/res/res/layout/harmful_app_warning_dialog.xml4
-rw-r--r--core/res/res/values-television/themes.xml1
-rw-r--r--core/res/res/values/themes.xml3
-rw-r--r--core/res/res/values/themes_leanback.xml3
-rw-r--r--core/tests/coretests/src/android/os/BinderTest.java37
9 files changed, 128 insertions, 9 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
diff --git a/core/java/android/view/TouchDelegate.java b/core/java/android/view/TouchDelegate.java
index 06b73dd29b3d..6fb32e36fb3f 100644
--- a/core/java/android/view/TouchDelegate.java
+++ b/core/java/android/view/TouchDelegate.java
@@ -165,7 +165,11 @@ public class TouchDelegate {
public TouchDelegateInfo getTouchDelegateInfo() {
if (mTouchDelegateInfo == null) {
final ArrayMap<Region, View> targetMap = new ArrayMap<>(1);
- targetMap.put(new Region(mBounds), mDelegateView);
+ Rect bounds = mBounds;
+ if (bounds == null) {
+ bounds = new Rect();
+ }
+ targetMap.put(new Region(bounds), mDelegateView);
mTouchDelegateInfo = new TouchDelegateInfo(targetMap);
}
return mTouchDelegateInfo;
diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp
index d023d22473c8..ec980800c410 100644
--- a/core/jni/android_util_Binder.cpp
+++ b/core/jni/android_util_Binder.cpp
@@ -904,6 +904,21 @@ static jint android_os_Binder_getThreadStrictModePolicy(JNIEnv* env, jobject cla
return IPCThreadState::self()->getStrictModePolicy();
}
+static jint android_os_Binder_setThreadWorkSource(jint workSource)
+{
+ return IPCThreadState::self()->setWorkSource(workSource);
+}
+
+static jint android_os_Binder_getThreadWorkSource()
+{
+ return IPCThreadState::self()->getWorkSource();
+}
+
+static jint android_os_Binder_clearThreadWorkSource()
+{
+ return IPCThreadState::self()->clearWorkSource();
+}
+
static void android_os_Binder_flushPendingCommands(JNIEnv* env, jobject clazz)
{
IPCThreadState::self()->flushCommands();
@@ -941,6 +956,12 @@ static const JNINativeMethod gBinderMethods[] = {
{ "restoreCallingIdentity", "(J)V", (void*)android_os_Binder_restoreCallingIdentity },
{ "setThreadStrictModePolicy", "(I)V", (void*)android_os_Binder_setThreadStrictModePolicy },
{ "getThreadStrictModePolicy", "()I", (void*)android_os_Binder_getThreadStrictModePolicy },
+ // @CriticalNative
+ { "setThreadWorkSource", "(I)I", (void*)android_os_Binder_setThreadWorkSource },
+ // @CriticalNative
+ { "getThreadWorkSource", "()I", (void*)android_os_Binder_getThreadWorkSource },
+ // @CriticalNative
+ { "clearThreadWorkSource", "()I", (void*)android_os_Binder_clearThreadWorkSource },
{ "flushPendingCommands", "()V", (void*)android_os_Binder_flushPendingCommands },
{ "getNativeBBinderHolder", "()J", (void*)android_os_Binder_getNativeBBinderHolder },
{ "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 1ae5f03a2f04..374c7eab1a2a 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -4342,7 +4342,7 @@
</activity>
<activity android:name="com.android.internal.app.NetInitiatedActivity"
- android:theme="@style/Theme.DeviceDefault.Light.Dialog.Alert"
+ android:theme="@style/Theme.Dialog.Confirmation"
android:excludeFromRecents="true"
android:process=":ui">
</activity>
@@ -4363,7 +4363,7 @@
<activity android:name="com.android.internal.app.ConfirmUserCreationActivity"
android:excludeFromRecents="true"
android:process=":ui"
- android:theme="@style/Theme.DeviceDefault.Light.Dialog.Alert">
+ android:theme="@style/Theme.Dialog.Confirmation">
<intent-filter android:priority="1000">
<action android:name="android.os.action.CREATE_USER" />
<category android:name="android.intent.category.DEFAULT" />
@@ -4371,24 +4371,24 @@
</activity>
<activity android:name="com.android.internal.app.SuspendedAppActivity"
- android:theme="@style/Theme.DeviceDefault.Light.Dialog.Alert"
+ android:theme="@style/Theme.Dialog.Confirmation"
android:excludeFromRecents="true"
android:process=":ui">
</activity>
<activity android:name="com.android.internal.app.UnlaunchableAppActivity"
- android:theme="@style/Theme.DeviceDefault.Light.Dialog.Alert"
+ android:theme="@style/Theme.Dialog.Confirmation"
android:excludeFromRecents="true"
android:process=":ui">
</activity>
<activity android:name="com.android.settings.notification.NotificationAccessConfirmationActivity"
- android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert"
+ android:theme="@style/Theme.Dialog.Confirmation"
android:excludeFromRecents="true">
</activity>
<activity android:name="com.android.internal.app.HarmfulAppWarningActivity"
- android:theme="@style/Theme.DeviceDefault.Light.Dialog.Alert"
+ android:theme="@style/Theme.Dialog.Confirmation"
android:excludeFromRecents="true"
android:process=":ui"
android:label="@string/harmful_app_warning_title"
diff --git a/core/res/res/layout/harmful_app_warning_dialog.xml b/core/res/res/layout/harmful_app_warning_dialog.xml
index d41691f4bb1b..62ca7a6fde5b 100644
--- a/core/res/res/layout/harmful_app_warning_dialog.xml
+++ b/core/res/res/layout/harmful_app_warning_dialog.xml
@@ -49,7 +49,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
- android:textColor="@color/primary_text_material_light"
+ android:textColor="?attr/textColorPrimary"
android:textSize="@dimen/text_size_subhead_material"
android:paddingLeft="@dimen/harmful_app_icon_name_padding">
</TextView>
@@ -65,4 +65,4 @@
android:lineSpacingMultiplier="@dimen/harmful_app_message_line_spacing_modifier"
android:textSize="@dimen/text_size_body_1_material"/>
</LinearLayout>
-</ScrollView> \ No newline at end of file
+</ScrollView>
diff --git a/core/res/res/values-television/themes.xml b/core/res/res/values-television/themes.xml
index 48b59c70a61e..176e89ebc691 100644
--- a/core/res/res/values-television/themes.xml
+++ b/core/res/res/values-television/themes.xml
@@ -15,6 +15,7 @@
-->
<resources>
<style name="Theme.Dialog.Alert" parent="Theme.Leanback.Light.Dialog.Alert" />
+ <style name="Theme.Dialog.Confirmation" parent="Theme.Leanback.Dialog.Confirmation" />
<style name="Theme.Holo.Dialog.Alert" parent="Theme.Leanback.Dialog.Alert" />
<style name="Theme.Holo.Light.Dialog.Alert" parent="Theme.Leanback.Light.Dialog.Alert" />
<style name="Theme.Material.Dialog.Alert" parent="Theme.Leanback.Dialog.Alert" />
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index a7530cea5d73..ad38f3d57c23 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -880,6 +880,9 @@ please see themes_device_defaults.xml.
<item name="windowActivityTransitions">false</item>
</style>
+ <!-- @hide Special theme for the default system Activity-based Alert dialogs. -->
+ <style name="Theme.Dialog.Confirmation" parent="Theme.DeviceDefault.Light.Dialog.Alert" />
+
<!-- Theme for a window that looks like a toast. -->
<style name="Theme.Toast" parent="Theme.DeviceDefault.Dialog">
<item name="windowBackground">?attr/toastFrameBackground</item>
diff --git a/core/res/res/values/themes_leanback.xml b/core/res/res/values/themes_leanback.xml
index f71df9fb4807..a80725c2758b 100644
--- a/core/res/res/values/themes_leanback.xml
+++ b/core/res/res/values/themes_leanback.xml
@@ -130,4 +130,7 @@
<item name="toolbarStyle">@style/Widget.DeviceDefault.Toolbar</item>
</style>
+ <!-- @hide Special theme for the default system Activity-based Alert dialogs. -->
+ <style name="Theme.Leanback.Dialog.Confirmation" parent="Theme.DeviceDefault.Dialog.Alert" />
+
</resources>
diff --git a/core/tests/coretests/src/android/os/BinderTest.java b/core/tests/coretests/src/android/os/BinderTest.java
new file mode 100644
index 000000000000..1beb598663d1
--- /dev/null
+++ b/core/tests/coretests/src/android/os/BinderTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import junit.framework.TestCase;
+
+public class BinderTest extends TestCase {
+
+ @SmallTest
+ public void testSetWorkSource() throws Exception {
+ Binder.setThreadWorkSource(100);
+ assertEquals(100, Binder.getThreadWorkSource());
+ }
+
+ @SmallTest
+ public void testClearWorkSource() throws Exception {
+ Binder.setThreadWorkSource(100);
+ Binder.clearThreadWorkSource();
+ assertEquals(-1, Binder.getThreadWorkSource());
+ }
+}