- 浏览: 1589291 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (289)
- java 语法基础 (51)
- spring (8)
- mvc struct /Ant --build.xml (8)
- SOA (0)
- oracle 9i/10g (23)
- sql server 2000-2005 (3)
- 数据库基础知识 (6)
- 设计模式与软件架构 (10)
- Hibernate 持久化 (9)
- J2SE/J2EE/J2ME/AJAX 技术 (8)
- JSF 技术 (3)
- JAVA 图形化 (0)
- JMS (40)
- Eclipse 3.2 IDE 开发技巧 (13)
- 项目处理方法集合 (2)
- html/jsp/javascript (2)
- Unix/Linux (9)
- j2me/ARM/windriver/嵌入式 (4)
- 电信科学 (8)
- jsp (1)
- c/c++ (1)
- LZW压缩算法(java) (2)
- Android (77)
- 版本管理git/svn (2)
最新评论
-
huihai:
有demo吗?
NamingStrategy实现动态表名映射 -
cangbaotu:
推荐给大家一些有用的爬虫源码:https://github.c ...
网络爬虫(源代码参考) -
tuspark:
除了.classpath文件以外,.project文件也应该了 ...
Eclipse .classpath文件浅谈 -
tuspark:
造成eclipse自动关闭的原因有很多,这里有很多介绍:ecl ...
eclipse 自动关闭 解决方案 -
DEMONU:
网上都是这些,这种文章。。。
ActiveMQ中的消息持久性
背光设置是在:设置->声音和显示->亮度,通过进度条来设置的。
文件:packages/apps/Settings/src/com/android/settings/BrightnessPreference.java
private static final int MINIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_DIM + 10;
private static final int MAXIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_ON;
mSeekBar.setMax(MAXIMUM_BACKLIGHT - MINIMUM_BACKLIGHT);
设置进度条的范围,BRIGHTNESS_DIM = 20 BRIGHTNESS_ON=255,它们的定义在:
frameworks/base/core/java/android/os/Power.java
3.1.2 设置亮度
文件:packages/apps/Settings/src/com/android/settings/BrightnessPreference.java
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
setMode(isChecked ? Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
: Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
if (!isChecked) {
setBrightness(mSeekBar.getProgress() + MINIMUM_BACKLIGHT);
}
}
private void setBrightness(int brightness) {
try {
IPowerManager power = IPowerManager.Stub.asInterface(
ServiceManager.getService("power"));
if (power != null) {
power.setBacklightBrightness(brightness);
}
} catch (RemoteException doe) {
}
}
由以上代码可知,brightness的范围是:20~255;代码通过服务管理器(ServiceManager)获得power服务,然后通过power服务设置亮度。
power.setBacklightBrightness的定义在:
rameworks/base/core/java/android/os/IPowerManager.aidl.java
frameworks/base/core/java/android/os/PowerManager.java
3.2 Power服务
文件:frameworks/base/core/java/android/os/Power.java
/**
* Brightness value for dim backlight
*/
public static final int BRIGHTNESS_DIM = 20;
/**
* Brightness value for fully on
*/
public static final int BRIGHTNESS_ON = 255;
文件:frameworks/base/core/java/android/os/PowerManager.java
/**
* sets the brightness of the backlights (screen, keyboard, button).
*
* @param brightness value from 0 to 255
*
* {@hide}
*/
public void setBacklightBrightness(int brightness)
{
try {
mService.setBacklightBrightness(brightness);
} catch (RemoteException e) {
}
}
电源管理器(powermager)将brightness转给电源服务,该服务位置如下:
文件:frameworks/base/services/java/com/android/server/PowerManagerService.java
public void setBacklightBrightness(int brightness) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
// Don't let applications turn the screen all the way off
brightness = Math.max(brightness, Power.BRIGHTNESS_DIM);
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BACKLIGHT, brightness,
HardwareService.BRIGHTNESS_MODE_USER);
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD,
(mKeyboardVisible ? brightness : 0), HardwareService.BRIGHTNESS_MODE_USER);
mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, brightness,
HardwareService.BRIGHTNESS_MODE_USER);
long identity = Binder.clearCallingIdentity();
try {
mBatteryStats.noteScreenBrightness(brightness);
} catch (RemoteException e) {
Log.w(TAG, "RemoteException calling noteScreenBrightness on BatteryStatsService", e);
} finally {
Binder.restoreCallingIdentity(identity);
}
// update our animation state
if (ANIMATE_SCREEN_LIGHTS) {
mScreenBrightness.curValue = brightness;
mScreenBrightness.animating = false;
mScreenBrightness.targetValue = -1;
}
if (ANIMATE_KEYBOARD_LIGHTS) {
mKeyboardBrightness.curValue = brightness;
mKeyboardBrightness.animating = false;
mKeyboardBrightness.targetValue = -1;
}
if (ANIMATE_BUTTON_LIGHTS) {
mButtonBrightness.curValue = brightness;
mButtonBrightness.animating = false;
mButtonBrightness.targetValue = -1;
}
}
由以上代码可知,同时设置了背光、键盘、按钮的亮度。mHardware 是硬件服务,通过该服务调用底层与设备打交道的C\C++代码,setLightBrightness_UNCHECKED原型如下:
文件:frameworks/base/services\java\com\android\server\HardwareService.java
void setLightBrightness_UNCHECKED(int light, int brightness, int brightnessMode) {
int b = brightness & 0x000000ff;
b = 0xff000000 | (b << 16) | (b << 8) | b;
setLight_native(mNativePointer, light, b, LIGHT_FLASH_NONE, 0, 0, brightnessMode);
}
参数说明:int light 表示类型,选项如下:
static final int LIGHT_ID_BACKLIGHT = 0;
static final int LIGHT_ID_KEYBOARD = 1;
static final int LIGHT_ID_BUTTONS = 2;
static final int LIGHT_ID_BATTERY = 3;
static final int LIGHT_ID_NOTIFICATIONS = 4;
static final int LIGHT_ID_ATTENTION = 5;
int brightness 表示亮度值
int brightnessMode 表示亮度的控制模式,选项如下:
/**
* Light brightness is managed by a user setting.
*/
static final int BRIGHTNESS_MODE_USER = 0;
/**
* Light brightness is managed by a light sensor.
*/
static final int BRIGHTNESS_MODE_SENSOR = 1;
由代码:
int b = brightness & 0x000000ff;
b = 0xff000000 | (b << 16) | (b << 8) | b;
可知,亮度值在此进行了修改,即亮度值的格式变成:FFRRGGBB,FF是没有的,RR、GG、BB分别是256色的红绿蓝,并且红绿蓝的值都是一样的亮度值。
3.3 硬件调用
3.3.1获取硬件
文件:frameworks/base/services/jni/com_android_server_HardwareService.cpp
enum {
LIGHT_INDEX_BACKLIGHT = 0,
LIGHT_INDEX_KEYBOARD = 1,
LIGHT_INDEX_BUTTONS = 2,
LIGHT_INDEX_BATTERY = 3,
LIGHT_INDEX_NOTIFICATIONS = 4,
LIGHT_INDEX_ATTENTION = 5,
LIGHT_COUNT
};
#define LIGHTS_HARDWARE_MODULE_ID "lights"
static jint init_native(JNIEnv *env, jobject clazz)
{
int err;
hw_module_t* module;
Devices* devices;
devices = (Devices*)malloc(sizeof(Devices));
err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
if (err == 0) {
devices->lights[LIGHT_INDEX_BACKLIGHT]
= get_device(module, LIGHT_ID_BACKLIGHT);
devices->lights[LIGHT_INDEX_KEYBOARD]
= get_device(module, LIGHT_ID_KEYBOARD);
devices->lights[LIGHT_INDEX_BUTTONS]
= get_device(module, LIGHT_ID_BUTTONS);
devices->lights[LIGHT_INDEX_BATTERY]
= get_device(module, LIGHT_ID_BATTERY);
devices->lights[LIGHT_INDEX_NOTIFICATIONS]
= get_device(module, LIGHT_ID_NOTIFICATIONS);
devices->lights[LIGHT_INDEX_ATTENTION]
= get_device(module, LIGHT_ID_ATTENTION);
} else {
memset(devices, 0, sizeof(Devices));
}
return (jint)devices;
}
用hw_get_module获取ID为LIGHTS_HARDWARE_MODULE_ID的硬件模块,该模块含有6个不同类型的亮度控制。
hw_get_module 的实现原理,如下:
文件:hardware/libhardware/Hardware.c
#define HAL_LIBRARY_PATH "/system/lib/hw"
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"
};
static const int HAL_VARIANT_KEYS_COUNT =
(sizeof(variant_keys)/sizeof(variant_keys[0]));
int hw_get_module(const char *id, const struct hw_module_t **module)
{
int status;
int i;
const struct hw_module_t *hmi = NULL;
char prop[PATH_MAX];
char path[PATH_MAX];
/*
* Here we rely on the fact that calling dlopen multiple times on
* the same .so will simply increment a refcount (and not load
* a new copy of the library).
* We also assume that dlopen() is thread-safe.
*/
/* Loop through the configuration variants looking for a module */
for (i=0 ; i<HAL_VARIANT_KEYS_COUNT+1 ; i++) {
if (i < HAL_VARIANT_KEYS_COUNT) {
if (property_get(variant_keys[i], prop, NULL) == 0) {
continue;
}
snprintf(path, sizeof(path), "%s/%s.%s.so",
HAL_LIBRARY_PATH, id, prop);
} else {
snprintf(path, sizeof(path), "%s/%s.default.so",
HAL_LIBRARY_PATH, id);
}
if (access(path, R_OK)) {
continue;
}
/* we found a library matching this id/variant */
break;
}
status = -ENOENT;
if (i < HAL_VARIANT_KEYS_COUNT+1) {
/* load the module, if this fails, we're doomed, and we should not try
* to load a different variant. */
status = load(id, path, module);
}
return status;
}
property_get(variant_keys[i], prop, NULL) 会按如下顺序去获取如下变量所对应的值,然后返回给prop:
"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"
它们对应的变量为:
"ro.product.board=$TARGET_BOOTLOADER_BOARD_NAME"
"ro.board.platform=$TARGET_BOARD_PLATFORM"
如vendor/htc/dream-open/BoardConfig.mk里定义的TARGET_BOARD_PLATFORM := msm7k,则prop返回” msm7k ”,所以path = /system/lib/hw/lights. msm7k.so,也就是说要获取的硬件模块为lights. msm7k.so。
3.3.2调用硬件
setLight_native对应的jni C/C++代码是:
文件:frameworks/base/services/jni/com_android_server_HardwareService.cpp
static void setLight_native(JNIEnv *env, jobject clazz, int ptr,
int light, int colorARGB, int flashMode, int onMS, int offMS, int brightnessMode)
{
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;
state.brightnessMode = brightnessMode;
devices->lights[light]->set_light(devices->lights[light], &state);
}
通过light标识找到对应的light设备,然后再设置亮度。
3.3.3 硬件原型
msm7k的lights对应的硬件原型是在:hardware/msm7k/liblights
文件:hardware/msm7k/liblights/Android.mk
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_MODULE := lights.$(TARGET_BOARD_PLATFORM)
也就是生成模块:/system/lib/hw/lights. msm7k.so
文件:hardware/msm7k/liblights/lights.c
/** Open a new instance of a lights device using name */
static int open_lights(const struct hw_module_t* module, char const* name,
struct hw_device_t** device)
{
int (*set_light)(struct light_device_t* dev,
struct light_state_t const* state);
if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) {
set_light = set_light_backlight;
}
else if (0 == strcmp(LIGHT_ID_KEYBOARD, name)) {
set_light = set_light_keyboard;
}
else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) {
set_light = set_light_buttons;
}
else if (0 == strcmp(LIGHT_ID_BATTERY, name)) {
set_light = set_light_battery;
}
else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) {
set_light = set_light_notifications;
}
else if (0 == strcmp(LIGHT_ID_ATTENTION, name)) {
set_light = set_light_attention;
}
else {
return -EINVAL;
}
pthread_once(&g_init, init_globals);
struct light_device_t *dev = malloc(sizeof(struct light_device_t));
memset(dev, 0, sizeof(*dev));
dev->common.tag = HARDWARE_DEVICE_TAG;
dev->common.version = 0;
dev->common.module = (struct hw_module_t*)module;
dev->common.close = (int (*)(struct hw_device_t*))close_lights;
dev->set_light = set_light;
*device = (struct hw_device_t*)dev;
return 0;
}
static struct hw_module_methods_t lights_module_methods = {
.open = open_lights,
};
以上代码对应的是:
devices->lights[LIGHT_INDEX_BACKLIGHT]
= get_device(module, LIGHT_ID_BACKLIGHT);
devices->lights[LIGHT_INDEX_KEYBOARD]
= get_device(module, LIGHT_ID_KEYBOARD);
devices->lights[LIGHT_INDEX_BUTTONS]
= get_device(module, LIGHT_ID_BUTTONS);
devices->lights[LIGHT_INDEX_BATTERY]
= get_device(module, LIGHT_ID_BATTERY);
devices->lights[LIGHT_INDEX_NOTIFICATIONS]
= get_device(module, LIGHT_ID_NOTIFICATIONS);
devices->lights[LIGHT_INDEX_ATTENTION]
= get_device(module, LIGHT_ID_ATTENTION);
也就是说,对不同的亮度设置给予了不同的设置函数。
举例,背光设置,背光对应的代码如下:
char const*const LCD_FILE
= "/sys/class/leds/lcd-backlight/brightness";
static int
rgb_to_brightness(struct light_state_t const* state)
{
int color = state->color & 0x00ffffff;
return ((77*((color>>16)&0x00ff))
+ (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8;
}
static int
set_light_backlight(struct light_device_t* dev,
struct light_state_t const* state)
{
int err = 0;
int brightness = rgb_to_brightness(state);
pthread_mutex_lock(&g_lock);
g_backlight = brightness;
err = write_int(LCD_FILE, brightness);
if (g_haveTrackballLight) {
handle_trackball_light_locked(dev);
}
pthread_mutex_unlock(&g_lock);
return err;
}
也就是往文件/sys/class/leds/lcd-backlight/brightness写入亮度值,然后驱动会根据该文件更改背光的亮度。LCD_FILE的路径根据实际情况更改,同时需要在init.rc 修改其权限,使其可写rgb_to_brightness也根据实际更改,比如要直接亮度值控制,那只要获取r,g,b其中的一个值就行了,如:
static int
rgb_to_brightness(struct light_state_t const* state)
{
int color = state->color & 0x000000ff;
return color;
}
发表评论
-
APN(default、mms、supl、dun、hipri接入点类型的区别)
2013-10-10 19:31 45800设置APN上网时,大家可能经常遇到这个问题:为什么有时要填写 ... -
AMR音频编码器概述及文件格式分析
2013-10-10 19:29 3949全称Adaptive Multi-Rate,自适应多速率编码 ... -
pad 强制加载 Hdpi资源 (2.3 dpi < 240)
2012-07-16 16:47 0pad 强制加载 Hdpi资源 (2.3 dpi < ... -
android 设计模式-享元模式
2011-12-16 23:01 2190享元(FlyWeight)模式,原意是“轻量级”模式,它用来解 ... -
statusbar 2.3
2011-11-08 16:04 1277以前我的文章分析过Stat ... -
android 输入法默认设置
2011-07-07 14:00 7189设置默认输入法 在 frameworks\base\co ... -
Android Media Scanner Process
2011-06-06 22:58 3399下面是系统图 Medi ... -
handler与多线程消息处理
2011-06-04 13:42 8277在Android下面也有多线程的概念,在C/C++中,子线程可 ... -
PowerManagerService sensor
2011-03-22 20:06 2667默认分类 2010-12-24 14:34:55 阅读144 ... -
android 单例
2011-02-15 09:26 42221. Framework层的代码: A ... -
Android 开发之 Services 服务
2010-11-02 18:21 4238Service Service ... -
深入学习android之AlarmManager
2010-11-01 16:50 34752对应AlarmManage有一个Alarm ... -
eclipse+android+ddms+adt
2010-09-14 10:30 8451用eclipse + ADT作为android ... -
Menus
2010-09-05 19:01 1785Android Menus 文章分类:移动开发 1.O ... -
Android开机自启动应用开发
2010-08-28 10:07 4589目前需要开发一个开机自启动的GTD应用程序来提醒用户的 ... -
Android2.1_Launcher学习笔记
2010-08-11 13:40 3866文章分类:移动开发 好么,2.0的源码没看几天,2.1的 ... -
Browsing Android Source in Eclipse
2010-08-09 16:00 3431Google’s Android SDK includes ... -
android 编译
2010-08-07 16:31 25191 我的系统是Ubuntu 8.04 * 2 系统上 ... -
Ubuntu linux 右键添加"以管理员身份打开","在终端中打开"
2010-08-02 15:04 4638Ubuntu linux 右键添加"以管理员身份打开 ... -
自制android1.5的源码包
2010-08-02 13:44 1895最近打算玩下android,听hong老大说最好看看源码。而a ...
相关推荐
Android BLE蓝牙例子(包括android版Lightblue)实例源码: 源码里面有Bluetooth4_3/BLEDemo/Android_Lightblue.apk三个.前两个是BLE的demo。BLEDemo这个功能较Bluetooth4_3多一些,有兴趣的可以都看下。Android_...
LightBlue是一款针对Android平台的蓝牙调试工具,它以其强大的功能和友好的用户界面深受开发者喜爱。在进行蓝牙设备开发、调试或测试时,LightBlue能够提供便利,帮助开发者快速理解和控制蓝牙低功耗(Bluetooth Low...
源码里面有Bluetooth4_3/BLEDemo/Android_Lightblue.apk三个.前两个是BLE的demo。BLEDemo这个功能较Bluetooth4_3多一些,有兴趣的可以都看下。Android_Lightblue.apk是Android版的lightblue,在进行ble开发的时候用...
Android-BLE 是一个专为Android平台设计的蓝牙低功耗(Bluetooth Low Energy,简称BLE)框架,它简化了蓝牙设备的交互过程,提供了丰富的功能,包括设备扫描、连接管理、数据传输、特性配置以及固件更新(OTA升级)...
Android 光线传感器 Light Sensor 的使用详解 Android 光线传感器 Light Sensor 是一種常見的感測器,能夠偵測周圍環境的亮度,從而實現各種智能化應用。下面我們將詳細介紹 Android 光线传感器 Light Sensor 的...
android light 驱动程序
android:theme="@style/Theme.AppCompat.Light.NoActionBar"> ``` 同时,在项目的res/values/styles.xml文件中,我们可以自定义应用的主题,引用`Theme.AppCompat.Light.NoActionBar`: ```xml ...
《Android代码-Light Touch:探索光影绘画的移动应用开发》 在移动技术日新月异的今天,Android平台为开发者提供了无限创新的空间。本项目"Light Touch"正是一个基于Android的创新应用,它将传统的光绘艺术与现代的...
在Android平台上,光线传感器(LightSensor)是一种硬件设备,它能够感知周围环境的光照强度,并将这些信息提供给操作系统和应用程序。光线传感器的应用主要在于自动调整设备的屏幕亮度,以达到最佳的视觉效果和节能...
本文将详细介绍Android Studio中的主题,特别是"Android Studio 主题-Solarized Light (Alternate)",并探讨主题对于开发过程的影响。 首先,我们来关注"Android Studio 主题-Solarized Light (Alternate)"。...
本篇文章将详细探讨如何在Android应用中实现对Mifare Ultralight类型的NFC标签进行读写操作。 首先,要进行NFC读写,你需要在AndroidManifest.xml中添加必要的权限: ```xml <uses-permission android:name=...
For androidWM-light only supports the visible watermarks (package size: 28Kb): implementation 'com.huangyz0918:androidwm-light:0.1.2' Quick Start Build a Watermark After downloading the library and ...
通过调用Android中的Light传感器,实时显示出环境的光强值
在Android应用开发中,组件化(Componentization)是一种常见的架构设计模式,它将应用程序的不同功能模块拆分成独立的组件,每个组件可以单独开发、测试和维护。这有助于提高代码的可复用性、可扩展性和可维护性。...
LightBlue测试工具是一款专为Android平台设计的高效BLE(Bluetooth Low Energy)测试应用,旨在帮助开发者和用户进行蓝牙设备的调试与管理。这款工具凭借其出色的性能和丰富的功能,已经成为了蓝牙技术爱好者和专业...
<uses-permission android:name="android.permission.ACCESS_LIGHT_SENSOR" /> <uses-permission android:name="android.permission.ACCESS_PROXIMITY_SENSOR" /> ``` 六、集成与调试 开发完成后,通过Android ...
而LED(Light Emitting Diode)则是一种常见的半导体发光二极管,常用于指示灯、显示屏等。 在Android设备上,我们需要开发一个应用程序,通过蓝牙或Wi-Fi与Arduino进行通信。Android系统提供了一套丰富的API,如...
- monoandroid:这是针对Android平台的版本,使开发者能在Android应用中利用MVVMLight的优势。 - net3.5, net4.0, net4.5:这些是针对.NET Framework的版本,分别支持.NET 3.5、4.0和4.5,适用于桌面应用程序和...
在Android系统中,实现语音通话时的自动息屏与亮屏功能是一项涉及到传感器管理、电源管理以及用户界面交互的重要技术。这项技术的核心是利用设备上的距离传感器和Android系统的API来检测手机与用户耳朵的距离,从而...