Skip to content

Commit 383a45f

Browse files
Iavor-Valentin IftimeAndroid (Google) Code Review
Iavor-Valentin Iftime
authored and
Android (Google) Code Review
committed
Merge "Update the autogroup summary visibility on notification changes" into main
2 parents 45a779e + abcce3d commit 383a45f

File tree

4 files changed

+159
-46
lines changed

4 files changed

+159
-46
lines changed

services/core/java/com/android/server/notification/GroupHelper.java

+37-20
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import static android.app.Notification.FLAG_LOCAL_ONLY;
2323
import static android.app.Notification.FLAG_NO_CLEAR;
2424
import static android.app.Notification.FLAG_ONGOING_EVENT;
25+
import static android.app.Notification.VISIBILITY_PRIVATE;
26+
import static android.app.Notification.VISIBILITY_PUBLIC;
2527

2628
import android.annotation.NonNull;
2729
import android.app.Notification;
@@ -145,7 +147,8 @@ private void maybeGroup(StatusBarNotification sbn, boolean autogroupSummaryExist
145147
mUngroupedNotifications.getOrDefault(key, new ArrayMap<>());
146148

147149
NotificationAttributes attr = new NotificationAttributes(sbn.getNotification().flags,
148-
sbn.getNotification().getSmallIcon(), sbn.getNotification().color);
150+
sbn.getNotification().getSmallIcon(), sbn.getNotification().color,
151+
sbn.getNotification().visibility);
149152
children.put(sbn.getKey(), attr);
150153
mUngroupedNotifications.put(key, children);
151154

@@ -158,25 +161,29 @@ private void maybeGroup(StatusBarNotification sbn, boolean autogroupSummaryExist
158161
if (notificationsToGroup.size() > 0) {
159162
if (autogroupSummaryExists) {
160163
NotificationAttributes attr = new NotificationAttributes(flags,
161-
sbn.getNotification().getSmallIcon(), sbn.getNotification().color);
164+
sbn.getNotification().getSmallIcon(), sbn.getNotification().color,
165+
VISIBILITY_PRIVATE);
162166
if (Flags.autogroupSummaryIconUpdate()) {
163-
attr = updateAutobundledSummaryIcon(sbn.getPackageName(), childrenAttr, attr);
167+
attr = updateAutobundledSummaryAttributes(sbn.getPackageName(), childrenAttr,
168+
attr);
164169
}
165170

166171
mCallback.updateAutogroupSummary(sbn.getUserId(), sbn.getPackageName(), attr);
167172
} else {
168173
Icon summaryIcon = sbn.getNotification().getSmallIcon();
169174
int summaryIconColor = sbn.getNotification().color;
175+
int summaryVisibility = VISIBILITY_PRIVATE;
170176
if (Flags.autogroupSummaryIconUpdate()) {
171-
// Calculate the initial summary icon and icon color
172-
NotificationAttributes iconAttr = getAutobundledSummaryIconAndColor(
177+
// Calculate the initial summary icon, icon color and visibility
178+
NotificationAttributes iconAttr = getAutobundledSummaryAttributes(
173179
sbn.getPackageName(), childrenAttr);
174180
summaryIcon = iconAttr.icon;
175181
summaryIconColor = iconAttr.iconColor;
182+
summaryVisibility = iconAttr.visibility;
176183
}
177184

178185
NotificationAttributes attr = new NotificationAttributes(flags, summaryIcon,
179-
summaryIconColor);
186+
summaryIconColor, summaryVisibility);
180187
mCallback.addAutoGroupSummary(sbn.getUserId(), sbn.getPackageName(), sbn.getKey(),
181188
attr);
182189
}
@@ -238,18 +245,19 @@ private void maybeUngroup(StatusBarNotification sbn, boolean notificationGone, i
238245
mCallback.removeAutoGroupSummary(userId, sbn.getPackageName());
239246
} else {
240247
NotificationAttributes attr = new NotificationAttributes(summaryFlags,
241-
sbn.getNotification().getSmallIcon(), sbn.getNotification().color);
242-
boolean iconUpdated = false;
248+
sbn.getNotification().getSmallIcon(), sbn.getNotification().color,
249+
VISIBILITY_PRIVATE);
250+
boolean attributesUpdated = false;
243251
if (Flags.autogroupSummaryIconUpdate()) {
244-
NotificationAttributes newAttr = updateAutobundledSummaryIcon(sbn.getPackageName(),
245-
childrenAttrs, attr);
252+
NotificationAttributes newAttr = updateAutobundledSummaryAttributes(
253+
sbn.getPackageName(), childrenAttrs, attr);
246254
if (!newAttr.equals(attr)) {
247-
iconUpdated = true;
255+
attributesUpdated = true;
248256
attr = newAttr;
249257
}
250258
}
251259

252-
if (updateSummaryFlags || iconUpdated) {
260+
if (updateSummaryFlags || attributesUpdated) {
253261
mCallback.updateAutogroupSummary(userId, sbn.getPackageName(), attr);
254262
}
255263
}
@@ -268,12 +276,13 @@ int getNotGroupedByAppCount(int userId, String pkg) {
268276
}
269277
}
270278

