Android按键灯流程分析
调用代码为:
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带入执行。
- Android开发技巧:软硬件的巧妙整合(01-16)
- 基于Android的VoIP系统的设计与实现(03-28)
- 基于Android系统的影音播放器开发(03-25)
- Android的阿喀琉斯之踵(07-08)
- Android开发之“hello World”的实现 (07-23)
- 基于Android平台的即时通信系统客户端设计(09-24)