mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 20:45:31 -04:00
universal7885: format code using clang-format-15
This commit is contained in:
parent
bfcbd0d355
commit
cb072badd5
55 changed files with 3946 additions and 3783 deletions
|
|
@ -22,172 +22,175 @@ namespace light {
|
|||
/*
|
||||
* Write value to path and close file.
|
||||
*/
|
||||
template <typename T>
|
||||
static void set(const std::string& path, const T& value) {
|
||||
std::ofstream file(path);
|
||||
file << value << std::endl;
|
||||
template <typename T> static void set(const std::string &path, const T &value) {
|
||||
std::ofstream file(path);
|
||||
file << value << std::endl;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T get(const std::string& path, const T& def) {
|
||||
std::ifstream file(path);
|
||||
T result;
|
||||
template <typename T> static T get(const std::string &path, const T &def) {
|
||||
std::ifstream file(path);
|
||||
T result;
|
||||
|
||||
file >> result;
|
||||
return file.fail() ? def : result;
|
||||
file >> result;
|
||||
return file.fail() ? def : result;
|
||||
}
|
||||
|
||||
Lights::Lights() {
|
||||
mLights.emplace(LightType::BACKLIGHT,
|
||||
std::bind(&Lights::handleBacklight, this, std::placeholders::_1));
|
||||
mLights.emplace(LightType::BACKLIGHT, std::bind(&Lights::handleBacklight,
|
||||
this, std::placeholders::_1));
|
||||
#ifdef BUTTON_BRIGHTNESS_NODE
|
||||
mLights.emplace(LightType::BUTTONS,
|
||||
std::bind(&Lights::handleButtons, this, std::placeholders::_1));
|
||||
mLights.emplace(LightType::BUTTONS, std::bind(&Lights::handleButtons, this,
|
||||
std::placeholders::_1));
|
||||
#endif /* BUTTON_BRIGHTNESS_NODE */
|
||||
#ifdef LED_BLINK_NODE
|
||||
mLights.emplace(LightType::BATTERY,
|
||||
std::bind(&Lights::handleBattery, this, std::placeholders::_1));
|
||||
mLights.emplace(LightType::NOTIFICATIONS,
|
||||
std::bind(&Lights::handleNotifications, this, std::placeholders::_1));
|
||||
mLights.emplace(LightType::ATTENTION,
|
||||
std::bind(&Lights::handleAttention, this, std::placeholders::_1));
|
||||
mLights.emplace(LightType::BATTERY, std::bind(&Lights::handleBattery, this,
|
||||
std::placeholders::_1));
|
||||
mLights.emplace(
|
||||
LightType::NOTIFICATIONS,
|
||||
std::bind(&Lights::handleNotifications, this, std::placeholders::_1));
|
||||
mLights.emplace(LightType::ATTENTION, std::bind(&Lights::handleAttention,
|
||||
this, std::placeholders::_1));
|
||||
#endif /* LED_BLINK_NODE */
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Lights::setLightState(int32_t id, const HwLightState& state) {
|
||||
LightType type = static_cast<LightType>(id);
|
||||
auto it = mLights.find(type);
|
||||
ndk::ScopedAStatus Lights::setLightState(int32_t id,
|
||||
const HwLightState &state) {
|
||||
LightType type = static_cast<LightType>(id);
|
||||
auto it = mLights.find(type);
|
||||
|
||||
if (it == mLights.end()) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
if (it == mLights.end()) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
/*
|
||||
* Lock global mutex until light state is updated.
|
||||
*/
|
||||
std::lock_guard<std::mutex> lock(mLock);
|
||||
/*
|
||||
* Lock global mutex until light state is updated.
|
||||
*/
|
||||
std::lock_guard<std::mutex> lock(mLock);
|
||||
|
||||
it->second(state);
|
||||
it->second(state);
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
void Lights::handleBacklight(const HwLightState& state) {
|
||||
uint32_t max_brightness = get(PANEL_MAX_BRIGHTNESS_NODE, MAX_INPUT_BRIGHTNESS);
|
||||
uint32_t brightness = rgbToBrightness(state);
|
||||
void Lights::handleBacklight(const HwLightState &state) {
|
||||
uint32_t max_brightness =
|
||||
get(PANEL_MAX_BRIGHTNESS_NODE, MAX_INPUT_BRIGHTNESS);
|
||||
uint32_t brightness = rgbToBrightness(state);
|
||||
|
||||
if (max_brightness != MAX_INPUT_BRIGHTNESS) {
|
||||
brightness = brightness * max_brightness / MAX_INPUT_BRIGHTNESS;
|
||||
}
|
||||
if (max_brightness != MAX_INPUT_BRIGHTNESS) {
|
||||
brightness = brightness * max_brightness / MAX_INPUT_BRIGHTNESS;
|
||||
}
|
||||
|
||||
set(PANEL_BRIGHTNESS_NODE, brightness);
|
||||
set(PANEL_BRIGHTNESS_NODE, brightness);
|
||||
}
|
||||
|
||||
#ifdef BUTTON_BRIGHTNESS_NODE
|
||||
void Lights::handleButtons(const HwLightState& state) {
|
||||
void Lights::handleButtons(const HwLightState &state) {
|
||||
#ifdef VAR_BUTTON_BRIGHTNESS
|
||||
uint32_t brightness = rgbToBrightness(state);
|
||||
uint32_t brightness = rgbToBrightness(state);
|
||||
#else
|
||||
uint32_t brightness = (state.color & COLOR_MASK) ? 1 : 0;
|
||||
uint32_t brightness = (state.color & COLOR_MASK) ? 1 : 0;
|
||||
#endif
|
||||
|
||||
set(BUTTON_BRIGHTNESS_NODE, brightness);
|
||||
set(BUTTON_BRIGHTNESS_NODE, brightness);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LED_BLINK_NODE
|
||||
void Lights::handleBattery(const HwLightState& state) {
|
||||
mBatteryState = state;
|
||||
setNotificationLED();
|
||||
void Lights::handleBattery(const HwLightState &state) {
|
||||
mBatteryState = state;
|
||||
setNotificationLED();
|
||||
}
|
||||
|
||||
void Lights::handleNotifications(const HwLightState& state) {
|
||||
mNotificationState = state;
|
||||
setNotificationLED();
|
||||
void Lights::handleNotifications(const HwLightState &state) {
|
||||
mNotificationState = state;
|
||||
setNotificationLED();
|
||||
}
|
||||
|
||||
void Lights::handleAttention(const HwLightState& state) {
|
||||
mAttentionState = state;
|
||||
setNotificationLED();
|
||||
void Lights::handleAttention(const HwLightState &state) {
|
||||
mAttentionState = state;
|
||||
setNotificationLED();
|
||||
}
|
||||
|
||||
void Lights::setNotificationLED() {
|
||||
int32_t adjusted_brightness = MAX_INPUT_BRIGHTNESS;
|
||||
HwLightState state;
|
||||
int32_t adjusted_brightness = MAX_INPUT_BRIGHTNESS;
|
||||
HwLightState state;
|
||||
#ifdef LED_BLN_NODE
|
||||
bool bln = false;
|
||||
bool bln = false;
|
||||
#endif /* LED_BLN_NODE */
|
||||
|
||||
if (mNotificationState.color & COLOR_MASK) {
|
||||
adjusted_brightness = LED_BRIGHTNESS_NOTIFICATION;
|
||||
state = mNotificationState;
|
||||
if (mNotificationState.color & COLOR_MASK) {
|
||||
adjusted_brightness = LED_BRIGHTNESS_NOTIFICATION;
|
||||
state = mNotificationState;
|
||||
#ifdef LED_BLN_NODE
|
||||
bln = true;
|
||||
bln = true;
|
||||
#endif /* LED_BLN_NODE */
|
||||
} else if (mAttentionState.color & COLOR_MASK) {
|
||||
adjusted_brightness = LED_BRIGHTNESS_ATTENTION;
|
||||
state = mAttentionState;
|
||||
if (state.flashMode == FlashMode::HARDWARE) {
|
||||
if (state.flashOnMs > 0 && state.flashOffMs == 0) state.flashMode = FlashMode::NONE;
|
||||
state.color = 0x000000ff;
|
||||
}
|
||||
if (state.flashMode == FlashMode::NONE) {
|
||||
state.color = 0;
|
||||
}
|
||||
} else if (mBatteryState.color & COLOR_MASK) {
|
||||
adjusted_brightness = LED_BRIGHTNESS_BATTERY;
|
||||
state = mBatteryState;
|
||||
} else {
|
||||
set(LED_BLINK_NODE, "0x00000000 0 0");
|
||||
return;
|
||||
} else if (mAttentionState.color & COLOR_MASK) {
|
||||
adjusted_brightness = LED_BRIGHTNESS_ATTENTION;
|
||||
state = mAttentionState;
|
||||
if (state.flashMode == FlashMode::HARDWARE) {
|
||||
if (state.flashOnMs > 0 && state.flashOffMs == 0)
|
||||
state.flashMode = FlashMode::NONE;
|
||||
state.color = 0x000000ff;
|
||||
}
|
||||
|
||||
if (state.flashMode == FlashMode::NONE) {
|
||||
state.flashOnMs = 0;
|
||||
state.flashOffMs = 0;
|
||||
state.color = 0;
|
||||
}
|
||||
} else if (mBatteryState.color & COLOR_MASK) {
|
||||
adjusted_brightness = LED_BRIGHTNESS_BATTERY;
|
||||
state = mBatteryState;
|
||||
} else {
|
||||
set(LED_BLINK_NODE, "0x00000000 0 0");
|
||||
return;
|
||||
}
|
||||
|
||||
state.color = calibrateColor(state.color & COLOR_MASK, adjusted_brightness);
|
||||
set(LED_BLINK_NODE, ::android::base::StringPrintf("0x%08x %d %d", state.color, state.flashOnMs,
|
||||
state.flashOffMs));
|
||||
if (state.flashMode == FlashMode::NONE) {
|
||||
state.flashOnMs = 0;
|
||||
state.flashOffMs = 0;
|
||||
}
|
||||
|
||||
state.color = calibrateColor(state.color & COLOR_MASK, adjusted_brightness);
|
||||
set(LED_BLINK_NODE,
|
||||
::android::base::StringPrintf("0x%08x %d %d", state.color,
|
||||
state.flashOnMs, state.flashOffMs));
|
||||
|
||||
#ifdef LED_BLN_NODE
|
||||
if (bln) {
|
||||
set(LED_BLN_NODE, (state.color & COLOR_MASK) ? 1 : 0);
|
||||
}
|
||||
if (bln) {
|
||||
set(LED_BLN_NODE, (state.color & COLOR_MASK) ? 1 : 0);
|
||||
}
|
||||
#endif /* LED_BLN_NODE */
|
||||
}
|
||||
|
||||
uint32_t Lights::calibrateColor(uint32_t color, int32_t brightness) {
|
||||
uint32_t red = ((color >> 16) & 0xFF) * LED_ADJUSTMENT_R;
|
||||
uint32_t green = ((color >> 8) & 0xFF) * LED_ADJUSTMENT_G;
|
||||
uint32_t blue = (color & 0xFF) * LED_ADJUSTMENT_B;
|
||||
uint32_t red = ((color >> 16) & 0xFF) * LED_ADJUSTMENT_R;
|
||||
uint32_t green = ((color >> 8) & 0xFF) * LED_ADJUSTMENT_G;
|
||||
uint32_t blue = (color & 0xFF) * LED_ADJUSTMENT_B;
|
||||
|
||||
return (((red * brightness) / 255) << 16) + (((green * brightness) / 255) << 8) +
|
||||
((blue * brightness) / 255);
|
||||
return (((red * brightness) / 255) << 16) +
|
||||
(((green * brightness) / 255) << 8) + ((blue * brightness) / 255);
|
||||
}
|
||||
#endif /* LED_BLINK_NODE */
|
||||
|
||||
#define AutoHwLight(light) \
|
||||
{ .id = (int32_t)light, .type = light, .ordinal = 0 }
|
||||
#define AutoHwLight(light) \
|
||||
{ .id = (int32_t)light, .type = light, .ordinal = 0 }
|
||||
|
||||
ndk::ScopedAStatus Lights::getLights(std::vector<HwLight>* _aidl_return) {
|
||||
for (auto const& light : mLights) {
|
||||
_aidl_return->push_back(AutoHwLight(light.first));
|
||||
}
|
||||
ndk::ScopedAStatus Lights::getLights(std::vector<HwLight> *_aidl_return) {
|
||||
for (auto const &light : mLights) {
|
||||
_aidl_return->push_back(AutoHwLight(light.first));
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
uint32_t Lights::rgbToBrightness(const HwLightState& state) {
|
||||
uint32_t color = state.color & COLOR_MASK;
|
||||
uint32_t Lights::rgbToBrightness(const HwLightState &state) {
|
||||
uint32_t color = state.color & COLOR_MASK;
|
||||
|
||||
return ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) +
|
||||
(29 * (color & 0xff))) >>
|
||||
8;
|
||||
return ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) +
|
||||
(29 * (color & 0xff))) >>
|
||||
8;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "samsung_lights.h"
|
||||
#include <aidl/android/hardware/light/BnLights.h>
|
||||
#include <unordered_map>
|
||||
#include "samsung_lights.h"
|
||||
|
||||
using ::aidl::android::hardware::light::HwLight;
|
||||
using ::aidl::android::hardware::light::HwLightState;
|
||||
|
|
@ -19,36 +19,38 @@ namespace hardware {
|
|||
namespace light {
|
||||
|
||||
class Lights : public BnLights {
|
||||
public:
|
||||
Lights();
|
||||
public:
|
||||
Lights();
|
||||
|
||||
ndk::ScopedAStatus setLightState(int32_t id, const HwLightState& state) override;
|
||||
ndk::ScopedAStatus getLights(std::vector<HwLight>* _aidl_return) override;
|
||||
ndk::ScopedAStatus setLightState(int32_t id,
|
||||
const HwLightState &state) override;
|
||||
ndk::ScopedAStatus getLights(std::vector<HwLight> *_aidl_return) override;
|
||||
|
||||
private:
|
||||
void handleBacklight(const HwLightState& state);
|
||||
private:
|
||||
void handleBacklight(const HwLightState &state);
|
||||
#ifdef BUTTON_BRIGHTNESS_NODE
|
||||
void handleButtons(const HwLightState& state);
|
||||
void handleButtons(const HwLightState &state);
|
||||
#endif /* BUTTON_BRIGHTNESS_NODE */
|
||||
#ifdef LED_BLINK_NODE
|
||||
void handleBattery(const HwLightState& state);
|
||||
void handleNotifications(const HwLightState& state);
|
||||
void handleAttention(const HwLightState& state);
|
||||
void setNotificationLED();
|
||||
uint32_t calibrateColor(uint32_t color, int32_t brightness);
|
||||
void handleBattery(const HwLightState &state);
|
||||
void handleNotifications(const HwLightState &state);
|
||||
void handleAttention(const HwLightState &state);
|
||||
void setNotificationLED();
|
||||
uint32_t calibrateColor(uint32_t color, int32_t brightness);
|
||||
|
||||
HwLightState mAttentionState;
|
||||
HwLightState mBatteryState;
|
||||
HwLightState mNotificationState;
|
||||
HwLightState mAttentionState;
|
||||
HwLightState mBatteryState;
|
||||
HwLightState mNotificationState;
|
||||
#endif /* LED_BLINK_NODE */
|
||||
|
||||
uint32_t rgbToBrightness(const HwLightState& state);
|
||||
uint32_t rgbToBrightness(const HwLightState &state);
|
||||
|
||||
std::mutex mLock;
|
||||
std::unordered_map<LightType, std::function<void(const HwLightState&)>> mLights;
|
||||
std::mutex mLock;
|
||||
std::unordered_map<LightType, std::function<void(const HwLightState &)>>
|
||||
mLights;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
#define LED_BLN_NODE "/sys/class/misc/backlightnotification/notification_led"
|
||||
|
||||
// Uncomment to enable variable button brightness
|
||||
//#define VAR_BUTTON_BRIGHTNESS 1
|
||||
// #define VAR_BUTTON_BRIGHTNESS 1
|
||||
|
||||
/*
|
||||
* Brightness adjustment factors
|
||||
|
|
@ -55,4 +55,4 @@
|
|||
#define LED_BRIGHTNESS_NOTIFICATION 255
|
||||
#define LED_BRIGHTNESS_ATTENTION 255
|
||||
|
||||
#endif // SAMSUNG_LIGHTS_H
|
||||
#endif // SAMSUNG_LIGHTS_H
|
||||
|
|
|
|||
|
|
@ -15,13 +15,14 @@
|
|||
using ::aidl::android::hardware::light::Lights;
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<Lights> lights = ndk::SharedRefBase::make<Lights>();
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<Lights> lights = ndk::SharedRefBase::make<Lights>();
|
||||
|
||||
const std::string instance = std::string() + Lights::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(lights->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
const std::string instance = std::string() + Lights::descriptor + "/default";
|
||||
binder_status_t status =
|
||||
AServiceManager_addService(lights->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@
|
|||
#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <memory>
|
||||
#include <poll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <utils/Log.h>
|
||||
#include <utils/Trace.h>
|
||||
#include <memory>
|
||||
|
||||
#include "InteractionHandler.h"
|
||||
|
||||
|
|
@ -33,227 +33,233 @@
|
|||
#define MSINSEC 1000L
|
||||
#define USINMS 1000000L
|
||||
|
||||
static const std::vector<std::string> fb_idle_patch = {"/sys/class/drm/card0/device/idle_state",
|
||||
"/sys/class/graphics/fb0/idle_state"};
|
||||
static const std::vector<std::string> fb_idle_patch = {
|
||||
"/sys/class/drm/card0/device/idle_state",
|
||||
"/sys/class/graphics/fb0/idle_state"};
|
||||
|
||||
InteractionHandler::InteractionHandler(std::shared_ptr<HintManager> const& hint_manager)
|
||||
: mState(INTERACTION_STATE_UNINITIALIZED),
|
||||
mWaitMs(100),
|
||||
mMinDurationMs(1400),
|
||||
mMaxDurationMs(5650),
|
||||
mDurationMs(0),
|
||||
InteractionHandler::InteractionHandler(
|
||||
std::shared_ptr<HintManager> const &hint_manager)
|
||||
: mState(INTERACTION_STATE_UNINITIALIZED), mWaitMs(100),
|
||||
mMinDurationMs(1400), mMaxDurationMs(5650), mDurationMs(0),
|
||||
mHintManager(hint_manager) {}
|
||||
|
||||
InteractionHandler::~InteractionHandler() {
|
||||
Exit();
|
||||
}
|
||||
InteractionHandler::~InteractionHandler() { Exit(); }
|
||||
|
||||
static int fb_idle_open(void) {
|
||||
int fd;
|
||||
for (auto& path : fb_idle_patch) {
|
||||
fd = open(path.c_str(), O_RDONLY);
|
||||
if (fd >= 0) return fd;
|
||||
}
|
||||
ALOGE("Unable to open fb idle state path (%d)", errno);
|
||||
return -1;
|
||||
int fd;
|
||||
for (auto &path : fb_idle_patch) {
|
||||
fd = open(path.c_str(), O_RDONLY);
|
||||
if (fd >= 0)
|
||||
return fd;
|
||||
}
|
||||
ALOGE("Unable to open fb idle state path (%d)", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool InteractionHandler::Init() {
|
||||
std::lock_guard<std::mutex> lk(mLock);
|
||||
|
||||
if (mState != INTERACTION_STATE_UNINITIALIZED) return true;
|
||||
|
||||
mIdleFd = fb_idle_open();
|
||||
|
||||
mEventFd = eventfd(0, EFD_NONBLOCK);
|
||||
if (mEventFd < 0) {
|
||||
ALOGE("Unable to create event fd (%d)", errno);
|
||||
if (mIdleFd >= 0) {
|
||||
close(mIdleFd);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
mState = INTERACTION_STATE_IDLE;
|
||||
mThread = std::unique_ptr<std::thread>(new std::thread(&InteractionHandler::Routine, this));
|
||||
std::lock_guard<std::mutex> lk(mLock);
|
||||
|
||||
if (mState != INTERACTION_STATE_UNINITIALIZED)
|
||||
return true;
|
||||
|
||||
mIdleFd = fb_idle_open();
|
||||
|
||||
mEventFd = eventfd(0, EFD_NONBLOCK);
|
||||
if (mEventFd < 0) {
|
||||
ALOGE("Unable to create event fd (%d)", errno);
|
||||
if (mIdleFd >= 0) {
|
||||
close(mIdleFd);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
mState = INTERACTION_STATE_IDLE;
|
||||
mThread = std::unique_ptr<std::thread>(
|
||||
new std::thread(&InteractionHandler::Routine, this));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InteractionHandler::Exit() {
|
||||
std::unique_lock<std::mutex> lk(mLock);
|
||||
if (mState == INTERACTION_STATE_UNINITIALIZED) return;
|
||||
std::unique_lock<std::mutex> lk(mLock);
|
||||
if (mState == INTERACTION_STATE_UNINITIALIZED)
|
||||
return;
|
||||
|
||||
AbortWaitLocked();
|
||||
mState = INTERACTION_STATE_UNINITIALIZED;
|
||||
lk.unlock();
|
||||
AbortWaitLocked();
|
||||
mState = INTERACTION_STATE_UNINITIALIZED;
|
||||
lk.unlock();
|
||||
|
||||
mCond.notify_all();
|
||||
mThread->join();
|
||||
mCond.notify_all();
|
||||
mThread->join();
|
||||
|
||||
close(mEventFd);
|
||||
if (mIdleFd >= 0) {
|
||||
close(mIdleFd);
|
||||
}
|
||||
close(mEventFd);
|
||||
if (mIdleFd >= 0) {
|
||||
close(mIdleFd);
|
||||
}
|
||||
}
|
||||
|
||||
void InteractionHandler::PerfLock() {
|
||||
ALOGV("%s: acquiring perf lock", __func__);
|
||||
if (!mHintManager->DoHint("INTERACTION")) {
|
||||
ALOGE("%s: do hint INTERACTION failed", __func__);
|
||||
}
|
||||
ATRACE_INT("interaction_lock", 1);
|
||||
ALOGV("%s: acquiring perf lock", __func__);
|
||||
if (!mHintManager->DoHint("INTERACTION")) {
|
||||
ALOGE("%s: do hint INTERACTION failed", __func__);
|
||||
}
|
||||
ATRACE_INT("interaction_lock", 1);
|
||||
}
|
||||
|
||||
void InteractionHandler::PerfRel() {
|
||||
ALOGV("%s: releasing perf lock", __func__);
|
||||
if (!mHintManager->EndHint("INTERACTION")) {
|
||||
ALOGE("%s: end hint INTERACTION failed", __func__);
|
||||
}
|
||||
ATRACE_INT("interaction_lock", 0);
|
||||
ALOGV("%s: releasing perf lock", __func__);
|
||||
if (!mHintManager->EndHint("INTERACTION")) {
|
||||
ALOGE("%s: end hint INTERACTION failed", __func__);
|
||||
}
|
||||
ATRACE_INT("interaction_lock", 0);
|
||||
}
|
||||
|
||||
size_t InteractionHandler::CalcTimespecDiffMs(struct timespec start, struct timespec end) {
|
||||
size_t diff_in_us = 0;
|
||||
diff_in_us += (end.tv_sec - start.tv_sec) * MSINSEC;
|
||||
diff_in_us += (end.tv_nsec - start.tv_nsec) / USINMS;
|
||||
return diff_in_us;
|
||||
size_t InteractionHandler::CalcTimespecDiffMs(struct timespec start,
|
||||
struct timespec end) {
|
||||
size_t diff_in_us = 0;
|
||||
diff_in_us += (end.tv_sec - start.tv_sec) * MSINSEC;
|
||||
diff_in_us += (end.tv_nsec - start.tv_nsec) / USINMS;
|
||||
return diff_in_us;
|
||||
}
|
||||
|
||||
void InteractionHandler::Acquire(int32_t duration) {
|
||||
ATRACE_CALL();
|
||||
ATRACE_CALL();
|
||||
|
||||
std::lock_guard<std::mutex> lk(mLock);
|
||||
if (mState == INTERACTION_STATE_UNINITIALIZED) {
|
||||
ALOGW("%s: called while uninitialized", __func__);
|
||||
return;
|
||||
std::lock_guard<std::mutex> lk(mLock);
|
||||
if (mState == INTERACTION_STATE_UNINITIALIZED) {
|
||||
ALOGW("%s: called while uninitialized", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
int inputDuration = duration + 650;
|
||||
int finalDuration;
|
||||
if (inputDuration > mMaxDurationMs)
|
||||
finalDuration = mMaxDurationMs;
|
||||
else if (inputDuration > mMinDurationMs)
|
||||
finalDuration = inputDuration;
|
||||
else
|
||||
finalDuration = mMinDurationMs;
|
||||
|
||||
struct timespec cur_timespec;
|
||||
clock_gettime(CLOCK_MONOTONIC, &cur_timespec);
|
||||
if (mState != INTERACTION_STATE_IDLE && finalDuration <= mDurationMs) {
|
||||
size_t elapsed_time = CalcTimespecDiffMs(mLastTimespec, cur_timespec);
|
||||
// don't hint if previous hint's duration covers this hint's duration
|
||||
if (elapsed_time <= (mDurationMs - finalDuration)) {
|
||||
ALOGV("%s: Previous duration (%d) cover this (%d) elapsed: %lld",
|
||||
__func__, static_cast<int>(mDurationMs),
|
||||
static_cast<int>(finalDuration),
|
||||
static_cast<long long>(elapsed_time));
|
||||
return;
|
||||
}
|
||||
}
|
||||
mLastTimespec = cur_timespec;
|
||||
mDurationMs = finalDuration;
|
||||
|
||||
int inputDuration = duration + 650;
|
||||
int finalDuration;
|
||||
if (inputDuration > mMaxDurationMs)
|
||||
finalDuration = mMaxDurationMs;
|
||||
else if (inputDuration > mMinDurationMs)
|
||||
finalDuration = inputDuration;
|
||||
else
|
||||
finalDuration = mMinDurationMs;
|
||||
ALOGV("%s: input: %d final duration: %d", __func__, duration, finalDuration);
|
||||
|
||||
struct timespec cur_timespec;
|
||||
clock_gettime(CLOCK_MONOTONIC, &cur_timespec);
|
||||
if (mState != INTERACTION_STATE_IDLE && finalDuration <= mDurationMs) {
|
||||
size_t elapsed_time = CalcTimespecDiffMs(mLastTimespec, cur_timespec);
|
||||
// don't hint if previous hint's duration covers this hint's duration
|
||||
if (elapsed_time <= (mDurationMs - finalDuration)) {
|
||||
ALOGV("%s: Previous duration (%d) cover this (%d) elapsed: %lld", __func__,
|
||||
static_cast<int>(mDurationMs), static_cast<int>(finalDuration),
|
||||
static_cast<long long>(elapsed_time));
|
||||
return;
|
||||
}
|
||||
}
|
||||
mLastTimespec = cur_timespec;
|
||||
mDurationMs = finalDuration;
|
||||
if (mState == INTERACTION_STATE_WAITING)
|
||||
AbortWaitLocked();
|
||||
else if (mState == INTERACTION_STATE_IDLE)
|
||||
PerfLock();
|
||||
|
||||
ALOGV("%s: input: %d final duration: %d", __func__, duration, finalDuration);
|
||||
|
||||
if (mState == INTERACTION_STATE_WAITING)
|
||||
AbortWaitLocked();
|
||||
else if (mState == INTERACTION_STATE_IDLE)
|
||||
PerfLock();
|
||||
|
||||
mState = INTERACTION_STATE_INTERACTION;
|
||||
mCond.notify_one();
|
||||
mState = INTERACTION_STATE_INTERACTION;
|
||||
mCond.notify_one();
|
||||
}
|
||||
|
||||
void InteractionHandler::Release() {
|
||||
std::lock_guard<std::mutex> lk(mLock);
|
||||
if (mState == INTERACTION_STATE_WAITING) {
|
||||
ATRACE_CALL();
|
||||
PerfRel();
|
||||
mState = INTERACTION_STATE_IDLE;
|
||||
} else {
|
||||
// clear any wait aborts pending in event fd
|
||||
uint64_t val;
|
||||
ssize_t ret = read(mEventFd, &val, sizeof(val));
|
||||
std::lock_guard<std::mutex> lk(mLock);
|
||||
if (mState == INTERACTION_STATE_WAITING) {
|
||||
ATRACE_CALL();
|
||||
PerfRel();
|
||||
mState = INTERACTION_STATE_IDLE;
|
||||
} else {
|
||||
// clear any wait aborts pending in event fd
|
||||
uint64_t val;
|
||||
ssize_t ret = read(mEventFd, &val, sizeof(val));
|
||||
|
||||
ALOGW_IF(ret < 0, "%s: failed to clear eventfd (%zd, %d)", __func__, ret, errno);
|
||||
}
|
||||
ALOGW_IF(ret < 0, "%s: failed to clear eventfd (%zd, %d)", __func__, ret,
|
||||
errno);
|
||||
}
|
||||
}
|
||||
|
||||
// should be called while locked
|
||||
void InteractionHandler::AbortWaitLocked() {
|
||||
uint64_t val = 1;
|
||||
ssize_t ret = write(mEventFd, &val, sizeof(val));
|
||||
if (ret != sizeof(val)) ALOGW("Unable to write to event fd (%zd)", ret);
|
||||
uint64_t val = 1;
|
||||
ssize_t ret = write(mEventFd, &val, sizeof(val));
|
||||
if (ret != sizeof(val))
|
||||
ALOGW("Unable to write to event fd (%zd)", ret);
|
||||
}
|
||||
|
||||
void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) {
|
||||
char data[MAX_LENGTH];
|
||||
ssize_t ret;
|
||||
struct pollfd pfd[2];
|
||||
char data[MAX_LENGTH];
|
||||
ssize_t ret;
|
||||
struct pollfd pfd[2];
|
||||
|
||||
ATRACE_CALL();
|
||||
ATRACE_CALL();
|
||||
|
||||
ALOGV("%s: wait:%d timeout:%d", __func__, wait_ms, timeout_ms);
|
||||
ALOGV("%s: wait:%d timeout:%d", __func__, wait_ms, timeout_ms);
|
||||
|
||||
pfd[0].fd = mEventFd;
|
||||
pfd[0].events = POLLIN;
|
||||
pfd[1].fd = mIdleFd;
|
||||
pfd[1].events = POLLPRI | POLLERR;
|
||||
pfd[0].fd = mEventFd;
|
||||
pfd[0].events = POLLIN;
|
||||
pfd[1].fd = mIdleFd;
|
||||
pfd[1].events = POLLPRI | POLLERR;
|
||||
|
||||
ret = poll(pfd, 1, wait_ms);
|
||||
ret = poll(pfd, 1, wait_ms);
|
||||
if (ret > 0) {
|
||||
ALOGV("%s: wait aborted", __func__);
|
||||
return;
|
||||
} else if (ret < 0) {
|
||||
ALOGE("%s: error in poll while waiting", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mIdleFd < 0) {
|
||||
ret = poll(pfd, 1, timeout_ms);
|
||||
if (ret > 0) {
|
||||
ALOGV("%s: wait aborted", __func__);
|
||||
return;
|
||||
ALOGV("%s: wait for duration aborted", __func__);
|
||||
return;
|
||||
} else if (ret < 0) {
|
||||
ALOGE("%s: error in poll while waiting", __func__);
|
||||
return;
|
||||
ALOGE("%s: Error on waiting for duration (%zd)", __func__, ret);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (mIdleFd < 0) {
|
||||
ret = poll(pfd, 1, timeout_ms);
|
||||
if (ret > 0) {
|
||||
ALOGV("%s: wait for duration aborted", __func__);
|
||||
return;
|
||||
} else if (ret < 0) {
|
||||
ALOGE("%s: Error on waiting for duration (%zd)", __func__, ret);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
ret = pread(mIdleFd, data, sizeof(data), 0);
|
||||
if (!ret) {
|
||||
ALOGE("%s: Unexpected EOF!", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = pread(mIdleFd, data, sizeof(data), 0);
|
||||
if (!ret) {
|
||||
ALOGE("%s: Unexpected EOF!", __func__);
|
||||
return;
|
||||
}
|
||||
if (!strncmp(data, "idle", 4)) {
|
||||
ALOGV("%s: already idle", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strncmp(data, "idle", 4)) {
|
||||
ALOGV("%s: already idle", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = poll(pfd, 2, timeout_ms);
|
||||
if (ret < 0)
|
||||
ALOGE("%s: Error on waiting for idle (%zd)", __func__, ret);
|
||||
else if (ret == 0)
|
||||
ALOGV("%s: timed out waiting for idle", __func__);
|
||||
else if (pfd[0].revents)
|
||||
ALOGV("%s: wait for idle aborted", __func__);
|
||||
else if (pfd[1].revents)
|
||||
ALOGV("%s: idle detected", __func__);
|
||||
ret = poll(pfd, 2, timeout_ms);
|
||||
if (ret < 0)
|
||||
ALOGE("%s: Error on waiting for idle (%zd)", __func__, ret);
|
||||
else if (ret == 0)
|
||||
ALOGV("%s: timed out waiting for idle", __func__);
|
||||
else if (pfd[0].revents)
|
||||
ALOGV("%s: wait for idle aborted", __func__);
|
||||
else if (pfd[1].revents)
|
||||
ALOGV("%s: idle detected", __func__);
|
||||
}
|
||||
|
||||
void InteractionHandler::Routine() {
|
||||
std::unique_lock<std::mutex> lk(mLock, std::defer_lock);
|
||||
std::unique_lock<std::mutex> lk(mLock, std::defer_lock);
|
||||
|
||||
while (true) {
|
||||
lk.lock();
|
||||
mCond.wait(lk, [&] { return mState != INTERACTION_STATE_IDLE; });
|
||||
if (mState == INTERACTION_STATE_UNINITIALIZED) return;
|
||||
mState = INTERACTION_STATE_WAITING;
|
||||
lk.unlock();
|
||||
while (true) {
|
||||
lk.lock();
|
||||
mCond.wait(lk, [&] { return mState != INTERACTION_STATE_IDLE; });
|
||||
if (mState == INTERACTION_STATE_UNINITIALIZED)
|
||||
return;
|
||||
mState = INTERACTION_STATE_WAITING;
|
||||
lk.unlock();
|
||||
|
||||
WaitForIdle(mWaitMs, mDurationMs);
|
||||
Release();
|
||||
}
|
||||
WaitForIdle(mWaitMs, mDurationMs);
|
||||
Release();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,47 +28,47 @@
|
|||
using ::android::perfmgr::HintManager;
|
||||
|
||||
enum interaction_state {
|
||||
INTERACTION_STATE_UNINITIALIZED,
|
||||
INTERACTION_STATE_IDLE,
|
||||
INTERACTION_STATE_INTERACTION,
|
||||
INTERACTION_STATE_WAITING,
|
||||
INTERACTION_STATE_UNINITIALIZED,
|
||||
INTERACTION_STATE_IDLE,
|
||||
INTERACTION_STATE_INTERACTION,
|
||||
INTERACTION_STATE_WAITING,
|
||||
};
|
||||
|
||||
class InteractionHandler {
|
||||
public:
|
||||
InteractionHandler(std::shared_ptr<HintManager> const& hint_manager);
|
||||
~InteractionHandler();
|
||||
bool Init();
|
||||
void Exit();
|
||||
void Acquire(int32_t duration);
|
||||
public:
|
||||
InteractionHandler(std::shared_ptr<HintManager> const &hint_manager);
|
||||
~InteractionHandler();
|
||||
bool Init();
|
||||
void Exit();
|
||||
void Acquire(int32_t duration);
|
||||
|
||||
private:
|
||||
void Release();
|
||||
void WaitForIdle(int32_t wait_ms, int32_t timeout_ms);
|
||||
void AbortWaitLocked();
|
||||
void Routine();
|
||||
private:
|
||||
void Release();
|
||||
void WaitForIdle(int32_t wait_ms, int32_t timeout_ms);
|
||||
void AbortWaitLocked();
|
||||
void Routine();
|
||||
|
||||
void PerfLock();
|
||||
void PerfRel();
|
||||
void PerfLock();
|
||||
void PerfRel();
|
||||
|
||||
size_t CalcTimespecDiffMs(struct timespec start, struct timespec end);
|
||||
size_t CalcTimespecDiffMs(struct timespec start, struct timespec end);
|
||||
|
||||
enum interaction_state mState;
|
||||
enum interaction_state mState;
|
||||
|
||||
int mIdleFd;
|
||||
int mEventFd;
|
||||
int mIdleFd;
|
||||
int mEventFd;
|
||||
|
||||
int32_t mWaitMs;
|
||||
int32_t mMinDurationMs;
|
||||
int32_t mMaxDurationMs;
|
||||
int32_t mDurationMs;
|
||||
int32_t mWaitMs;
|
||||
int32_t mMinDurationMs;
|
||||
int32_t mMaxDurationMs;
|
||||
int32_t mDurationMs;
|
||||
|
||||
struct timespec mLastTimespec;
|
||||
struct timespec mLastTimespec;
|
||||
|
||||
std::unique_ptr<std::thread> mThread;
|
||||
std::mutex mLock;
|
||||
std::condition_variable mCond;
|
||||
std::shared_ptr<HintManager> mHintManager;
|
||||
std::unique_ptr<std::thread> mThread;
|
||||
std::mutex mLock;
|
||||
std::condition_variable mCond;
|
||||
std::shared_ptr<HintManager> mHintManager;
|
||||
};
|
||||
|
||||
#endif // POWER_LIBPERFMGR_INTERACTIONHANDLER_H_
|
||||
#endif // POWER_LIBPERFMGR_INTERACTIONHANDLER_H_
|
||||
|
|
|
|||
|
|
@ -42,221 +42,221 @@ constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio";
|
|||
constexpr char kPowerHalRenderingProp[] = "vendor.powerhal.rendering";
|
||||
|
||||
Power::Power(std::shared_ptr<HintManager> hm)
|
||||
: mHintManager(hm),
|
||||
mInteractionHandler(nullptr),
|
||||
mVRModeOn(false),
|
||||
: mHintManager(hm), mInteractionHandler(nullptr), mVRModeOn(false),
|
||||
mSustainedPerfModeOn(false) {
|
||||
mInteractionHandler = std::make_unique<InteractionHandler>(mHintManager);
|
||||
mInteractionHandler->Init();
|
||||
mInteractionHandler = std::make_unique<InteractionHandler>(mHintManager);
|
||||
mInteractionHandler->Init();
|
||||
|
||||
std::string state = ::android::base::GetProperty(kPowerHalStateProp, "");
|
||||
if (state == "SUSTAINED_PERFORMANCE") {
|
||||
ALOGI("Initialize with SUSTAINED_PERFORMANCE on");
|
||||
mHintManager->DoHint("SUSTAINED_PERFORMANCE");
|
||||
mSustainedPerfModeOn = true;
|
||||
} else if (state == "VR") {
|
||||
ALOGI("Initialize with VR on");
|
||||
mHintManager->DoHint(state);
|
||||
mVRModeOn = true;
|
||||
} else if (state == "VR_SUSTAINED_PERFORMANCE") {
|
||||
ALOGI("Initialize with SUSTAINED_PERFORMANCE and VR on");
|
||||
mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE");
|
||||
mSustainedPerfModeOn = true;
|
||||
mVRModeOn = true;
|
||||
} else {
|
||||
ALOGI("Initialize PowerHAL");
|
||||
}
|
||||
std::string state = ::android::base::GetProperty(kPowerHalStateProp, "");
|
||||
if (state == "SUSTAINED_PERFORMANCE") {
|
||||
ALOGI("Initialize with SUSTAINED_PERFORMANCE on");
|
||||
mHintManager->DoHint("SUSTAINED_PERFORMANCE");
|
||||
mSustainedPerfModeOn = true;
|
||||
} else if (state == "VR") {
|
||||
ALOGI("Initialize with VR on");
|
||||
mHintManager->DoHint(state);
|
||||
mVRModeOn = true;
|
||||
} else if (state == "VR_SUSTAINED_PERFORMANCE") {
|
||||
ALOGI("Initialize with SUSTAINED_PERFORMANCE and VR on");
|
||||
mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE");
|
||||
mSustainedPerfModeOn = true;
|
||||
mVRModeOn = true;
|
||||
} else {
|
||||
ALOGI("Initialize PowerHAL");
|
||||
}
|
||||
|
||||
state = ::android::base::GetProperty(kPowerHalAudioProp, "");
|
||||
if (state == "AUDIO_STREAMING_LOW_LATENCY") {
|
||||
ALOGI("Initialize with AUDIO_LOW_LATENCY on");
|
||||
mHintManager->DoHint(state);
|
||||
}
|
||||
state = ::android::base::GetProperty(kPowerHalAudioProp, "");
|
||||
if (state == "AUDIO_STREAMING_LOW_LATENCY") {
|
||||
ALOGI("Initialize with AUDIO_LOW_LATENCY on");
|
||||
mHintManager->DoHint(state);
|
||||
}
|
||||
|
||||
state = ::android::base::GetProperty(kPowerHalRenderingProp, "");
|
||||
if (state == "EXPENSIVE_RENDERING") {
|
||||
ALOGI("Initialize with EXPENSIVE_RENDERING on");
|
||||
mHintManager->DoHint("EXPENSIVE_RENDERING");
|
||||
}
|
||||
state = ::android::base::GetProperty(kPowerHalRenderingProp, "");
|
||||
if (state == "EXPENSIVE_RENDERING") {
|
||||
ALOGI("Initialize with EXPENSIVE_RENDERING on");
|
||||
mHintManager->DoHint("EXPENSIVE_RENDERING");
|
||||
}
|
||||
|
||||
// Now start to take powerhint
|
||||
ALOGI("PowerHAL ready to process hints");
|
||||
// Now start to take powerhint
|
||||
ALOGI("PowerHAL ready to process hints");
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
|
||||
LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << enabled;
|
||||
ATRACE_INT(toString(type).c_str(), enabled);
|
||||
switch (type) {
|
||||
case Mode::LOW_POWER:
|
||||
if (enabled) {
|
||||
mHintManager->DoHint(toString(type));
|
||||
} else {
|
||||
mHintManager->EndHint(toString(type));
|
||||
}
|
||||
break;
|
||||
case Mode::SUSTAINED_PERFORMANCE:
|
||||
if (enabled && !mSustainedPerfModeOn) {
|
||||
if (!mVRModeOn) { // Sustained mode only.
|
||||
mHintManager->DoHint("SUSTAINED_PERFORMANCE");
|
||||
} else { // Sustained + VR mode.
|
||||
mHintManager->EndHint("VR");
|
||||
mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE");
|
||||
}
|
||||
mSustainedPerfModeOn = true;
|
||||
} else if (!enabled && mSustainedPerfModeOn) {
|
||||
mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE");
|
||||
mHintManager->EndHint("SUSTAINED_PERFORMANCE");
|
||||
if (mVRModeOn) { // Switch back to VR Mode.
|
||||
mHintManager->DoHint("VR");
|
||||
}
|
||||
mSustainedPerfModeOn = false;
|
||||
}
|
||||
break;
|
||||
case Mode::VR:
|
||||
if (enabled && !mVRModeOn) {
|
||||
if (!mSustainedPerfModeOn) { // VR mode only.
|
||||
mHintManager->DoHint("VR");
|
||||
} else { // Sustained + VR mode.
|
||||
mHintManager->EndHint("SUSTAINED_PERFORMANCE");
|
||||
mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE");
|
||||
}
|
||||
mVRModeOn = true;
|
||||
} else if (!enabled && mVRModeOn) {
|
||||
mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE");
|
||||
mHintManager->EndHint("VR");
|
||||
if (mSustainedPerfModeOn) { // Switch back to sustained Mode.
|
||||
mHintManager->DoHint("SUSTAINED_PERFORMANCE");
|
||||
}
|
||||
mVRModeOn = false;
|
||||
}
|
||||
break;
|
||||
case Mode::LAUNCH:
|
||||
if (mVRModeOn || mSustainedPerfModeOn) {
|
||||
break;
|
||||
}
|
||||
[[fallthrough]];
|
||||
case Mode::DOUBLE_TAP_TO_WAKE:
|
||||
[[fallthrough]];
|
||||
case Mode::FIXED_PERFORMANCE:
|
||||
[[fallthrough]];
|
||||
case Mode::EXPENSIVE_RENDERING:
|
||||
[[fallthrough]];
|
||||
case Mode::INTERACTIVE:
|
||||
[[fallthrough]];
|
||||
case Mode::DEVICE_IDLE:
|
||||
[[fallthrough]];
|
||||
case Mode::DISPLAY_INACTIVE:
|
||||
[[fallthrough]];
|
||||
case Mode::AUDIO_STREAMING_LOW_LATENCY:
|
||||
[[fallthrough]];
|
||||
case Mode::CAMERA_STREAMING_SECURE:
|
||||
[[fallthrough]];
|
||||
case Mode::CAMERA_STREAMING_LOW:
|
||||
[[fallthrough]];
|
||||
case Mode::CAMERA_STREAMING_MID:
|
||||
[[fallthrough]];
|
||||
case Mode::CAMERA_STREAMING_HIGH:
|
||||
[[fallthrough]];
|
||||
default:
|
||||
if (enabled) {
|
||||
mHintManager->DoHint(toString(type));
|
||||
} else {
|
||||
mHintManager->EndHint(toString(type));
|
||||
}
|
||||
break;
|
||||
LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << enabled;
|
||||
ATRACE_INT(toString(type).c_str(), enabled);
|
||||
switch (type) {
|
||||
case Mode::LOW_POWER:
|
||||
if (enabled) {
|
||||
mHintManager->DoHint(toString(type));
|
||||
} else {
|
||||
mHintManager->EndHint(toString(type));
|
||||
}
|
||||
break;
|
||||
case Mode::SUSTAINED_PERFORMANCE:
|
||||
if (enabled && !mSustainedPerfModeOn) {
|
||||
if (!mVRModeOn) { // Sustained mode only.
|
||||
mHintManager->DoHint("SUSTAINED_PERFORMANCE");
|
||||
} else { // Sustained + VR mode.
|
||||
mHintManager->EndHint("VR");
|
||||
mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE");
|
||||
}
|
||||
mSustainedPerfModeOn = true;
|
||||
} else if (!enabled && mSustainedPerfModeOn) {
|
||||
mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE");
|
||||
mHintManager->EndHint("SUSTAINED_PERFORMANCE");
|
||||
if (mVRModeOn) { // Switch back to VR Mode.
|
||||
mHintManager->DoHint("VR");
|
||||
}
|
||||
mSustainedPerfModeOn = false;
|
||||
}
|
||||
break;
|
||||
case Mode::VR:
|
||||
if (enabled && !mVRModeOn) {
|
||||
if (!mSustainedPerfModeOn) { // VR mode only.
|
||||
mHintManager->DoHint("VR");
|
||||
} else { // Sustained + VR mode.
|
||||
mHintManager->EndHint("SUSTAINED_PERFORMANCE");
|
||||
mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE");
|
||||
}
|
||||
mVRModeOn = true;
|
||||
} else if (!enabled && mVRModeOn) {
|
||||
mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE");
|
||||
mHintManager->EndHint("VR");
|
||||
if (mSustainedPerfModeOn) { // Switch back to sustained Mode.
|
||||
mHintManager->DoHint("SUSTAINED_PERFORMANCE");
|
||||
}
|
||||
mVRModeOn = false;
|
||||
}
|
||||
break;
|
||||
case Mode::LAUNCH:
|
||||
if (mVRModeOn || mSustainedPerfModeOn) {
|
||||
break;
|
||||
}
|
||||
[[fallthrough]];
|
||||
case Mode::DOUBLE_TAP_TO_WAKE:
|
||||
[[fallthrough]];
|
||||
case Mode::FIXED_PERFORMANCE:
|
||||
[[fallthrough]];
|
||||
case Mode::EXPENSIVE_RENDERING:
|
||||
[[fallthrough]];
|
||||
case Mode::INTERACTIVE:
|
||||
[[fallthrough]];
|
||||
case Mode::DEVICE_IDLE:
|
||||
[[fallthrough]];
|
||||
case Mode::DISPLAY_INACTIVE:
|
||||
[[fallthrough]];
|
||||
case Mode::AUDIO_STREAMING_LOW_LATENCY:
|
||||
[[fallthrough]];
|
||||
case Mode::CAMERA_STREAMING_SECURE:
|
||||
[[fallthrough]];
|
||||
case Mode::CAMERA_STREAMING_LOW:
|
||||
[[fallthrough]];
|
||||
case Mode::CAMERA_STREAMING_MID:
|
||||
[[fallthrough]];
|
||||
case Mode::CAMERA_STREAMING_HIGH:
|
||||
[[fallthrough]];
|
||||
default:
|
||||
if (enabled) {
|
||||
mHintManager->DoHint(toString(type));
|
||||
} else {
|
||||
mHintManager->EndHint(toString(type));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Power::isModeSupported(Mode type, bool* _aidl_return) {
|
||||
bool supported = mHintManager->IsHintSupported(toString(type));
|
||||
switch (type) {
|
||||
case Mode::LOW_POWER: // LOW_POWER handled insides PowerHAL specifically
|
||||
supported = true;
|
||||
break;
|
||||
case Mode::DOUBLE_TAP_TO_WAKE:
|
||||
supported = true;
|
||||
break;
|
||||
case Mode::INTERACTIVE:
|
||||
supported = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) {
|
||||
bool supported = mHintManager->IsHintSupported(toString(type));
|
||||
switch (type) {
|
||||
case Mode::LOW_POWER: // LOW_POWER handled insides PowerHAL specifically
|
||||
supported = true;
|
||||
break;
|
||||
case Mode::DOUBLE_TAP_TO_WAKE:
|
||||
supported = true;
|
||||
break;
|
||||
case Mode::INTERACTIVE:
|
||||
supported = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Power mode " << toString(type) << " isModeSupported: " << supported;
|
||||
*_aidl_return = supported;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
LOG(INFO) << "Power mode " << toString(type)
|
||||
<< " isModeSupported: " << supported;
|
||||
*_aidl_return = supported;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
|
||||
LOG(DEBUG) << "Power setBoost: " << toString(type) << " duration: " << durationMs;
|
||||
ATRACE_INT(toString(type).c_str(), durationMs);
|
||||
switch (type) {
|
||||
case Boost::INTERACTION:
|
||||
if (mVRModeOn || mSustainedPerfModeOn) {
|
||||
break;
|
||||
}
|
||||
mInteractionHandler->Acquire(durationMs);
|
||||
break;
|
||||
case Boost::DISPLAY_UPDATE_IMMINENT:
|
||||
[[fallthrough]];
|
||||
case Boost::ML_ACC:
|
||||
[[fallthrough]];
|
||||
case Boost::AUDIO_LAUNCH:
|
||||
[[fallthrough]];
|
||||
case Boost::CAMERA_LAUNCH:
|
||||
[[fallthrough]];
|
||||
case Boost::CAMERA_SHOT:
|
||||
[[fallthrough]];
|
||||
default:
|
||||
if (mVRModeOn || mSustainedPerfModeOn) {
|
||||
break;
|
||||
}
|
||||
if (durationMs > 0) {
|
||||
mHintManager->DoHint(toString(type), std::chrono::milliseconds(durationMs));
|
||||
} else if (durationMs == 0) {
|
||||
mHintManager->DoHint(toString(type));
|
||||
} else {
|
||||
mHintManager->EndHint(toString(type));
|
||||
}
|
||||
break;
|
||||
LOG(DEBUG) << "Power setBoost: " << toString(type)
|
||||
<< " duration: " << durationMs;
|
||||
ATRACE_INT(toString(type).c_str(), durationMs);
|
||||
switch (type) {
|
||||
case Boost::INTERACTION:
|
||||
if (mVRModeOn || mSustainedPerfModeOn) {
|
||||
break;
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool* _aidl_return) {
|
||||
bool supported = mHintManager->IsHintSupported(toString(type));
|
||||
LOG(INFO) << "Power boost " << toString(type) << " isBoostSupported: " << supported;
|
||||
*_aidl_return = supported;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
constexpr const char* boolToString(bool b) {
|
||||
return b ? "true" : "false";
|
||||
}
|
||||
|
||||
binder_status_t Power::dump(int fd, const char**, uint32_t) {
|
||||
std::string buf(::android::base::StringPrintf(
|
||||
"HintManager Running: %s\n"
|
||||
"VRMode: %s\n"
|
||||
"SustainedPerformanceMode: %s\n",
|
||||
boolToString(mHintManager->IsRunning()), boolToString(mVRModeOn),
|
||||
boolToString(mSustainedPerfModeOn)));
|
||||
// Dump nodes through libperfmgr
|
||||
mHintManager->DumpToFd(fd);
|
||||
if (!::android::base::WriteStringToFd(buf, fd)) {
|
||||
PLOG(ERROR) << "Failed to dump state to fd";
|
||||
mInteractionHandler->Acquire(durationMs);
|
||||
break;
|
||||
case Boost::DISPLAY_UPDATE_IMMINENT:
|
||||
[[fallthrough]];
|
||||
case Boost::ML_ACC:
|
||||
[[fallthrough]];
|
||||
case Boost::AUDIO_LAUNCH:
|
||||
[[fallthrough]];
|
||||
case Boost::CAMERA_LAUNCH:
|
||||
[[fallthrough]];
|
||||
case Boost::CAMERA_SHOT:
|
||||
[[fallthrough]];
|
||||
default:
|
||||
if (mVRModeOn || mSustainedPerfModeOn) {
|
||||
break;
|
||||
}
|
||||
fsync(fd);
|
||||
return STATUS_OK;
|
||||
if (durationMs > 0) {
|
||||
mHintManager->DoHint(toString(type),
|
||||
std::chrono::milliseconds(durationMs));
|
||||
} else if (durationMs == 0) {
|
||||
mHintManager->DoHint(toString(type));
|
||||
} else {
|
||||
mHintManager->EndHint(toString(type));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace pixel
|
||||
} // namespace impl
|
||||
} // namespace power
|
||||
} // namespace hardware
|
||||
} // namespace google
|
||||
} // namespace aidl
|
||||
ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool *_aidl_return) {
|
||||
bool supported = mHintManager->IsHintSupported(toString(type));
|
||||
LOG(INFO) << "Power boost " << toString(type)
|
||||
<< " isBoostSupported: " << supported;
|
||||
*_aidl_return = supported;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
constexpr const char *boolToString(bool b) { return b ? "true" : "false"; }
|
||||
|
||||
binder_status_t Power::dump(int fd, const char **, uint32_t) {
|
||||
std::string buf(::android::base::StringPrintf(
|
||||
"HintManager Running: %s\n"
|
||||
"VRMode: %s\n"
|
||||
"SustainedPerformanceMode: %s\n",
|
||||
boolToString(mHintManager->IsRunning()), boolToString(mVRModeOn),
|
||||
boolToString(mSustainedPerfModeOn)));
|
||||
// Dump nodes through libperfmgr
|
||||
mHintManager->DumpToFd(fd);
|
||||
if (!::android::base::WriteStringToFd(buf, fd)) {
|
||||
PLOG(ERROR) << "Failed to dump state to fd";
|
||||
}
|
||||
fsync(fd);
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
} // namespace pixel
|
||||
} // namespace impl
|
||||
} // namespace power
|
||||
} // namespace hardware
|
||||
} // namespace google
|
||||
} // namespace aidl
|
||||
|
|
|
|||
|
|
@ -38,24 +38,24 @@ using ::aidl::android::hardware::power::Mode;
|
|||
using ::android::perfmgr::HintManager;
|
||||
|
||||
class Power : public ::aidl::android::hardware::power::BnPower {
|
||||
public:
|
||||
Power(std::shared_ptr<HintManager> hm);
|
||||
ndk::ScopedAStatus setMode(Mode type, bool enabled) override;
|
||||
ndk::ScopedAStatus isModeSupported(Mode type, bool* _aidl_return) override;
|
||||
ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override;
|
||||
ndk::ScopedAStatus isBoostSupported(Boost type, bool* _aidl_return) override;
|
||||
binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
|
||||
public:
|
||||
Power(std::shared_ptr<HintManager> hm);
|
||||
ndk::ScopedAStatus setMode(Mode type, bool enabled) override;
|
||||
ndk::ScopedAStatus isModeSupported(Mode type, bool *_aidl_return) override;
|
||||
ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override;
|
||||
ndk::ScopedAStatus isBoostSupported(Boost type, bool *_aidl_return) override;
|
||||
binder_status_t dump(int fd, const char **args, uint32_t numArgs) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<HintManager> mHintManager;
|
||||
std::unique_ptr<InteractionHandler> mInteractionHandler;
|
||||
std::atomic<bool> mVRModeOn;
|
||||
std::atomic<bool> mSustainedPerfModeOn;
|
||||
private:
|
||||
std::shared_ptr<HintManager> mHintManager;
|
||||
std::unique_ptr<InteractionHandler> mInteractionHandler;
|
||||
std::atomic<bool> mVRModeOn;
|
||||
std::atomic<bool> mSustainedPerfModeOn;
|
||||
};
|
||||
|
||||
} // namespace pixel
|
||||
} // namespace impl
|
||||
} // namespace power
|
||||
} // namespace hardware
|
||||
} // namespace google
|
||||
} // namespace aidl
|
||||
} // namespace pixel
|
||||
} // namespace impl
|
||||
} // namespace power
|
||||
} // namespace hardware
|
||||
} // namespace google
|
||||
} // namespace aidl
|
||||
|
|
|
|||
|
|
@ -37,51 +37,54 @@ namespace power {
|
|||
namespace impl {
|
||||
namespace pixel {
|
||||
|
||||
ndk::ScopedAStatus PowerExt::setMode(const std::string& mode, bool enabled) {
|
||||
LOG(DEBUG) << "PowerExt setMode: " << mode << " to: " << enabled;
|
||||
ATRACE_INT(mode.c_str(), enabled);
|
||||
ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) {
|
||||
LOG(DEBUG) << "PowerExt setMode: " << mode << " to: " << enabled;
|
||||
ATRACE_INT(mode.c_str(), enabled);
|
||||
|
||||
if (enabled) {
|
||||
mHintManager->DoHint(mode);
|
||||
} else {
|
||||
mHintManager->EndHint(mode);
|
||||
}
|
||||
if (enabled) {
|
||||
mHintManager->DoHint(mode);
|
||||
} else {
|
||||
mHintManager->EndHint(mode);
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus PowerExt::isModeSupported(const std::string& mode, bool* _aidl_return) {
|
||||
bool supported = mHintManager->IsHintSupported(mode);
|
||||
LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported;
|
||||
*_aidl_return = supported;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode,
|
||||
bool *_aidl_return) {
|
||||
bool supported = mHintManager->IsHintSupported(mode);
|
||||
LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported;
|
||||
*_aidl_return = supported;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus PowerExt::setBoost(const std::string& boost, int32_t durationMs) {
|
||||
LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs;
|
||||
ATRACE_INT(boost.c_str(), durationMs);
|
||||
ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost,
|
||||
int32_t durationMs) {
|
||||
LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs;
|
||||
ATRACE_INT(boost.c_str(), durationMs);
|
||||
|
||||
if (durationMs > 0) {
|
||||
mHintManager->DoHint(boost, std::chrono::milliseconds(durationMs));
|
||||
} else if (durationMs == 0) {
|
||||
mHintManager->DoHint(boost);
|
||||
} else {
|
||||
mHintManager->EndHint(boost);
|
||||
}
|
||||
if (durationMs > 0) {
|
||||
mHintManager->DoHint(boost, std::chrono::milliseconds(durationMs));
|
||||
} else if (durationMs == 0) {
|
||||
mHintManager->DoHint(boost);
|
||||
} else {
|
||||
mHintManager->EndHint(boost);
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string& boost, bool* _aidl_return) {
|
||||
bool supported = mHintManager->IsHintSupported(boost);
|
||||
LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported;
|
||||
*_aidl_return = supported;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string &boost,
|
||||
bool *_aidl_return) {
|
||||
bool supported = mHintManager->IsHintSupported(boost);
|
||||
LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported;
|
||||
*_aidl_return = supported;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace pixel
|
||||
} // namespace impl
|
||||
} // namespace power
|
||||
} // namespace hardware
|
||||
} // namespace google
|
||||
} // namespace aidl
|
||||
} // namespace pixel
|
||||
} // namespace impl
|
||||
} // namespace power
|
||||
} // namespace hardware
|
||||
} // namespace google
|
||||
} // namespace aidl
|
||||
|
|
|
|||
|
|
@ -32,21 +32,25 @@ namespace pixel {
|
|||
|
||||
using ::android::perfmgr::HintManager;
|
||||
|
||||
class PowerExt : public ::aidl::google::hardware::power::extension::pixel::BnPowerExt {
|
||||
public:
|
||||
PowerExt(std::shared_ptr<HintManager> hm) : mHintManager(hm) {}
|
||||
ndk::ScopedAStatus setMode(const std::string& mode, bool enabled) override;
|
||||
ndk::ScopedAStatus isModeSupported(const std::string& mode, bool* _aidl_return) override;
|
||||
ndk::ScopedAStatus setBoost(const std::string& boost, int32_t durationMs) override;
|
||||
ndk::ScopedAStatus isBoostSupported(const std::string& boost, bool* _aidl_return) override;
|
||||
class PowerExt
|
||||
: public ::aidl::google::hardware::power::extension::pixel::BnPowerExt {
|
||||
public:
|
||||
PowerExt(std::shared_ptr<HintManager> hm) : mHintManager(hm) {}
|
||||
ndk::ScopedAStatus setMode(const std::string &mode, bool enabled) override;
|
||||
ndk::ScopedAStatus isModeSupported(const std::string &mode,
|
||||
bool *_aidl_return) override;
|
||||
ndk::ScopedAStatus setBoost(const std::string &boost,
|
||||
int32_t durationMs) override;
|
||||
ndk::ScopedAStatus isBoostSupported(const std::string &boost,
|
||||
bool *_aidl_return) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<HintManager> mHintManager;
|
||||
private:
|
||||
std::shared_ptr<HintManager> mHintManager;
|
||||
};
|
||||
|
||||
} // namespace pixel
|
||||
} // namespace impl
|
||||
} // namespace power
|
||||
} // namespace hardware
|
||||
} // namespace google
|
||||
} // namespace aidl
|
||||
} // namespace pixel
|
||||
} // namespace impl
|
||||
} // namespace power
|
||||
} // namespace hardware
|
||||
} // namespace google
|
||||
} // namespace aidl
|
||||
|
|
|
|||
|
|
@ -34,41 +34,44 @@ constexpr char kPowerHalConfigPath[] = "/vendor/etc/powerhint.json";
|
|||
constexpr char kPowerHalInitProp[] = "vendor.powerhal.init";
|
||||
|
||||
int main() {
|
||||
LOG(INFO) << "Pixel Power HAL AIDL Service with Extension is starting.";
|
||||
LOG(INFO) << "Pixel Power HAL AIDL Service with Extension is starting.";
|
||||
|
||||
// Parse config but do not start the looper
|
||||
std::shared_ptr<HintManager> hm = HintManager::GetFromJSON(kPowerHalConfigPath, false);
|
||||
if (!hm) {
|
||||
LOG(FATAL) << "Invalid config: " << kPowerHalConfigPath;
|
||||
}
|
||||
// Parse config but do not start the looper
|
||||
std::shared_ptr<HintManager> hm =
|
||||
HintManager::GetFromJSON(kPowerHalConfigPath, false);
|
||||
if (!hm) {
|
||||
LOG(FATAL) << "Invalid config: " << kPowerHalConfigPath;
|
||||
}
|
||||
|
||||
// single thread
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
// single thread
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
|
||||
// core service
|
||||
std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>(hm);
|
||||
ndk::SpAIBinder pwBinder = pw->asBinder();
|
||||
// core service
|
||||
std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>(hm);
|
||||
ndk::SpAIBinder pwBinder = pw->asBinder();
|
||||
|
||||
// extension service
|
||||
std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>(hm);
|
||||
// extension service
|
||||
std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>(hm);
|
||||
|
||||
// attach the extension to the same binder we will be registering
|
||||
CHECK(STATUS_OK == AIBinder_setExtension(pwBinder.get(), pwExt->asBinder().get()));
|
||||
// attach the extension to the same binder we will be registering
|
||||
CHECK(STATUS_OK ==
|
||||
AIBinder_setExtension(pwBinder.get(), pwExt->asBinder().get()));
|
||||
|
||||
const std::string instance = std::string() + Power::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(pw->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
LOG(INFO) << "Pixel Power HAL AIDL Service with Extension is started.";
|
||||
const std::string instance = std::string() + Power::descriptor + "/default";
|
||||
binder_status_t status =
|
||||
AServiceManager_addService(pw->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
LOG(INFO) << "Pixel Power HAL AIDL Service with Extension is started.";
|
||||
|
||||
std::thread initThread([&]() {
|
||||
::android::base::WaitForProperty(kPowerHalInitProp, "1");
|
||||
hm->Start();
|
||||
});
|
||||
initThread.detach();
|
||||
std::thread initThread([&]() {
|
||||
::android::base::WaitForProperty(kPowerHalInitProp, "1");
|
||||
hm->Start();
|
||||
});
|
||||
initThread.detach();
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
ABinderProcess_joinThreadPool();
|
||||
|
||||
// should not reach
|
||||
LOG(ERROR) << "Pixel Power HAL AIDL Service with Extension just died.";
|
||||
return EXIT_FAILURE;
|
||||
// should not reach
|
||||
LOG(ERROR) << "Pixel Power HAL AIDL Service with Extension just died.";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,296 +19,317 @@ namespace android {
|
|||
namespace hardware {
|
||||
namespace vibrator {
|
||||
|
||||
static std::map<Effect, int> CP_TRIGGER_EFFECTS {
|
||||
{ Effect::CLICK, 10 },
|
||||
{ Effect::DOUBLE_CLICK, 14 },
|
||||
{ Effect::HEAVY_CLICK, 23 },
|
||||
{ Effect::TEXTURE_TICK, 50 },
|
||||
{ Effect::TICK, 50 }
|
||||
};
|
||||
static std::map<Effect, int> CP_TRIGGER_EFFECTS{{Effect::CLICK, 10},
|
||||
{Effect::DOUBLE_CLICK, 14},
|
||||
{Effect::HEAVY_CLICK, 23},
|
||||
{Effect::TEXTURE_TICK, 50},
|
||||
{Effect::TICK, 50}};
|
||||
|
||||
/*
|
||||
* Write value to path and close file.
|
||||
*/
|
||||
template <typename T>
|
||||
static ndk::ScopedAStatus writeNode(const std::string& path, const T& value) {
|
||||
std::ofstream node(path);
|
||||
if (!node) {
|
||||
LOG(ERROR) << "Failed to open: " << path;
|
||||
return ndk::ScopedAStatus::fromStatus(STATUS_UNKNOWN_ERROR);
|
||||
}
|
||||
static ndk::ScopedAStatus writeNode(const std::string &path, const T &value) {
|
||||
std::ofstream node(path);
|
||||
if (!node) {
|
||||
LOG(ERROR) << "Failed to open: " << path;
|
||||
return ndk::ScopedAStatus::fromStatus(STATUS_UNKNOWN_ERROR);
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "writeNode node: " << path << " value: " << value;
|
||||
LOG(DEBUG) << "writeNode node: " << path << " value: " << value;
|
||||
|
||||
node << value << std::endl;
|
||||
if (!node) {
|
||||
LOG(ERROR) << "Failed to write: " << value;
|
||||
return ndk::ScopedAStatus::fromStatus(STATUS_UNKNOWN_ERROR);
|
||||
}
|
||||
node << value << std::endl;
|
||||
if (!node) {
|
||||
LOG(ERROR) << "Failed to write: " << value;
|
||||
return ndk::ScopedAStatus::fromStatus(STATUS_UNKNOWN_ERROR);
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
static bool nodeExists(const std::string& path) {
|
||||
std::ofstream f(path.c_str());
|
||||
return f.good();
|
||||
static bool nodeExists(const std::string &path) {
|
||||
std::ofstream f(path.c_str());
|
||||
return f.good();
|
||||
}
|
||||
|
||||
Vibrator::Vibrator() {
|
||||
mIsTimedOutVibrator = nodeExists(VIBRATOR_TIMEOUT_PATH);
|
||||
mHasTimedOutIntensity = nodeExists(VIBRATOR_INTENSITY_PATH);
|
||||
mHasTimedOutEffect = nodeExists(VIBRATOR_CP_TRIGGER_PATH);
|
||||
mIsTimedOutVibrator = nodeExists(VIBRATOR_TIMEOUT_PATH);
|
||||
mHasTimedOutIntensity = nodeExists(VIBRATOR_INTENSITY_PATH);
|
||||
mHasTimedOutEffect = nodeExists(VIBRATOR_CP_TRIGGER_PATH);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) {
|
||||
*_aidl_return = IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK |
|
||||
IVibrator::CAP_EXTERNAL_CONTROL /*| IVibrator::CAP_COMPOSE_EFFECTS |
|
||||
IVibrator::CAP_ALWAYS_ON_CONTROL*/;
|
||||
ndk::ScopedAStatus Vibrator::getCapabilities(int32_t *_aidl_return) {
|
||||
*_aidl_return =
|
||||
IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK |
|
||||
IVibrator::CAP_EXTERNAL_CONTROL /*| IVibrator::CAP_COMPOSE_EFFECTS |
|
||||
IVibrator::CAP_ALWAYS_ON_CONTROL*/
|
||||
;
|
||||
|
||||
if (mHasTimedOutIntensity) {
|
||||
*_aidl_return = *_aidl_return | IVibrator::CAP_AMPLITUDE_CONTROL |
|
||||
IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL;
|
||||
}
|
||||
if (mHasTimedOutIntensity) {
|
||||
*_aidl_return = *_aidl_return | IVibrator::CAP_AMPLITUDE_CONTROL |
|
||||
IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL;
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::off() {
|
||||
return activate(0);
|
||||
ndk::ScopedAStatus Vibrator::off() { return activate(0); }
|
||||
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::on(int32_t timeoutMs,
|
||||
const std::shared_ptr<IVibratorCallback> &callback) {
|
||||
ndk::ScopedAStatus status;
|
||||
|
||||
if (mHasTimedOutEffect)
|
||||
writeNode(VIBRATOR_CP_TRIGGER_PATH, 0); // Clear all effects
|
||||
|
||||
status = activate(timeoutMs);
|
||||
|
||||
if (callback != nullptr) {
|
||||
std::thread([=] {
|
||||
LOG(DEBUG) << "Starting on on another thread";
|
||||
usleep(timeoutMs * 1000);
|
||||
LOG(DEBUG) << "Notifying on complete";
|
||||
if (!callback->onComplete().isOk()) {
|
||||
LOG(ERROR) << "Failed to call onComplete";
|
||||
}
|
||||
}).detach();
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& callback) {
|
||||
ndk::ScopedAStatus status;
|
||||
|
||||
if (mHasTimedOutEffect)
|
||||
writeNode(VIBRATOR_CP_TRIGGER_PATH, 0); // Clear all effects
|
||||
|
||||
status = activate(timeoutMs);
|
||||
|
||||
if (callback != nullptr) {
|
||||
std::thread([=] {
|
||||
LOG(DEBUG) << "Starting on on another thread";
|
||||
usleep(timeoutMs * 1000);
|
||||
LOG(DEBUG) << "Notifying on complete";
|
||||
if (!callback->onComplete().isOk()) {
|
||||
LOG(ERROR) << "Failed to call onComplete";
|
||||
}
|
||||
}).detach();
|
||||
}
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::perform(Effect effect, EffectStrength strength,
|
||||
const std::shared_ptr<IVibratorCallback> &callback,
|
||||
int32_t *_aidl_return) {
|
||||
ndk::ScopedAStatus status;
|
||||
uint32_t amplitude = strengthToAmplitude(strength, &status);
|
||||
uint32_t ms = 1000;
|
||||
|
||||
if (!status.isOk())
|
||||
return status;
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, const std::shared_ptr<IVibratorCallback>& callback, int32_t* _aidl_return) {
|
||||
ndk::ScopedAStatus status;
|
||||
uint32_t amplitude = strengthToAmplitude(strength, &status);
|
||||
uint32_t ms = 1000;
|
||||
activate(0);
|
||||
setAmplitude(amplitude);
|
||||
|
||||
if (mHasTimedOutEffect &&
|
||||
CP_TRIGGER_EFFECTS.find(effect) != CP_TRIGGER_EFFECTS.end()) {
|
||||
writeNode(VIBRATOR_CP_TRIGGER_PATH, CP_TRIGGER_EFFECTS[effect]);
|
||||
} else {
|
||||
if (mHasTimedOutEffect)
|
||||
writeNode(VIBRATOR_CP_TRIGGER_PATH, 0); // Clear previous effect
|
||||
|
||||
ms = effectToMs(effect, &status);
|
||||
|
||||
if (!status.isOk())
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
activate(0);
|
||||
setAmplitude(amplitude);
|
||||
status = activate(ms);
|
||||
|
||||
if (mHasTimedOutEffect && CP_TRIGGER_EFFECTS.find(effect) != CP_TRIGGER_EFFECTS.end()) {
|
||||
writeNode(VIBRATOR_CP_TRIGGER_PATH, CP_TRIGGER_EFFECTS[effect]);
|
||||
} else {
|
||||
if (mHasTimedOutEffect)
|
||||
writeNode(VIBRATOR_CP_TRIGGER_PATH, 0); // Clear previous effect
|
||||
if (callback != nullptr) {
|
||||
std::thread([=] {
|
||||
LOG(DEBUG) << "Starting perform on another thread";
|
||||
usleep(ms * 1000);
|
||||
LOG(DEBUG) << "Notifying perform complete";
|
||||
callback->onComplete();
|
||||
}).detach();
|
||||
}
|
||||
|
||||
ms = effectToMs(effect, &status);
|
||||
|
||||
if (!status.isOk())
|
||||
return status;
|
||||
}
|
||||
|
||||
status = activate(ms);
|
||||
|
||||
if (callback != nullptr) {
|
||||
std::thread([=] {
|
||||
LOG(DEBUG) << "Starting perform on another thread";
|
||||
usleep(ms * 1000);
|
||||
LOG(DEBUG) << "Notifying perform complete";
|
||||
callback->onComplete();
|
||||
}).detach();
|
||||
}
|
||||
|
||||
*_aidl_return = ms;
|
||||
return status;
|
||||
*_aidl_return = ms;
|
||||
return status;
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) {
|
||||
*_aidl_return = {Effect::CLICK, Effect::DOUBLE_CLICK, Effect::HEAVY_CLICK,
|
||||
Effect::TICK, Effect::TEXTURE_TICK, Effect::THUD, Effect::POP,
|
||||
Effect::RINGTONE_1, Effect::RINGTONE_2, Effect::RINGTONE_3,
|
||||
Effect::RINGTONE_4, Effect::RINGTONE_5, Effect::RINGTONE_6,
|
||||
Effect::RINGTONE_7, Effect::RINGTONE_7, Effect::RINGTONE_8,
|
||||
Effect::RINGTONE_9, Effect::RINGTONE_10, Effect::RINGTONE_11,
|
||||
Effect::RINGTONE_12, Effect::RINGTONE_13, Effect::RINGTONE_14,
|
||||
Effect::RINGTONE_15};
|
||||
return ndk::ScopedAStatus::ok();
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::getSupportedEffects(std::vector<Effect> *_aidl_return) {
|
||||
*_aidl_return = {
|
||||
Effect::CLICK, Effect::DOUBLE_CLICK, Effect::HEAVY_CLICK,
|
||||
Effect::TICK, Effect::TEXTURE_TICK, Effect::THUD,
|
||||
Effect::POP, Effect::RINGTONE_1, Effect::RINGTONE_2,
|
||||
Effect::RINGTONE_3, Effect::RINGTONE_4, Effect::RINGTONE_5,
|
||||
Effect::RINGTONE_6, Effect::RINGTONE_7, Effect::RINGTONE_7,
|
||||
Effect::RINGTONE_8, Effect::RINGTONE_9, Effect::RINGTONE_10,
|
||||
Effect::RINGTONE_11, Effect::RINGTONE_12, Effect::RINGTONE_13,
|
||||
Effect::RINGTONE_14, Effect::RINGTONE_15};
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) {
|
||||
uint32_t intensity;
|
||||
uint32_t intensity;
|
||||
|
||||
if (amplitude == 0) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||
}
|
||||
if (amplitude == 0) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Setting amplitude: " << (uint32_t)amplitude;
|
||||
LOG(DEBUG) << "Setting amplitude: " << (uint32_t)amplitude;
|
||||
|
||||
intensity = std::lround((amplitude - 1) * INTENSITY_MAX / 254.0);
|
||||
if (intensity > INTENSITY_MAX) {
|
||||
intensity = INTENSITY_MAX;
|
||||
}
|
||||
LOG(DEBUG) << "Setting intensity: " << intensity;
|
||||
intensity = std::lround((amplitude - 1) * INTENSITY_MAX / 254.0);
|
||||
if (intensity > INTENSITY_MAX) {
|
||||
intensity = INTENSITY_MAX;
|
||||
}
|
||||
LOG(DEBUG) << "Setting intensity: " << intensity;
|
||||
|
||||
if (mHasTimedOutIntensity) {
|
||||
return writeNode(VIBRATOR_INTENSITY_PATH, intensity);
|
||||
}
|
||||
if (mHasTimedOutIntensity) {
|
||||
return writeNode(VIBRATOR_INTENSITY_PATH, intensity);
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled) {
|
||||
if (mEnabled) {
|
||||
LOG(WARNING) << "Setting external control while the vibrator is enabled is "
|
||||
"unsupported!";
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
if (mEnabled) {
|
||||
LOG(WARNING) << "Setting external control while the vibrator is enabled is "
|
||||
"unsupported!";
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
LOG(INFO) << "ExternalControl: " << mExternalControl << " -> " << enabled;
|
||||
mExternalControl = enabled;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
LOG(INFO) << "ExternalControl: " << mExternalControl << " -> " << enabled;
|
||||
mExternalControl = enabled;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getCompositionDelayMax(int32_t* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::getCompositionDelayMax(int32_t * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getSupportedPrimitives(std::vector<CompositePrimitive>* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus Vibrator::getSupportedPrimitives(
|
||||
std::vector<CompositePrimitive> * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getPrimitiveDuration(CompositePrimitive /*primitive*/, int32_t* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::getPrimitiveDuration(CompositePrimitive /*primitive*/,
|
||||
int32_t * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& /*composite*/, const std::shared_ptr<IVibratorCallback>& /*callback*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::compose(const std::vector<CompositeEffect> & /*composite*/,
|
||||
const std::shared_ptr<IVibratorCallback> & /*callback*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getSupportedAlwaysOnEffects(std::vector<Effect>* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::getSupportedAlwaysOnEffects(std::vector<Effect> * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t /*id*/, Effect /*effect*/, EffectStrength /*strength*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t /*id*/, Effect /*effect*/,
|
||||
EffectStrength /*strength*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::alwaysOnDisable(int32_t /*id*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getResonantFrequency(float* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus Vibrator::getResonantFrequency(float * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getQFactor(float* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus Vibrator::getQFactor(float * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getFrequencyResolution(float* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus Vibrator::getFrequencyResolution(float * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getFrequencyMinimum(float* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus Vibrator::getFrequencyMinimum(float * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getBandwidthAmplitudeMap(std::vector<float>* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::getBandwidthAmplitudeMap(std::vector<float> * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getPwlePrimitiveDurationMax(int32_t* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::getPwlePrimitiveDurationMax(int32_t * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getPwleCompositionSizeMax(int32_t* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::getPwleCompositionSizeMax(int32_t * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getSupportedBraking(std::vector<Braking>* /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::getSupportedBraking(std::vector<Braking> * /*_aidl_return*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::composePwle(const std::vector<PrimitivePwle>& /*composite*/, const std::shared_ptr<IVibratorCallback>& /*callback*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
ndk::ScopedAStatus
|
||||
Vibrator::composePwle(const std::vector<PrimitivePwle> & /*composite*/,
|
||||
const std::shared_ptr<IVibratorCallback> & /*callback*/) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::activate(uint32_t timeoutMs) {
|
||||
std::lock_guard<std::mutex> lock{mMutex};
|
||||
if (!mIsTimedOutVibrator) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
std::lock_guard<std::mutex> lock{mMutex};
|
||||
if (!mIsTimedOutVibrator) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
return writeNode(VIBRATOR_TIMEOUT_PATH, timeoutMs);
|
||||
return writeNode(VIBRATOR_TIMEOUT_PATH, timeoutMs);
|
||||
}
|
||||
|
||||
uint8_t Vibrator::strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatus* status) {
|
||||
*status = ndk::ScopedAStatus::ok();
|
||||
uint8_t Vibrator::strengthToAmplitude(EffectStrength strength,
|
||||
ndk::ScopedAStatus *status) {
|
||||
*status = ndk::ScopedAStatus::ok();
|
||||
|
||||
switch (strength) {
|
||||
case EffectStrength::LIGHT:
|
||||
return 64;
|
||||
case EffectStrength::MEDIUM:
|
||||
return 128;
|
||||
case EffectStrength::STRONG:
|
||||
return 255;
|
||||
}
|
||||
switch (strength) {
|
||||
case EffectStrength::LIGHT:
|
||||
return 64;
|
||||
case EffectStrength::MEDIUM:
|
||||
return 128;
|
||||
case EffectStrength::STRONG:
|
||||
return 255;
|
||||
}
|
||||
|
||||
*status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
return 0;
|
||||
*status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t Vibrator::effectToMs(Effect effect, ndk::ScopedAStatus* status) {
|
||||
*status = ndk::ScopedAStatus::ok();
|
||||
switch (effect) {
|
||||
case Effect::CLICK:
|
||||
return 10;
|
||||
case Effect::DOUBLE_CLICK:
|
||||
return 15;
|
||||
case Effect::TICK:
|
||||
case Effect::TEXTURE_TICK:
|
||||
case Effect::THUD:
|
||||
case Effect::POP:
|
||||
return 5;
|
||||
case Effect::HEAVY_CLICK:
|
||||
return 10;
|
||||
case Effect::RINGTONE_1:
|
||||
case Effect::RINGTONE_2:
|
||||
case Effect::RINGTONE_3:
|
||||
case Effect::RINGTONE_4:
|
||||
case Effect::RINGTONE_5:
|
||||
case Effect::RINGTONE_6:
|
||||
case Effect::RINGTONE_7:
|
||||
case Effect::RINGTONE_8:
|
||||
case Effect::RINGTONE_9:
|
||||
case Effect::RINGTONE_10:
|
||||
case Effect::RINGTONE_11:
|
||||
case Effect::RINGTONE_12:
|
||||
case Effect::RINGTONE_13:
|
||||
case Effect::RINGTONE_14:
|
||||
case Effect::RINGTONE_15:
|
||||
return 30000;
|
||||
}
|
||||
*status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
return 0;
|
||||
uint32_t Vibrator::effectToMs(Effect effect, ndk::ScopedAStatus *status) {
|
||||
*status = ndk::ScopedAStatus::ok();
|
||||
switch (effect) {
|
||||
case Effect::CLICK:
|
||||
return 10;
|
||||
case Effect::DOUBLE_CLICK:
|
||||
return 15;
|
||||
case Effect::TICK:
|
||||
case Effect::TEXTURE_TICK:
|
||||
case Effect::THUD:
|
||||
case Effect::POP:
|
||||
return 5;
|
||||
case Effect::HEAVY_CLICK:
|
||||
return 10;
|
||||
case Effect::RINGTONE_1:
|
||||
case Effect::RINGTONE_2:
|
||||
case Effect::RINGTONE_3:
|
||||
case Effect::RINGTONE_4:
|
||||
case Effect::RINGTONE_5:
|
||||
case Effect::RINGTONE_6:
|
||||
case Effect::RINGTONE_7:
|
||||
case Effect::RINGTONE_8:
|
||||
case Effect::RINGTONE_9:
|
||||
case Effect::RINGTONE_10:
|
||||
case Effect::RINGTONE_11:
|
||||
case Effect::RINGTONE_12:
|
||||
case Effect::RINGTONE_13:
|
||||
case Effect::RINGTONE_14:
|
||||
case Effect::RINGTONE_15:
|
||||
return 30000;
|
||||
}
|
||||
*status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace vibrator
|
||||
|
|
|
|||
|
|
@ -14,14 +14,15 @@
|
|||
|
||||
#define VIBRATOR_TIMEOUT_PATH "/sys/class/timed_output/vibrator/enable"
|
||||
#define VIBRATOR_INTENSITY_PATH "/sys/class/timed_output/vibrator/intensity"
|
||||
#define VIBRATOR_CP_TRIGGER_PATH "/sys/class/timed_output/vibrator/cp_trigger_index"
|
||||
#define VIBRATOR_CP_TRIGGER_PATH \
|
||||
"/sys/class/timed_output/vibrator/cp_trigger_index"
|
||||
|
||||
using ::aidl::android::hardware::vibrator::IVibratorCallback;
|
||||
using ::aidl::android::hardware::vibrator::Braking;
|
||||
using ::aidl::android::hardware::vibrator::Effect;
|
||||
using ::aidl::android::hardware::vibrator::EffectStrength;
|
||||
using ::aidl::android::hardware::vibrator::CompositeEffect;
|
||||
using ::aidl::android::hardware::vibrator::CompositePrimitive;
|
||||
using ::aidl::android::hardware::vibrator::Effect;
|
||||
using ::aidl::android::hardware::vibrator::EffectStrength;
|
||||
using ::aidl::android::hardware::vibrator::IVibratorCallback;
|
||||
using ::aidl::android::hardware::vibrator::PrimitivePwle;
|
||||
|
||||
namespace aidl {
|
||||
|
|
@ -31,44 +32,61 @@ namespace vibrator {
|
|||
|
||||
class Vibrator : public BnVibrator {
|
||||
public:
|
||||
Vibrator();
|
||||
ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override;
|
||||
ndk::ScopedAStatus off() override;
|
||||
ndk::ScopedAStatus on(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& callback) override;
|
||||
ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, const std::shared_ptr<IVibratorCallback>& callback, int32_t* _aidl_return) override;
|
||||
ndk::ScopedAStatus getSupportedEffects(std::vector<Effect>* _aidl_return) override;
|
||||
ndk::ScopedAStatus setAmplitude(float amplitude) override;
|
||||
ndk::ScopedAStatus setExternalControl(bool enabled) override;
|
||||
ndk::ScopedAStatus getCompositionDelayMax(int32_t* _aidl_return) override;
|
||||
ndk::ScopedAStatus getCompositionSizeMax(int32_t* _aidl_return) override;
|
||||
ndk::ScopedAStatus getSupportedPrimitives(std::vector<CompositePrimitive>* _aidl_return) override;
|
||||
ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive, int32_t* _aidl_return) override;
|
||||
ndk::ScopedAStatus compose(const std::vector<CompositeEffect>& composite, const std::shared_ptr<IVibratorCallback>& callback) override;
|
||||
ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector<Effect>* _aidl_return) override;
|
||||
ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override;
|
||||
ndk::ScopedAStatus alwaysOnDisable(int32_t id) override;
|
||||
ndk::ScopedAStatus getResonantFrequency(float* _aidl_return) override;
|
||||
ndk::ScopedAStatus getQFactor(float* _aidl_return) override;
|
||||
ndk::ScopedAStatus getFrequencyResolution(float* _aidl_return) override;
|
||||
ndk::ScopedAStatus getFrequencyMinimum(float* _aidl_return) override;
|
||||
ndk::ScopedAStatus getBandwidthAmplitudeMap(std::vector<float>* _aidl_return) override;
|
||||
ndk::ScopedAStatus getPwlePrimitiveDurationMax(int32_t* _aidl_return) override;
|
||||
ndk::ScopedAStatus getPwleCompositionSizeMax(int32_t* _aidl_return) override;
|
||||
ndk::ScopedAStatus getSupportedBraking(std::vector<Braking>* _aidl_return) override;
|
||||
ndk::ScopedAStatus composePwle(const std::vector<PrimitivePwle>& composite, const std::shared_ptr<IVibratorCallback>& callback) override;
|
||||
Vibrator();
|
||||
ndk::ScopedAStatus getCapabilities(int32_t *_aidl_return) override;
|
||||
ndk::ScopedAStatus off() override;
|
||||
ndk::ScopedAStatus
|
||||
on(int32_t timeoutMs,
|
||||
const std::shared_ptr<IVibratorCallback> &callback) override;
|
||||
ndk::ScopedAStatus perform(Effect effect, EffectStrength strength,
|
||||
const std::shared_ptr<IVibratorCallback> &callback,
|
||||
int32_t *_aidl_return) override;
|
||||
ndk::ScopedAStatus
|
||||
getSupportedEffects(std::vector<Effect> *_aidl_return) override;
|
||||
ndk::ScopedAStatus setAmplitude(float amplitude) override;
|
||||
ndk::ScopedAStatus setExternalControl(bool enabled) override;
|
||||
ndk::ScopedAStatus getCompositionDelayMax(int32_t *_aidl_return) override;
|
||||
ndk::ScopedAStatus getCompositionSizeMax(int32_t *_aidl_return) override;
|
||||
ndk::ScopedAStatus getSupportedPrimitives(
|
||||
std::vector<CompositePrimitive> *_aidl_return) override;
|
||||
ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive,
|
||||
int32_t *_aidl_return) override;
|
||||
ndk::ScopedAStatus
|
||||
compose(const std::vector<CompositeEffect> &composite,
|
||||
const std::shared_ptr<IVibratorCallback> &callback) override;
|
||||
ndk::ScopedAStatus
|
||||
getSupportedAlwaysOnEffects(std::vector<Effect> *_aidl_return) override;
|
||||
ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect,
|
||||
EffectStrength strength) override;
|
||||
ndk::ScopedAStatus alwaysOnDisable(int32_t id) override;
|
||||
ndk::ScopedAStatus getResonantFrequency(float *_aidl_return) override;
|
||||
ndk::ScopedAStatus getQFactor(float *_aidl_return) override;
|
||||
ndk::ScopedAStatus getFrequencyResolution(float *_aidl_return) override;
|
||||
ndk::ScopedAStatus getFrequencyMinimum(float *_aidl_return) override;
|
||||
ndk::ScopedAStatus
|
||||
getBandwidthAmplitudeMap(std::vector<float> *_aidl_return) override;
|
||||
ndk::ScopedAStatus
|
||||
getPwlePrimitiveDurationMax(int32_t *_aidl_return) override;
|
||||
ndk::ScopedAStatus getPwleCompositionSizeMax(int32_t *_aidl_return) override;
|
||||
ndk::ScopedAStatus
|
||||
getSupportedBraking(std::vector<Braking> *_aidl_return) override;
|
||||
ndk::ScopedAStatus
|
||||
composePwle(const std::vector<PrimitivePwle> &composite,
|
||||
const std::shared_ptr<IVibratorCallback> &callback) override;
|
||||
|
||||
private:
|
||||
ndk::ScopedAStatus activate(uint32_t ms);
|
||||
static uint32_t effectToMs(Effect effect, ndk::ScopedAStatus* status);
|
||||
static uint8_t strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatus* status);
|
||||
ndk::ScopedAStatus activate(uint32_t ms);
|
||||
static uint32_t effectToMs(Effect effect, ndk::ScopedAStatus *status);
|
||||
static uint8_t strengthToAmplitude(EffectStrength strength,
|
||||
ndk::ScopedAStatus *status);
|
||||
|
||||
bool mEnabled{false};
|
||||
bool mExternalControl{false};
|
||||
std::mutex mMutex;
|
||||
bool mEnabled{false};
|
||||
bool mExternalControl{false};
|
||||
std::mutex mMutex;
|
||||
|
||||
bool mIsTimedOutVibrator;
|
||||
bool mHasTimedOutIntensity;
|
||||
bool mHasTimedOutEffect;
|
||||
bool mIsTimedOutVibrator;
|
||||
bool mHasTimedOutIntensity;
|
||||
bool mHasTimedOutEffect;
|
||||
};
|
||||
|
||||
} // namespace vibrator
|
||||
|
|
|
|||
|
|
@ -6,20 +6,22 @@
|
|||
|
||||
#include "Vibrator.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
#include <android-base/logging.h>
|
||||
|
||||
using ::aidl::android::hardware::vibrator::Vibrator;
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<Vibrator> vibrator = ndk::SharedRefBase::make<Vibrator>();
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<Vibrator> vibrator = ndk::SharedRefBase::make<Vibrator>();
|
||||
|
||||
const std::string instance = std::string() + Vibrator::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(vibrator->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
const std::string instance =
|
||||
std::string() + Vibrator::descriptor + "/default";
|
||||
binder_status_t status =
|
||||
AServiceManager_addService(vibrator->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue