Android按鍵燈流程分析
調(diào)用代碼為:
本文引用地址:http://m.butianyuan.cn/article/201610/306010.htmalpsframeworksbaseservicesjavacomAndroidserverLightsService.java
使用方法:
private LightsService.Light mButtonLight;
mButtonLight = mLightsService.getLight(LightsService.LIGHT_ID_BUTTONS);
mButtonLight.setBrightness(screenBrightness);
mButtonLight.turnOff();
本地代碼在:
alpsframeworksbaseservicesjnicom_android_server_LightsService.cpp
接口關(guān)聯(lián)使用:
static JNINativeMethod method_table[] = {
{ init_native, ()I, (void*)init_native },
{ finalize_native, (I)V, (void*)finalize_native },
{ setLight_native, (IIIIIII)V, (void*)setLight_native },
};
int register_android_server_LightsService(JNIEnv *env)
{
return jniRegisterNativeMethods(env, com/android/server/LightsService,
method_table, NELEM(method_table));
}
register_android_server_LightsService函數(shù)在alpsframeworksbaseservicesjnionload.cpp里面注冊(cè)
本地c代碼在:
alpsmediatekhardwareliblightslights.c里面open_lights里面
static int
set_light_buttons(struct light_device_t* dev,
struct light_state_t const* state)
{
int err = 0;
int on = is_lit(state);
pthread_mutex_lock(g_lock);
g_buttons = on;
err = write_int(BUTTON_FILE, on?255:0);
pthread_mutex_unlock(g_lock);
return err;
}
com_android_server_LightsService.cp里面使用 devices->lights[light]->set_light(devices->lights[light], state);來調(diào)用真正的代碼
如果有root機(jī)子,可以如下測試:
echo 0 > /sys/class/leds/button-backlight/brightness 關(guān)按鍵燈
echo 1 > /sys/class/leds/button-backlight/brightness 開按鍵燈
echo 0 > /sys/class/leds/button-backlight/brightness 執(zhí)行的意思為:輸出0,作為/sys/class/leds/button-backlight/brightness的輸入傳入。
如此便會(huì)打開brightness設(shè)備,并執(zhí)行write將0帶入執(zhí)行。
評(píng)論