@@ -167,7 +167,10 @@ public void setMediaNotificationProvider(MediaNotification.Provider mediaNotific
167
167
* @param session A session that needs notification update.
168
168
* @param startInForegroundRequired Whether the service is required to start in the foreground.
169
169
*/
170
- public void updateNotification (MediaSession session , boolean startInForegroundRequired ) {
170
+ public void updateNotification (
171
+ MediaSession session ,
172
+ boolean startInForegroundRequired ,
173
+ @ MediaSessionService .NotificationUpdate int reason ) {
171
174
if (!mediaSessionService .isSessionAdded (session ) || !shouldShowNotification (session )) {
172
175
removeNotification ();
173
176
return ;
@@ -185,7 +188,7 @@ public void updateNotification(MediaSession session, boolean startInForegroundRe
185
188
() -> {
186
189
MediaNotification mediaNotification =
187
190
this .mediaNotificationProvider .createNotification (
188
- session , mediaButtonPreferences , actionFactory , callback );
191
+ session , mediaButtonPreferences , actionFactory , callback , reason );
189
192
mainExecutor .execute (
190
193
() ->
191
194
updateNotificationInternal (
@@ -207,7 +210,8 @@ public void setShowNotificationForIdlePlayer(
207
210
List <MediaSession > sessions = mediaSessionService .getSessions ();
208
211
for (int i = 0 ; i < sessions .size (); i ++) {
209
212
mediaSessionService .onUpdateNotificationInternal (
210
- sessions .get (i ), /* startInForegroundWhenPaused= */ false );
213
+ sessions .get (i ), /* startInForegroundWhenPaused= */ false ,
214
+ MediaSessionService .NOTIFICATION_UPDATE_IDLE_PLAYER_SETTING_CHANGED );
211
215
}
212
216
}
213
217
@@ -217,7 +221,9 @@ public boolean handleMessage(Message msg) {
217
221
List <MediaSession > sessions = mediaSessionService .getSessions ();
218
222
for (int i = 0 ; i < sessions .size (); i ++) {
219
223
mediaSessionService .onUpdateNotificationInternal (
220
- sessions .get (i ), /* startInForegroundWhenPaused= */ false );
224
+ sessions .get (i ),
225
+ /* startInForegroundWhenPaused= */ false ,
226
+ MediaSessionService .NOTIFICATION_UPDATE_ENGAGED_TIMEOUT );
221
227
}
222
228
return true ;
223
229
}
@@ -262,7 +268,9 @@ private boolean isAnySessionUserEngaged(boolean startInForegroundWhenPaused) {
262
268
List <MediaSession > sessions = mediaSessionService .getSessions ();
263
269
for (int i = 0 ; i < sessions .size (); i ++) {
264
270
mediaSessionService .onUpdateNotificationInternal (
265
- sessions .get (i ), /* startInForegroundWhenPaused= */ false );
271
+ sessions .get (i ),
272
+ /* startInForegroundWhenPaused= */ false ,
273
+ MediaSessionService .NOTIFICATION_UPDATE_ENGAGED_TIMEOUT_DISABLED );
266
274
}
267
275
}
268
276
}
@@ -402,22 +410,28 @@ public MediaControllerListener(MediaSessionService mediaSessionService, MediaSes
402
410
public void onConnected (boolean shouldShowNotification ) {
403
411
if (shouldShowNotification ) {
404
412
mediaSessionService .onUpdateNotificationInternal (
405
- session , /* startInForegroundWhenPaused= */ false );
413
+ session ,
414
+ /* startInForegroundWhenPaused= */ false ,
415
+ MediaSessionService .NOTIFICATION_UPDATE_CONNECTED );
406
416
}
407
417
}
408
418
409
419
@ Override
410
420
public void onMediaButtonPreferencesChanged (
411
421
MediaController controller , List <CommandButton > mediaButtonPreferences ) {
412
422
mediaSessionService .onUpdateNotificationInternal (
413
- session , /* startInForegroundWhenPaused= */ false );
423
+ session ,
424
+ /* startInForegroundWhenPaused= */ false ,
425
+ MediaSessionService .NOTIFICATION_UPDATE_BUTTON_PREFERENCES_CHANGED );
414
426
}
415
427
416
428
@ Override
417
429
public void onAvailableSessionCommandsChanged (
418
430
MediaController controller , SessionCommands commands ) {
419
431
mediaSessionService .onUpdateNotificationInternal (
420
- session , /* startInForegroundWhenPaused= */ false );
432
+ session ,
433
+ /* startInForegroundWhenPaused= */ false ,
434
+ MediaSessionService .NOTIFICATION_UPDATE_SESSION_COMMANDS_CHANGED );
421
435
}
422
436
423
437
@ Override
@@ -438,7 +452,9 @@ public void onDisconnected(MediaController controller) {
438
452
}
439
453
// We may need to hide the notification.
440
454
mediaSessionService .onUpdateNotificationInternal (
441
- session , /* startInForegroundWhenPaused= */ false );
455
+ session ,
456
+ /* startInForegroundWhenPaused= */ false ,
457
+ MediaSessionService .NOTIFICATION_UPDATE_DISCONNECTED );
442
458
}
443
459
444
460
@ Override
@@ -451,7 +467,9 @@ public void onEvents(Player player, Player.Events events) {
451
467
Player .EVENT_MEDIA_METADATA_CHANGED ,
452
468
Player .EVENT_TIMELINE_CHANGED )) {
453
469
mediaSessionService .onUpdateNotificationInternal (
454
- session , /* startInForegroundWhenPaused= */ false );
470
+ session ,
471
+ /* startInForegroundWhenPaused= */ false ,
472
+ MediaSessionService .NOTIFICATION_UPDATE_PLAYER_EVENT );
455
473
}
456
474
}
457
475
}
0 commit comments