新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > Android按键灯流程分析

Android按键灯流程分析

作者:时间:2016-10-29来源:网络收藏

调用代码为:

本文引用地址:http://www.eepw.com.cn/article/201610/306010.htm

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__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__server_LightsService(JNIEnv *env)

{

return jniRegisterNativeMethods(env, com//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 按键

评论


相关推荐

技术专区

关闭