Initial submit of Vehicle HAL 2.1
Major changes / decisions:
- created empty IVehicle@2.1 interface to distinguish HAL impls
from client's (Car Service) perspective;
- created default 2.1 implementation that currently delegates all
calls to existing 2.0 implementation
- had to refactor a little bit 2.0 thus components could be esily
imported in 2.1
TOOD:
- move OBD and VMS code to 2.1
- decouple "DefaultVehicleHal.cpp"
- rename "DefaultVehicleHal" to Emulator (let's call things by their names)
b/34716856
Test: todo
Change-Id: Ib23650ca1277f0dfb24e5c789d65a19dce8b1abc
diff --git a/automotive/vehicle/2.1/default/Android.mk b/automotive/vehicle/2.1/default/Android.mk
new file mode 100644
index 0000000..1874cb3
--- /dev/null
+++ b/automotive/vehicle/2.1/default/Android.mk
@@ -0,0 +1,84 @@
+# 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.
+
+LOCAL_PATH := $(call my-dir)
+
+vhal_v2_0 = android.hardware.automotive.vehicle@2.0
+vhal_v2_1 = android.hardware.automotive.vehicle@2.1
+
+###############################################################################
+# Vehicle default VehicleHAL implementation
+###############################################################################
+include $(CLEAR_VARS)
+
+LOCAL_MODULE:= $(vhal_v2_1)-default-impl-lib
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/impl/vhal_v2_1
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+ $(LOCAL_PATH)/impl
+
+
+# LOCAL_WHOLE_STATIC_LIBRARIES := \
+
+LOCAL_STATIC_LIBRARIES := \
+ $(vhal_v2_0)-default-impl-lib \
+ $(vhal_v2_0)-manager-lib \
+ $(vhal_v2_0)-libproto-native
+
+LOCAL_SHARED_LIBRARIES := \
+ libbinder \
+ libhidlbase \
+ libhidltransport \
+ libhwbinder \
+ liblog \
+ libutils \
+ libprotobuf-cpp-lite \
+ $(vhal_v2_0) \
+ $(vhal_v2_1) \
+
+include $(BUILD_STATIC_LIBRARY)
+
+###############################################################################
+# Vehicle HAL service
+###############################################################################
+include $(CLEAR_VARS)
+LOCAL_MODULE := $(vhal_v2_1)-service
+LOCAL_INIT_RC := $(vhal_v2_1)-service.rc
+LOCAL_MODULE_RELATIVE_PATH := hw
+
+LOCAL_SRC_FILES := \
+ service.cpp
+
+LOCAL_WHOLE_STATIC_LIBRARIES := \
+ $(vhal_v2_0)-libproto-native \
+
+LOCAL_STATIC_LIBRARIES := \
+ $(vhal_v2_0)-manager-lib \
+ $(vhal_v2_0)-default-impl-lib \
+ $(vhal_v2_1)-default-impl-lib \
+
+LOCAL_SHARED_LIBRARIES := \
+ libbinder \
+ libhidlbase \
+ libhidltransport \
+ libhwbinder \
+ liblog \
+ libutils \
+ libprotobuf-cpp-lite \
+ $(vhal_v2_0) \
+ $(vhal_v2_1) \
+
+include $(BUILD_EXECUTABLE)
diff --git a/automotive/vehicle/2.1/default/android.hardware.automotive.vehicle@2.1-service.rc b/automotive/vehicle/2.1/default/android.hardware.automotive.vehicle@2.1-service.rc
new file mode 100644
index 0000000..0b642d5
--- /dev/null
+++ b/automotive/vehicle/2.1/default/android.hardware.automotive.vehicle@2.1-service.rc
@@ -0,0 +1,4 @@
+service vehicle-hal-2.1 /system/bin/hw/android.hardware.automotive.vehicle@2.1-service
+ class hal
+ user vehicle_network
+ group system inet
diff --git a/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultConfig.h b/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultConfig.h
new file mode 100644
index 0000000..ab08cec
--- /dev/null
+++ b/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultConfig.h
@@ -0,0 +1,47 @@
+/*
+ * 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_automotive_vehicle_V2_1_impl_DefaultConfig_H_
+#define android_hardware_automotive_vehicle_V2_1_impl_DefaultConfig_H_
+
+#include <android/hardware/automotive/vehicle/2.1/types.h>
+#include <vhal_v2_0/VehicleUtils.h>
+
+namespace android {
+namespace hardware {
+namespace automotive {
+namespace vehicle {
+namespace V2_1 {
+
+namespace impl {
+
+const V2_0::VehiclePropConfig kVehicleProperties[] = {
+ {
+ .prop = V2_0::toInt(V2_1::VehicleProperty::WHEEL_TICK),
+ .access = V2_0::VehiclePropertyAccess::READ,
+ .changeMode = V2_0::VehiclePropertyChangeMode::CONTINUOUS,
+ }
+};
+
+} // impl
+
+} // namespace V2_1
+} // namespace vehicle
+} // namespace automotive
+} // namespace hardware
+} // namespace android
+
+#endif // android_hardware_automotive_vehicle_V2_1_impl_DefaultConfig_H_
diff --git a/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultVehicleHal.h b/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultVehicleHal.h
new file mode 100644
index 0000000..7ccb354
--- /dev/null
+++ b/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultVehicleHal.h
@@ -0,0 +1,93 @@
+/*
+ * 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_automotive_vehicle_V2_1_impl_DefaultVehicleHal_H_
+#define android_hardware_automotive_vehicle_V2_1_impl_DefaultVehicleHal_H_
+
+#include <memory>
+
+#include <utils/SystemClock.h>
+
+#include <vhal_v2_0/VehicleHal.h>
+#include <vhal_v2_0/DefaultVehicleHal.h>
+
+#include "DefaultConfig.h"
+
+namespace android {
+namespace hardware {
+namespace automotive {
+namespace vehicle {
+namespace V2_1 {
+
+namespace impl {
+
+using namespace std::placeholders;
+
+class DefaultVehicleHal : public V2_0::VehicleHal {
+public:
+ DefaultVehicleHal(V2_0::VehicleHal* vhal20) : mVehicleHal20(vhal20) {}
+
+ std::vector<V2_0::VehiclePropConfig> listProperties() override {
+ std::vector<V2_0::VehiclePropConfig> propConfigs(mVehicleHal20->listProperties());
+
+ // Join Vehicle Hal 2.0 and 2.1 configs.
+ propConfigs.insert(propConfigs.end(),
+ std::begin(kVehicleProperties),
+ std::end(kVehicleProperties));
+
+ return propConfigs;
+ }
+
+ VehiclePropValuePtr get(const V2_0::VehiclePropValue& requestedPropValue,
+ V2_0::StatusCode* outStatus) override {
+ // TODO(pavelm): put logic related to VHAL 2.1 here (OBD, VMS, etc)
+ return mVehicleHal20->get(requestedPropValue, outStatus);
+ }
+
+ V2_0::StatusCode set(const V2_0::VehiclePropValue& propValue) override {
+ return mVehicleHal20->set(propValue);
+ }
+
+ V2_0::StatusCode subscribe(int32_t property,
+ int32_t areas,
+ float sampleRate) override {
+ return mVehicleHal20->subscribe(property, areas, sampleRate);
+ }
+
+ V2_0::StatusCode unsubscribe(int32_t property) override {
+ return mVehicleHal20->unsubscribe(property);
+ }
+
+ void onCreate() override {
+ mVehicleHal20->init(getValuePool(),
+ std::bind(&DefaultVehicleHal::doHalEvent, this, _1),
+ std::bind(&DefaultVehicleHal::doHalPropertySetError, this, _1, _2, _3));
+ }
+
+private:
+ V2_0::VehicleHal* mVehicleHal20;
+};
+
+} // impl
+
+} // namespace V2_1
+} // namespace vehicle
+} // namespace automotive
+} // namespace hardware
+} // namespace android
+
+
+#endif // android_hardware_automotive_vehicle_V2_0_impl_DefaultVehicleHal_H_
diff --git a/automotive/vehicle/2.1/default/service.cpp b/automotive/vehicle/2.1/default/service.cpp
new file mode 100644
index 0000000..aaadf17
--- /dev/null
+++ b/automotive/vehicle/2.1/default/service.cpp
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "automotive.vehicle@2.1-service"
+#include <android/log.h>
+#include <hidl/HidlTransportSupport.h>
+
+#include <iostream>
+
+#include <android/hardware/automotive/vehicle/2.1/IVehicle.h>
+
+#include <vhal_v2_0/VehicleHalManager.h>
+#include <vhal_v2_0/DefaultVehicleHal.h>
+
+#include <vhal_v2_1/DefaultVehicleHal.h>
+
+using namespace android;
+using namespace android::hardware;
+
+namespace V2_1 = ::android::hardware::automotive::vehicle::V2_1;
+namespace V2_0 = ::android::hardware::automotive::vehicle::V2_0;
+
+using StatusCode = V2_0::StatusCode;
+using VehiclePropValue = V2_0::VehiclePropValue;
+
+/* Just wrapper that passes all calls to the provided V2_0::IVehicle object */
+struct Vehicle_V2_1 : public V2_1::IVehicle {
+
+ Vehicle_V2_1(V2_0::IVehicle* vehicle20) : mVehicle20(vehicle20) {}
+
+ // Methods derived from IVehicle
+ Return<void> getAllPropConfigs(getAllPropConfigs_cb _hidl_cb) override {
+ return mVehicle20->getAllPropConfigs(_hidl_cb);
+ }
+
+ Return<void> getPropConfigs(const hidl_vec<int32_t>& properties,
+ getPropConfigs_cb _hidl_cb) override {
+ return mVehicle20->getPropConfigs(properties, _hidl_cb);
+ }
+
+ Return<void> get(const V2_0::VehiclePropValue& requestedPropValue,
+ get_cb _hidl_cb) override {
+ return mVehicle20->get(requestedPropValue, _hidl_cb);
+ }
+
+ Return<StatusCode> set(const VehiclePropValue& value) override {
+ return mVehicle20->set(value);
+ }
+
+ Return<StatusCode> subscribe(const sp<V2_0::IVehicleCallback>& callback,
+ const hidl_vec<V2_0::SubscribeOptions>&
+ options) override {
+ return mVehicle20->subscribe(callback, options);
+ }
+
+ Return<StatusCode> unsubscribe(const sp<V2_0::IVehicleCallback>& callback,
+ int32_t propId) override {
+ return mVehicle20->unsubscribe(callback, propId);
+ }
+
+ Return<void> debugDump(debugDump_cb _hidl_cb = nullptr) override {
+ return mVehicle20->debugDump(_hidl_cb);
+ }
+
+private:
+ V2_0::IVehicle* mVehicle20;
+};
+
+int main(int /* argc */, char* /* argv */ []) {
+ auto halImpl20 = std::make_unique<V2_0::impl::DefaultVehicleHal>();
+ auto halImpl21 = std::make_unique<V2_1::impl::DefaultVehicleHal>(halImpl20.get());
+
+ auto vehicleManager = std::make_unique<V2_0::VehicleHalManager>(halImpl21.get());
+
+ Vehicle_V2_1 vehicle21(vehicleManager.get());
+
+ ALOGI("Registering as service...");
+ vehicle21.registerAsService("Vehicle");
+
+ configureRpcThreadpool(1, true /* callerWillJoin */);
+
+ ALOGI("Ready");
+ joinRpcThreadpool();
+}