diff options
author | Daniel Nishi <dhnishi@google.com> | 2017-04-18 16:00:45 -0700 |
---|---|---|
committer | Daniel Nishi <dhnishi@google.com> | 2017-04-19 10:00:06 -0700 |
commit | 7dd8d56e89c4b0fb40673817d1470df9ca936b3f (patch) | |
tree | 237deef1cc3d0b37570e6fc0ee76f91dad2df4ca /src | |
parent | 426ed140b77d62489907523028d9a7ed98c739b5 (diff) | |
download | StorageManager-7dd8d56e89c4b0fb40673817d1470df9ca936b3f.tar.gz |
Fix broken NotificationController robotests.
Because we are now using the O-feature NotificationChannels and this
feature isn't in Robolectric, it causes wackiness during the test run.
By guarding the setting of the NotificationChannel with Build.OS.Version
check, we can act like how an unbundled app does API version detection.
Bug: 37481810
Test: StorMan Robotest actually passes.
Change-Id: I8790d341e97550235080e497e0840076e2d5f078
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/storagemanager/automatic/NotificationController.java | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/com/android/storagemanager/automatic/NotificationController.java b/src/com/android/storagemanager/automatic/NotificationController.java index 413cdcf..b8b67b6 100644 --- a/src/com/android/storagemanager/automatic/NotificationController.java +++ b/src/com/android/storagemanager/automatic/NotificationController.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; +import android.os.Build; import android.os.SystemProperties; import android.provider.Settings; import android.support.annotation.VisibleForTesting; @@ -191,28 +192,30 @@ public class NotificationController extends BroadcastReceiver { PendingIntent tapIntent = PendingIntent.getBroadcast(context, 0, contentIntent, PendingIntent.FLAG_ONE_SHOT); - makeNotificationChannel(context); - - Notification.Builder builder = - new Notification.Builder(context, CHANNEL_ID) - .setSmallIcon(R.drawable.ic_settings_24dp) - .setContentTitle( - res.getString( - R.string.automatic_storage_manager_notification_title)) - .setContentText( - res.getString( - R.string.automatic_storage_manager_notification_summary)) - .setStyle( - new Notification.BigTextStyle() - .bigText( - res.getString( - R.string - .automatic_storage_manager_notification_summary))) - .addAction(cancelAction.build()) - .addAction(activateAutomaticAction.build()) - .setContentIntent(tapIntent) - .setDeleteIntent(deleteIntent) - .setLocalOnly(true); + Notification.Builder builder; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + makeNotificationChannel(context); + builder = new Notification.Builder(context, CHANNEL_ID); + } else { + builder = new Notification.Builder(context); + } + + builder.setSmallIcon(R.drawable.ic_settings_24dp) + .setContentTitle( + res.getString(R.string.automatic_storage_manager_notification_title)) + .setContentText( + res.getString(R.string.automatic_storage_manager_notification_summary)) + .setStyle( + new Notification.BigTextStyle() + .bigText( + res.getString( + R.string + .automatic_storage_manager_notification_summary))) + .addAction(cancelAction.build()) + .addAction(activateAutomaticAction.build()) + .setContentIntent(tapIntent) + .setDeleteIntent(deleteIntent) + .setLocalOnly(true); NotificationManager manager = ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)); |