調用代碼為:
alps\frameworks\base\services\java\com\Android\server\LightsService.java
使用方法:
private LightsService.Light mButtonLight;
mButtonLight = mLightsService.getLight(LightsService.LIGHT_ID_BUTTONS);
mButtonLight.setBrightness(screenBrightness);
mButtonLight.turnOff();
本地代碼在:
alps\frameworks\base\services\jni\com_android_server_LightsService.cpp
接口關聯使用:
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函數在alps\frameworks\base\services\jni\onload.cpp裡面注冊
本地c代碼在:
alps\mediatek\hardware\liblights\lights.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);來調用真正的代碼
如果有root機子,可以如下測試:
echo 0 > /sys/class/leds/button-backlight/brightness 關按鍵燈
echo 1 > /sys/class/leds/button-backlight/brightness 開按鍵燈
echo 0 > /sys/class/leds/button-backlight/brightness 執行的意思為:輸出0,作為/sys/class/leds/button-backlight/brightness的輸入傳入。
如此便會打開brightness設備,並執行write將0帶入執行。