echo 23 > /sys/devices/platform/atmel_lcdfb.0/backlight/backlight/brightness
android 源代码
http://blog.chinaunix.net/u1/49742/showart_2077813.html android 知识总结
http://www.limodev.cn/
Android 背光的控制:
屏幕背光设置
packages/apps/Settings/src/com/android/settings/BrightnessPreference.java
背光设置滚动条和关闭按钮都会调用 setBrightness(mOldBrightness);
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromTouch)
protected void onDialogClosed(boolean positiveResult)
private void setBrightness(int brightness) {
try {
IHardwareService hardware = IHardwareService.Stub.asInterface(
ServiceManager.getService("hardware"));
if (hardware != null) {
hardware.setBacklights(brightness);
}
} catch (RemoteException doe) {
}
}
调用硬件服务器 HardwareService 的 setBacklights 函数
HardwareService.java (frameworks\base\services\java\com\android\server):
public void setBacklights(int brightness)
{
. . .
// Don't let applications turn the screen all the way off
brightness = Math.max(brightness, Power.BRIGHTNESS_DIM);
setLightBrightness_UNCHECKED(LIGHT_ID_BACKLIGHT, brightness);
setLightBrightness_UNCHECKED(LIGHT_ID_KEYBOARD, brightness);
setLightBrightness_UNCHECKED(LIGHT_ID_BUTTONS, brightness);
. . .
}
void setLightOff_UNCHECKED(int light)
{
//本地调用 setLight_native
setLight_native(mNativePointer, light, 0, LIGHT_FLASH_NONE, 0, 0);
}
void setLightBrightness_UNCHECKED(int light, int brightness) {
int b = brightness & 0x000000ff;
b = 0xff000000 | (b << 16) | (b << 8) | b;
setLight_native(mNativePointer, light, b, LIGHT_FLASH_NONE, 0, 0);
}
因为有:
com_android_server_HardwareService.cpp (frameworks\base\services\jni):
static JNINativeMethod method_table[] = {
{ "init_native", "()I", (void*)init_native },
{ "finalize_native", "(I)V", (void*)init_native },
{ "setLight_native", "(IIIIII)V", (void*)setLight_native },
{ "vibratorOn", "(J)V", (void*)vibratorOn },
{ "vibratorOff", "()V", (void*)vibratorOff }
};
所以最终调用的是文件:
com_android_server_HardwareService.cpp (frameworks\base\services\jni)中的函数:
static void setLight_native(JNIEnv *env, jobject clazz, int ptr,
int light, int colorARGB, int flashMode, int onMS, int offMS)
{
Devices* devices = (Devices*)ptr;
light_state_t state;
if (light < 0 || light >= LIGHT_COUNT || devices->lights[light] == NULL) {
return ;
}
memset(&state, 0, sizeof(light_state_t));
state.color = colorARGB;
state.flashMode = flashMode;
state.flashOnMS = onMS;
state.flashOffMS = offMS;
devices->lights[light]->set_light(devices->lights[light], &state);
}
Lights.h (hardware\libhardware\include\hardware):#define LIGHTS_HARDWARE_MODULE_ID "lights"
com_android_server_HardwareService.cpp (frameworks\base\services\jni)
err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
static const char *variant_keys[] = {
"ro.hardware", /* This goes first so that it can pick up a different
file on the emulator. */
"ro.product.board",
"ro.board.platform",
"ro.arch"
};
int hw_get_module(const char *id, const struct hw_module_t **module)
status = load(id, prop, &hmi);
status = load(id, HAL_DEFAULT_VARIANT, &hmi);
static int load(const char *id, const char *variant,const struct hw_module_t **pHmi)
snprintf(path, sizeof(path), "%s/%s.%s.so", HAL_LIBRARY_PATH, id, variant);
#define HAL_DEFAULT_VARIANT "default"
#define HAL_LIBRARY_PATH "/system/lib/hw"
所以path等于:
/system/lib/hw/light.marvell.so
/system/lib/hw/light.default.so
我们编译的light模块放在 /system/lib/hw/light.default.so 所以初始化成功。
property_get(variant_keys[i], prop, NULL) 只有 ro.hardware 存在 [ro.hardware]: [marvell]
static int lights_device_open(const struct hw_module_t* module, const char* name,struct hw_device_t** device)
dev->set_light = set_light_backlight;
static struct hw_module_methods_t lights_module_methods = {
open: lights_device_open
};
hardware/libhardware/modules/lights/Android.mk
LOCAL_MODULE:= lights.default
err = module->methods->open(module, name, &device);
执行的是 : lights_device_open
const char * const brightness_file = "/sys/class/backlight/micco-bl/brightness";
static int set_light_backlight(struct light_device_t* dev,
struct light_state_t const* state)
{
. . .
color = state->color;
tmp = ((77*((color>>16)&0x00ff)) + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8;
brightness = tmp/16;
LOGD("---->calling %s(),line=%d state->color=%d,brightness=%d\n",__FUNCTION__,__LINE__,state->color,brightness);
len = sprintf(buf,"%d",brightness);
len = write(fd, buf, len);
. . .
}
上面的函数完成了与内核的交互
综上所述,程序调用流程如下,上层应用通过 /sys/class/leds/lcd-backlight/brightnes 于内核打交道
设置模块 -> 硬件服务器 -> 本地调用 ->功能库 -> 读写 /sys/class/leds/lcd-backlight/brightness 函数与内核交互
Init.rc (vendor\marvell\littleton): chown system system /sys/class/leds/keyboard-backlight/brightness
Init.rc (vendor\marvell\littleton): chown system system /sys/class/leds/lcd-backlight/brightness
Init.rc (vendor\marvell\littleton): chown system system /sys/class/leds/button-backlight/brightness
这个是博客中记录的,非常详细,很具有参考价值。
在 Atmel 开发板的背光问题解决中使用了 另外一个路径:
# pwd
/sys/class/backlight
# ls -l
lrwxrwxrwx root root 1970-01-01 00:00 backlight -> ../../devices/platform/atmel_lcdfb.0/backlight/backlight
改变该路径的属性: 可读可写。 init.rc
MK 文件
LOCAL_PATH:= $(call my-dir)
# HAL module implemenation, not prelinked and stored in
# hw/..so
include $(CLEAR_VARS)
LOCAL_SRC_FILES := lights.c
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_MODULE := lights.atmel
include $(BUILD_SHARED_LIBRARY)
改变 lights.c 文件中的路径。
# ls -l /system/lib/hw
-rwxrwxrwx root root 9560 2010-07-06 10:21 lights.default.so
-rwxrwxrwx root root 14040 2010-07-06 09:03 gralloc.default.so
-rwxrwxrwx root root 9560 2010-07-06 09:03 light.atmel.so.bak
-rwxrwxrwx root root 9752 2010-07-06 10:21 alsa.default.so
-rwxrwxrwx root root 9848 2010-07-06 09:03 sensors.goldfish.so
-rwxrwxrwx root root 5308 2010-07-06 10:21 acoustics.default.so
lights.default.so light.atmel.so 均可实现亮度控制。
阅读(2353) | 评论(0) | 转发(0) |