Implement POST SWITCH with LEGACY_ANDROID_SWITCH
Bug: 154720740
Test: atest CarServiceUnitTest:com.android.car.user.CarUserServiceTest
Test: atest CarServiceUnitTest:com.android.car.hal.UserHalServiceTest
Change-Id: Ie5754376117d89da4100bc10802798b5d2dc18ae
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java
index f193815..e708b24 100644
--- a/service/src/com/android/car/user/CarUserService.java
+++ b/service/src/com/android/car/user/CarUserService.java
@@ -939,6 +939,11 @@
// shouldn't happen
throw new IllegalStateException("Could not get current user: ", e);
}
+ return getUsersInfo(currentUser);
+ }
+
+ // TODO(b/144120654): use helper to generate UsersInfo
+ private UsersInfo getUsersInfo(@NonNull UserInfo currentUser) {
List<UserInfo> existingUsers = mUserManager.getUsers();
int size = existingUsers.size();
@@ -1150,7 +1155,7 @@
// Handle special cases first...
if (eventType == CarUserManager.USER_LIFECYCLE_EVENT_TYPE_SWITCHING) {
- onUserSwitching(userId);
+ onUserSwitching(fromUserId, toUserId);
} else if (eventType == CarUserManager.USER_LIFECYCLE_EVENT_TYPE_UNLOCKED) {
onUserUnlocked(userId);
}
@@ -1257,24 +1262,43 @@
t.traceEnd(); // notify-listeners-user-USERID-event-EVENT_TYPE
}
- private void onUserSwitching(@UserIdInt int userId) {
- Log.i(TAG_USER, "onSwitchUser() callback for user " + userId);
+ private void onUserSwitching(@UserIdInt int fromUserId, @UserIdInt int toUserId) {
+ Log.i(TAG_USER, "onSwitchUser() callback for user " + toUserId);
TimingsTraceLog t = new TimingsTraceLog(TAG_USER, Trace.TRACE_TAG_SYSTEM_SERVER);
- t.traceBegin("onUserSwitching-" + userId);
+ t.traceBegin("onUserSwitching-" + toUserId);
- if (!isSystemUser(userId)) {
- mCarUserManagerHelper.setLastActiveUser(userId);
+ // Switch HAL users if user switch is not requested by CarUserService
+ notifyHalLegacySwitch(fromUserId, toUserId);
+
+ if (!isSystemUser(toUserId)) {
+ mCarUserManagerHelper.setLastActiveUser(toUserId);
}
if (mLastPassengerId != UserHandle.USER_NULL) {
stopPassengerInternal(mLastPassengerId, false);
}
if (mEnablePassengerSupport && isPassengerDisplayAvailable()) {
setupPassengerUser();
- startFirstPassenger(userId);
+ startFirstPassenger(toUserId);
}
t.traceEnd();
}
+ private void notifyHalLegacySwitch(@UserIdInt int fromUserId, @UserIdInt int toUserId) {
+ synchronized (mLockUser) {
+ if (mUserIdForUserSwitchInProcess != UserHandle.USER_NULL) return;
+ }
+
+ // switch HAL user
+ UserInfo targetUser = mUserManager.getUserInfo(toUserId);
+ android.hardware.automotive.vehicle.V2_0.UserInfo halTargetUser =
+ new android.hardware.automotive.vehicle.V2_0.UserInfo();
+ halTargetUser.userId = targetUser.id;
+ halTargetUser.flags = UserHalHelper.convertFlags(targetUser);
+ UserInfo currentUser = mUserManager.getUserInfo(fromUserId);
+ UsersInfo usersInfo = getUsersInfo(currentUser);
+ mHal.legacyUserSwitch(halTargetUser, usersInfo);
+ }
+
/**
* Runs the given runnable when user 0 is unlocked. If user 0 is already unlocked, it is
* run inside this call.