upload android base code part4

This commit is contained in:
August 2018-08-08 17:00:29 +08:00
parent b9e30e05b1
commit 78ea2404cd
23455 changed files with 5250148 additions and 0 deletions

View file

@ -0,0 +1,66 @@
// This file is autogenerated by hidl-gen. Do not edit manually.
filegroup {
name: "android.hardware.light@2.0_hal",
srcs: [
"types.hal",
"ILight.hal",
],
}
genrule {
name: "android.hardware.light@2.0_genc++",
tools: ["hidl-gen"],
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.light@2.0",
srcs: [
":android.hardware.light@2.0_hal",
],
out: [
"android/hardware/light/2.0/types.cpp",
"android/hardware/light/2.0/LightAll.cpp",
],
}
genrule {
name: "android.hardware.light@2.0_genc++_headers",
tools: ["hidl-gen"],
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.light@2.0",
srcs: [
":android.hardware.light@2.0_hal",
],
out: [
"android/hardware/light/2.0/types.h",
"android/hardware/light/2.0/hwtypes.h",
"android/hardware/light/2.0/ILight.h",
"android/hardware/light/2.0/IHwLight.h",
"android/hardware/light/2.0/BnHwLight.h",
"android/hardware/light/2.0/BpHwLight.h",
"android/hardware/light/2.0/BsLight.h",
],
}
cc_library {
name: "android.hardware.light@2.0",
defaults: ["hidl-module-defaults"],
generated_sources: ["android.hardware.light@2.0_genc++"],
generated_headers: ["android.hardware.light@2.0_genc++_headers"],
export_generated_headers: ["android.hardware.light@2.0_genc++_headers"],
vendor_available: true,
vndk: {
enabled: true,
},
shared_libs: [
"libhidlbase",
"libhidltransport",
"libhwbinder",
"liblog",
"libutils",
"libcutils",
],
export_shared_lib_headers: [
"libhidlbase",
"libhidltransport",
"libhwbinder",
"libutils",
],
}

View file

