diff options
author | Daniel Nishi <dhnishi@google.com> | 2016-10-17 14:12:13 -0700 |
---|---|---|
committer | Daniel Nishi <dhnishi@google.com> | 2016-10-17 17:28:18 -0700 |
commit | d4f434bf0e4dc30d10671ffccbe305fe51e3fc54 (patch) | |
tree | 64a01712f0684236002168bc50bb10a623f7f293 | |
parent | c3f027167a26119ed956ad6532df14cc37c5ef21 (diff) | |
download | StorageManager-d4f434bf0e4dc30d10671ffccbe305fe51e3fc54.tar.gz |
Fix a bug where the storage manager notification showed too many times.nougat-mr1-dev
This occurred when the user dismisses the notification. An intent without
metadata was being used as the delete intent, causing the notification
controller to not increment its shown count.
Bug: 32183602
Test: StorageManager robotests
Change-Id: Ide3a038d475ef313a71b262419c8720c65fb140d
(cherry picked from commit 9f6d7f00138afbb634fabf04d8dd67f6e86b60f5)
-rw-r--r-- | src/com/android/storagemanager/automatic/NotificationController.java | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/com/android/storagemanager/automatic/NotificationController.java b/src/com/android/storagemanager/automatic/NotificationController.java index 8f50bdb..443caa3 100644 --- a/src/com/android/storagemanager/automatic/NotificationController.java +++ b/src/com/android/storagemanager/automatic/NotificationController.java @@ -76,11 +76,13 @@ public class NotificationController extends BroadcastReceiver { private static final String SHARED_PREFERENCES_NAME = "NotificationController"; private static final String NOTIFICATION_NEXT_SHOW_TIME = "notification_next_show_time"; private static final String NOTIFICATION_SHOWN_COUNT = "notification_shown_count"; + private static final String NOTIFICATION_DISMISS_COUNT = "notification_dismiss_count"; private static final String STORAGE_MANAGER_PROPERTY = "ro.storage_manager.enabled"; private static final long DISMISS_DELAY = TimeUnit.DAYS.toMillis(15); private static final long NO_THANKS_DELAY = TimeUnit.DAYS.toMillis(90); private static final long MAXIMUM_SHOWN_COUNT = 4; + private static final long MAXIMUM_DISMISS_COUNT = 9; private static final int NOTIFICATION_ID = 0; @Override @@ -130,7 +132,8 @@ public class NotificationController extends BroadcastReceiver { SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); int timesShown = sp.getInt(NOTIFICATION_SHOWN_COUNT, 0); - if (timesShown > MAXIMUM_SHOWN_COUNT) { + int timesDismissed = sp.getInt(NOTIFICATION_DISMISS_COUNT, 0); + if (timesShown >= MAXIMUM_SHOWN_COUNT || timesDismissed >= MAXIMUM_DISMISS_COUNT) { return false; } @@ -159,7 +162,7 @@ public class NotificationController extends BroadcastReceiver { Intent dismissIntent = new Intent(INTENT_ACTION_DISMISS); dismissIntent.putExtra(INTENT_EXTRA_ID, NOTIFICATION_ID); PendingIntent deleteIntent = PendingIntent.getBroadcast(context, 0, - new Intent(INTENT_ACTION_DISMISS), + dismissIntent, PendingIntent.FLAG_ONE_SHOT); Intent contentIntent = new Intent(INTENT_ACTION_TAP); @@ -186,6 +189,12 @@ public class NotificationController extends BroadcastReceiver { } private void cancelNotification(Context context, Intent intent) { + if (intent.getAction() == INTENT_ACTION_DISMISS) { + incrementNotificationDismissedCount(context); + } else { + incrementNotificationShownCount(context); + } + int id = intent.getIntExtra(INTENT_EXTRA_ID, -1); if (id == -1) { return; @@ -193,8 +202,6 @@ public class NotificationController extends BroadcastReceiver { NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); manager.cancel(id); - - incrementNotificationShownCount(context); } private void incrementNotificationShownCount(Context context) { @@ -206,6 +213,15 @@ public class NotificationController extends BroadcastReceiver { editor.apply(); } + private void incrementNotificationDismissedCount(Context context) { + SharedPreferences sp = context.getSharedPreferences(SHARED_PREFERENCES_NAME, + Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + int dismissCount = sp.getInt(NOTIFICATION_DISMISS_COUNT, 0) + 1; + editor.putInt(NOTIFICATION_DISMISS_COUNT, dismissCount); + editor.apply(); + } + private void delayNextNotification(Context context, long timeInMillis) { SharedPreferences sp = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); |