调用代码为:
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带入履行。