Added example vendor extension for light.
Test: make
Bug: 32065239
Change-Id: I8004eaea180d768ccdec0e932d08c1167f5c10cd
diff --git a/example/extension/light/2.0/default/Android.mk b/example/extension/light/2.0/default/Android.mk
new file mode 100644
index 0000000..fa68787
--- /dev/null
+++ b/example/extension/light/2.0/default/Android.mk
@@ -0,0 +1,17 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.example.extension.light@2.0-service
+LOCAL_INIT_RC := android.hardware.example.extension.light@2.0-service.rc
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := \
+ Light.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+ libhidl \
+ libhwbinder \
+ libutils \
+ android.hardware.light@2.0 \
+ android.hardware.example.extension.light@2.0 \
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/example/extension/light/2.0/default/Light.cpp b/example/extension/light/2.0/default/Light.cpp
new file mode 100644
index 0000000..d738a6d
--- /dev/null
+++ b/example/extension/light/2.0/default/Light.cpp
@@ -0,0 +1,56 @@
+#include "Light.h"
+
+namespace android {
+namespace hardware {
+namespace example {
+namespace extension {
+namespace light {
+namespace V2_0 {
+namespace implementation {
+
+// Methods from ::android::hardware::light::V2_0::ILight follow.
+Return<Status> Light::setLight(Type type, const LightState& state) {
+ // Forward types for new methods.
+
+ ExtLightState extState {
+ .state = state,
+ .interpolationOmega =
+ static_cast<int32_t>(Default::INTERPOLATION_OMEGA),
+ .brightness = // ExtBrightness inherits from Brightness
+ static_cast<ExtBrightness>(state.brightnessMode)
+ };
+
+ return setExtLight(type, extState);
+}
+
+Return<void> Light::getSupportedTypes(getSupportedTypes_cb _hidl_cb) {
+ // implement unchanged method as you would always
+ hidl_vec<Type> vec{};
+
+ // ******************************************************
+ // Note: awesome proprietary hardware implementation here
+ // ******************************************************
+
+ _hidl_cb(vec);
+
+ return Void();
+}
+
+// Methods from ::android::hardware::example::extension::light::V2_0::ILight follow.
+Return<Status> Light::setExtLight(Type /* type */,
+ const ExtLightState& /* state */) {
+
+ // ******************************************************
+ // Note: awesome proprietary hardware implementation here
+ // ******************************************************
+
+ return Status::SUCCESS;
+}
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace light
+} // namespace extension
+} // namespace example
+} // namespace hardware
+} // namespace android
diff --git a/example/extension/light/2.0/default/Light.h b/example/extension/light/2.0/default/Light.h
new file mode 100644
index 0000000..e09ec92
--- /dev/null
+++ b/example/extension/light/2.0/default/Light.h
@@ -0,0 +1,46 @@
+#ifndef HIDL_GENERATED_android_hardware_example_extension_light_V2_0_Light_H_
+#define HIDL_GENERATED_android_hardware_example_extension_light_V2_0_Light_H_
+
+#include <android/hardware/example/extension/light/2.0/IExtLight.h>
+#include <hidl/Status.h>
+
+#include <hidl/MQDescriptor.h>
+namespace android {
+namespace hardware {
+namespace example {
+namespace extension {
+namespace light {
+namespace V2_0 {
+namespace implementation {
+
+using ::android::hardware::example::extension::light::V2_0::ExtLightState;
+using ::android::hardware::example::extension::light::V2_0::IExtLight;
+using ::android::hardware::light::V2_0::ILight;
+using ::android::hardware::light::V2_0::LightState;
+using ::android::hardware::light::V2_0::Status;
+using ::android::hardware::light::V2_0::Type;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+struct Light : public IExtLight {
+ // Methods from ::android::hardware::light::V2_0::ILight follow.
+ Return<Status> setLight(Type type, const LightState& state) override;
+ Return<void> getSupportedTypes(getSupportedTypes_cb _hidl_cb) override;
+
+ // Methods from ::android::hardware::example::extension::light::V2_0::ILight follow.
+ Return<Status> setExtLight(Type type, const ExtLightState& state) override;
+
+};
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace light
+} // namespace extension
+} // namespace example
+} // namespace hardware
+} // namespace android
+
+#endif // HIDL_GENERATED_android_hardware_example_extension_light_V2_0_Light_H_
diff --git a/example/extension/light/2.0/default/android.hardware.example.extension.light@2.0-service.rc b/example/extension/light/2.0/default/android.hardware.example.extension.light@2.0-service.rc
new file mode 100644
index 0000000..8a90d81
--- /dev/null
+++ b/example/extension/light/2.0/default/android.hardware.example.extension.light@2.0-service.rc
@@ -0,0 +1,4 @@
+service light-ext-2-0 /system/bin/hw/android.hardware.example.extension.light@2.0-service
+ class hal
+ user system
+ group system readproc
\ No newline at end of file
diff --git a/example/extension/light/2.0/default/service.cpp b/example/extension/light/2.0/default/service.cpp
new file mode 100644
index 0000000..55121d9
--- /dev/null
+++ b/example/extension/light/2.0/default/service.cpp
@@ -0,0 +1,34 @@
+#define LOG_TAG "android.hardware.light@2.0-service"
+#include <utils/Log.h>
+
+// #include <iostream>
+// #include <unistd.h>
+
+// #include <hidl/IServiceManager.h>
+// #include <hwbinder/IPCThreadState.h>
+// #include <hwbinder/ProcessState.h>
+// #include <utils/Errors.h>
+// #include <utils/StrongPointer.h>
+
+#include "Light.h"
+
+using android::sp;
+
+// libhwbinder:
+using android::hardware::IPCThreadState;
+using android::hardware::ProcessState;
+
+// Generated HIDL files
+using android::hardware::light::V2_0::ILight;
+
+int main() {
+ const char instance[] = "light";
+
+ android::sp<ILight> service = new Light();
+
+ service->registerAsService(instance);
+
+ ProcessState::self()->setThreadPoolMaxThreadCount(0);
+ ProcessState::self()->startThreadPool();
+ IPCThreadState::self()->joinThreadPool();
+}