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

Commit d433f568 authored by Dan Sandler's avatar Dan Sandler Committed by Daniel Sandler
Browse files

Defend against underspecified notifications.

While we're here, show the channelId and other O features of
notifications in the extra text.

(Also make a halfhearted attempt to keep an expanded
notification open while other notifications are updating.)

Bug: 37646836
Test: none
Change-Id: I1b34ae9aaeb0af1e9f993354cebef8644050bed2
parent 3de32ae4
Loading
Loading
Loading
Loading
+204 −178
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ public class NotificationStation extends SettingsPreferenceFragment {
    private Handler mHandler;

    private static class HistoricalNotificationInfo {
        public String key;
        public String channel;
        public String pkg;
        public Drawable pkgicon;
        public CharSequence pkgname;
@@ -271,8 +273,6 @@ public class NotificationStation extends SettingsPreferenceFragment {
            List<HistoricalNotificationInfo> list
                    = new ArrayList<HistoricalNotificationInfo>(active.length + dismissed.length);

            final Ranking rank = new Ranking();

            for (StatusBarNotification[] resultset
                    : new StatusBarNotification[][] { active, dismissed }) {
                for (StatusBarNotification sbn : resultset) {
@@ -293,9 +293,30 @@ public class NotificationStation extends SettingsPreferenceFragment {
                    }
                    info.timestamp = sbn.getPostTime();
                    info.priority = n.priority;
                    info.channel = n.getChannelId();
                    info.key = sbn.getKey();

                    info.active = (resultset == active);

                    info.extra = generateExtraText(sbn, info);

                    logd("   [%d] %s: %s", info.timestamp, info.pkg, info.title);
                    list.add(info);
                }
            }

            return list;
        } catch (RemoteException e) {
            Log.e(TAG, "Cannot load Notifications: ", e);
        }
        return null;
    }

    private CharSequence generateExtraText(StatusBarNotification sbn,
                                           HistoricalNotificationInfo info) {
        final Ranking rank = new Ranking();

        final Notification n = sbn.getNotification();
        final SpannableStringBuilder sb = new SpannableStringBuilder();
        final String delim = getString(R.string.notification_log_details_delimiter);
        sb.append(bold(getString(R.string.notification_log_details_package)))
@@ -308,12 +329,26 @@ public class NotificationStation extends SettingsPreferenceFragment {
        sb.append("\n")
                .append(bold(getString(R.string.notification_log_details_icon)))
                .append(delim)
                            .append(n.getSmallIcon().toString());
                .append(String.valueOf(n.getSmallIcon()));
        sb.append("\n")
                .append(bold("channelId"))
                .append(delim)
                .append(String.valueOf(n.getChannelId()));
        sb.append("\n")
                .append(bold("postTime"))
                .append(delim)
                .append(String.valueOf(sbn.getPostTime()));
        if (n.getTimeoutAfter() != 0) {
            sb.append("\n")
                    .append(bold("timeoutAfter"))
                    .append(delim)
                    .append(String.valueOf(n.getTimeoutAfter()));
        }
        if (sbn.isGroup()) {
            sb.append("\n")
                    .append(bold(getString(R.string.notification_log_details_group)))
                    .append(delim)
                                .append(sbn.getGroupKey());
                    .append(String.valueOf(sbn.getGroupKey()));
            if (n.isGroupSummary()) {
                sb.append(bold(
                        getString(R.string.notification_log_details_group_summary)));
@@ -357,7 +392,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
                .append(bold(getString(R.string.notification_log_details_priority)))
                .append(delim)
                .append(Notification.priorityToString(n.priority));
                    if (resultset == active) {
        if (info.active) {
            // mRanking only applies to active notifications
            if (mRanking != null && mRanking.getRanking(sbn.getKey(), rank)) {
                sb.append("\n")
@@ -469,19 +504,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
                    .append(String.valueOf(p.getBlobAshmemSize()))
                    .append("\n");
        }

                    info.extra = sb;

                    logd("   [%d] %s: %s", info.timestamp, info.pkg, info.title);
                    list.add(info);
                }
            }

            return list;
        } catch (RemoteException e) {
            Log.e(TAG, "Cannot load Notifications: ", e);
        }
        return null;
        return sb;
    }

    private Resources getResourcesForUserPackage(String pkg, int userId) {
@@ -545,6 +568,7 @@ public class NotificationStation extends SettingsPreferenceFragment {

    private static class HistoricalNotificationPreference extends Preference {
        private final HistoricalNotificationInfo mInfo;
        private static long sLastExpandedTimestamp; // quick hack to keep things from collapsing

        public HistoricalNotificationPreference(Context context, HistoricalNotificationInfo info) {
            super(context);
@@ -569,7 +593,8 @@ public class NotificationStation extends SettingsPreferenceFragment {

            final TextView extra = (TextView) row.findViewById(R.id.extra);
            extra.setText(mInfo.extra);
            extra.setVisibility(View.GONE);
            extra.setVisibility(mInfo.timestamp == sLastExpandedTimestamp
                    ? View.VISIBLE : View.GONE);

            row.itemView.setOnClickListener(
                    new View.OnClickListener() {
@@ -577,6 +602,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
                        public void onClick(View view) {
                            extra.setVisibility(extra.getVisibility() == View.VISIBLE
                                    ? View.GONE : View.VISIBLE);
                            sLastExpandedTimestamp = mInfo.timestamp;
                        }
                    });