From 182f73fc4da13a6417e5086ec9ecce80eb8423ca Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Thu, 5 Dec 2013 16:48:06 -0800 Subject: Introduce a Lifecycle for system services Provide an abstract class for system services to extend from, similar to the android.app.Service. This will allow services to receive events in a uniform way, and will allow services to be created and started in the correct order regardless of whether or not a particular service exists. Similar to android.app.Service, services are meant to implement Binder interfaces as inner classes. This prevents services from having incestuous access to each other and makes them use the public API. Change-Id: Iaacfee8d5f080a28d7cc606761f4624673ed390f --- services/jni/Android.mk | 2 +- services/jni/com_android_server_LightsService.cpp | 141 --------------------- .../com_android_server_lights_LightsService.cpp | 141 +++++++++++++++++++++ 3 files changed, 142 insertions(+), 142 deletions(-) delete mode 100644 services/jni/com_android_server_LightsService.cpp create mode 100644 services/jni/com_android_server_lights_LightsService.cpp (limited to 'services/jni') diff --git a/services/jni/Android.mk b/services/jni/Android.mk index 98e9b30..a98b1c3 100644 --- a/services/jni/Android.mk +++ b/services/jni/Android.mk @@ -8,7 +8,7 @@ LOCAL_SRC_FILES:= \ com_android_server_input_InputApplicationHandle.cpp \ com_android_server_input_InputManagerService.cpp \ com_android_server_input_InputWindowHandle.cpp \ - com_android_server_LightsService.cpp \ + com_android_server_lights_LightsService.cpp \ com_android_server_power_PowerManagerService.cpp \ com_android_server_SerialService.cpp \ com_android_server_SystemServer.cpp \ diff --git a/services/jni/com_android_server_LightsService.cpp b/services/jni/com_android_server_LightsService.cpp deleted file mode 100644 index 401e1aa..0000000 --- a/services/jni/com_android_server_LightsService.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "LightsService" - -#include "jni.h" -#include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" - -#include -#include -#include -#include - -#include - -namespace android -{ - -// These values must correspond with the LIGHT_ID constants in -// LightsService.java -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_INDEX_BLUETOOTH = 6, - LIGHT_INDEX_WIFI = 7, - LIGHT_COUNT -}; - -struct Devices { - light_device_t* lights[LIGHT_COUNT]; -}; - -static light_device_t* get_device(hw_module_t* module, char const* name) -{ - int err; - hw_device_t* device; - err = module->methods->open(module, name, &device); - if (err == 0) { - return (light_device_t*)device; - } else { - return NULL; - } -} - -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 finalize_native(JNIEnv *env, jobject clazz, int ptr) -{ - Devices* devices = (Devices*)ptr; - if (devices == NULL) { - return; - } - - free(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; - - { - ALOGD_IF_SLOW(50, "Excessive delay setting light"); - devices->lights[light]->set_light(devices->lights[light], &state); - } -} - -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_android_server_LightsService(JNIEnv *env) -{ - return jniRegisterNativeMethods(env, "com/android/server/LightsService", - method_table, NELEM(method_table)); -} - -}; diff --git a/services/jni/com_android_server_lights_LightsService.cpp b/services/jni/com_android_server_lights_LightsService.cpp new file mode 100644 index 0000000..ea03cfa --- /dev/null +++ b/services/jni/com_android_server_lights_LightsService.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LightsService" + +#include "jni.h" +#include "JNIHelp.h" +#include "android_runtime/AndroidRuntime.h" + +#include +#include +#include +#include + +#include + +namespace android +{ + +// These values must correspond with the LIGHT_ID constants in +// LightsService.java +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_INDEX_BLUETOOTH = 6, + LIGHT_INDEX_WIFI = 7, + LIGHT_COUNT +}; + +struct Devices { + light_device_t* lights[LIGHT_COUNT]; +}; + +static light_device_t* get_device(hw_module_t* module, char const* name) +{ + int err; + hw_device_t* device; + err = module->methods->open(module, name, &device); + if (err == 0) { + return (light_device_t*)device; + } else { + return NULL; + } +} + +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 finalize_native(JNIEnv *env, jobject clazz, int ptr) +{ + Devices* devices = (Devices*)ptr; + if (devices == NULL) { + return; + } + + free(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; + + { + ALOGD_IF_SLOW(50, "Excessive delay setting light"); + devices->lights[light]->set_light(devices->lights[light], &state); + } +} + +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_android_server_LightsService(JNIEnv *env) +{ + return jniRegisterNativeMethods(env, "com/android/server/lights/LightsService", + method_table, NELEM(method_table)); +} + +}; -- cgit v1.1