Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66152339 authored by Antonio Kantek's avatar Antonio Kantek
Browse files

(TouchMode Permission 2.6/n) Revert Instrumentation#setInTouchMode

Allow Instrumentation#setInTouchMode to always switch touch mode when
running in instrumented environment.

Bug: 198487159
Fixes: 218118731
Test: atest FrameworksCoreTests
Test: atest CtsWindowManagerDeviceTestCases
Test: atest android.app.cts.ListActivityTest
Test: atest AlertDialog_BuilderCursorTest
Change-Id: I22e4bf0245dcf75a354f2cdc19d7f6107d0abaee
parent 4353b0b0
Loading
Loading
Loading
Loading
+0 −4
Original line number Original line Diff line number Diff line
@@ -381,10 +381,6 @@ public class Instrumentation {
     * Force the global system in or out of touch mode. This can be used if your
     * Force the global system in or out of touch mode. This can be used if your
     * instrumentation relies on the UI being in one more or the other when it starts.
     * instrumentation relies on the UI being in one more or the other when it starts.
     *
     *
     * <p><b>Note:</b> Starting from Android {@link Build.VERSION_CODES#TIRAMISU}, this method
     * will only have an effect if the calling process is also the focused window owner or has
     * {@link android.permission#MODIFY_TOUCH_MODE_STATE} permission granted.
     *
     * @param inTouch Set to true to be in touch mode, false to be in focus mode.
     * @param inTouch Set to true to be in touch mode, false to be in focus mode.
     */
     */
    public void setInTouchMode(boolean inTouch) {
    public void setInTouchMode(boolean inTouch) {
+12 −0
Original line number Original line Diff line number Diff line
@@ -5267,6 +5267,18 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
        }
    }
    }


    /**
     * Returns {@code true} if the process represented by the pid passed as argument is
     * instrumented.
     */
    boolean isInstrumenting(int pid) {
        final WindowProcessController process;
        synchronized (mGlobalLock) {
            process = mProcessMap.getProcess(pid);
        }
        return process != null ? process.isInstrumenting() : false;
    }

    final class H extends Handler {
    final class H extends Handler {
        static final int REPORT_TIME_TRACKER_MSG = 1;
        static final int REPORT_TIME_TRACKER_MSG = 1;
        static final int UPDATE_PROCESS_ANIMATING_STATE = 2;
        static final int UPDATE_PROCESS_ANIMATING_STATE = 2;
+5 −3
Original line number Original line Diff line number Diff line
@@ -3698,7 +3698,8 @@ public class WindowManagerService extends IWindowManager.Stub
     * Sets the touch mode state.
     * Sets the touch mode state.
     *
     *
     * To be able to change touch mode state, the caller must either own the focused window, or must
     * To be able to change touch mode state, the caller must either own the focused window, or must
     * have the MODIFY_TOUCH_MODE_STATE permission.
     * have the MODIFY_TOUCH_MODE_STATE permission. Instrumented processes are allowed to switch
     * touch mode at any time.
     *
     *
     * @param mode the touch mode to set
     * @param mode the touch mode to set
     */
     */
@@ -3710,8 +3711,9 @@ public class WindowManagerService extends IWindowManager.Stub
            }
            }
            final int pid = Binder.getCallingPid();
            final int pid = Binder.getCallingPid();
            final int uid = Binder.getCallingUid();
            final int uid = Binder.getCallingUid();
            final boolean hasPermission = checkCallingPermission(MODIFY_TOUCH_MODE_STATE,

                    "setInTouchMode()");
            final boolean hasPermission = mAtmService.isInstrumenting(pid)
                    || checkCallingPermission(MODIFY_TOUCH_MODE_STATE, "setInTouchMode()");
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
            try {
            try {
                if (mInputManager.setInTouchMode(mode, pid, uid, hasPermission)) {
                if (mInputManager.setInTouchMode(mode, pid, uid, hasPermission)) {