This attempts to work around a ROM crash bug

getActiveNotifications() seems to throw an NPE on some Motorola
ROMs, all of which appear to be 6.0.1.  This change just swallows
the exception.

6.0 doesn't support bundled notifications, so I think it's alright
if they don't get canceled, since the summary notification will
still be displayed correctly.

This would only affect users who have an android wear device
attached to one of these buggy ROMs. By swallowing this exception,
they would not always get notifictions dismissed on their wear
 device.

Fixes #6043
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-01-17 20:41:24 -08:00
parent cfef855d99
commit 360c2b2a50

View File

@ -130,6 +130,7 @@ public class MessageNotifier {
notifications.cancel(SUMMARY_NOTIFICATION_ID); notifications.cancel(SUMMARY_NOTIFICATION_ID);
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
try {
StatusBarNotification[] activeNotifications = notifications.getActiveNotifications(); StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
for (StatusBarNotification activeNotification : activeNotifications) { for (StatusBarNotification activeNotification : activeNotifications) {
@ -137,11 +138,17 @@ public class MessageNotifier {
notifications.cancel(activeNotification.getId()); notifications.cancel(activeNotification.getId());
} }
} }
} catch (Throwable e) {
// XXX Appears to be a ROM bug, see #6043
Log.w(TAG, e);
notifications.cancelAll();
}
} }
} }
private static void cancelOrphanedNotifications(@NonNull Context context, NotificationState notificationState) { private static void cancelOrphanedNotifications(@NonNull Context context, NotificationState notificationState) {
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
try {
NotificationManager notifications = ServiceUtil.getNotificationManager(context); NotificationManager notifications = ServiceUtil.getNotificationManager(context);
StatusBarNotification[] activeNotifications = notifications.getActiveNotifications(); StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
@ -161,6 +168,10 @@ public class MessageNotifier {
} }
} }
} }
} catch (Throwable e) {
// XXX Android ROM Bug, see #6043
Log.w(TAG, e);
}
} }
} }