271-
NotificationAttributes getAutobundledSummaryIconAndColor(@NonNull String packageName,
279+
NotificationAttributes getAutobundledSummaryAttributes(@NonNull String packageName,
272280
@NonNull List<NotificationAttributes> childrenAttr) {
273281
Icon newIcon = null;
274282
boolean childrenHaveSameIcon = true;
275283
int newColor = Notification.COLOR_INVALID;
276284
boolean childrenHaveSameColor = true;
285+
int newVisibility = VISIBILITY_PRIVATE;
277286

278287
// Both the icon drawable and the icon background color are updated according to this rule:
279288
// - if all child icons are identical => use the common icon
@@ -296,6 +305,10 @@ NotificationAttributes getAutobundledSummaryIconAndColor(@NonNull String package
296305
childrenHaveSameColor = false;
297306
}
298307
}
308+
// Check for visibility. If at least one child is public, then set to public
309+
if (state.visibility == VISIBILITY_PUBLIC) {
310+
newVisibility = VISIBILITY_PUBLIC;
311+
}
299312
}
300313
if (!childrenHaveSameIcon) {
301314
newIcon = getMonochromeAppIcon(packageName);
@@ -304,13 +317,13 @@ NotificationAttributes getAutobundledSummaryIconAndColor(@NonNull String package
304317
newColor = COLOR_DEFAULT;
305318
}
306319

307-
return new NotificationAttributes(0, newIcon, newColor);
320+
return new NotificationAttributes(0, newIcon, newColor, newVisibility);
308321
}
309322

