Add previous user id to data sent to UserLifecycleListener
Bug: 153897790
Test: m -j && adb sync && atest
CtsCarTestCases: android.car.cts.CarUserManagerTest -c
Change-Id: Iece35782bb43b229c9abd11c9a8ca397202fb22c
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java
index 6f0e714..b950369 100644
--- a/service/src/com/android/car/user/CarUserService.java
+++ b/service/src/com/android/car/user/CarUserService.java
@@ -1050,7 +1050,7 @@
}
// ...then notify listeners.
- UserLifecycleEvent event = new UserLifecycleEvent(eventType, userId);
+ UserLifecycleEvent event = new UserLifecycleEvent(eventType, fromUserId, userId);
mHandler.post(() -> {
handleNotifyServiceUserLifecycleListeners(event);
@@ -1102,8 +1102,12 @@
IResultReceiver listener = mAppLifecycleListeners.valueAt(i);
Bundle data = new Bundle();
data.putInt(CarUserManager.BUNDLE_PARAM_ACTION, event.getEventType());
- // TODO(b/144120654): should pass currentId from CarServiceHelperService so it
- // can set BUNDLE_PARAM_PREVIOUS_USER_ID (and unit test it)
+
+ int fromUid = event.getPreviousUserId();
+ if (fromUid != UserHandle.USER_NULL) {
+ data.putInt(CarUserManager.BUNDLE_PARAM_PREVIOUS_USER_ID, fromUid);
+ }
+
if (Log.isLoggable(TAG_USER, Log.DEBUG)) {
Log.d(TAG_USER, "Notifying listener for uid " + uid);
}