Merge "Defend against underspecified notifications." into oc-dev

This commit is contained in:
TreeHugger Robot
2017-05-05 02:21:10 +00:00
committed by Android (Google) Code Review

View File

@@ -72,6 +72,8 @@ public class NotificationStation extends SettingsPreferenceFragment {
private Handler mHandler; private Handler mHandler;
private static class HistoricalNotificationInfo { private static class HistoricalNotificationInfo {
public String key;
public String channel;
public String pkg; public String pkg;
public Drawable pkgicon; public Drawable pkgicon;
public CharSequence pkgname; public CharSequence pkgname;
@@ -271,8 +273,6 @@ public class NotificationStation extends SettingsPreferenceFragment {
List<HistoricalNotificationInfo> list List<HistoricalNotificationInfo> list
= new ArrayList<HistoricalNotificationInfo>(active.length + dismissed.length); = new ArrayList<HistoricalNotificationInfo>(active.length + dismissed.length);
final Ranking rank = new Ranking();
for (StatusBarNotification[] resultset for (StatusBarNotification[] resultset
: new StatusBarNotification[][] { active, dismissed }) { : new StatusBarNotification[][] { active, dismissed }) {
for (StatusBarNotification sbn : resultset) { for (StatusBarNotification sbn : resultset) {
@@ -293,9 +293,30 @@ public class NotificationStation extends SettingsPreferenceFragment {
} }
info.timestamp = sbn.getPostTime(); info.timestamp = sbn.getPostTime();
info.priority = n.priority; info.priority = n.priority;
info.channel = n.getChannelId();
info.key = sbn.getKey();
info.active = (resultset == active); 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 SpannableStringBuilder sb = new SpannableStringBuilder();
final String delim = getString(R.string.notification_log_details_delimiter); final String delim = getString(R.string.notification_log_details_delimiter);
sb.append(bold(getString(R.string.notification_log_details_package))) sb.append(bold(getString(R.string.notification_log_details_package)))
@@ -308,12 +329,26 @@ public class NotificationStation extends SettingsPreferenceFragment {
sb.append("\n") sb.append("\n")
.append(bold(getString(R.string.notification_log_details_icon))) .append(bold(getString(R.string.notification_log_details_icon)))
.append(delim) .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()) { if (sbn.isGroup()) {
sb.append("\n") sb.append("\n")
.append(bold(getString(R.string.notification_log_details_group))) .append(bold(getString(R.string.notification_log_details_group)))
.append(delim) .append(delim)
.append(sbn.getGroupKey()); .append(String.valueOf(sbn.getGroupKey()));
if (n.isGroupSummary()) { if (n.isGroupSummary()) {
sb.append(bold( sb.append(bold(
getString(R.string.notification_log_details_group_summary))); 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(bold(getString(R.string.notification_log_details_priority)))
.append(delim) .append(delim)
.append(Notification.priorityToString(n.priority)); .append(Notification.priorityToString(n.priority));
if (resultset == active) { if (info.active) {
// mRanking only applies to active notifications // mRanking only applies to active notifications
if (mRanking != null && mRanking.getRanking(sbn.getKey(), rank)) { if (mRanking != null && mRanking.getRanking(sbn.getKey(), rank)) {
sb.append("\n") sb.append("\n")
@@ -469,19 +504,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
.append(String.valueOf(p.getBlobAshmemSize())) .append(String.valueOf(p.getBlobAshmemSize()))
.append("\n"); .append("\n");
} }
return sb;
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;
} }
private Resources getResourcesForUserPackage(String pkg, int userId) { private Resources getResourcesForUserPackage(String pkg, int userId) {
@@ -545,6 +568,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
private static class HistoricalNotificationPreference extends Preference { private static class HistoricalNotificationPreference extends Preference {
private final HistoricalNotificationInfo mInfo; private final HistoricalNotificationInfo mInfo;
private static long sLastExpandedTimestamp; // quick hack to keep things from collapsing
public HistoricalNotificationPreference(Context context, HistoricalNotificationInfo info) { public HistoricalNotificationPreference(Context context, HistoricalNotificationInfo info) {
super(context); super(context);
@@ -569,7 +593,8 @@ public class NotificationStation extends SettingsPreferenceFragment {
final TextView extra = (TextView) row.findViewById(R.id.extra); final TextView extra = (TextView) row.findViewById(R.id.extra);
extra.setText(mInfo.extra); extra.setText(mInfo.extra);
extra.setVisibility(View.GONE); extra.setVisibility(mInfo.timestamp == sLastExpandedTimestamp
? View.VISIBLE : View.GONE);
row.itemView.setOnClickListener( row.itemView.setOnClickListener(
new View.OnClickListener() { new View.OnClickListener() {
@@ -577,6 +602,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
public void onClick(View view) { public void onClick(View view) {
extra.setVisibility(extra.getVisibility() == View.VISIBLE extra.setVisibility(extra.getVisibility() == View.VISIBLE
? View.GONE : View.VISIBLE); ? View.GONE : View.VISIBLE);
sLastExpandedTimestamp = mInfo.timestamp;
} }
}); });