Merge "Fix NPE onNotificationRemoved"

This commit is contained in:
TreeHugger Robot
2018-12-20 21:40:50 +00:00
committed by Android (Google) Code Review
3 changed files with 24 additions and 2 deletions

View File

@@ -294,7 +294,7 @@ public class Assistant extends NotificationAssistantService {
synchronized (mkeyToImpressions) {
ChannelImpressions ci = mkeyToImpressions.getOrDefault(key,
createChannelImpressionsWithThresholds());
if (stats.hasSeen()) {
if (stats != null && stats.hasSeen()) {
ci.incrementViews();
updatedImpressions = true;
}

View File

@@ -4939,7 +4939,7 @@ public class NotificationManagerService extends SystemService {
Slog.e(TAG, "Not posting notification without small icon: " + notification);
if (old != null && !old.isCanceled) {
mListeners.notifyRemovedLocked(r,
NotificationListenerService.REASON_ERROR, null);
NotificationListenerService.REASON_ERROR, r.getStats());
mHandler.post(new Runnable() {
@Override
public void run() {

View File

@@ -3849,4 +3849,26 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.reportSeen(r);
verify(mAppUsageStats, times(1)).reportEvent(anyString(), anyInt(), anyInt());
}
@Test
public void testNotificationStats_notificationError() {
NotificationRecord r = generateNotificationRecord(mTestNotificationChannel);
mService.addNotification(r);
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, "tag", mUid, 0,
new Notification.Builder(mContext, mTestNotificationChannel.getId()).build(),
new UserHandle(mUid), null, 0);
NotificationRecord update = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
mService.addEnqueuedNotification(update);
assertNull(update.sbn.getNotification().getSmallIcon());
NotificationManagerService.PostNotificationRunnable runnable =
mService.new PostNotificationRunnable(update.getKey());
runnable.run();
waitForIdle();
ArgumentCaptor<NotificationStats> captor = ArgumentCaptor.forClass(NotificationStats.class);
verify(mListeners).notifyRemovedLocked(any(), anyInt(), captor.capture());
assertNotNull(captor.getValue());
}
}