Handle multi-user in notif log

Test: manual
Fixes: 141575553
Change-Id: I03ff85358e8ae6ed5e6699358c4f9c785c416ecf
This commit is contained in:
Julia Reynolds
2019-10-02 10:02:09 -04:00
parent 616707f486
commit 7e7271fff8
2 changed files with 29 additions and 10 deletions

View File

@@ -71,6 +71,18 @@
android:src="@drawable/ic_notifications_alert" android:src="@drawable/ic_notifications_alert"
/> />
<ImageView
android:id="@+id/profile_badge"
android:layout_width="@*android:dimen/status_bar_icon_size"
android:layout_height="@*android:dimen/status_bar_icon_size"
android:layout_centerVertical="true"
android:layout_marginEnd="6dp"
android:paddingTop="1dp"
android:scaleType="fitCenter"
android:visibility="gone"
android:layout_toStartOf="@id/timestamp"
/>
<DateTimeView <DateTimeView
android:id="@+id/timestamp" android:id="@+id/timestamp"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -83,6 +83,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
public Drawable pkgicon; public Drawable pkgicon;
public CharSequence pkgname; public CharSequence pkgname;
public Drawable icon; public Drawable icon;
public boolean badged;
public CharSequence title; public CharSequence title;
public CharSequence text; public CharSequence text;
public int priority; public int priority;
@@ -268,8 +269,8 @@ public class NotificationStation extends SettingsPreferenceFragment {
if (needsAdd) { if (needsAdd) {
mNotificationInfos.addFirst(newInfo); mNotificationInfos.addFirst(newInfo);
getPreferenceScreen().addPreference(new HistoricalNotificationPreference( getPreferenceScreen().addPreference(new HistoricalNotificationPreference(
getPrefContext(), getPrefContext(), mNotificationInfos.peekFirst(),
mNotificationInfos.peekFirst(), -1 * mNotificationInfos.size())); -1 * mNotificationInfos.size()));
} }
} }
@@ -338,9 +339,9 @@ public class NotificationStation extends SettingsPreferenceFragment {
return text == null ? null : String.valueOf(text); return text == null ? null : String.valueOf(text);
} }
private static Drawable loadIcon(Context context, StatusBarNotification sbn) { private Drawable loadIcon(HistoricalNotificationInfo info, StatusBarNotification sbn) {
Drawable draw = sbn.getNotification().getSmallIcon().loadDrawableAsUser( Drawable draw = sbn.getNotification().getSmallIcon().loadDrawableAsUser(
sbn.getPackageContext(context), sbn.getUserId()); sbn.getPackageContext(mContext), info.user);
if (draw == null) { if (draw == null) {
return null; return null;
} }
@@ -367,7 +368,6 @@ public class NotificationStation extends SettingsPreferenceFragment {
* booted), stores the data we need to present them, and sorts them chronologically for display. * booted), stores the data we need to present them, and sorts them chronologically for display.
*/ */
private void loadNotifications() { private void loadNotifications() {
final int currentUserId = ActivityManager.getCurrentUser();
try { try {
StatusBarNotification[] active = mNoMan.getActiveNotifications( StatusBarNotification[] active = mNoMan.getActiveNotifications(
mContext.getPackageName()); mContext.getPackageName());
@@ -380,9 +380,6 @@ public class NotificationStation extends SettingsPreferenceFragment {
for (StatusBarNotification[] resultSet for (StatusBarNotification[] resultSet
: new StatusBarNotification[][] { active, dismissed }) { : new StatusBarNotification[][] { active, dismissed }) {
for (StatusBarNotification sbn : resultSet) { for (StatusBarNotification sbn : resultSet) {
if (sbn.getUserId() != UserHandle.USER_ALL & sbn.getUserId() != currentUserId) {
continue;
}
if (sbn.getNotification().isGroupSummary()) { if (sbn.getNotification().isGroupSummary()) {
continue; continue;
} }
@@ -406,8 +403,10 @@ public class NotificationStation extends SettingsPreferenceFragment {
final Notification n = sbn.getNotification(); final Notification n = sbn.getNotification();
final HistoricalNotificationInfo info = new HistoricalNotificationInfo(); final HistoricalNotificationInfo info = new HistoricalNotificationInfo();
info.pkg = sbn.getPackageName(); info.pkg = sbn.getPackageName();
info.user = sbn.getUserId(); info.user = sbn.getUserId() == UserHandle.USER_ALL
info.icon = loadIcon(mContext, sbn); ? UserHandle.USER_SYSTEM : sbn.getUserId();
info.badged = info.user != ActivityManager.getCurrentUser();
info.icon = loadIcon(info, sbn);
if (info.icon == null) { if (info.icon == null) {
info.icon = loadPackageIconDrawable(info.pkg, info.user); info.icon = loadPackageIconDrawable(info.pkg, info.user);
} }
@@ -645,6 +644,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
private final HistoricalNotificationInfo mInfo; private final HistoricalNotificationInfo mInfo;
private static long sLastExpandedTimestamp; // quick hack to keep things from collapsing private static long sLastExpandedTimestamp; // quick hack to keep things from collapsing
public ViewGroup mItemView; // hack to update prefs fast; public ViewGroup mItemView; // hack to update prefs fast;
private Context mContext;
public HistoricalNotificationPreference(Context context, HistoricalNotificationInfo info, public HistoricalNotificationPreference(Context context, HistoricalNotificationInfo info,
int order) { int order) {
@@ -653,6 +653,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
setOrder(order); setOrder(order);
setKey(info.key); setKey(info.key);
mInfo = info; mInfo = info;
mContext = context;
} }
@Override @Override
@@ -697,6 +698,12 @@ public class NotificationStation extends SettingsPreferenceFragment {
((ImageView) mItemView.findViewById(R.id.icon)).setImageDrawable(info.icon); ((ImageView) mItemView.findViewById(R.id.icon)).setImageDrawable(info.icon);
} }
ImageView profileBadge = mItemView.findViewById(R.id.profile_badge);
Drawable profile = mContext.getPackageManager().getUserBadgeForDensity(
UserHandle.of(info.user), -1);
profileBadge.setImageDrawable(profile);
profileBadge.setVisibility(info.badged ? View.VISIBLE : View.GONE);
((DateTimeView) mItemView.findViewById(R.id.timestamp)).setTime(mInfo.timestamp); ((DateTimeView) mItemView.findViewById(R.id.timestamp)).setTime(mInfo.timestamp);
((TextView) mItemView.findViewById(R.id.notification_extra)) ((TextView) mItemView.findViewById(R.id.notification_extra))