1.framework/base/services/java/com/android/server/lightsService.java
- 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;
- static final int LIGHT_ID_BLUETOOTH = 6;
- static final int LIGHT_ID_WIFI = 7; //暂时未使用
- static final int LIGHT_ID_COUNT = 8; //暂时未使用
- static final int LIGHT_FLASH_NONE = 0;
- static final int LIGHT_FLASH_TIMED = 1;
- static final int LIGHT_FLASH_HARDWARE = 2;
- private static native int init_native();
- private static native void finalize_native(int ptr);
- private static native void setLight_native(int ptr, int light, int color, int mode,
- int onMS, int offMS, int brightnessMode);
2.framework/base/service/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 },
- };
- 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);
- devices->lights[LIGHT_INDEX_BLUETOOTH]
- = get_device(module, LIGHT_ID_BLUETOOTH);
- devices->lights[LIGHT_INDEX_WIFI]
- = get_device(module, LIGHT_ID_WIFI);
- } else {
- memset(devices, 0, sizeof(Devices));
- }
- return (jint)devices;
- }
- 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);
- }
- static void finalize_native(JNIEnv *env, jobject clazz, int ptr)
- {
- Devices* devices = (Devices*)ptr;
- if (devices == NULL) {
- return;
- }
- free(devices);
- }
阅读(1663) | 评论(0) | 转发(0) |