@ -0,0 +1,270 @@
# This file is autogenerated by hidl-gen. Do not edit manually.
LOCAL_PATH := $(call my-dir)
################################################################################
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.light-V2.0-java
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
intermediates := $(call local-generated-sources-dir, COMMON)
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
LOCAL_JAVA_LIBRARIES := \
android.hidl.base-V1.0-java \
#
# Build types.hal (Brightness)
#
GEN := $(intermediates)/android/hardware/light/V2_0/Brightness.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.Brightness
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build types.hal (Flash)
#
GEN := $(intermediates)/android/hardware/light/V2_0/Flash.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.Flash
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build types.hal (LightState)
#
GEN := $(intermediates)/android/hardware/light/V2_0/LightState.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.LightState
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build types.hal (Status)
#
GEN := $(intermediates)/android/hardware/light/V2_0/Status.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.Status
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build types.hal (Type)
#
GEN := $(intermediates)/android/hardware/light/V2_0/Type.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.Type
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build ILight.hal
#
GEN := $(intermediates)/android/hardware/light/V2_0/ILight.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/ILight.hal
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
$(GEN): $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::ILight
$(GEN): $(LOCAL_PATH)/ILight.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
include $(BUILD_JAVA_LIBRARY)
################################################################################
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.light-V2.0-java-static
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
intermediates := $(call local-generated-sources-dir, COMMON)
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
LOCAL_STATIC_JAVA_LIBRARIES := \
android.hidl.base-V1.0-java-static \
#
# Build types.hal (Brightness)
#
GEN := $(intermediates)/android/hardware/light/V2_0/Brightness.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.Brightness
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build types.hal (Flash)
#
GEN := $(intermediates)/android/hardware/light/V2_0/Flash.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.Flash
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build types.hal (LightState)
#
GEN := $(intermediates)/android/hardware/light/V2_0/LightState.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.LightState
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build types.hal (Status)
#
GEN := $(intermediates)/android/hardware/light/V2_0/Status.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.Status
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build types.hal (Type)
#
GEN := $(intermediates)/android/hardware/light/V2_0/Type.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::types.Type
$(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build ILight.hal
#
GEN := $(intermediates)/android/hardware/light/V2_0/ILight.java
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/ILight.hal
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
$(GEN): $(LOCAL_PATH)/types.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Ljava \
-randroid.hardware:hardware/interfaces \
-randroid.hidl:system/libhidl/transport \
android.hardware.light@2.0::ILight
$(GEN): $(LOCAL_PATH)/ILight.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
include $(BUILD_STATIC_JAVA_LIBRARY)
include $(call all-makefiles-under,$(LOCAL_PATH))

View file

@ -0,0 +1,37 @@
/*
* 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.
*/
package android.hardware.light@2.0;
interface ILight {
/**
* Set the provided lights to the provided values.
*
* @param type logical light to set
* @param state describes what the light should look like.
* @return status result of applying state transformation.
*/
setLight(Type type, LightState state) generates (Status status);
/**
* Discover what indicator lights are available.
*
* @return types list of available lights
*/
getSupportedTypes() generates (vec<Type> types);
};

View file

@ -0,0 +1,44 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.light@2.0-impl
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
Light.cpp \
LOCAL_SHARED_LIBRARIES := \
libhidlbase \
libhidltransport \
libutils \
liblog \
libcutils \
libhardware \
libbase \
libcutils \
android.hardware.light@2.0 \
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE := android.hardware.light@2.0-service
LOCAL_INIT_RC := android.hardware.light@2.0-service.rc
LOCAL_SRC_FILES := \
service.cpp \
LOCAL_SHARED_LIBRARIES := \
liblog \
libcutils \
libdl \
libbase \
libutils \
libhardware \
LOCAL_SHARED_LIBRARIES += \
libhidlbase \
libhidltransport \
android.hardware.light@2.0 \
include $(BUILD_EXECUTABLE)

View file

@ -0,0 +1,160 @@
/*
* 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 "light"
#include <log/log.h>
#include "Light.h"
namespace android {
namespace hardware {
namespace light {
namespace V2_0 {
namespace implementation {
static_assert(LIGHT_FLASH_NONE == static_cast<int>(Flash::NONE),
"Flash::NONE must match legacy value.");
static_assert(LIGHT_FLASH_TIMED == static_cast<int>(Flash::TIMED),
"Flash::TIMED must match legacy value.");
static_assert(LIGHT_FLASH_HARDWARE == static_cast<int>(Flash::HARDWARE),
"Flash::HARDWARE must match legacy value.");
static_assert(BRIGHTNESS_MODE_USER == static_cast<int>(Brightness::USER),
"Brightness::USER must match legacy value.");
static_assert(BRIGHTNESS_MODE_SENSOR == static_cast<int>(Brightness::SENSOR),
"Brightness::SENSOR must match legacy value.");
static_assert(BRIGHTNESS_MODE_LOW_PERSISTENCE ==
static_cast<int>(Brightness::LOW_PERSISTENCE),
"Brightness::LOW_PERSISTENCE must match legacy value.");
Light::Light(std::map<Type, light_device_t*> &&lights)
: mLights(std::move(lights)) {}
// Methods from ::android::hardware::light::V2_0::ILight follow.
Return<Status> Light::setLight(Type type, const LightState& state) {
auto it = mLights.find(type);
if (it == mLights.end()) {
return Status::LIGHT_NOT_SUPPORTED;
}
light_device_t* hwLight = it->second;
light_state_t legacyState {
.color = state.color,
.flashMode = static_cast<int>(state.flashMode),
.flashOnMS = state.flashOnMs,
.flashOffMS = state.flashOffMs,
.brightnessMode = static_cast<int>(state.brightnessMode),
};
int ret = hwLight->set_light(hwLight, &legacyState);
switch (ret) {
case -ENOSYS:
return Status::BRIGHTNESS_NOT_SUPPORTED;
case 0:
return Status::SUCCESS;
default:
return Status::UNKNOWN;
}
}
Return<void> Light::getSupportedTypes(getSupportedTypes_cb _hidl_cb) {
Type *types = new Type[mLights.size()];
int idx = 0;
for(auto const &pair : mLights) {
Type type = pair.first;
types[idx++] = type;
}
{
hidl_vec<Type> hidl_types{};
hidl_types.setToExternal(types, mLights.size());
_hidl_cb(hidl_types);
}
delete[] types;
return Void();
}
const static std::map<Type, const char*> kLogicalLights = {
{Type::BACKLIGHT, LIGHT_ID_BACKLIGHT},
{Type::KEYBOARD, LIGHT_ID_KEYBOARD},
{Type::BUTTONS, LIGHT_ID_BUTTONS},
{Type::BATTERY, LIGHT_ID_BATTERY},
{Type::NOTIFICATIONS, LIGHT_ID_NOTIFICATIONS},
{Type::ATTENTION, LIGHT_ID_ATTENTION},
{Type::BLUETOOTH, LIGHT_ID_BLUETOOTH},
{Type::WIFI, LIGHT_ID_WIFI}
};
light_device_t* getLightDevice(const char* name) {
light_device_t* lightDevice;
const hw_module_t* hwModule = NULL;
int ret = hw_get_module (LIGHTS_HARDWARE_MODULE_ID, &hwModule);
if (ret == 0) {
ret = hwModule->methods->open(hwModule, name,
reinterpret_cast<hw_device_t**>(&lightDevice));
if (ret != 0) {
ALOGE("light_open %s %s failed: %d", LIGHTS_HARDWARE_MODULE_ID, name, ret);
}
} else {
ALOGE("hw_get_module %s %s failed: %d", LIGHTS_HARDWARE_MODULE_ID, name, ret);
}
if (ret == 0) {
return lightDevice;
} else {
ALOGE("Light passthrough failed to load legacy HAL.");
return nullptr;
}
}
ILight* HIDL_FETCH_ILight(const char* /* name */) {
std::map<Type, light_device_t*> lights;
for(auto const &pair : kLogicalLights) {
Type type = pair.first;
const char* name = pair.second;
light_device_t* light = getLightDevice(name);
if (light != nullptr) {
lights[type] = light;
}
}
if (lights.size() == 0) {
// Log information, but still return new Light.
// Some devices may not have any lights.
ALOGI("Could not open any lights.");
}
return new Light(std::move(lights));
}
} // namespace implementation
} // namespace V2_0
} // namespace light
} // namespace hardware
} // namespace android

