From 700a093b0ccabeb5c420ecdf77e1cd907bab1353 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Thu, 4 Jun 2020 15:59:35 -0400 Subject: [PATCH] Only show error if screenshot process dies within timeout period Currently, we show a "Couldn't take screenshot" error any time the screenshot process disconnects. However, if the screenshot process remains up, this can result in strange superfluous notifications, where hours later the screenshot process gets frozen/killed due to memory pressure, and we show the notification despite the user not trying to take a screenshot at that point. This change adds a check so that we only show the error notification if the screenshot process is disconnected within the timeout period (10 seconds). Bug: 156064134 Fix: 156064134 Test: manual -- killed the process with 'adb shell ps | grep screenshot' and then 'adb shell kill ' to verify that the error notification appeared, then made sure it did not appear post-change. Change-Id: I2419634ad888300abc8b50aadab5888ce653e363 --- core/java/com/android/internal/util/ScreenshotHelper.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/java/com/android/internal/util/ScreenshotHelper.java b/core/java/com/android/internal/util/ScreenshotHelper.java index adc7ba30c1572..d0052ab013316 100644 --- a/core/java/com/android/internal/util/ScreenshotHelper.java +++ b/core/java/com/android/internal/util/ScreenshotHelper.java @@ -351,8 +351,11 @@ public class ScreenshotHelper { mContext.unbindService(mScreenshotConnection); mScreenshotConnection = null; mScreenshotService = null; - handler.removeCallbacks(mScreenshotTimeout); - notifyScreenshotError(); + // only log an error if we're still within the timeout period + if (handler.hasCallbacks(mScreenshotTimeout)) { + handler.removeCallbacks(mScreenshotTimeout); + notifyScreenshotError(); + } } } }