Merge "Fixed EmulatedUserHal merge issues." into rvc-qpr-dev

This commit is contained in:
TreeHugger Robot
2020-07-18 05:56:23 +00:00
committed by Android (Google) Code Review
7 changed files with 228 additions and 5 deletions

View File

@@ -1036,6 +1036,22 @@ const ConfigDeclaration kVehicleProperties[]{
.changeMode = VehiclePropertyChangeMode::ON_CHANGE,
},
},
{
.config =
{
.prop = toInt(VehicleProperty::CREATE_USER),
.access = VehiclePropertyAccess::READ_WRITE,
.changeMode = VehiclePropertyChangeMode::ON_CHANGE,
},
},
{
.config =
{
.prop = toInt(VehicleProperty::REMOVE_USER),
.access = VehiclePropertyAccess::READ_WRITE,
.changeMode = VehiclePropertyChangeMode::ON_CHANGE,
},
},
{
.config =
{

View File

@@ -30,11 +30,18 @@ namespace impl {
constexpr int INITIAL_USER_INFO = static_cast<int>(VehicleProperty::INITIAL_USER_INFO);
constexpr int SWITCH_USER = static_cast<int>(VehicleProperty::SWITCH_USER);
constexpr int CREATE_USER = static_cast<int>(VehicleProperty::CREATE_USER);
constexpr int REMOVE_USER = static_cast<int>(VehicleProperty::REMOVE_USER);
constexpr int USER_IDENTIFICATION_ASSOCIATION =
static_cast<int>(VehicleProperty::USER_IDENTIFICATION_ASSOCIATION);
bool EmulatedUserHal::isSupported(int32_t prop) {
switch (prop) {
case INITIAL_USER_INFO:
case SWITCH_USER:
case CREATE_USER:
case REMOVE_USER:
case USER_IDENTIFICATION_ASSOCIATION:
return true;
default:
return false;
@@ -50,12 +57,58 @@ android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onSetP
return onSetInitialUserInfoResponse(value);
case SWITCH_USER:
return onSetSwitchUserResponse(value);
case CREATE_USER:
return onSetCreateUserResponse(value);
case REMOVE_USER:
ALOGI("REMOVE_USER is FYI only, nothing to do...");
return {};
case USER_IDENTIFICATION_ASSOCIATION:
return onSetUserIdentificationAssociation(value);
default:
return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG))
<< "Unsupported property: " << toString(value);
}
}
android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onGetProperty(
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", value.prop);
return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG))
<< "only supported on SET";
case USER_IDENTIFICATION_ASSOCIATION:
return onGetUserIdentificationAssociation(value);
default:
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) {
@@ -144,6 +197,79 @@ android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onSetS
return updatedValue;
}
android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onSetCreateUserResponse(
const VehiclePropValue& value) {
if (value.value.int32Values.size() == 0) {
ALOGE("set(CREATE_USER): no int32values, ignoring it: %s", toString(value).c_str());
return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG))
<< "no int32values on " << toString(value);
}
if (value.areaId != 0) {
ALOGD("set(CREATE_USER) called from lshal; storing it: %s", toString(value).c_str());
mCreateUserResponseFromCmd.reset(new VehiclePropValue(value));
return {};
}
ALOGD("set(CREATE_USER) called from Android: %s", toString(value).c_str());
int32_t requestId = value.value.int32Values[0];
if (mCreateUserResponseFromCmd != nullptr) {
ALOGI("replying CREATE_USER with lshal value: %s",
toString(*mCreateUserResponseFromCmd).c_str());
return sendUserHalResponse(std::move(mCreateUserResponseFromCmd), requestId);
}
// Returns default response
auto updatedValue = std::unique_ptr<VehiclePropValue>(new VehiclePropValue);
updatedValue->prop = CREATE_USER;
updatedValue->timestamp = elapsedRealtimeNano();
updatedValue->value.int32Values.resize(2);
updatedValue->value.int32Values[0] = requestId;
updatedValue->value.int32Values[1] = (int32_t)CreateUserStatus::SUCCESS;
ALOGI("no lshal response; replying with SUCCESS: %s", toString(*updatedValue).c_str());
return updatedValue;
}
android::base::Result<std::unique_ptr<VehiclePropValue>>
EmulatedUserHal::onSetUserIdentificationAssociation(const VehiclePropValue& value) {
if (value.value.int32Values.size() == 0) {
ALOGE("set(USER_IDENTIFICATION_ASSOCIATION): no int32values, ignoring it: %s",
toString(value).c_str());
return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG))
<< "no int32values on " << toString(value);
}
if (value.areaId != 0) {
ALOGD("set(USER_IDENTIFICATION_ASSOCIATION) called from lshal; storing it: %s",
toString(value).c_str());
mSetUserIdentificationAssociationResponseFromCmd.reset(new VehiclePropValue(value));
return {};
}
ALOGD("set(USER_IDENTIFICATION_ASSOCIATION) called from Android: %s", toString(value).c_str());
int32_t requestId = value.value.int32Values[0];
if (mSetUserIdentificationAssociationResponseFromCmd != nullptr) {
ALOGI("replying USER_IDENTIFICATION_ASSOCIATION with lshal value: %s",
toString(*mSetUserIdentificationAssociationResponseFromCmd).c_str());
// Not moving response so it can be used on GET requests
auto copy = std::unique_ptr<VehiclePropValue>(
new VehiclePropValue(*mSetUserIdentificationAssociationResponseFromCmd));
return sendUserHalResponse(std::move(copy), requestId);
}
// Returns default response
return defaultUserIdentificationAssociation(value);
}
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(
std::unique_ptr<VehiclePropValue> response, int32_t requestId) {
switch (response->areaId) {
@@ -189,6 +315,18 @@ void EmulatedUserHal::dump(int fd, std::string indent) {
} else {
dprintf(fd, "%sNo SwitchUser response\n", indent.c_str());
}
if (mCreateUserResponseFromCmd != nullptr) {
dprintf(fd, "%sCreateUser response: %s\n", indent.c_str(),
toString(*mCreateUserResponseFromCmd).c_str());
} else {
dprintf(fd, "%sNo CreateUser response\n", indent.c_str());
}
if (mSetUserIdentificationAssociationResponseFromCmd != nullptr) {
dprintf(fd, "%sSetUserIdentificationAssociation response: %s\n", indent.c_str(),
toString(*mSetUserIdentificationAssociationResponseFromCmd).c_str());
} else {
dprintf(fd, "%sNo SetUserIdentificationAssociation response\n", indent.c_str());
}
}
} // namespace impl