View file

@ -0,0 +1,61 @@
/*
* 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_LIGHT_V2_0_LIGHT_H
#define ANDROID_HARDWARE_LIGHT_V2_0_LIGHT_H
#include <android/hardware/light/2.0/ILight.h>
#include <hardware/hardware.h>
#include <hardware/lights.h>
#include <hidl/Status.h>
#include <hidl/MQDescriptor.h>
#include <map>
namespace android {
namespace hardware {
namespace light {
namespace V2_0 {
namespace implementation {
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 ILight {
Light(std::map<Type, light_device_t*> &&lights);
// 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;
private:
std::map<Type, light_device_t*> mLights;
};
extern "C" ILight* HIDL_FETCH_ILight(const char* name);
} // namespace implementation
} // namespace V2_0
} // namespace light
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_LIGHT_V2_0_LIGHT_H

View file

@ -0,0 +1,4 @@
service light-hal-2-0 /vendor/bin/hw/android.hardware.light@2.0-service
class hal
user system
group system

View file

@ -0,0 +1,27 @@
/*
* Copyright 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 "android.hardware.light@2.0-service"
#include <android/hardware/light/2.0/ILight.h>
#include <hidl/LegacySupport.h>
using android::hardware::light::V2_0::ILight;
using android::hardware::defaultPassthroughServiceImplementation;
int main() {
return defaultPassthroughServiceImplementation<ILight>();
}

View file

@ -0,0 +1,134 @@
/*
* 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.
*/
package android.hardware.light@2.0;
enum Status : int32_t {
SUCCESS,
LIGHT_NOT_SUPPORTED,
BRIGHTNESS_NOT_SUPPORTED,
UNKNOWN,
};
enum Flash : int32_t {
/**
* Keep the light steady on or off.
*/
NONE,
/**
* Flash the light at specified rate.
*/
TIMED,
/**
* Flash the light using hardware assist.
*/
HARDWARE,
};
enum Brightness : int32_t {
/**
* Light brightness is managed by a user setting.
*/
USER,
/**
* Light brightness is managed by a light sensor.
*/
SENSOR,
/**
* Use a low-persistence mode for display backlights.
*
* When set, the device driver must switch to a mode optimized for low display
* persistence that is intended to be used when the device is being treated as a
* head mounted display (HMD). The actual display brightness in this mode is
* implementation dependent, and any value set for color in LightState may be
* overridden by the HAL implementation.
*
* For an optimal HMD viewing experience, the display must meet the following
* criteria in this mode:
* - Gray-to-Gray, White-to-Black, and Black-to-White switching time must be ≤ 3 ms.
* - The display must support low-persistence with ≤ 3.5 ms persistence.
* Persistence is defined as the amount of time for which a pixel is
* emitting light for a single frame.
* - Any "smart panel" or other frame buffering options that increase display
* latency are disabled.
* - Display brightness is set so that the display is still visible to the user
* under normal indoor lighting.
* - The display must update at 60 Hz at least, but higher refresh rates are
* recommended for low latency.
*
*/
LOW_PERSISTENCE,
};
/**
* These light IDs correspond to logical lights, not physical.
* So for example, if your INDICATOR light is in line with your
* BUTTONS, it might make sense to also light the INDICATOR
* light to a reasonable color when the BUTTONS are lit.
*/
enum Type : int32_t {
BACKLIGHT,
KEYBOARD,
BUTTONS,
BATTERY,
NOTIFICATIONS,
ATTENTION,
BLUETOOTH,
WIFI,
COUNT,
};
/**
* The parameters that can be set for a given light.
*
* Not all lights must support all parameters. If you
* can do something backward-compatible, do it.
*/
struct LightState {
/**
* The color of the LED in ARGB.
*
* Do your best here.
* - If your light can only do red or green, if they ask for blue,
* you should do green.
* - If you can only do a brightness ramp, then use this formula:
* unsigned char brightness = ((77*((color>>16)&0x00ff))
* + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8;
* - If you can only do on or off, 0 is off, anything else is on.
*
* The high byte should be ignored. Callers will set it to 0xff (which
* would correspond to 255 alpha).
*/
uint32_t color;
/**
* To flash the light at a given rate, set flashMode to LIGHT_FLASH_TIMED,
* and then flashOnMS should be set to the number of milliseconds to turn
* the light on, followed by the number of milliseconds to turn the light
* off.
*/
Flash flashMode;
int32_t flashOnMs;
int32_t flashOffMs;
Brightness brightnessMode;
};

