@@ -286,24 +286,36 @@ public void onBugreportFailed(Context context, Intent intent, int failureCode) {
286
286
@ TargetApi (Build .VERSION_CODES .O )
287
287
@ Override
288
288
public void onUserAdded (Context context , Intent intent , UserHandle newUser ) {
289
- UserManager userManager = (UserManager ) context .getSystemService (Context .USER_SERVICE );
290
- String message = context .getString (R .string .on_user_added_message ,
291
- userManager .getSerialNumberForUser (newUser ));
292
- Log .i (TAG , message );
293
- NotificationUtil .showNotification (context , R .string .on_user_added_title ,
294
- message ,
295
- NotificationUtil .USER_ADDED_NOTIFICATION_ID );
289
+ handleUserAction (context , newUser , R .string .on_user_added_title ,
290
+ R .string .on_user_added_message , NotificationUtil .USER_ADDED_NOTIFICATION_ID );
296
291
}
297
292
298
293
@ TargetApi (Build .VERSION_CODES .O )
299
294
@ Override
300
295
public void onUserRemoved (Context context , Intent intent , UserHandle removedUser ) {
301
- UserManager userManager = (UserManager ) context .getSystemService (Context .USER_SERVICE );
302
- String message = context .getString (R .string .on_user_removed_message ,
303
- userManager .getSerialNumberForUser (removedUser ));
304
- Log .i (TAG , message );
305
- NotificationUtil .showNotification (context , R .string .on_user_removed_title , message ,
306
- NotificationUtil .USER_REMOVED_NOTIFICATION_ID );
296
+ handleUserAction (context , removedUser , R .string .on_user_removed_title ,
297
+ R .string .on_user_removed_message , NotificationUtil .USER_REMOVED_NOTIFICATION_ID );
298
+ }
299
+
300
+ @ TargetApi (Build .VERSION_CODES .P )
301
+ @ Override
302
+ public void onUserStarted (Context context , Intent intent , UserHandle startedUser ) {
303
+ handleUserAction (context , startedUser , R .string .on_user_started_title ,
304
+ R .string .on_user_started_message , NotificationUtil .USER_STARTED_NOTIFICATION_ID );
305
+ }
306
+
307
+ @ TargetApi (Build .VERSION_CODES .P )
308
+ @ Override
309
+ public void onUserStopped (Context context , Intent intent , UserHandle stoppedUser ) {
310
+ handleUserAction (context , stoppedUser , R .string .on_user_stopped_title ,
311
+ R .string .on_user_stopped_message , NotificationUtil .USER_STOPPED_NOTIFICATION_ID );
312
+ }
313
+
314
+ @ TargetApi (Build .VERSION_CODES .P )
315
+ @ Override
316
+ public void onUserSwitched (Context context , Intent intent , UserHandle switchedUser ) {
317
+ handleUserAction (context , switchedUser , R .string .on_user_switched_title ,
318
+ R .string .on_user_switched_message , NotificationUtil .USER_SWITCHED_NOTIFICATION_ID );
307
319
}
308
320
309
321
@ TargetApi (Build .VERSION_CODES .M )
@@ -636,4 +648,13 @@ public void onTransferAffiliatedProfileOwnershipComplete(Context context, UserHa
636
648
context .getString (R .string .transfer_ownership_affiliated_complete_message , user ),
637
649
NotificationUtil .TRANSFER_AFFILIATED_PROFILE_OWNERSHIP_COMPLETE_ID );
638
650
}
651
+
652
+ private void handleUserAction (Context context , UserHandle userHandle , int titleResId ,
653
+ int messageResId , int notificationId ) {
654
+ UserManager userManager = (UserManager ) context .getSystemService (Context .USER_SERVICE );
655
+ String message = context .getString (messageResId ,
656
+ userManager .getSerialNumberForUser (userHandle ));
657
+ Log .i (TAG , message );
658
+ NotificationUtil .showNotification (context , titleResId , message , notificationId );
659
+ }
639
660
}
0 commit comments