diff options
Diffstat (limited to 'services/jni')
5 files changed, 197 insertions, 29 deletions
diff --git a/services/jni/com_android_server_AlarmManagerService.cpp b/services/jni/com_android_server_AlarmManagerService.cpp index 1d66fb1..85d63c9 100644 --- a/services/jni/com_android_server_AlarmManagerService.cpp +++ b/services/jni/com_android_server_AlarmManagerService.cpp @@ -19,8 +19,8 @@ #include "JNIHelp.h" #include "jni.h" -#include "utils/Log.h" -#include "utils/misc.h" +#include <utils/Log.h> +#include <utils/misc.h> #include <fcntl.h> #include <stdio.h> diff --git a/services/jni/com_android_server_BatteryService.cpp b/services/jni/com_android_server_BatteryService.cpp index 2524966..8e7cadc 100644 --- a/services/jni/com_android_server_BatteryService.cpp +++ b/services/jni/com_android_server_BatteryService.cpp @@ -18,8 +18,8 @@ #include "JNIHelp.h" #include "jni.h" -#include "utils/Log.h" -#include "utils/misc.h" +#include <utils/Log.h> +#include <utils/misc.h> #include <fcntl.h> #include <stdio.h> @@ -31,6 +31,7 @@ #include <stdlib.h> #include <errno.h> #include <unistd.h> +#include <dirent.h> #if HAVE_ANDROID_OS #include <linux/ioctl.h> @@ -38,15 +39,7 @@ namespace android { -#define AC_ONLINE_PATH "/sys/class/power_supply/ac/online" -#define USB_ONLINE_PATH "/sys/class/power_supply/usb/online" -#define BATTERY_STATUS_PATH "/sys/class/power_supply/battery/status" -#define BATTERY_HEALTH_PATH "/sys/class/power_supply/battery/health" -#define BATTERY_PRESENT_PATH "/sys/class/power_supply/battery/present" -#define BATTERY_CAPACITY_PATH "/sys/class/power_supply/battery/capacity" -#define BATTERY_VOLTAGE_PATH "/sys/class/power_supply/battery/batt_vol" -#define BATTERY_TEMPERATURE_PATH "/sys/class/power_supply/battery/batt_temp" -#define BATTERY_TECHNOLOGY_PATH "/sys/class/power_supply/battery/technology" +#define POWER_SUPPLY_PATH "/sys/class/power_supply" struct FieldIds { // members @@ -77,6 +70,21 @@ struct BatteryManagerConstants { }; static BatteryManagerConstants gConstants; +struct PowerSupplyPaths { + char* acOnlinePath; + char* usbOnlinePath; + char* batteryStatusPath; + char* batteryHealthPath; + char* batteryPresentPath; + char* batteryCapacityPath; + char* batteryVoltagePath; + char* batteryTemperaturePath; + char* batteryTechnologyPath; +}; +static PowerSupplyPaths gPaths; + +static int gVoltageDivisor = 1; + static jint getBatteryStatus(const char* status) { switch (status[0]) { @@ -126,6 +134,8 @@ static jint getBatteryHealth(const char* status) static int readFromFile(const char* path, char* buf, size_t size) { + if (!path) + return -1; int fd = open(path, O_RDONLY, 0); if (fd == -1) { LOGE("Could not open '%s'", path); @@ -171,29 +181,43 @@ static void setIntField(JNIEnv* env, jobject obj, const char* path, jfieldID fie env->SetIntField(obj, fieldID, value); } +static void setVoltageField(JNIEnv* env, jobject obj, const char* path, jfieldID fieldID) +{ + const int SIZE = 128; + char buf[SIZE]; + + jint value = 0; + if (readFromFile(path, buf, SIZE) > 0) { + value = atoi(buf); + value /= gVoltageDivisor; + } + env->SetIntField(obj, fieldID, value); +} + + static void android_server_BatteryService_update(JNIEnv* env, jobject obj) { - setBooleanField(env, obj, AC_ONLINE_PATH, gFieldIds.mAcOnline); - setBooleanField(env, obj, USB_ONLINE_PATH, gFieldIds.mUsbOnline); - setBooleanField(env, obj, BATTERY_PRESENT_PATH, gFieldIds.mBatteryPresent); + setBooleanField(env, obj, gPaths.acOnlinePath, gFieldIds.mAcOnline); + setBooleanField(env, obj, gPaths.usbOnlinePath, gFieldIds.mUsbOnline); + setBooleanField(env, obj, gPaths.batteryPresentPath, gFieldIds.mBatteryPresent); - setIntField(env, obj, BATTERY_CAPACITY_PATH, gFieldIds.mBatteryLevel); - setIntField(env, obj, BATTERY_VOLTAGE_PATH, gFieldIds.mBatteryVoltage); - setIntField(env, obj, BATTERY_TEMPERATURE_PATH, gFieldIds.mBatteryTemperature); + setIntField(env, obj, gPaths.batteryCapacityPath, gFieldIds.mBatteryLevel); + setVoltageField(env, obj, gPaths.batteryVoltagePath, gFieldIds.mBatteryVoltage); + setIntField(env, obj, gPaths.batteryTemperaturePath, gFieldIds.mBatteryTemperature); const int SIZE = 128; char buf[SIZE]; - if (readFromFile(BATTERY_STATUS_PATH, buf, SIZE) > 0) + if (readFromFile(gPaths.batteryStatusPath, buf, SIZE) > 0) env->SetIntField(obj, gFieldIds.mBatteryStatus, getBatteryStatus(buf)); else env->SetIntField(obj, gFieldIds.mBatteryStatus, gConstants.statusUnknown); - if (readFromFile(BATTERY_HEALTH_PATH, buf, SIZE) > 0) + if (readFromFile(gPaths.batteryHealthPath, buf, SIZE) > 0) env->SetIntField(obj, gFieldIds.mBatteryHealth, getBatteryHealth(buf)); - if (readFromFile(BATTERY_TECHNOLOGY_PATH, buf, SIZE) > 0) + if (readFromFile(gPaths.batteryTechnologyPath, buf, SIZE) > 0) env->SetObjectField(obj, gFieldIds.mBatteryTechnology, env->NewStringUTF(buf)); } @@ -204,6 +228,101 @@ static JNINativeMethod sMethods[] = { int register_android_server_BatteryService(JNIEnv* env) { + char path[PATH_MAX]; + struct dirent* entry; + + DIR* dir = opendir(POWER_SUPPLY_PATH); + if (dir == NULL) { + LOGE("Could not open %s\n", POWER_SUPPLY_PATH); + return -1; + } + while ((entry = readdir(dir))) { + const char* name = entry->d_name; + + // ignore "." and ".." + if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0))) { + continue; + } + + char buf[20]; + // Look for "type" file in each subdirectory + snprintf(path, sizeof(path), "%s/%s/type", POWER_SUPPLY_PATH, name); + int length = readFromFile(path, buf, sizeof(buf)); + if (length > 0) { + if (buf[length - 1] == '\n') + buf[length - 1] = 0; + + if (strcmp(buf, "Mains") == 0) { + snprintf(path, sizeof(path), "%s/%s/online", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.acOnlinePath = strdup(path); + } + else if (strcmp(buf, "USB") == 0) { + snprintf(path, sizeof(path), "%s/%s/online", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.usbOnlinePath = strdup(path); + } + else if (strcmp(buf, "Battery") == 0) { + snprintf(path, sizeof(path), "%s/%s/status", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryStatusPath = strdup(path); + snprintf(path, sizeof(path), "%s/%s/health", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryHealthPath = strdup(path); + snprintf(path, sizeof(path), "%s/%s/present", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryPresentPath = strdup(path); + snprintf(path, sizeof(path), "%s/%s/capacity", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryCapacityPath = strdup(path); + + snprintf(path, sizeof(path), "%s/%s/voltage_now", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) { + gPaths.batteryVoltagePath = strdup(path); + // voltage_now is in microvolts, not millivolts + gVoltageDivisor = 1000; + } else { + snprintf(path, sizeof(path), "%s/%s/batt_vol", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryVoltagePath = strdup(path); + } + + snprintf(path, sizeof(path), "%s/%s/temp", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) { + gPaths.batteryTemperaturePath = strdup(path); + } else { + snprintf(path, sizeof(path), "%s/%s/batt_temp", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryTemperaturePath = strdup(path); + } + + snprintf(path, sizeof(path), "%s/%s/technology", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryTechnologyPath = strdup(path); + } + } + } + closedir(dir); + + if (!gPaths.acOnlinePath) + LOGE("acOnlinePath not found"); + if (!gPaths.usbOnlinePath) + LOGE("usbOnlinePath not found"); + if (!gPaths.batteryStatusPath) + LOGE("batteryStatusPath not found"); + if (!gPaths.batteryHealthPath) + LOGE("batteryHealthPath not found"); + if (!gPaths.batteryPresentPath) + LOGE("batteryPresentPath not found"); + if (!gPaths.batteryCapacityPath) + LOGE("batteryCapacityPath not found"); + if (!gPaths.batteryVoltagePath) + LOGE("batteryVoltagePath not found"); + if (!gPaths.batteryTemperaturePath) + LOGE("batteryTemperaturePath not found"); + if (!gPaths.batteryTechnologyPath) + LOGE("batteryTechnologyPath not found"); + jclass clazz = env->FindClass("com/android/server/BatteryService"); if (clazz == NULL) { diff --git a/services/jni/com_android_server_HardwareService.cpp b/services/jni/com_android_server_HardwareService.cpp index b0aab59..253e655 100644 --- a/services/jni/com_android_server_HardwareService.cpp +++ b/services/jni/com_android_server_HardwareService.cpp @@ -101,7 +101,7 @@ static void finalize_native(JNIEnv *env, jobject clazz, int ptr) } static void setLight_native(JNIEnv *env, jobject clazz, int ptr, - int light, int colorARGB, int flashMode, int onMS, int offMS) + int light, int colorARGB, int flashMode, int onMS, int offMS, int brightnessMode) { Devices* devices = (Devices*)ptr; light_state_t state; @@ -115,6 +115,7 @@ static void setLight_native(JNIEnv *env, jobject clazz, int ptr, state.flashMode = flashMode; state.flashOnMS = onMS; state.flashOffMS = offMS; + state.brightnessMode = brightnessMode; devices->lights[light]->set_light(devices->lights[light], &state); } @@ -133,8 +134,8 @@ static void vibratorOff(JNIEnv *env, jobject clazz) static JNINativeMethod method_table[] = { { "init_native", "()I", (void*)init_native }, - { "finalize_native", "(I)V", (void*)init_native }, - { "setLight_native", "(IIIIII)V", (void*)setLight_native }, + { "finalize_native", "(I)V", (void*)finalize_native }, + { "setLight_native", "(IIIIIII)V", (void*)setLight_native }, { "vibratorOn", "(J)V", (void*)vibratorOn }, { "vibratorOff", "()V", (void*)vibratorOff } }; diff --git a/services/jni/com_android_server_KeyInputQueue.cpp b/services/jni/com_android_server_KeyInputQueue.cpp index 63830d5..c92f8df 100644 --- a/services/jni/com_android_server_KeyInputQueue.cpp +++ b/services/jni/com_android_server_KeyInputQueue.cpp @@ -110,6 +110,23 @@ android_server_KeyInputQueue_getDeviceName(JNIEnv* env, jobject clazz, return NULL; } +static void +android_server_KeyInputQueue_addExcludedDevice(JNIEnv* env, jobject clazz, + jstring deviceName) +{ + gLock.lock(); + sp<EventHub> hub = gHub; + if (hub == NULL) { + hub = new EventHub; + gHub = hub; + } + gLock.unlock(); + + const char* nameStr = env->GetStringUTFChars(deviceName, NULL); + gHub->addExcludedDevice(nameStr); + env->ReleaseStringUTFChars(deviceName, nameStr); +} + static jboolean android_server_KeyInputQueue_getAbsoluteInfo(JNIEnv* env, jobject clazz, jint deviceId, jint axis, @@ -205,6 +222,23 @@ android_server_KeyInputQueue_getKeycodeStateDevice(JNIEnv* env, jobject clazz, return st; } +static jint +android_server_KeyInputQueue_scancodeToKeycode(JNIEnv* env, jobject clazz, + jint deviceId, jint scancode) +{ + jint res = 0; + gLock.lock(); + if (gHub != NULL) { + int32_t keycode; + uint32_t flags; + gHub->scancodeToKeycode(deviceId, scancode, &keycode, &flags); + res = keycode; + } + gLock.unlock(); + + return res; +} + static jboolean android_server_KeyInputQueue_hasKeys(JNIEnv* env, jobject clazz, jintArray keyCodes, jbooleanArray outFlags) @@ -238,22 +272,26 @@ static JNINativeMethod gInputMethods[] = { (void*) android_server_KeyInputQueue_getDeviceClasses }, { "getDeviceName", "(I)Ljava/lang/String;", (void*) android_server_KeyInputQueue_getDeviceName }, + { "addExcludedDevice", "(Ljava/lang/String;)V", + (void*) android_server_KeyInputQueue_addExcludedDevice }, { "getAbsoluteInfo", "(IILcom/android/server/InputDevice$AbsoluteInfo;)Z", (void*) android_server_KeyInputQueue_getAbsoluteInfo }, { "getSwitchState", "(I)I", (void*) android_server_KeyInputQueue_getSwitchState }, { "getSwitchState", "(II)I", (void*) android_server_KeyInputQueue_getSwitchStateDevice }, - { "getScancodeState", "(I)I", + { "nativeGetScancodeState", "(I)I", (void*) android_server_KeyInputQueue_getScancodeState }, - { "getScancodeState", "(II)I", + { "nativeGetScancodeState", "(II)I", (void*) android_server_KeyInputQueue_getScancodeStateDevice }, - { "getKeycodeState", "(I)I", + { "nativeGetKeycodeState", "(I)I", (void*) android_server_KeyInputQueue_getKeycodeState }, - { "getKeycodeState", "(II)I", + { "nativeGetKeycodeState", "(II)I", (void*) android_server_KeyInputQueue_getKeycodeStateDevice }, { "hasKeys", "([I[Z)Z", (void*) android_server_KeyInputQueue_hasKeys }, + { "scancodeToKeycode", "(II)I", + (void*) android_server_KeyInputQueue_scancodeToKeycode }, }; int register_android_server_KeyInputQueue(JNIEnv* env) diff --git a/services/jni/com_android_server_SensorService.cpp b/services/jni/com_android_server_SensorService.cpp index 7390786..3911d1f 100644 --- a/services/jni/com_android_server_SensorService.cpp +++ b/services/jni/com_android_server_SensorService.cpp @@ -111,6 +111,15 @@ android_open(JNIEnv *env, jclass clazz) return bundle; } +static jint +android_close(JNIEnv *env, jclass clazz) +{ + if (sSensorDevice->close_data_source) + return sSensorDevice->close_data_source(sSensorDevice); + else + return 0; +} + static jboolean android_activate(JNIEnv *env, jclass clazz, jint sensor, jboolean activate) { @@ -135,6 +144,7 @@ android_data_wake(JNIEnv *env, jclass clazz) static JNINativeMethod gMethods[] = { {"_sensors_control_init", "()I", (void*) android_init }, {"_sensors_control_open", "()Landroid/os/Bundle;", (void*) android_open }, + {"_sensors_control_close", "()I", (void*) android_close }, {"_sensors_control_activate", "(IZ)Z", (void*) android_activate }, {"_sensors_control_wake", "()I", (void*) android_data_wake }, {"_sensors_control_set_delay","(I)I", (void*) android_set_delay }, |