Added user hal check in CarUserService if Hal is supported
Bug: 157938045
Test: atest CarServiceUnitTest:com.android.car.user.CarUserManagerUnitTest
Test: atest CarServiceUnitTest:com.android.car.hal.UserHalServiceTest
Test: atest CarServiceUnitTest:com.android.car.user.CarUserServiceTest
Change-Id: Iec42c4e8558ed00efd14771915f86a350cd26be4
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java
index 8e08b28..b9c54a0 100644
--- a/service/src/com/android/car/user/CarUserService.java
+++ b/service/src/com/android/car/user/CarUserService.java
@@ -134,6 +134,8 @@
public static final String BUNDLE_INITIAL_INFO_ACTION =
CarUserServiceConstants.BUNDLE_INITIAL_INFO_ACTION;
+ public static final String VEHICLE_HAL_NOT_SUPPORTED = "Vehicle Hal not supported.";
+
private final Context mContext;
private final CarUserManagerHelper mCarUserManagerHelper;
private final IActivityManager mAm;
@@ -627,6 +629,10 @@
timeoutMs);
Objects.requireNonNull(receiver, "receiver cannot be null");
checkManageUsersPermission("getInitialInfo");
+ if (!isUserHalSupported()) {
+ sendResult(receiver, HalCallback.STATUS_HAL_NOT_SUPPORTED, null);
+ return;
+ }
UsersInfo usersInfo = UserHalHelper.newUsersInfo(mUserManager);
mHal.getInitialUserInfo(requestType, timeoutMs, usersInfo, (status, resp) -> {
Bundle resultData = null;
@@ -729,6 +735,10 @@
mHalTimeoutMs);
Objects.requireNonNull(callback, "callback cannot be null");
checkManageUsersPermission("getInitialUserInfo");
+ if (!isUserHalSupported()) {
+ callback.onResponse(HalCallback.STATUS_HAL_NOT_SUPPORTED, null);
+ return;
+ }
UsersInfo usersInfo = UserHalHelper.newUsersInfo(mUserManager);
mHal.getInitialUserInfo(requestType, mHalTimeoutMs, usersInfo, callback);
}
@@ -790,6 +800,22 @@
return;
}
+ // If User Hal is not supported, just android user switch.
+ if (!isUserHalSupported()) {
+ try {
+ if (mAm.switchUser(targetUserId)) {
+ sendUserSwitchResult(receiver, UserSwitchResult.STATUS_SUCCESSFUL);
+ return;
+ }
+ } catch (RemoteException e) {
+ // ignore
+ Log.w(TAG_USER,
+ "error while switching user " + targetUser.toFullString(), e);
+ }
+ sendUserSwitchResult(receiver, UserSwitchResult.STATUS_ANDROID_FAILURE);
+ return;
+ }
+
synchronized (mLockUser) {
if (Log.isLoggable(TAG_USER, Log.DEBUG)) {
Log.d(TAG_USER, "switchUser(" + targetUserId + "): currentuser=" + currentUser
@@ -937,10 +963,13 @@
return logAndGetResults(userId, UserRemovalResult.STATUS_ANDROID_FAILURE);
}
- RemoveUserRequest request = new RemoveUserRequest();
- request.removedUserInfo = halUser;
- request.usersInfo = usersInfo;
- mHal.removeUser(request);
+ if (isUserHalSupported()) {
+ RemoveUserRequest request = new RemoveUserRequest();
+ request.removedUserInfo = halUser;
+ request.usersInfo = usersInfo;
+ mHal.removeUser(request);
+ }
+
return logAndGetResults(userId, UserRemovalResult.STATUS_SUCCESSFUL);
}
@@ -994,6 +1023,11 @@
return;
}
+ if (!isUserHalSupported()) {
+ sendUserCreationResult(receiver, UserCreationResult.STATUS_SUCCESSFUL, newUser, null);
+ return;
+ }
+
CreateUserRequest request = new CreateUserRequest();
request.usersInfo = UserHalHelper.newUsersInfo(mUserManager);
if (!TextUtils.isEmpty(name)) {
@@ -1066,6 +1100,10 @@
@Override
public UserIdentificationAssociationResponse getUserIdentificationAssociation(int[] types) {
+ if (!isUserHalUserAssociationSupported()) {
+ return UserIdentificationAssociationResponse.forFailure(VEHICLE_HAL_NOT_SUPPORTED);
+ }
+
Preconditions.checkArgument(!ArrayUtils.isEmpty(types), "must have at least one type");
checkManageUsersPermission("getUserIdentificationAssociation");
@@ -1101,6 +1139,12 @@
@Override
public void setUserIdentificationAssociation(int timeoutMs, int[] types, int[] values,
AndroidFuture<UserIdentificationAssociationResponse> result) {
+ if (!isUserHalUserAssociationSupported()) {
+ result.complete(
+ UserIdentificationAssociationResponse.forFailure(VEHICLE_HAL_NOT_SUPPORTED));
+ return;
+ }
+
Preconditions.checkArgument(!ArrayUtils.isEmpty(types), "must have at least one type");
Preconditions.checkArgument(!ArrayUtils.isEmpty(values), "must have at least one value");
if (types.length != values.length) {
@@ -1246,7 +1290,10 @@
mRequestIdForUserSwitchInProcess = requestId;
}
}
+
private void postSwitchHalResponse(int requestId, @UserIdInt int targetUserId) {
+ if (!isUserHalSupported()) return;
+
UsersInfo usersInfo = UserHalHelper.newUsersInfo(mUserManager);
EventLog.writeEvent(EventLogTags.CAR_USER_SVC_POST_SWITCH_USER_REQ, requestId,
targetUserId, usersInfo.currentUser.userId);
@@ -1276,6 +1323,14 @@
}
/**
+ * Checks if the User HAL user association is supported.
+ */
+ @Override
+ public boolean isUserHalUserAssociationSupported() {
+ return mHal.isUserAssociationSupported();
+ }
+
+ /**
* Sets a callback which is invoked before user switch.
*
* <p>
@@ -1655,6 +1710,8 @@
}
}
+ if (!isUserHalSupported()) return;
+
// switch HAL user
UsersInfo usersInfo = UserHalHelper.newUsersInfo(mUserManager, fromUserId);
SwitchUserRequest request = createUserSwitchRequest(toUserId, usersInfo);