Fixed EmulatedUserHal::get(USER_IDENTIFICATION_ASSOCIATION).

It must set the requestId in the response.

Test: adb shell lshal debug android.hardware.automotive.vehicle@2.0::IVehicle/default --set 299896587 a 1 i 666 i 1 i 1 i 2 && \
      adb shell cmd car_service get-user-auth-association --hal-only KEY_FOB
Fixes: 159497444
Bug: 159498909

Change-Id: Ib3f87b45714883c3e5b72464813df24ec4124dbb
This commit is contained in:
felipeal
2020-06-19 18:03:54 -07:00
parent 5f86b51408
commit 1972df27b9
3 changed files with 49 additions and 27 deletions

View File

@@ -71,34 +71,44 @@ android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onSetP
}
android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onGetProperty(
int32_t prop) {
ALOGV("onGetProperty(%d)", prop);
switch (prop) {
const VehiclePropValue& value) {
ALOGV("onGetProperty(%s)", toString(value).c_str());
switch (value.prop) {
case INITIAL_USER_INFO:
case SWITCH_USER:
case CREATE_USER:
case REMOVE_USER:
ALOGE("onGetProperty(): %d is only supported on SET", prop);
ALOGE("onGetProperty(): %d is only supported on SET", value.prop);
return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG))
<< "only supported on SET";
case USER_IDENTIFICATION_ASSOCIATION:
if (mSetUserIdentificationAssociationResponseFromCmd != nullptr) {
ALOGI("onGetProperty(%d): returning %s", prop,
toString(*mSetUserIdentificationAssociationResponseFromCmd).c_str());
auto value = std::unique_ptr<VehiclePropValue>(
new VehiclePropValue(*mSetUserIdentificationAssociationResponseFromCmd));
return value;
}
ALOGE("onGetProperty(%d): USER_IDENTIFICATION_ASSOCIATION not set by lshal", prop);
return android::base::Error(static_cast<int>(StatusCode::NOT_AVAILABLE))
<< "not set by lshal";
return onGetUserIdentificationAssociation(value);
default:
ALOGE("onGetProperty(): %d is not supported", prop);
ALOGE("onGetProperty(): %d is not supported", value.prop);
return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG))
<< "not supported by User HAL";
}
}
android::base::Result<std::unique_ptr<VehiclePropValue>>
EmulatedUserHal::onGetUserIdentificationAssociation(const VehiclePropValue& value) {
if (mSetUserIdentificationAssociationResponseFromCmd != nullptr) {
ALOGI("get(USER_IDENTIFICATION_ASSOCIATION): returning %s",
toString(*mSetUserIdentificationAssociationResponseFromCmd).c_str());
auto newValue = std::unique_ptr<VehiclePropValue>(
new VehiclePropValue(*mSetUserIdentificationAssociationResponseFromCmd));
// Must use the same requestId
if (value.value.int32Values.size() > 0) {
newValue->value.int32Values[0] = value.value.int32Values[0];
} else {
ALOGE("get(USER_IDENTIFICATION_ASSOCIATION): no requestId on %s",
toString(value).c_str());
}
return newValue;
}
return defaultUserIdentificationAssociation(value);
}
android::base::Result<std::unique_ptr<VehiclePropValue>>
EmulatedUserHal::onSetInitialUserInfoResponse(const VehiclePropValue& value) {
if (value.value.int32Values.size() == 0) {
@@ -250,16 +260,14 @@ EmulatedUserHal::onSetUserIdentificationAssociation(const VehiclePropValue& valu
}
// Returns default response
auto updatedValue = std::unique_ptr<VehiclePropValue>(new VehiclePropValue);
updatedValue->prop = USER_IDENTIFICATION_ASSOCIATION;
updatedValue->timestamp = elapsedRealtimeNano();
updatedValue->value.int32Values.resize(1);
updatedValue->value.int32Values[0] = requestId;
updatedValue->value.stringValue = "Response not set by LSHAL";
return defaultUserIdentificationAssociation(value);
}
ALOGI("no lshal response; replying with an error message: %s", toString(*updatedValue).c_str());
return updatedValue;
android::base::Result<std::unique_ptr<VehiclePropValue>>
EmulatedUserHal::defaultUserIdentificationAssociation(const VehiclePropValue& request) {
// TODO(b/159498909): return a response with NOT_ASSOCIATED_ANY_USER for all requested types
ALOGE("no lshal response for %s; replying with NOT_AVAILABLE", toString(request).c_str());
return android::base::Error(static_cast<int>(StatusCode::NOT_AVAILABLE)) << "not set by lshal";
}
android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::sendUserHalResponse(

View File

@@ -58,7 +58,8 @@ class EmulatedUserHal {
*
* @return property value and StatusCode
*/
android::base::Result<std::unique_ptr<VehiclePropValue>> onGetProperty(int32_t prop);
android::base::Result<std::unique_ptr<VehiclePropValue>> onGetProperty(
const VehiclePropValue& value);
/**
* Shows the User HAL emulation help.
@@ -111,12 +112,25 @@ class EmulatedUserHal {
const VehiclePropValue& value);
/**
* Used to emulate USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for
* Used to emulate set USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for
* usage.
*/
android::base::Result<std::unique_ptr<VehiclePropValue>> onSetUserIdentificationAssociation(
const VehiclePropValue& value);
/**
* Used to emulate get USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for
* usage.
*/
android::base::Result<std::unique_ptr<VehiclePropValue>> onGetUserIdentificationAssociation(
const VehiclePropValue& value);
/**
* Creates a default USER_IDENTIFICATION_ASSOCIATION when it was not set by lshal.
*/
android::base::Result<std::unique_ptr<VehiclePropValue>> defaultUserIdentificationAssociation(
const VehiclePropValue& request);
android::base::Result<std::unique_ptr<VehiclePropValue>> sendUserHalResponse(
std::unique_ptr<VehiclePropValue> response, int32_t requestId);

View File

@@ -153,7 +153,7 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get(
default:
if (mEmulatedUserHal != nullptr && mEmulatedUserHal->isSupported(propId)) {
ALOGI("get(): getting value for prop %d from User HAL", propId);
const auto& ret = mEmulatedUserHal->onGetProperty(propId);
const auto& ret = mEmulatedUserHal->onGetProperty(requestedPropValue);
if (!ret.ok()) {
ALOGE("get(): User HAL returned error: %s", ret.error().message().c_str());
*outStatus = StatusCode(ret.error().code());