WM: Fix input dispatch timeout for instrumented processes
Input dispatch timeout varies based on the process
state. This state was queried when the ActivityRecord
was reparented. But this happens too early and as a
result the ActivityRecord always got a default
timeout.
Fix this by updating the timeout when attaching a
process to ActivityRecord.
Test: atest WmTests:ActivityRecordTests#testKeyDispatchTimeout
Bug: 162542125
Change-Id: I85db6b652790affc85d3464cca98ff8da3bab73b
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index c929cbb..eecc8d4 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -95,6 +95,7 @@
import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET;
import static android.os.Build.VERSION_CODES.HONEYCOMB;
import static android.os.Build.VERSION_CODES.O;
+import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
import static android.os.Process.SYSTEM_UID;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.view.Display.COLOR_MODE_DEFAULT;
@@ -635,7 +636,7 @@
private boolean mOccludesParent;
// The input dispatching timeout for this application token in milliseconds.
- long mInputDispatchingTimeoutMillis;
+ long mInputDispatchingTimeoutMillis = DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
private boolean mShowWhenLocked;
private boolean mInheritShownWhenLocked;
@@ -1443,7 +1444,6 @@
if (oldParent == null && newParent != null) {
// First time we are adding the activity to the system.
mVoiceInteraction = newTask.voiceSession != null;
- mInputDispatchingTimeoutMillis = getInputDispatchingTimeoutMillisLocked(this);
// TODO(b/36505427): Maybe this call should be moved inside
// updateOverrideConfiguration()
@@ -1983,6 +1983,7 @@
task.setRootProcess(proc);
}
proc.addActivityIfNeeded(this);
+ mInputDispatchingTimeoutMillis = getInputDispatchingTimeoutMillisLocked(this);
// Update the associated task fragment after setting the process, since it's required for
// filtering to only report activities that belong to the same process.
@@ -3562,6 +3563,7 @@
app.removeActivity(this, false /* keepAssociation */);
}
app = null;
+ mInputDispatchingTimeoutMillis = DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
}
void makeFinishingLocked() {
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
index 8a057f7..38e10453 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
@@ -41,6 +41,7 @@
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
+import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
import static android.os.Process.NOBODY_UID;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.InsetsState.ITYPE_IME;
@@ -84,6 +85,7 @@
import static com.android.server.wm.ActivityRecord.State.STARTED;
import static com.android.server.wm.ActivityRecord.State.STOPPED;
import static com.android.server.wm.ActivityRecord.State.STOPPING;
+import static com.android.server.wm.ActivityTaskManagerService.INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MILLIS;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION;
import static com.android.server.wm.TaskFragment.TASK_FRAGMENT_VISIBILITY_INVISIBLE;
import static com.android.server.wm.TaskFragment.TASK_FRAGMENT_VISIBILITY_VISIBLE;
@@ -3259,6 +3261,29 @@
CAMERA_COMPAT_CONTROL_TREATMENT_APPLIED);
}
+ @Test // b/162542125
+ public void testInputDispatchTimeout() throws RemoteException {
+ final ActivityRecord activity = createActivityWithTask();
+ final WindowProcessController wpc = activity.app;
+ spyOn(wpc);
+ doReturn(true).when(wpc).isInstrumenting();
+ final ActivityRecord instrumentingActivity = createActivityOnDisplay(
+ true /* defaultDisplay */, wpc);
+ assertEquals(INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MILLIS,
+ instrumentingActivity.mInputDispatchingTimeoutMillis);
+
+ doReturn(false).when(wpc).isInstrumenting();
+ final ActivityRecord nonInstrumentingActivity = createActivityOnDisplay(
+ true /* defaultDisplay */, wpc);
+ assertEquals(DEFAULT_DISPATCHING_TIMEOUT_MILLIS,
+ nonInstrumentingActivity.mInputDispatchingTimeoutMillis);
+
+ final ActivityRecord noProcActivity = createActivityOnDisplay(true /* defaultDisplay */,
+ null);
+ assertEquals(DEFAULT_DISPATCHING_TIMEOUT_MILLIS,
+ noProcActivity.mInputDispatchingTimeoutMillis);
+ }
+
private ICompatCameraControlCallback getCompatCameraControlCallback() {
return new ICompatCameraControlCallback.Stub() {
@Override