From 010eef52830c82a22c4258c9b253e01944813b96 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 25 Jul 2022 18:38:36 +0900 Subject: [PATCH] Protect IME tracing IPCs with CONTROL_UI_TRACING With this CL, the following IPCs start requiring callers to have CONTROL_UI_TRACING permission [1]. * IInputMethodManager#startImeTrace() * IInputMethodManager#stopImeTrace() Note that the following shell commands adb shell cmd input_method tracing start adb shell cmd input_method tracing stop should not be affected by this CL because those commands are directly handled by * IInputMethodManager#onShellCommand(), which has been guarded with calling UID check [2]. [1]: Ibdeb38dc9a066cb8ed2904adcdac29014b166526 2ad02a383b036b02a836a50a43c679a17c2fde6b [2]: If87189563ccaacd4f9c666bab4f9ad08a9343084 b8d240fa3f96b7b4ea35dd271beda789044d63ab Bug: 34886274 Bug: 172444310 Bug: 237316307 Test: make RunSettingsRoboTests ROBOTEST_FILTER="WinscopeTraceTest" Test: Manually verifies as follows. 1. build aosp_coral-userdebug and flash it. 2. Go to System Settings. 3. Enable Developer Mode. 4. Go to Developer Options. 5. Tap "Quick settings developer tiles" 6. Enable "Winscope Trace" 7. Pull down the quick settings drawer then Tap Winscope Trace. 8. Tap some edit field to show AOSP Keyboard. 9. Pull down the quick settings drawer then Tap Winscope Trace. 10. adb root 11. adb shell ls -al /data/misc/wmtrace/ 12. Make sure that tracing files are saved there. Test: Manually verifies as follows. 1. build aosp_coral-userdebug and flash it. 2. adb shell cmd input_method tracing start 3. Tap some edit field to show AOSP Keyboard. 4. adb shell cmd input_method tracing stop 5. adb root 6. adb shell ls -al /data/misc/wmtrace/ 7. Make sure that tracing files are saved there. Test: Manually verifies as follows. 1. build aosp_coral-userdebug and flash it. 2. adb root 3. adb shell cmd input_method tracing start 4. Tap some edit field to show AOSP Keyboard. 5. adb shell cmd input_method tracing stop 6. adb shell ls -al /data/misc/wmtrace/ 7. Make sure that tracing files are saved there. Change-Id: Iaee7be9fb5066664b283a64273bf8685ba966046 --- core/java/com/android/internal/inputmethod/ImeTracing.java | 3 +++ .../com/android/internal/view/IInputMethodManager.aidl | 7 +++++++ .../server/inputmethod/InputMethodManagerService.java | 2 ++ 3 files changed, 12 insertions(+) diff --git a/core/java/com/android/internal/inputmethod/ImeTracing.java b/core/java/com/android/internal/inputmethod/ImeTracing.java index 8b21b7ef10ea4..ee6713118f754 100644 --- a/core/java/com/android/internal/inputmethod/ImeTracing.java +++ b/core/java/com/android/internal/inputmethod/ImeTracing.java @@ -17,6 +17,7 @@ package com.android.internal.inputmethod; import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.app.ActivityThread; import android.content.Context; import android.os.RemoteException; @@ -93,6 +94,7 @@ public abstract class ImeTracing { /** * Calling {@link IInputMethodManager#startImeTrace()}} to capture IME trace. */ + @RequiresPermission(android.Manifest.permission.CONTROL_UI_TRACING) public final void startImeTrace() { try { mService.startImeTrace(); @@ -104,6 +106,7 @@ public abstract class ImeTracing { /** * Calling {@link IInputMethodManager#stopImeTrace()} to stop IME trace. */ + @RequiresPermission(android.Manifest.permission.CONTROL_UI_TRACING) public final void stopImeTrace() { try { mService.stopImeTrace(); diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl index 9e0b2495969e0..278279a893bcb 100644 --- a/core/java/com/android/internal/view/IInputMethodManager.aidl +++ b/core/java/com/android/internal/view/IInputMethodManager.aidl @@ -104,8 +104,15 @@ interface IInputMethodManager { boolean isImeTraceEnabled(); // Starts an ime trace. + @EnforcePermission("CONTROL_UI_TRACING") + @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = " + + "android.Manifest.permission.CONTROL_UI_TRACING)") void startImeTrace(); + // Stops an ime trace. + @EnforcePermission("CONTROL_UI_TRACING") + @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = " + + "android.Manifest.permission.CONTROL_UI_TRACING)") void stopImeTrace(); /** Start Stylus handwriting session **/ diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index cddbad64f2fdd..0c6cc89e20d25 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -4549,6 +4549,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } @BinderThread + @EnforcePermission(Manifest.permission.CONTROL_UI_TRACING) @Override public void startImeTrace() { ImeTracing.getInstance().startTrace(null /* printwriter */); @@ -4564,6 +4565,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } @BinderThread + @EnforcePermission(Manifest.permission.CONTROL_UI_TRACING) @Override public void stopImeTrace() { ImeTracing.getInstance().stopTrace(null /* printwriter */);