Merge "Fix NPE onNotificationRemoved"
This commit is contained in:
committed by
Android (Google) Code Review
commit
e93d98bf8b
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user