Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4d4556aa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Implemented SWITCH_USER in the emulated User HAL." into rvc-dev am: 5a869716

Change-Id: I94ff3ceec6ae85b25ea5f9f89526713f896cccb8
parents 1e63f783 5a869716
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ constexpr int WHEEL_FRONT_RIGHT = (int)VehicleAreaWheel::RIGHT_FRONT;
constexpr int WHEEL_REAR_LEFT = (int)VehicleAreaWheel::LEFT_REAR;
constexpr int WHEEL_REAR_RIGHT = (int)VehicleAreaWheel::RIGHT_REAR;
constexpr int INITIAL_USER_INFO = (int)VehicleProperty::INITIAL_USER_INFO;
constexpr int SWITCH_USER = (int)VehicleProperty::SWITCH_USER;

/**
 * This property is used for test purpose to generate fake events. Here is the test package that
@@ -1019,6 +1020,14 @@ const ConfigDeclaration kVehicleProperties[]{
                                .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
                        },
        },
        {
                .config =
                        {
                                .prop = toInt(VehicleProperty::SWITCH_USER),
                                .access = VehiclePropertyAccess::READ_WRITE,
                                .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
                        },
        },
};

}  // impl
+8 −2
Original line number Diff line number Diff line
@@ -73,10 +73,16 @@ bool EmulatedPassthroughConnector::onDump(const hidl_handle& handle,

void EmulatedPassthroughConnector::dumpUserHal(int fd, std::string indent) {
    if (mInitialUserResponseFromCmd != nullptr) {
        dprintf(fd, "%sInitial User Info: %s\n", indent.c_str(),
        dprintf(fd, "%sInitialUserInfo response: %s\n", indent.c_str(),
                toString(*mInitialUserResponseFromCmd).c_str());
    } else {
        dprintf(fd, "%sNo Initial User Info\n", indent.c_str());
        dprintf(fd, "%sNo InitialUserInfo response\n", indent.c_str());
    }
    if (mSwitchUserResponseFromCmd != nullptr) {
        dprintf(fd, "%sSwitchUser response: %s\n", indent.c_str(),
                toString(*mSwitchUserResponseFromCmd).c_str());
    } else {
        dprintf(fd, "%sNo SwitchUser response\n", indent.c_str());
    }
}

+77 −4
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 */

#define LOG_TAG "VehicleHalServer"

#include "VehicleHalServer.h"

#include <fstream>
@@ -244,7 +246,9 @@ StatusCode VehicleHalServer::onSetProperty(const VehiclePropValue& value, bool u
            }
            break;
        case INITIAL_USER_INFO:
            return onSetInitialUserInfo(value, updateStatus);
            return onSetInitialUserInfoResponse(value, updateStatus);
        case SWITCH_USER:
            return onSetSwitchUserResponse(value, updateStatus);
        default:
            break;
    }
