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

Commit 4ae948a5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Vehicle HAL reference impl Part I"

parents 4bc95f1d e2603e3d
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -64,11 +64,11 @@ interface IVehicle {
   * Clients must be able to subscribe to multiple properties at a time
   * depending on data provided in options argument.
   *
   * @param listener This client must be called on aproperiate event.
   * @param listener This client must be called on appropriate event.
   * @param options List of options to subscribe. SubscribeOption contains
   *                information such as propery Id, area Id, sample rate, etc.
   *                information such as property Id, area Id, sample rate, etc.
   */
  subscribe(IVehicleCallback listener, vec<SubscribeOptions> options)
  subscribe(IVehicleCallback callback, vec<SubscribeOptions> options)
          generates (StatusCode status);

  /**
@@ -77,7 +77,8 @@ interface IVehicle {
   * If this client wasn't subscribed to the given property, this method
   * must return StatusCode::INVALID_ARGUMENT.
   */
  unsubscribe(VehicleProperty propId) generates (StatusCode status);
  unsubscribe(IVehicleCallback callback, VehicleProperty propId)
          generates (StatusCode status);

  /**
   * Print out debugging state for the vehicle hal.
@@ -91,7 +92,7 @@ interface IVehicle {
   * primitives used (such as mutex locks or semaphores) must be acquired
   * with a timeout.
   *
   * TODO(pavelm): we cannot use handle here due to Java compatability, it's
   * TODO(pavelm): we cannot use handle here due to Java compatibility, it's
   * better to pass file descriptor and write debug data directly in vehicle HAL
   * rather than passing back a string.
   */
+5 −5
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ interface IVehicleCallback {
     *
     * @param values that has been updated.
     */
    onPropertyEvent(vec<VehiclePropValue> propValues);
    oneway onPropertyEvent(vec<VehiclePropValue> propValues);

    /*
     * This method gets called if the client was susbscribed to a property using
@@ -40,7 +40,7 @@ interface IVehicleCallback {
     *
     * @param value Value that was set by a client.
     */
    onPropertySet(VehiclePropValue propValue);
    oneway onPropertySet(VehiclePropValue propValue);

    /*
     * Called by HAL server when error condition has occurred.
@@ -50,7 +50,7 @@ interface IVehicleCallback {
     * a generic error, this value should be VehicleProperty::INVALID.
     * @param operation Represent the operation where the error has happened.
     */
    onError(StatusCode errorCode,
    oneway onError(StatusCode errorCode,
                   VehicleProperty propId,
                   VehiclePropertyOperation operation);
};
+71 −8
Original line number Diff line number Diff line
@@ -14,29 +14,92 @@

LOCAL_PATH := $(call my-dir)

module_prefix = android.hardware.vehicle@2.0

###############################################################################
# Vehicle reference implementation lib
###############################################################################
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.vehicle@2.0-impl
# TODO(pavelm): add LOCAL_INIT_RC
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_MODULE := $(module_prefix)-manager-lib
LOCAL_SRC_FILES := \
    vehicle_hal_manager/SubscriptionManager.cpp \
    vehicle_hal_manager/VehicleHalManager.cpp \
    vehicle_hal_manager/VehicleCallback.cpp \

LOCAL_SHARED_LIBRARIES := \
    liblog \
    libbinder \
    libhidl \
    libhwbinder \
    libutils \
    $(module_prefix) \

include $(BUILD_STATIC_LIBRARY)

###############################################################################
# Vehicle default VehicleHAL implementation
###############################################################################
include $(CLEAR_VARS)

LOCAL_MODULE:= $(module_prefix)-default-impl-lib
LOCAL_SRC_FILES:= \
    impl/DefaultVehicleHal.cpp \

LOCAL_SHARED_LIBRARIES := \
    liblog \
    libbinder \
    libhidl \
    libhwbinder \
    libutils \
    $(module_prefix) \

include $(BUILD_STATIC_LIBRARY)


###############################################################################
# Vehicle reference implementation unit tests
###############################################################################
include $(CLEAR_VARS)

LOCAL_MODULE:= $(module_prefix)-manager-unit-tests

LOCAL_WHOLE_STATIC_LIBRARIES := $(module_prefix)-manager-lib

LOCAL_SRC_FILES:= \
    Vehicle.cpp \
    VehicleCallback.cpp \
    tests/VehicleObjectPool_test.cpp \
    tests/VehiclePropConfigIndex_test.cpp \
    tests/SubscriptionManager_test.cpp \
    tests/VehicleHalManager_test.cpp \

LOCAL_SHARED_LIBRARIES := \
    liblog \
    libbinder \
    libhidl \
    libhwbinder \
    libutils \
    android.hardware.vehicle@2.0 \
    $(module_prefix) \

include $(BUILD_SHARED_LIBRARY)
LOCAL_CFLAGS += -Wall -Wextra
LOCAL_MODULE_TAGS := tests

include $(BUILD_NATIVE_TEST)


###############################################################################
# Vehicle HAL service
###############################################################################
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.vehicle@2.0-service
LOCAL_MODULE := $(module_prefix)-service
LOCAL_MODULE_RELATIVE_PATH := hw
# TODO(pavelm): add LOCAL_INIT_RC

LOCAL_SRC_FILES := \
    VehicleService.cpp

LOCAL_WHOLE_STATIC_LIBRARIES := \
    $(module_prefix)-manager-lib \
    $(module_prefix)-default-impl-lib \

LOCAL_SHARED_LIBRARIES := \
    liblog \
    libbinder \
+115 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef android_hardware_vehicle_V2_0_VehicleHal_H_
#define android_hardware_vehicle_V2_0_VehicleHal_H_

#include <android/hardware/vehicle/2.0/IVehicle.h>
#include "vehicle_hal_manager/VehicleObjectPool.h"


namespace android {
namespace hardware {
namespace vehicle {
namespace V2_0 {

/**
 * This is a low-level vehicle hal interface that should be implemented by
 * Vendor.
 */
class VehicleHal {
public:
    using VehiclePropValuePtr = recyclable_ptr<VehiclePropValue>;

    using HalEventFunction = std::function<void(VehiclePropValuePtr)>;
    using HalErrorFunction = std::function<void(
            VehicleProperty property,
            status_t errorCode,
            VehiclePropertyOperation operation)>;

    virtual ~VehicleHal() {}

    virtual std::vector<VehiclePropConfig> listProperties() = 0;
    virtual VehiclePropValuePtr get(VehicleProperty property,
                                    int32_t areaId,
                                    status_t* outStatus) = 0;

    virtual status_t set(const VehiclePropValue& propValue) = 0;

    /**
     * Subscribe to HAL property events. This method might be called multiple
     * times for the same vehicle property to update subscribed areas or sample
     * rate.
     *
     * @param property to subscribe
     * @param areas a bitwise vehicle areas or 0 for all supported areas
     * @param sampleRate sample rate in Hz for properties that support sample
     *                   rate, e.g. for properties with
     *                   VehiclePropertyChangeMode::CONTINUOUS
     */
    virtual status_t subscribe(VehicleProperty property,
                               int32_t areas,
                               float sampleRate) = 0;

    /**
     * Unsubscribe from HAL events for given property
     *
     * @param property vehicle property to unsubscribe
     */
    virtual status_t unsubscribe(VehicleProperty property) = 0;

    /**
     * Override this method if you need to do one-time initialization.
     */
    virtual void onCreate() {}

    void init(
        VehiclePropValuePool* valueObjectPool,
        const HalEventFunction& onHalEvent,
        const HalErrorFunction& onHalError) {
        mValuePool = valueObjectPool;
        mOnHalEvent = onHalEvent;
        mOnHalError = onHalError;

        onCreate();
    }

    VehiclePropValuePool* getValuePool() {
        return mValuePool;
    }
protected:
    void doHalEvent(VehiclePropValuePtr v) {
        mOnHalEvent(std::move(v));
    }

    void doHalError(VehicleProperty property,
                    status_t errorCode,
                    VehiclePropertyOperation operation) {
        mOnHalError(property, errorCode, operation);
    }

private:
    HalEventFunction mOnHalEvent;
    HalErrorFunction mOnHalError;
    VehiclePropValuePool* mValuePool;
};

}  // namespace V2_0
}  // namespace vehicle
}  // namespace hardware
}  // namespace android

#endif //android_hardware_vehicle_V2_0_VehicleHal_H_
+6 −10
Original line number Diff line number Diff line
@@ -21,22 +21,18 @@

#include <hwbinder/IPCThreadState.h>

#include <android/hardware/vehicle/2.0/IVehicle.h>
#include <vehicle_hal_manager/VehicleHalManager.h>
#include <impl/DefaultVehicleHal.h>

using namespace android;
using namespace android::hardware;
using namespace android::hardware::vehicle::V2_0;

int main(int /* argc */, char* /* argv */ []) {
    ALOGI("Service is starting");
    android::sp<IVehicle> service = IVehicle::getService("Vehicle");
    if (service.get() == NULL) {
        ALOGE("IVehicle::getService returned NULL, exiting");
        return 1;
    }
    auto hal = std::make_unique<impl::DefaultVehicleHal>();
    auto service = std::make_unique<VehicleHalManager>(hal.get());

    ALOGI("Registering as service");
    // will register the -impl as a binderized service in this process
    ALOGI("Registering as service...");
    service->registerAsService("Vehicle");

    ALOGI("Ready");
Loading