Fixed EmulatedUserHal::get(USER_IDENTIFICATION_ASSOCIATION). am: 1972df27b9 am: cd942acff5 am: 02e8cc070e am: b97720d992
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/interfaces/+/11940099
Change-Id: I1dd65979f7789c0780fa9e9d2b6a873a5836ddb8
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.cpp
index c1db124..8c9ffb9 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.cpp
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.cpp
@@ -71,35 +71,45 @@
}
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) {
ALOGE("set(INITIAL_USER_INFO): no int32values, ignoring it: %s", toString(value).c_str());
@@ -250,16 +260,14 @@
}
// 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(
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.h b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.h
index 5243b96..db2f117 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.h
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.h
@@ -58,7 +58,8 @@
*
* @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 @@
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);
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp
index 9cfcc1c..a0b566d 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp
@@ -153,7 +153,7 @@
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());