新聞中心

Android按鍵燈流程分析

作者: 時(shí)間:2016-10-29 來源:網(wǎng)絡(luò) 收藏

調(diào)用代碼為:

本文引用地址:http://m.butianyuan.cn/article/201610/306010.htm

alpsframeworksbaseservicesjavacomAndroidserverLightsService.java

使用方法:

private LightsService.Light mButtonLight;

mButtonLight = mLightsService.getLight(LightsService.LIGHT_ID_BUTTONS);

mButtonLight.setBrightness(screenBrightness);

mButtonLight.turnOff();

本地代碼在:

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

{

return jniRegisterNativeMethods(env, com//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í)行。



關(guān)鍵詞: android 按鍵

評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