View file

@ -0,0 +1,19 @@
#
# 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)
include $(call all-makefiles-under,$(LOCAL_PATH))

View file

@ -0,0 +1,23 @@
//
// 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.
//
cc_test {
name: "VtsHalLightV2_0TargetTest",
defaults: ["VtsHalTargetTestDefaults"],
srcs: ["VtsHalLightV2_0TargetTest.cpp"],
static_libs: ["android.hardware.light@2.0"],
}

View file

@ -0,0 +1,156 @@
/*
* 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 "light_hidl_hal_test"
#include <android-base/logging.h>
#include <android/hardware/light/2.0/ILight.h>
#include <android/hardware/light/2.0/types.h>
#include <VtsHalHidlTargetTestBase.h>
#include <set>
#include <unistd.h>
using ::android::hardware::light::V2_0::Brightness;
using ::android::hardware::light::V2_0::Flash;
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::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
#define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk())
const static LightState kWhite = {
.color = 0xFFFFFFFF,
.flashMode = Flash::TIMED,
.flashOnMs = 100,
.flashOffMs = 50,
.brightnessMode = Brightness::USER,
};
const static LightState kLowPersistance = {
.color = 0xFF123456,
.flashMode = Flash::TIMED,
.flashOnMs = 100,
.flashOffMs = 50,
.brightnessMode = Brightness::LOW_PERSISTENCE,
};
const static LightState kOff = {
.color = 0x00000000,
.flashMode = Flash::NONE,
.flashOnMs = 0,
.flashOffMs = 0,
.brightnessMode = Brightness::USER,
};
const static std::set<Type> kAllTypes = {
Type::BACKLIGHT,
Type::KEYBOARD,
Type::BUTTONS,
Type::BATTERY,
Type::NOTIFICATIONS,
Type::ATTENTION,
Type::BLUETOOTH,
Type::WIFI
};
class LightHidlTest : public ::testing::VtsHalHidlTargetTestBase {
public:
virtual void SetUp() override {
light = ::testing::VtsHalHidlTargetTestBase::getService<ILight>();
ASSERT_NE(light, nullptr);
LOG(INFO) << "Test is remote " << light->isRemote();
ASSERT_OK(light->getSupportedTypes([this](const hidl_vec<Type> &types) {
supportedTypes = types;
}));
}
sp<ILight> light;
std::vector<Type> supportedTypes;
virtual void TearDown() override {
for (const Type& type: supportedTypes) {
Return<Status> ret = light->setLight(type, kOff);
EXPECT_OK(ret);
EXPECT_EQ(Status::SUCCESS, static_cast<Status>(ret));
}
// must leave the device in a useable condition
if (std::find(supportedTypes.begin(),
supportedTypes.end(),
Type::BACKLIGHT) != supportedTypes.end()) {
Return<Status> ret = light->setLight(Type::BACKLIGHT, kWhite);
EXPECT_OK(ret);
EXPECT_EQ(Status::SUCCESS, static_cast<Status>(ret));
}
}
};
/**
* Ensure all lights which are reported as supported work.
*/
TEST_F(LightHidlTest, TestSupported) {
for (const Type& type: supportedTypes) {
Return<Status> ret = light->setLight(type, kWhite);
EXPECT_OK(ret);
EXPECT_EQ(Status::SUCCESS, static_cast<Status>(ret));
}
}
/**
* Ensure BRIGHTNESS_NOT_SUPPORTED is returned if LOW_PERSISTANCE is not supported.
*/
TEST_F(LightHidlTest, TestLowPersistance) {
for (const Type& type: supportedTypes) {
Return<Status> ret = light->setLight(type, kLowPersistance);
EXPECT_OK(ret);
Status status = ret;
EXPECT_TRUE(Status::SUCCESS == status ||
Status::BRIGHTNESS_NOT_SUPPORTED == status);
}
}
/**
* Ensure lights which are not supported return LIGHT_NOT_SUPPORTED
*/
TEST_F(LightHidlTest, TestUnsupported) {
std::set<Type> unsupportedTypes = kAllTypes;
for (const Type& type: supportedTypes) {
unsupportedTypes.erase(type);
}
for (const Type& type: unsupportedTypes) {
Return<Status> ret = light->setLight(type, kWhite);
EXPECT_OK(ret);
EXPECT_EQ(Status::LIGHT_NOT_SUPPORTED, static_cast<Status>(ret));
}
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
int status = RUN_ALL_TESTS();
LOG(INFO) << "Test result = " << status;
return status;
}

View file

@ -0,0 +1,5 @@
// This is an autogenerated file, do not edit.
subdirs = [
"2.0",
"2.0/vts/functional",
]