310-
NotificationAttributes updateAutobundledSummaryIcon(@NonNull String packageName,
323+
NotificationAttributes updateAutobundledSummaryAttributes(@NonNull String packageName,
311324
@NonNull List<NotificationAttributes> childrenAttr,
312325
@NonNull NotificationAttributes oldAttr) {
313-
NotificationAttributes newAttr = getAutobundledSummaryIconAndColor(packageName,
326+
NotificationAttributes newAttr = getAutobundledSummaryAttributes(packageName,
314327
childrenAttr);
315328
Icon newIcon = newAttr.icon;
316329
int newColor = newAttr.iconColor;
@@ -321,7 +334,7 @@ NotificationAttributes updateAutobundledSummaryIcon(@NonNull String packageName,
321334
newColor = oldAttr.iconColor;
322335
}
323336

324-
return new NotificationAttributes(oldAttr.flags, newIcon, newColor);
337+
return new NotificationAttributes(oldAttr.flags, newIcon, newColor, newAttr.visibility);
325338
}
326339

327340
/**
@@ -358,17 +371,20 @@ protected static class NotificationAttributes {
358371
public final int flags;
359372
public final int iconColor;
360373
public final Icon icon;
374+
public final int visibility;
361375

362-
public NotificationAttributes(int flags, Icon icon, int iconColor) {
376+
public NotificationAttributes(int flags, Icon icon, int iconColor, int visibility) {
363377
this.flags = flags;
364378
this.icon = icon;
365379
this.iconColor = iconColor;
380+
this.visibility = visibility;
366381
}
367382

368383
public NotificationAttributes(@NonNull NotificationAttributes attr) {
369384
this.flags = attr.flags;
370385
this.icon = attr.icon;
371386
this.iconColor = attr.iconColor;
387+
this.visibility = attr.visibility;
372388
}
373389

374390
@Override
@@ -379,12 +395,13 @@ public boolean equals(Object o) {
379395
if (!(o instanceof NotificationAttributes that)) {
380396
return false;
381397
}
382-
return flags == that.flags && iconColor == that.iconColor && icon.sameAs(that.icon);
398+
return flags == that.flags && iconColor == that.iconColor && icon.sameAs(that.icon)
399+
&& visibility == that.visibility;
383400
}
384401

385402
@Override
386403
public int hashCode() {
387-
return Objects.hash(flags, iconColor, icon);
404+
return Objects.hash(flags, iconColor, icon, visibility);
388405
}
389406
}
390407

services/core/java/com/android/server/notification/NotificationManagerService.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -1038,15 +1038,17 @@ protected void updateAutobundledSummaryLocked(int userId, String pkg,
10381038
}
10391039
int oldFlags = summary.getSbn().getNotification().flags;
10401040

1041-
boolean iconUpdated =
1041+
boolean attributesUpdated =
10421042
!summaryAttr.icon.sameAs(summary.getSbn().getNotification().getSmallIcon())
1043-
|| summaryAttr.iconColor != summary.getSbn().getNotification().color;
1043+
|| summaryAttr.iconColor != summary.getSbn().getNotification().color
1044+
|| summaryAttr.visibility != summary.getSbn().getNotification().visibility;
10441045

1045-
if (oldFlags != summaryAttr.flags || iconUpdated) {
1046+
if (oldFlags != summaryAttr.flags || attributesUpdated) {
10461047
summary.getSbn().getNotification().flags =
10471048
summaryAttr.flags != GroupHelper.FLAG_INVALID ? summaryAttr.flags : oldFlags;
10481049
summary.getSbn().getNotification().setSmallIcon(summaryAttr.icon);
10491050
summary.getSbn().getNotification().color = summaryAttr.iconColor;
1051+
summary.getSbn().getNotification().visibility = summaryAttr.visibility;
10501052
mHandler.post(new EnqueueNotificationRunnable(userId, summary, isAppForeground,
10511053
mPostNotificationTrackerFactory.newTracker(null)));
10521054
}
@@ -2939,7 +2941,8 @@ public void removeAutoGroup(String key) {
29392941
public void addAutoGroupSummary(int userId, String pkg, String triggeringKey,
29402942
NotificationAttributes summaryAttr) {
29412943
NotificationRecord r = createAutoGroupSummary(userId, pkg, triggeringKey,
2942-
summaryAttr.flags, summaryAttr.icon, summaryAttr.iconColor);
2944+
summaryAttr.flags, summaryAttr.icon, summaryAttr.iconColor,
2945+
summaryAttr.visibility);
29432946
if (r != null) {
29442947
final boolean isAppForeground =
29452948
mActivityManager.getPackageImportance(pkg) == IMPORTANCE_FOREGROUND;
@@ -6725,7 +6728,7 @@ private boolean hasAutoGroupSummaryLocked(StatusBarNotification sbn) {
67256728

67266729
// Creates a 'fake' summary for a package that has exceeded the solo-notification limit.
67276730
NotificationRecord createAutoGroupSummary(int userId, String pkg, String triggeringKey,
6728-
int flagsToSet, Icon summaryIcon, int summaryIconColor) {
6731+
int flagsToSet, Icon summaryIcon, int summaryIconColor, int summaryVisibilty) {
67296732
NotificationRecord summaryRecord = null;
67306733
boolean isPermissionFixed = mPermissionHelper.isPermissionFixed(pkg, userId);
67316734
synchronized (mNotificationLock) {
@@ -6760,6 +6763,7 @@ NotificationRecord createAutoGroupSummary(int userId, String pkg, String trigger
67606763
.setGroup(GroupHelper.AUTOGROUP_KEY)
67616764
.setFlag(flagsToSet, true)
67626765
.setColor(summaryIconColor)
6766+
.setVisibility(summaryVisibilty)
67636767
.build();
67646768
summaryNotification.extras.putAll(extras);
67656769
Intent appIntent = getContext().getPackageManager().getLaunchIntentForPackage(pkg);

0 commit comments

Comments
 (0)