mirror of
https://github.com/LineageOS/android_device_essential_mata.git
synced 2025-10-29 11:49:27 +00:00
mata: Migrate light HAL from HIDL to AIDL
Change-Id: I8d861846af89724050fba5159e0fb7983d04222f
This commit is contained in:
parent
9f9cfbec4f
commit
74db3178db
@ -243,7 +243,7 @@ PRODUCT_PACKAGES += \
|
||||
|
||||
# Led packages
|
||||
PRODUCT_PACKAGES += \
|
||||
android.hardware.light@2.0-service.mata
|
||||
android.hardware.light-service.mata
|
||||
|
||||
# LiveDisplay native
|
||||
PRODUCT_PACKAGES += \
|
||||
|
||||
@ -1,31 +1,21 @@
|
||||
//
|
||||
// Copyright (C) 2017 The LineageOS Project
|
||||
// SPDX-FileCopyrightText: 2018-2024 The LineageOS Project
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// 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_binary {
|
||||
name: "android.hardware.light-service.mata",
|
||||
relative_install_path: "hw",
|
||||
defaults: ["hidl_defaults"],
|
||||
name: "android.hardware.light@2.0-service.mata",
|
||||
proprietary: true,
|
||||
init_rc: ["android.hardware.light@2.0-service.mata.rc"],
|
||||
vintf_fragments: ["android.hardware.light@2.0-service.mata.xml"],
|
||||
srcs: ["service.cpp", "Light.cpp"],
|
||||
init_rc: ["android.hardware.light-service.mata.rc"],
|
||||
vintf_fragments: ["android.hardware.light-service.mata.xml"],
|
||||
vendor: true,
|
||||
srcs: [
|
||||
"Lights.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libhardware",
|
||||
"libhidlbase",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"android.hardware.light@2.0",
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"android.hardware.light-V2-ndk",
|
||||
],
|
||||
}
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The LineageOS 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/lights.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
namespace V2_0 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::hidl_vec;
|
||||
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;
|
||||
|
||||
class Light : public ILight {
|
||||
public:
|
||||
Light();
|
||||
|
||||
Return<Status> setLight(Type type, const LightState& state) override;
|
||||
Return<void> getSupportedTypes(getSupportedTypes_cb _hidl_cb) override;
|
||||
|
||||
private:
|
||||
std::mutex globalLock;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V2_0
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_LIGHT_V2_0_LIGHT_H
|
||||
@ -1,33 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The LineageOS 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.
|
||||
* SPDX-FileCopyrightText: 2018-2024 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define LOG_TAG "LightService"
|
||||
|
||||
#include <log/log.h>
|
||||
#include "Lights.h"
|
||||
|
||||
#include "Light.h"
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
namespace V2_0 {
|
||||
namespace implementation {
|
||||
|
||||
#define LEDS "/sys/class/leds/"
|
||||
|
||||
#define LCD_LED LEDS "lcd-backlight/"
|
||||
@ -36,13 +19,15 @@ namespace implementation {
|
||||
#define BLUE_LED LEDS "blue/"
|
||||
#define RGB_LED LEDS "rgb/"
|
||||
|
||||
#define BLINK "blink"
|
||||
#define BRIGHTNESS "brightness"
|
||||
#define DUTY_PCTS "duty_pcts"
|
||||
#define START_IDX "start_idx"
|
||||
#define PAUSE_LO "pause_lo"
|
||||
#define PAUSE_HI "pause_hi"
|
||||
#define PAUSE_LO "pause_lo"
|
||||
#define RAMP_STEP_MS "ramp_step_ms"
|
||||
#define RGB_BLINK "rgb_blink"
|
||||
#define START_IDX "start_idx"
|
||||
|
||||
|
||||
/*
|
||||
* 8 duty percent steps.
|
||||
@ -57,6 +42,7 @@ namespace implementation {
|
||||
*/
|
||||
static int32_t BRIGHTNESS_RAMP[RAMP_STEPS] = {0, 12, 25, 37, 50, 72, 85, 100};
|
||||
|
||||
namespace {
|
||||
/*
|
||||
* Write value to path and close file.
|
||||
*/
|
||||
@ -64,7 +50,7 @@ static void set(std::string path, std::string value) {
|
||||
std::ofstream file(path);
|
||||
|
||||
if (!file.is_open()) {
|
||||
ALOGE("failed to write %s to %s", value.c_str(), path.c_str());
|
||||
LOG(WARNING) << "failed to write " << value.c_str() << " to " << path.c_str();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -75,7 +61,7 @@ static void set(std::string path, int value) {
|
||||
set(path, std::to_string(value));
|
||||
}
|
||||
|
||||
static void handleBacklight(const LightState& state) {
|
||||
static void handleBacklight(const HwLightState& state) {
|
||||
uint32_t brightness = state.color & 0xFF;
|
||||
set(LCD_LED BRIGHTNESS, brightness);
|
||||
}
|
||||
@ -88,15 +74,14 @@ static std::string getScaledRamp(uint32_t brightness) {
|
||||
std::string ramp, pad;
|
||||
|
||||
for (auto const& step : BRIGHTNESS_RAMP) {
|
||||
int32_t scaledStep = (step * brightness) / 0xFF;
|
||||
ramp += pad + std::to_string(scaledStep);
|
||||
ramp += pad + std::to_string(step * brightness / 0xFF);
|
||||
pad = ",";
|
||||
}
|
||||
|
||||
return ramp;
|
||||
}
|
||||
|
||||
static void handleNotification(const LightState& state) {
|
||||
static void handleNotification(const HwLightState& state) {
|
||||
uint32_t redBrightness, greenBrightness, blueBrightness, brightness;
|
||||
|
||||
/*
|
||||
@ -120,7 +105,7 @@ static void handleNotification(const LightState& state) {
|
||||
/* Disable blinking. */
|
||||
set(RGB_LED RGB_BLINK, 0);
|
||||
|
||||
if (state.flashMode == Flash::TIMED) {
|
||||
if (state.flashMode == FlashMode::TIMED) {
|
||||
/*
|
||||
* If the flashOnMs duration is not long enough to fit ramping up
|
||||
* and down at the default step duration, step duration is modified
|
||||
@ -165,44 +150,75 @@ static void handleNotification(const LightState& state) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::map<Type, std::function<void(const LightState&)>> lights = {
|
||||
{Type::BACKLIGHT, handleBacklight},
|
||||
{Type::BATTERY, handleNotification},
|
||||
{Type::NOTIFICATIONS, handleNotification},
|
||||
{Type::ATTENTION, handleNotification},
|
||||
static inline bool isLit(const HwLightState& state) {
|
||||
return state.color & 0x00ffffff;
|
||||
}
|
||||
|
||||
/* Keep sorted in the order of importance. */
|
||||
static std::vector<LightBackend> backends = {
|
||||
{ LightType::ATTENTION, handleNotification },
|
||||
{ LightType::NOTIFICATIONS, handleNotification },
|
||||
{ LightType::BATTERY, handleNotification },
|
||||
{ LightType::BACKLIGHT, handleBacklight },
|
||||
};
|
||||
|
||||
Light::Light() {}
|
||||
} // anonymous namespace
|
||||
|
||||
Return<Status> Light::setLight(Type type, const LightState& state) {
|
||||
auto it = lights.find(type);
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
if (it == lights.end()) {
|
||||
return Status::LIGHT_NOT_SUPPORTED;
|
||||
}
|
||||
ndk::ScopedAStatus Lights::setLightState(int id, const HwLightState& state) {
|
||||
LightStateHandler handler = nullptr;
|
||||
LightType type = static_cast<LightType>(id);
|
||||
|
||||
/*
|
||||
* Lock global mutex until light state is updated.
|
||||
*/
|
||||
/* Lock global mutex until light state is updated. */
|
||||
std::lock_guard<std::mutex> lock(globalLock);
|
||||
|
||||
it->second(state);
|
||||
/* Update the cached state value for the current type. */
|
||||
for (LightBackend& backend : backends) {
|
||||
if (backend.type == type) {
|
||||
backend.state = state;
|
||||
handler = backend.handler;
|
||||
}
|
||||
}
|
||||
|
||||
return Status::SUCCESS;
|
||||
/* If no handler has been found, then the type is not supported. */
|
||||
if (!handler) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
/* Light up the type with the highest priority that matches the current handler. */
|
||||
for (LightBackend& backend : backends) {
|
||||
if (handler == backend.handler && isLit(backend.state)) {
|
||||
handler(backend.state);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
}
|
||||
|
||||
/* If no type has been lit up, then turn off the hardware. */
|
||||
handler(state);
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
Return<void> Light::getSupportedTypes(getSupportedTypes_cb _hidl_cb) {
|
||||
std::vector<Type> types;
|
||||
ndk::ScopedAStatus Lights::getLights(std::vector<HwLight>* lights) {
|
||||
int i = 0;
|
||||
|
||||
for (auto const& light : lights) types.push_back(light.first);
|
||||
for (const LightBackend& backend : backends) {
|
||||
HwLight hwLight;
|
||||
hwLight.id = (int) backend.type;
|
||||
hwLight.type = backend.type;
|
||||
hwLight.ordinal = i;
|
||||
lights->push_back(hwLight);
|
||||
i++;
|
||||
}
|
||||
|
||||
_hidl_cb(types);
|
||||
|
||||
return Void();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V2_0
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
48
light/Lights.h
Normal file
48
light/Lights.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2018-2024 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/light/BnLights.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
using ::aidl::android::hardware::light::BnLights;
|
||||
using ::aidl::android::hardware::light::FlashMode;
|
||||
using ::aidl::android::hardware::light::HwLight;
|
||||
using ::aidl::android::hardware::light::HwLightState;
|
||||
using ::aidl::android::hardware::light::LightType;
|
||||
|
||||
typedef void (*LightStateHandler)(const HwLightState&);
|
||||
|
||||
struct LightBackend {
|
||||
LightType type;
|
||||
HwLightState state;
|
||||
LightStateHandler handler;
|
||||
|
||||
LightBackend(LightType type, LightStateHandler handler) : type(type), handler(handler) {
|
||||
this->state.color = 0xff000000;
|
||||
}
|
||||
};
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class Lights : public BnLights {
|
||||
public:
|
||||
ndk::ScopedAStatus setLightState(int id, const HwLightState& state) override;
|
||||
ndk::ScopedAStatus getLights(std::vector<HwLight>* types) override;
|
||||
|
||||
private:
|
||||
std::mutex globalLock;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
4
light/android.hardware.light-service.mata.rc
Normal file
4
light/android.hardware.light-service.mata.rc
Normal file
@ -0,0 +1,4 @@
|
||||
service vendor.light-mata /vendor/bin/hw/android.hardware.light-service.mata
|
||||
class hal
|
||||
user system
|
||||
group system
|
||||
7
light/android.hardware.light-service.mata.xml
Normal file
7
light/android.hardware.light-service.mata.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.light</name>
|
||||
<version>2</version>
|
||||
<fqname>ILights/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
@ -1,5 +0,0 @@
|
||||
service vendor.light-hal-2-0 /vendor/bin/hw/android.hardware.light@2.0-service.mata
|
||||
interface android.hardware.light@2.0::ILight default
|
||||
class hal
|
||||
user system
|
||||
group system
|
||||
@ -1,11 +0,0 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="hidl">
|
||||
<name>android.hardware.light</name>
|
||||
<transport>hwbinder</transport>
|
||||
<version>2.0</version>
|
||||
<interface>
|
||||
<name>ILight</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
</hal>
|
||||
</manifest>
|
||||
@ -1,50 +1,24 @@
|
||||
/*
|
||||
* Copyright 2017 The LineageOS 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.
|
||||
* SPDX-FileCopyrightText: 2018-2024 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.light@2.0-service.mata"
|
||||
#include "Lights.h"
|
||||
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
|
||||
#include "Light.h"
|
||||
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
using android::hardware::joinRpcThreadpool;
|
||||
|
||||
using android::hardware::light::V2_0::ILight;
|
||||
using android::hardware::light::V2_0::implementation::Light;
|
||||
|
||||
using android::OK;
|
||||
using android::sp;
|
||||
using android::status_t;
|
||||
using ::aidl::android::hardware::light::Lights;
|
||||
|
||||
int main() {
|
||||
android::sp<ILight> service = new Light();
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<Lights> lights = ndk::SharedRefBase::make<Lights>();
|
||||
|
||||
configureRpcThreadpool(1, true);
|
||||
const std::string instance = std::string() + Lights::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(lights->asBinder().get(), instance.c_str());
|
||||
CHECK_EQ(status, STATUS_OK);
|
||||
|
||||
status_t status = service->registerAsService();
|
||||
if (status != OK) {
|
||||
ALOGE("Cannot register Light HAL service.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ALOGI("Light HAL service ready.");
|
||||
|
||||
joinRpcThreadpool();
|
||||
|
||||
ALOGI("Light HAL service failed to join thread pool.");
|
||||
return 1;
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
|
||||
2
sepolicy/vendor/file_contexts
vendored
2
sepolicy/vendor/file_contexts
vendored
@ -28,7 +28,7 @@
|
||||
/vendor/bin/hw/android\.hardware\.biometrics\.fingerprint@2\.1-service\.mata u:object_r:hal_fingerprint_essential_exec:s0
|
||||
/(vendor|system/vendor)/bin/hw/android\.hardware\.drm@[0-9]+\.[0-9]+-service\.clearkey u:object_r:hal_drm_clearkey_exec:s0
|
||||
/(vendor|system/vendor)/bin/hw/android\.hardware\.drm@[0-9]+\.[0-9]+-service\.widevine u:object_r:hal_drm_widevine_exec:s0
|
||||
/vendor/bin/hw/android\.hardware\.light@2\.0-service\.mata u:object_r:hal_light_default_exec:s0
|
||||
/(vendor|system/vendor)/bin/hw/android\.hardware\.light-service\.mata u:object_r:hal_light_default_exec:s0
|
||||
/vendor/bin/hw/android\.hardware\.power@1\.3-service\.mata-libperfmgr u:object_r:hal_power_default_exec:s0
|
||||
/vendor/bin/hw/android\.hardware\.power\.stats@1\.0-service\.pixel u:object_r:hal_power_stats_default_exec:s0
|
||||
/vendor/bin/hw/vendor\.essential\.hardware\.sidecar@1\.0-service u:object_r:hal_sidecar_essential_default_exec:s0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user