diff options
author | Daniel Nishi <dhnishi@google.com> | 2016-10-18 20:09:38 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-10-18 20:09:38 +0000 |
commit | 2104043818b535db2d9d8c9de004e421193c19fb (patch) | |
tree | c133ec619191faef0cc39bcab32e5476443646fb | |
parent | 9600163d421ee828a2978106e1aaf0b329ee5579 (diff) | |
parent | d4f434bf0e4dc30d10671ffccbe305fe51e3fc54 (diff) | |
download | StorageManager-2104043818b535db2d9d8c9de004e421193c19fb.tar.gz |
Fix a bug where the storage manager notification showed too many times.
am: d4f434bf0e
Change-Id: I341e09f34fdab2ba95d508fdec31d728232763c7
-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); |