22
22
import static android .app .Notification .FLAG_LOCAL_ONLY ;
23
23
import static android .app .Notification .FLAG_NO_CLEAR ;
24
24
import static android .app .Notification .FLAG_ONGOING_EVENT ;
25
+ import static android .app .Notification .VISIBILITY_PRIVATE ;
26
+ import static android .app .Notification .VISIBILITY_PUBLIC ;
25
27
26
28
import android .annotation .NonNull ;
27
29
import android .app .Notification ;
@@ -145,7 +147,8 @@ private void maybeGroup(StatusBarNotification sbn, boolean autogroupSummaryExist
145
147
mUngroupedNotifications .getOrDefault (key , new ArrayMap <>());
146
148
147
149
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 );
149
152
children .put (sbn .getKey (), attr );
150
153
mUngroupedNotifications .put (key , children );
151
154
@@ -158,25 +161,29 @@ private void maybeGroup(StatusBarNotification sbn, boolean autogroupSummaryExist
158
161
if (notificationsToGroup .size () > 0 ) {
159
162
if (autogroupSummaryExists ) {
160
163
NotificationAttributes attr = new NotificationAttributes (flags ,
161
- sbn .getNotification ().getSmallIcon (), sbn .getNotification ().color );
164
+ sbn .getNotification ().getSmallIcon (), sbn .getNotification ().color ,
165
+ VISIBILITY_PRIVATE );
162
166
if (Flags .autogroupSummaryIconUpdate ()) {
163
- attr = updateAutobundledSummaryIcon (sbn .getPackageName (), childrenAttr , attr );
167
+ attr = updateAutobundledSummaryAttributes (sbn .getPackageName (), childrenAttr ,
168
+ attr );
164
169
}
165
170
166
171
mCallback .updateAutogroupSummary (sbn .getUserId (), sbn .getPackageName (), attr );
167
172
} else {
168
173
Icon summaryIcon = sbn .getNotification ().getSmallIcon ();
169
174
int summaryIconColor = sbn .getNotification ().color ;
175
+ int summaryVisibility = VISIBILITY_PRIVATE ;
170
176
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 (
173
179
sbn .getPackageName (), childrenAttr );
174
180
summaryIcon = iconAttr .icon ;
175
181
summaryIconColor = iconAttr .iconColor ;
182
+ summaryVisibility = iconAttr .visibility ;
176
183
}
177
184
178
185
NotificationAttributes attr = new NotificationAttributes (flags , summaryIcon ,
179
- summaryIconColor );
186
+ summaryIconColor , summaryVisibility );
180
187
mCallback .addAutoGroupSummary (sbn .getUserId (), sbn .getPackageName (), sbn .getKey (),
181
188
attr );
182
189
}
@@ -238,18 +245,19 @@ private void maybeUngroup(StatusBarNotification sbn, boolean notificationGone, i
238
245
mCallback .removeAutoGroupSummary (userId , sbn .getPackageName ());
239
246
} else {
240
247
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 ;
243
251
if (Flags .autogroupSummaryIconUpdate ()) {
244
- NotificationAttributes newAttr = updateAutobundledSummaryIcon ( sbn . getPackageName (),
245
- childrenAttrs , attr );
252
+ NotificationAttributes newAttr = updateAutobundledSummaryAttributes (
253
+ sbn . getPackageName (), childrenAttrs , attr );
246
254
if (!newAttr .equals (attr )) {
247
- iconUpdated = true ;
255
+ attributesUpdated = true ;
248
256
attr = newAttr ;
249
257
}
250
258
}
251
259
252
- if (updateSummaryFlags || iconUpdated ) {
260
+ if (updateSummaryFlags || attributesUpdated ) {
253
261
mCallback .updateAutogroupSummary (userId , sbn .getPackageName (), attr );
254
262
}
255
263
}
@@ -268,12 +276,13 @@ int getNotGroupedByAppCount(int userId, String pkg) {
268
276
}
269
277
}
270
278
271
- NotificationAttributes getAutobundledSummaryIconAndColor (@ NonNull String packageName ,
279
+ NotificationAttributes getAutobundledSummaryAttributes (@ NonNull String packageName ,
272
280
@ NonNull List <NotificationAttributes > childrenAttr ) {
273
281
Icon newIcon = null ;
274
282
boolean childrenHaveSameIcon = true ;
275
283
int newColor = Notification .COLOR_INVALID ;
276
284
boolean childrenHaveSameColor = true ;
285
+ int newVisibility = VISIBILITY_PRIVATE ;
277
286
278
287
// Both the icon drawable and the icon background color are updated according to this rule:
279
288
// - if all child icons are identical => use the common icon
@@ -296,6 +305,10 @@ NotificationAttributes getAutobundledSummaryIconAndColor(@NonNull String package
296
305
childrenHaveSameColor = false ;
297
306
}
298
307
}
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
+ }
299
312
}
300
313
if (!childrenHaveSameIcon ) {
301
314
newIcon = getMonochromeAppIcon (packageName );
@@ -304,13 +317,13 @@ NotificationAttributes getAutobundledSummaryIconAndColor(@NonNull String package
304
317
newColor = COLOR_DEFAULT ;
305
318
}
306
319
307
- return new NotificationAttributes (0 , newIcon , newColor );
320
+ return new NotificationAttributes (0 , newIcon , newColor , newVisibility );
308
321
}
309
322
310
- NotificationAttributes updateAutobundledSummaryIcon (@ NonNull String packageName ,
323
+ NotificationAttributes updateAutobundledSummaryAttributes (@ NonNull String packageName ,
311
324
@ NonNull List <NotificationAttributes > childrenAttr ,
312
325
@ NonNull NotificationAttributes oldAttr ) {
313
- NotificationAttributes newAttr = getAutobundledSummaryIconAndColor (packageName ,
326
+ NotificationAttributes newAttr = getAutobundledSummaryAttributes (packageName ,
314
327
childrenAttr );
315
328
Icon newIcon = newAttr .icon ;
316
329
int newColor = newAttr .iconColor ;
@@ -321,7 +334,7 @@ NotificationAttributes updateAutobundledSummaryIcon(@NonNull String packageName,
321
334
newColor = oldAttr .iconColor ;
322
335
}
323
336
324
- return new NotificationAttributes (oldAttr .flags , newIcon , newColor );
337
+ return new NotificationAttributes (oldAttr .flags , newIcon , newColor , newAttr . visibility );
325
338
}
326
339
327
340
/**
@@ -358,17 +371,20 @@ protected static class NotificationAttributes {
358
371
public final int flags ;
359
372
public final int iconColor ;
360
373
public final Icon icon ;
374
+ public final int visibility ;
361
375
362
- public NotificationAttributes (int flags , Icon icon , int iconColor ) {
376
+ public NotificationAttributes (int flags , Icon icon , int iconColor , int visibility ) {
363
377
this .flags = flags ;
364
378
this .icon = icon ;
365
379
this .iconColor = iconColor ;
380
+ this .visibility = visibility ;
366
381
}
367
382
368
383
public NotificationAttributes (@ NonNull NotificationAttributes attr ) {
369
384
this .flags = attr .flags ;
370
385
this .icon = attr .icon ;
371
386
this .iconColor = attr .iconColor ;
387
+ this .visibility = attr .visibility ;
372
388
}
373
389
374
390
@ Override
@@ -379,12 +395,13 @@ public boolean equals(Object o) {
379
395
if (!(o instanceof NotificationAttributes that )) {
380
396
return false ;
381
397
}
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 ;
383
400
}
384
401
385
402
@ Override
386
403
public int hashCode () {
387
- return Objects .hash (flags , iconColor , icon );
404
+ return Objects .hash (flags , iconColor , icon , visibility );
388
405
}
389
406
}
390
407
0 commit comments