View File

@@ -46,13 +46,21 @@ class EmulatedUserHal {
bool isSupported(int32_t prop);
/**
* Lets the emulator handle the property.
* Lets the emulator set the property.
*
* @return updated property and StatusCode
*/
android::base::Result<std::unique_ptr<VehiclePropValue>> onSetProperty(
const VehiclePropValue& value);
/**
* Gets the property value from the emulator.
*
* @return property value and StatusCode
*/
android::base::Result<std::unique_ptr<VehiclePropValue>> onGetProperty(
const VehiclePropValue& value);
/**
* Shows the User HAL emulation help.
*/
@@ -97,11 +105,39 @@ class EmulatedUserHal {
android::base::Result<std::unique_ptr<VehiclePropValue>> onSetSwitchUserResponse(
const VehiclePropValue& value);
/**
* Used to emulate CREATE_USER - see onSetInitialUserInfoResponse() for usage.
*/
android::base::Result<std::unique_ptr<VehiclePropValue>> onSetCreateUserResponse(
const VehiclePropValue& value);
/**
* 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);
std::unique_ptr<VehiclePropValue> mInitialUserResponseFromCmd;
std::unique_ptr<VehiclePropValue> mSwitchUserResponseFromCmd;
std::unique_ptr<VehiclePropValue> mCreateUserResponseFromCmd;
std::unique_ptr<VehiclePropValue> mSetUserIdentificationAssociationResponseFromCmd;
};
} // namespace impl

View File

@@ -87,12 +87,14 @@ static std::unique_ptr<Obd2SensorStore> fillDefaultObd2Frame(size_t numVendorInt
return sensorStore;
}
EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore, VehicleHalClient* client)
EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore, VehicleHalClient* client,
EmulatedUserHal* emulatedUserHal)
: mPropStore(propStore),
mHvacPowerProps(std::begin(kHvacPowerProperties), std::end(kHvacPowerProperties)),
mRecurrentTimer(std::bind(&EmulatedVehicleHal::onContinuousPropertyTimer, this,
std::placeholders::_1)),
mVehicleClient(client) {
mVehicleClient(client),
mEmulatedUserHal(emulatedUserHal) {
initStaticConfig();
for (size_t i = 0; i < arraysize(kVehicleProperties); i++) {
mPropStore->registerProperty(kVehicleProperties[i].config);
@@ -105,6 +107,8 @@ EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore, VehicleH
VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get(
const VehiclePropValue& requestedPropValue, StatusCode* outStatus) {
auto propId = requestedPropValue.prop;
ALOGV("get(%d)", propId);
auto& pool = *getValuePool();
VehiclePropValuePtr v = nullptr;
@@ -118,6 +122,26 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get(
*outStatus = fillObd2DtcInfo(v.get());
break;
default:
if (mEmulatedUserHal != nullptr && mEmulatedUserHal->isSupported(propId)) {
ALOGI("get(): getting value for prop %d from User HAL", 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());
} else {
auto value = ret.value().get();
if (value != nullptr) {
ALOGI("get(): User HAL returned value: %s", toString(*value).c_str());
v = getValuePool()->obtain(*value);
*outStatus = StatusCode::OK;
} else {
ALOGE("get(): User HAL returned null value");
*outStatus = StatusCode::INTERNAL_ERROR;
}
}
break;
}
auto internalPropValue = mPropStore->readValueOrNull(requestedPropValue);
if (internalPropValue != nullptr) {
v = getValuePool()->obtain(*internalPropValue);

View File

@@ -30,6 +30,7 @@
#include "vhal_v2_0/VehiclePropertyStore.h"
#include "DefaultConfig.h"
#include "EmulatedUserHal.h"
#include "EmulatedVehicleConnector.h"
#include "GeneratorHub.h"
#include "VehicleEmulator.h"
@@ -45,8 +46,8 @@ namespace impl {
/** Implementation of VehicleHal that connected to emulator instead of real vehicle network. */
class EmulatedVehicleHal : public EmulatedVehicleHalIface {
public:
EmulatedVehicleHal(VehiclePropertyStore* propStore,
VehicleHalClient* client);
EmulatedVehicleHal(VehiclePropertyStore* propStore, VehicleHalClient* client,
EmulatedUserHal* emulatedUserHal = nullptr);
~EmulatedVehicleHal() = default;
// Methods from VehicleHal
@@ -86,6 +87,7 @@ private:
std::unordered_set<int32_t> mHvacPowerProps;
RecurrentTimer mRecurrentTimer;
VehicleHalClient* mVehicleClient;
EmulatedUserHal* mEmulatedUserHal;
};
} // impl

View File

@@ -41,6 +41,10 @@ VehiclePropValuePool* VehicleHalServer::getValuePool() const {
return mValuePool;
}
EmulatedUserHal* VehicleHalServer::getEmulatedUserHal() {
return &mEmulatedUserHal;
}
void VehicleHalServer::setValuePool(VehiclePropValuePool* valuePool) {
if (!valuePool) {
LOG(WARNING) << __func__ << ": Setting value pool to nullptr!";
@@ -197,6 +201,7 @@ StatusCode VehicleHalServer::onSetProperty(const VehiclePropValue& value, bool u
}
return StatusCode::OK;
}
LOG(DEBUG) << "onSetProperty(" << value.prop << ")";
// Some properties need to be treated non-trivially
switch (value.prop) {

View File

@@ -38,6 +38,8 @@ class VehicleHalServer : public IVehicleServer {
// Set the Property Value Pool used in this server
void setValuePool(VehiclePropValuePool* valuePool);
EmulatedUserHal* getEmulatedUserHal();
private:
using VehiclePropValuePtr = recyclable_ptr<VehiclePropValue>;