Fix some crashes in notification history
- Can't remove from a fixed size list
- Not everyone likes USER_ALL
Test: manual
Fixes: 149937911
Fixes: 149841327
Change-Id: Ia732522f65138fbcefed5d7c4f2c1e88455a8d1f
diff --git a/src/com/android/settings/notification/history/NotificationHistoryActivity.java b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
index 9b78ae9..9f8a07f 100644
--- a/src/com/android/settings/notification/history/NotificationHistoryActivity.java
+++ b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
@@ -51,6 +51,7 @@
import com.android.settings.notification.NotificationBackend;
import com.android.settings.widget.SwitchBar;
+import java.util.ArrayList;
import java.util.Arrays;
public class NotificationHistoryActivity extends Activity {
@@ -252,7 +253,7 @@
rv.setNestedScrollingEnabled(false);
((NotificationSbnAdapter) rv.getAdapter()).onRebuildComplete(
- Arrays.asList(snoozed));
+ new ArrayList<>(Arrays.asList(snoozed)));
}
try {
@@ -268,7 +269,7 @@
rv.setNestedScrollingEnabled(false);
((NotificationSbnAdapter) rv.getAdapter()).onRebuildComplete(
- Arrays.asList(dismissed));
+ new ArrayList<>(Arrays.asList(dismissed)));
mDismissView.setVisibility(View.VISIBLE);
} catch (Exception e) {
Slog.e(TAG, "Cannot load recently dismissed", e);
diff --git a/src/com/android/settings/notification/history/NotificationSbnAdapter.java b/src/com/android/settings/notification/history/NotificationSbnAdapter.java
index a35b5d4..f1dcf47 100644
--- a/src/com/android/settings/notification/history/NotificationSbnAdapter.java
+++ b/src/com/android/settings/notification/history/NotificationSbnAdapter.java
@@ -17,6 +17,8 @@
package com.android.settings.notification.history;
import static android.content.pm.PackageManager.*;
+import static android.os.UserHandle.USER_ALL;
+import static android.os.UserHandle.USER_CURRENT;
import android.app.Notification;
import android.content.Context;
@@ -77,12 +79,13 @@
holder.setTitle(getTitleString(sbn.getNotification()));
holder.setSummary(getTextString(mContext, sbn.getNotification()));
holder.setPostedTime(sbn.getPostTime());
- if (!mUserBadgeCache.containsKey(sbn.getUserId())) {
+ int userId = normalizeUserId(sbn);
+ if (!mUserBadgeCache.containsKey(userId)) {
Drawable profile = mContext.getPackageManager().getUserBadgeForDensity(
- UserHandle.of(sbn.getUserId()), -1);
- mUserBadgeCache.put(sbn.getUserId(), profile);
+ UserHandle.of(userId), -1);
+ mUserBadgeCache.put(userId, profile);
}
- holder.setProfileBadge(mUserBadgeCache.get(sbn.getUserId()));
+ holder.setProfileBadge(mUserBadgeCache.get(userId));
} else {
Slog.w(TAG, "null entry in list at position " + position);
}
@@ -153,7 +156,7 @@
private Drawable loadIcon(StatusBarNotification sbn) {
Drawable draw = sbn.getNotification().getSmallIcon().loadDrawableAsUser(
- sbn.getPackageContext(mContext), sbn.getUserId());
+ sbn.getPackageContext(mContext), normalizeUserId(sbn));
if (draw == null) {
return null;
}
@@ -161,4 +164,12 @@
draw.setColorFilter(sbn.getNotification().color, PorterDuff.Mode.SRC_ATOP);
return draw;
}
+
+ private int normalizeUserId(StatusBarNotification sbn) {
+ int userId = sbn.getUserId();
+ if (userId == USER_ALL) {
+ userId = USER_CURRENT;
+ }
+ return userId;
+ }
}