From 32a96b8ad4829ff6149a7e23f871bddd9ebddd5c Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Thu, 3 Mar 2022 21:56:58 +0800 Subject: [PATCH] Add Intrsumentation#resetInTouchMode for instrumenting As IWindowManager#setInTouchMode(boolean) will override the global touch mode state for testing usage, it would be nice to add an API for restoring the original default touch mode state after the test. Bug: 220180252 Bug: 220907843 Test: m checkapi Change-Id: I60909e7da5be3158e2630848f2b6b4b213fc3a01 --- core/api/current.txt | 1 + core/java/android/app/Instrumentation.java | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index d8ea767a64005..101a824659c4b 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -5623,6 +5623,7 @@ package android.app { method public boolean onException(Object, Throwable); method public void onStart(); method public void removeMonitor(android.app.Instrumentation.ActivityMonitor); + method public void resetInTouchMode(); method public void runOnMainSync(Runnable); method public void sendCharacterSync(int); method public void sendKeyDownUpSync(int); diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java index e0c69df0aa18c..ac979c495cf34 100644 --- a/core/java/android/app/Instrumentation.java +++ b/core/java/android/app/Instrumentation.java @@ -392,6 +392,15 @@ public class Instrumentation { } } + /** + * Resets the {@link #setInTouchMode touch mode} to the device default. + */ + public void resetInTouchMode() { + final boolean defaultInTouchMode = getContext().getResources().getBoolean( + com.android.internal.R.bool.config_defaultInTouchMode); + setInTouchMode(defaultInTouchMode); + } + /** * Schedule a callback for when the application's main thread goes idle * (has no more events to process).