Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0678b84a authored by Julia Reynolds's avatar Julia Reynolds
Browse files

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
parent ea74ce99
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.settings.R;
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 @@ public class NotificationHistoryActivity extends Activity {
                rv.setNestedScrollingEnabled(false);

                ((NotificationSbnAdapter) rv.getAdapter()).onRebuildComplete(
                        Arrays.asList(snoozed));
                        new ArrayList<>(Arrays.asList(snoozed)));
            }

            try {
@@ -268,7 +269,7 @@ public class NotificationHistoryActivity extends Activity {
                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);
+16 −5
Original line number Diff line number Diff line
@@ -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 @@ public class NotificationSbnAdapter extends
            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 @@ public class NotificationSbnAdapter extends

    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 @@ public class NotificationSbnAdapter extends
        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;
    }
}