From 1972df27b9576b3aa41ffc842352446203f5fd7e Mon Sep 17 00:00:00 2001 From: felipeal Date: Fri, 19 Jun 2020 18:03:54 -0700 Subject: [PATCH] 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 --- .../impl/vhal_v2_0/EmulatedUserHal.cpp | 56 +++++++++++-------- .../default/impl/vhal_v2_0/EmulatedUserHal.h | 18 +++++- .../impl/vhal_v2_0/EmulatedVehicleHal.cpp | 2 +- 3 files changed, 49 insertions(+), 27 deletions(-) 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 2c2f23c4c6..ea38cb3941 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,34 +71,44 @@ android::base::Result> EmulatedUserHal::onSetP } android::base::Result> 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(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( - new VehiclePropValue(*mSetUserIdentificationAssociationResponseFromCmd)); - return value; - } - ALOGE("onGetProperty(%d): USER_IDENTIFICATION_ASSOCIATION not set by lshal", prop); - return android::base::Error(static_cast(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(StatusCode::INVALID_ARG)) << "not supported by User HAL"; } } +android::base::Result> +EmulatedUserHal::onGetUserIdentificationAssociation(const VehiclePropValue& value) { + if (mSetUserIdentificationAssociationResponseFromCmd != nullptr) { + ALOGI("get(USER_IDENTIFICATION_ASSOCIATION): returning %s", + toString(*mSetUserIdentificationAssociationResponseFromCmd).c_str()); + auto newValue = std::unique_ptr( + 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> 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(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> +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(StatusCode::NOT_AVAILABLE)) << "not set by lshal"; } android::base::Result> 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 5243b969d8..db2f117e3e 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 @@ class EmulatedUserHal { * * @return property value and StatusCode */ - android::base::Result> onGetProperty(int32_t prop); + android::base::Result> 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> onSetUserIdentificationAssociation( const VehiclePropValue& value); + /** + * Used to emulate get USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for + * usage. + */ + android::base::Result> onGetUserIdentificationAssociation( + const VehiclePropValue& value); + + /** + * Creates a default USER_IDENTIFICATION_ASSOCIATION when it was not set by lshal. + */ + android::base::Result> defaultUserIdentificationAssociation( + const VehiclePropValue& request); + android::base::Result> sendUserHalResponse( std::unique_ptr 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 9cfcc1c605..a0b566d1ee 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 @@ 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());