From 65ac7619f9f6dceb83c26ce1a1bf7bfbaf2f57da Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 7 Jun 2017 14:34:38 -0600 Subject: [PATCH] Add timeout to StrictMode flash. Consider an app that requests that a StrictMode border be shown, and then immediately crashes. We'd end up showing the bars indefinitely, which is a terrible UX. This CL enqueues a second message to tear down the bars if nobody asks for them to be taken down within 1 second. Test: manual app that crashed after showing violation bars Bug: 37787765 Change-Id: I45d2078d0dcaa94e8f24087d028f5f06d12c4349 --- .../com/android/server/wm/WindowManagerService.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 9d1b3d9ed81aa..8c42d58fa2c75 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -158,6 +158,7 @@ import android.os.Trace; import android.os.UserHandle; import android.os.WorkSource; import android.provider.Settings; +import android.text.format.DateUtils; import android.util.ArraySet; import android.util.DisplayMetrics; import android.util.EventLog; @@ -3596,8 +3597,16 @@ public class WindowManagerService extends IWindowManager.Stub // only allow disables from pids which have count on, etc. @Override public void showStrictModeViolation(boolean on) { - int pid = Binder.getCallingPid(); - mH.sendMessage(mH.obtainMessage(H.SHOW_STRICT_MODE_VIOLATION, on ? 1 : 0, pid)); + final int pid = Binder.getCallingPid(); + if (on) { + // Show the visualization, and enqueue a second message to tear it + // down if we don't hear back from the app. + mH.sendMessage(mH.obtainMessage(H.SHOW_STRICT_MODE_VIOLATION, 1, pid)); + mH.sendMessageDelayed(mH.obtainMessage(H.SHOW_STRICT_MODE_VIOLATION, 0, pid), + DateUtils.SECOND_IN_MILLIS); + } else { + mH.sendMessage(mH.obtainMessage(H.SHOW_STRICT_MODE_VIOLATION, 0, pid)); + } } private void showStrictModeViolation(int arg, int pid) {