From 1eee1996f5d57b42d4beed2790321480fbe03a4c Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Tue, 16 Feb 2016 13:01:38 -0800 Subject: [PATCH] Cancel notifications when user tap on Details or Take Screenshot after service died. There are scenarios when the user is running low on resources and it kills Shell after it start monitoring a dumpstate process, in which case the BugreportInfo is not available anymore when the user tap a notification action. We could add a mechanism to recover that info (like persistenting the user-provided values in a shared preference), but would incur in more costs when the device is already in a resource-constrained state, so it's better to just stop monitoring and switch back to the traditional model where the user is notified after the bugreport finishes (the drawback is that all user-provided information will be lost). Also improved how info.name is checked to avoid crash in similar cases. BUG: 27186542 BUG: 27203559 Change-Id: I57076b098a3fce493e1a27121b6e070366808668 --- .../shell/BugreportProgressService.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index bad7e202e1d10..9926ae5e7ffc3 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -158,7 +158,7 @@ public class BugreportProgressService extends Service { static final long POLLING_FREQUENCY = 2 * DateUtils.SECOND_IN_MILLIS; /** How long (in ms) a dumpstate process will be monitored if it didn't show progress. */ - private static final long INACTIVITY_TIMEOUT = 3 * DateUtils.MINUTE_IN_MILLIS; + private static final long INACTIVITY_TIMEOUT = 10 * DateUtils.MINUTE_IN_MILLIS; /** System properties used for monitoring progress. */ private static final String DUMPSTATE_PREFIX = "dumpstate."; @@ -586,6 +586,12 @@ public class BugreportProgressService extends Service { final String name, title, description; final BugreportInfo info = getInfo(id); if (info == null) { + // Most likely am killed Shell before user tapped the notification. Since system might + // be too busy anwyays, it's better to ignore the notification and switch back to the + // non-interactive mode (where the bugerport will be shared upon completion). + Log.d(TAG, "launchBugreportInfoDialog(" + id + "): cancel notification"); + // TODO: add test case to make sure notification is canceled. + NotificationManager.from(mContext).cancel(TAG, id); return; } @@ -604,6 +610,15 @@ public class BugreportProgressService extends Service { * upon receiving a {@link #INTENT_BUGREPORT_STARTED}. */ private void takeScreenshot(int id, boolean delayed) { + if (getInfo(id) == null) { + // Most likely am killed Shell before user tapped the notification. Since system might + // be too busy anwyays, it's better to ignore the notification and switch back to the + // non-interactive mode (where the bugerport will be shared upon completion). + Log.d(TAG, "takeScreenshot(" + id + ", " + delayed + "): cancel notification"); + // TODO: add test case to make sure notification is canceled. + NotificationManager.from(mContext).cancel(TAG, id); + return; + } setTakingScreenshot(true); if (delayed) { collapseNotificationBar(); @@ -1126,7 +1141,7 @@ public class BugreportProgressService extends Service { } info.title = title; info.description = description; - if (name != null && !info.name.equals(name)) { + if (name != null && !name.equals(info.name)) { info.name = name; updateProgress(info); }