@@ -282,7 +286,7 @@ StatusCode VehicleHalServer::onSetProperty(const VehiclePropValue& value, bool u
 * - if it's 3, then don't send a property change (so Android can emulate a timeout)
 *
 */
StatusCode VehicleHalServer::onSetInitialUserInfo(const VehiclePropValue& value,
StatusCode VehicleHalServer::onSetInitialUserInfoResponse(const VehiclePropValue& value,
                                                          bool updateStatus) {
    // TODO: LOG calls below might be more suited to be DEBUG, but those are not being logged
    // (even when explicitly calling setprop log.tag. As this class should be using ALOG instead of
@@ -320,7 +324,7 @@ StatusCode VehicleHalServer::onSetInitialUserInfo(const VehiclePropValue& value,
    // mInitialUserResponseFromCmd is used for just one request
    std::unique_ptr<VehiclePropValue> response = std::move(mInitialUserResponseFromCmd);

    // TODO(b/138709788): rather than populate the raw values directly, it should use the
    // TODO(b/150409377): rather than populate the raw values directly, it should use the
    // libraries that convert a InitialUserInfoResponse into a VehiclePropValue)

    switch (response->areaId) {
@@ -350,4 +354,73 @@ StatusCode VehicleHalServer::onSetInitialUserInfo(const VehiclePropValue& value,
    return StatusCode::OK;
}

/**
 * Used to emulate SWITCH_USER - see onSetInitialUserInfoResponse() for usage.
 */
StatusCode VehicleHalServer::onSetSwitchUserResponse(const VehiclePropValue& value,
                                                     bool updateStatus) {
    if (value.value.int32Values.size() == 0) {
        LOG(ERROR) << "set(SWITCH_USER): no int32values, ignoring it: " << toString(value);
        return StatusCode::INVALID_ARG;
    }

    if (value.areaId != 0) {
        LOG(INFO) << "set(SWITCH_USER) called from lshal; storing it: " << toString(value);
        mSwitchUserResponseFromCmd.reset(new VehiclePropValue(value));
        return StatusCode::OK;
    }
    LOG(INFO) << "set(SWITCH_USER) called from Android: " << toString(value);

    int32_t requestId = value.value.int32Values[0];

    // Create the update property and set common values
    auto updatedValue = createVehiclePropValue(VehiclePropertyType::MIXED, 0);
    updatedValue->prop = SWITCH_USER;
    updatedValue->timestamp = elapsedRealtimeNano();

    if (mSwitchUserResponseFromCmd == nullptr) {
        updatedValue->value.int32Values.resize(3);
        updatedValue->value.int32Values[0] = requestId;
        updatedValue->value.int32Values[1] = (int32_t)SwitchUserMessageType::VEHICLE_RESPONSE;
        updatedValue->value.int32Values[2] = (int32_t)SwitchUserStatus::SUCCESS;
        LOG(INFO) << "no lshal response; returning VEHICLE_RESPONSE / SUCCESS: "
                  << toString(*updatedValue);
        onPropertyValueFromCar(*updatedValue, updateStatus);
        return StatusCode::OK;
    }

    // mSwitchUserResponseFromCmd is used for just one request
    std::unique_ptr<VehiclePropValue> response = std::move(mSwitchUserResponseFromCmd);

    // TODO(b/150409377): move code below to a local function like sendUserHalResponse(),
    // as it's the same for all (like onSetInitialUserInfoResponse)

    switch (response->areaId) {
        case 1:
            LOG(INFO) << "returning response with right request id";
            *updatedValue = *response;
            updatedValue->areaId = 0;
            updatedValue->value.int32Values[0] = requestId;
            break;
        case 2:
            LOG(INFO) << "returning response with wrong request id";
            *updatedValue = *response;
            updatedValue->areaId = 0;
            updatedValue->value.int32Values[0] = -requestId;
            break;
        case 3:
            LOG(INFO) << "not generating a property change event because of lshal prop: "
                      << toString(*response);
            return StatusCode::OK;
        default:
            LOG(ERROR) << "invalid action on lshal response: " << toString(*response);
            return StatusCode::INTERNAL_ERROR;
    }

    LOG(INFO) << "updating property to: " << toString(*updatedValue);
    onPropertyValueFromCar(*updatedValue, updateStatus);

    return StatusCode::OK;
}

}  // namespace android::hardware::automotive::vehicle::V2_0::impl
+4 −2
Original line number Diff line number Diff line
@@ -53,13 +53,15 @@ class VehicleHalServer : public IVehicleServer {
    VehiclePropValuePtr createHwInputKeyProp(VehicleHwKeyInputAction action, int32_t keyCode,
                                             int32_t targetDisplay);

    StatusCode onSetInitialUserInfo(const VehiclePropValue& value, bool updateStatus);
    StatusCode onSetInitialUserInfoResponse(const VehiclePropValue& value, bool updateStatus);
    StatusCode onSetSwitchUserResponse(const VehiclePropValue& value, bool updateStatus);

    // data members

  protected:
    // TODO(b/146207078): it might be clearer to move members below to an EmulatedUserHal class
    std::unique_ptr<VehiclePropValue> mInitialUserResponseFromCmd;
    std::unique_ptr<VehiclePropValue> mSwitchUserResponseFromCmd;

  private:
    GeneratorHub mGeneratorHub{