summaryrefslogtreecommitdiffstats
path: root/core/jni/server
diff options
context:
space:
mode:
Diffstat (limited to 'core/jni/server')
-rw-r--r--core/jni/server/Android.mk37
-rw-r--r--core/jni/server/com_android_server_AlarmManagerService.cpp120
-rw-r--r--core/jni/server/com_android_server_BatteryService.cpp274
-rw-r--r--core/jni/server/com_android_server_HardwareService.cpp54
-rw-r--r--core/jni/server/com_android_server_KeyInputQueue.cpp299
-rw-r--r--core/jni/server/com_android_server_SensorService.cpp107
-rw-r--r--core/jni/server/com_android_server_SystemServer.cpp47
-rw-r--r--core/jni/server/onload.cpp36
8 files changed, 974 insertions, 0 deletions
diff --git a/core/jni/server/Android.mk b/core/jni/server/Android.mk
new file mode 100644
index 0000000..d108330
--- /dev/null
+++ b/core/jni/server/Android.mk
@@ -0,0 +1,37 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ com_android_server_AlarmManagerService.cpp \
+ com_android_server_BatteryService.cpp \
+ com_android_server_HardwareService.cpp \
+ com_android_server_KeyInputQueue.cpp \
+ com_android_server_SensorService.cpp \
+ com_android_server_SystemServer.cpp \
+ onload.cpp
+
+LOCAL_C_INCLUDES += \
+ $(JNI_H_INCLUDE)
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ libhardware \
+ libnativehelper \
+ libsystem_server \
+ libutils \
+ libui
+
+ifeq ($(TARGET_OS),linux)
+ifeq ($(TARGET_ARCH),x86)
+LOCAL_LDLIBS += -lpthread -ldl -lrt
+endif
+endif
+
+ifeq ($(WITH_MALLOC_LEAK_CHECK),true)
+ LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK
+endif
+
+LOCAL_MODULE:= libandroid_servers
+
+include $(BUILD_SHARED_LIBRARY)
+
diff --git a/core/jni/server/com_android_server_AlarmManagerService.cpp b/core/jni/server/com_android_server_AlarmManagerService.cpp
new file mode 100644
index 0000000..a81a0ff
--- /dev/null
+++ b/core/jni/server/com_android_server_AlarmManagerService.cpp
@@ -0,0 +1,120 @@
+/* //device/libs/android_runtime/android_server_AlarmManagerService.cpp
+**
+** Copyright 2006, 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 "AlarmManagerService"
+
+#include "JNIHelp.h"
+#include "jni.h"
+#include "utils/Log.h"
+#include "utils/misc.h"
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+
+#if HAVE_ANDROID_OS
+#include <linux/ioctl.h>
+#include <linux/android_alarm.h>
+#endif
+
+#define ONE_NANOSECOND 1000000000LL
+#define NANOSECONDS_TO_SECONDS(x) (x / ONE_NANOSECOND)
+#define SECONDS_TO_NANOSECONDS(x) (x * ONE_NANOSECOND)
+
+namespace android {
+
+static jint android_server_AlarmManagerService_init(JNIEnv* env, jobject obj)
+{
+#if HAVE_ANDROID_OS
+ return open("/dev/alarm", O_RDWR);
+#else
+ return -1;
+#endif
+}
+
+static void android_server_AlarmManagerService_close(JNIEnv* env, jobject obj, jint fd)
+{
+#if HAVE_ANDROID_OS
+ close(fd);
+#endif
+}
+
+static void android_server_AlarmManagerService_set(JNIEnv* env, jobject obj, jint fd, jint type, jlong nanoseconds)
+{
+#if HAVE_ANDROID_OS
+ struct timespec ts;
+ ts.tv_sec = NANOSECONDS_TO_SECONDS(nanoseconds);
+ ts.tv_nsec = nanoseconds - SECONDS_TO_NANOSECONDS(ts.tv_sec);
+
+ int result = ioctl(fd, ANDROID_ALARM_SET(type), &ts);
+ if (result < 0)
+ {
+ LOGE("Unable to set alarm to %lld: %s\n", nanoseconds, strerror(errno));
+ }
+#endif
+}
+
+static jint android_server_AlarmManagerService_waitForAlarm(JNIEnv* env, jobject obj, jint fd)
+{
+#if HAVE_ANDROID_OS
+ int result = 0;
+
+ do
+ {
+ result = ioctl(fd, ANDROID_ALARM_WAIT);
+ } while (result < 0 && errno == EINTR);
+
+ if (result < 0)
+ {
+ LOGE("Unable to wait on alarm: %s\n", strerror(errno));
+ return 0;
+ }
+
+ return result;
+#endif
+}
+
+static JNINativeMethod sMethods[] = {
+ /* name, signature, funcPtr */
+ {"init", "()I", (void*)android_server_AlarmManagerService_init},
+ {"close", "(I)V", (void*)android_server_AlarmManagerService_close},
+ {"set", "(IIJ)V", (void*)android_server_AlarmManagerService_set},
+ {"waitForAlarm", "(I)I", (void*)android_server_AlarmManagerService_waitForAlarm},
+};
+
+int register_android_server_AlarmManagerService(JNIEnv* env)
+{
+ jclass clazz = env->FindClass("com/android/server/AlarmManagerService");
+
+ if (clazz == NULL)
+ {
+ LOGE("Can't find com/android/server/AlarmManagerService");
+ return -1;
+ }
+
+ return jniRegisterNativeMethods(env, "com/android/server/AlarmManagerService",
+ sMethods, NELEM(sMethods));
+}
+
+} /* namespace android */
diff --git a/core/jni/server/com_android_server_BatteryService.cpp b/core/jni/server/com_android_server_BatteryService.cpp
new file mode 100644
index 0000000..6636a97
--- /dev/null
+++ b/core/jni/server/com_android_server_BatteryService.cpp
@@ -0,0 +1,274 @@
+/*
+ * Copyright (C) 2008 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 "BatteryService"
+
+#include "JNIHelp.h"
+#include "jni.h"
+#include "utils/Log.h"
+#include "utils/misc.h"
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+
+#if HAVE_ANDROID_OS
+#include <linux/ioctl.h>
+#endif
+
+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"
+
+struct FieldIds {
+ // members
+ jfieldID mAcOnline;
+ jfieldID mUsbOnline;
+ jfieldID mBatteryStatus;
+ jfieldID mBatteryHealth;
+ jfieldID mBatteryPresent;
+ jfieldID mBatteryLevel;
+ jfieldID mBatteryVoltage;
+ jfieldID mBatteryTemperature;
+ jfieldID mBatteryTechnology;
+};
+static FieldIds gFieldIds;
+
+struct BatteryManagerConstants {
+ jint statusUnknown;
+ jint statusCharging;
+ jint statusDischarging;
+ jint statusNotCharging;
+ jint statusFull;
+ jint healthUnknown;
+ jint healthGood;
+ jint healthOverheat;
+ jint healthDead;
+ jint healthOverVoltage;
+ jint healthUnspecifiedFailure;
+};
+static BatteryManagerConstants gConstants;
+
+static jint getBatteryStatus(const char* status)
+{
+ switch (status[0]) {
+ case 'C': return gConstants.statusCharging; // Charging
+ case 'D': return gConstants.statusDischarging; // Discharging
+ case 'F': return gConstants.statusFull; // Not charging
+ case 'N': return gConstants.statusNotCharging; // Full
+ case 'U': return gConstants.statusUnknown; // Unknown
+
+ default: {
+ LOGW("Unknown battery status '%s'", status);
+ return gConstants.statusUnknown;
+ }
+ }
+}
+
+static jint getBatteryHealth(const char* status)
+{
+ switch (status[0]) {
+ case 'D': return gConstants.healthDead; // Dead
+ case 'G': return gConstants.healthGood; // Good
+ case 'O': {
+ if (strcmp(status, "Overheat") == 0) {
+ return gConstants.healthOverheat;
+ } else if (strcmp(status, "Over voltage") == 0) {
+ return gConstants.healthOverVoltage;
+ }
+ LOGW("Unknown battery health[1] '%s'", status);
+ return gConstants.healthUnknown;
+ }
+
+ case 'U': {
+ if (strcmp(status, "Unspecified failure") == 0) {
+ return gConstants.healthUnspecifiedFailure;
+ } else if (strcmp(status, "Unknown") == 0) {
+ return gConstants.healthUnknown;
+ }
+ // fall through
+ }
+
+ default: {
+ LOGW("Unknown battery health[2] '%s'", status);
+ return gConstants.healthUnknown;
+ }
+ }
+}
+
+static int readFromFile(const char* path, char* buf, size_t size)
+{
+ int fd = open(path, O_RDONLY, 0);
+ if (fd == -1) {
+ LOGE("Could not open '%s'", path);
+ return -1;
+ }
+
+ size_t count = read(fd, buf, size);
+ if (count > 0) {
+ count = (count < size) ? count : size - 1;
+ while (count > 0 && buf[count-1] == '\n') count--;
+ buf[count] = '\0';
+ } else {
+ buf[0] = '\0';
+ }
+
+ close(fd);
+ return count;
+}
+
+static void setBooleanField(JNIEnv* env, jobject obj, const char* path, jfieldID fieldID)
+{
+ const int SIZE = 16;
+ char buf[SIZE];
+
+ jboolean value = false;
+ if (readFromFile(path, buf, SIZE) > 0) {
+ if (buf[0] == '1') {
+ value = true;
+ }
+ }
+ env->SetBooleanField(obj, fieldID, value);
+}
+
+static void setIntField(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);
+ }
+ 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);
+
+ setIntField(env, obj, BATTERY_CAPACITY_PATH, gFieldIds.mBatteryLevel);
+ setIntField(env, obj, BATTERY_VOLTAGE_PATH, gFieldIds.mBatteryVoltage);
+ setIntField(env, obj, BATTERY_TEMPERATURE_PATH, gFieldIds.mBatteryTemperature);
+
+ const int SIZE = 128;
+ char buf[SIZE];
+
+ if (readFromFile(BATTERY_STATUS_PATH, buf, SIZE) > 0)
+ env->SetIntField(obj, gFieldIds.mBatteryStatus, getBatteryStatus(buf));
+
+ if (readFromFile(BATTERY_HEALTH_PATH, buf, SIZE) > 0)
+ env->SetIntField(obj, gFieldIds.mBatteryHealth, getBatteryHealth(buf));
+
+ if (readFromFile(BATTERY_TECHNOLOGY_PATH, buf, SIZE) > 0)
+ env->SetObjectField(obj, gFieldIds.mBatteryTechnology, env->NewStringUTF(buf));
+}
+
+static JNINativeMethod sMethods[] = {
+ /* name, signature, funcPtr */
+ {"native_update", "()V", (void*)android_server_BatteryService_update},
+};
+
+int register_android_server_BatteryService(JNIEnv* env)
+{
+ jclass clazz = env->FindClass("com/android/server/BatteryService");
+
+ if (clazz == NULL) {
+ LOGE("Can't find com/android/server/BatteryService");
+ return -1;
+ }
+
+ gFieldIds.mAcOnline = env->GetFieldID(clazz, "mAcOnline", "Z");
+ gFieldIds.mUsbOnline = env->GetFieldID(clazz, "mUsbOnline", "Z");
+ gFieldIds.mBatteryStatus = env->GetFieldID(clazz, "mBatteryStatus", "I");
+ gFieldIds.mBatteryHealth = env->GetFieldID(clazz, "mBatteryHealth", "I");
+ gFieldIds.mBatteryPresent = env->GetFieldID(clazz, "mBatteryPresent", "Z");
+ gFieldIds.mBatteryLevel = env->GetFieldID(clazz, "mBatteryLevel", "I");
+ gFieldIds.mBatteryTechnology = env->GetFieldID(clazz, "mBatteryTechnology", "Ljava/lang/String;");
+ gFieldIds.mBatteryVoltage = env->GetFieldID(clazz, "mBatteryVoltage", "I");
+ gFieldIds.mBatteryTemperature = env->GetFieldID(clazz, "mBatteryTemperature", "I");
+
+ LOG_FATAL_IF(gFieldIds.mAcOnline == NULL, "Unable to find BatteryService.AC_ONLINE_PATH");
+ LOG_FATAL_IF(gFieldIds.mUsbOnline == NULL, "Unable to find BatteryService.USB_ONLINE_PATH");
+ LOG_FATAL_IF(gFieldIds.mBatteryStatus == NULL, "Unable to find BatteryService.BATTERY_STATUS_PATH");
+ LOG_FATAL_IF(gFieldIds.mBatteryHealth == NULL, "Unable to find BatteryService.BATTERY_HEALTH_PATH");
+ LOG_FATAL_IF(gFieldIds.mBatteryPresent == NULL, "Unable to find BatteryService.BATTERY_PRESENT_PATH");
+ LOG_FATAL_IF(gFieldIds.mBatteryLevel == NULL, "Unable to find BatteryService.BATTERY_CAPACITY_PATH");
+ LOG_FATAL_IF(gFieldIds.mBatteryVoltage == NULL, "Unable to find BatteryService.BATTERY_VOLTAGE_PATH");
+ LOG_FATAL_IF(gFieldIds.mBatteryTemperature == NULL, "Unable to find BatteryService.BATTERY_TEMPERATURE_PATH");
+ LOG_FATAL_IF(gFieldIds.mBatteryTechnology == NULL, "Unable to find BatteryService.BATTERY_TECHNOLOGY_PATH");
+
+ clazz = env->FindClass("android/os/BatteryManager");
+
+ if (clazz == NULL) {
+ LOGE("Can't find android/os/BatteryManager");
+ return -1;
+ }
+
+ gConstants.statusUnknown = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_STATUS_UNKNOWN", "I"));
+
+ gConstants.statusCharging = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_STATUS_CHARGING", "I"));
+
+ gConstants.statusDischarging = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_STATUS_DISCHARGING", "I"));
+
+ gConstants.statusNotCharging = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_STATUS_NOT_CHARGING", "I"));
+
+ gConstants.statusFull = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_STATUS_FULL", "I"));
+
+ gConstants.healthUnknown = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_HEALTH_UNKNOWN", "I"));
+
+ gConstants.healthGood = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_HEALTH_GOOD", "I"));
+
+ gConstants.healthOverheat = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_HEALTH_OVERHEAT", "I"));
+
+ gConstants.healthDead = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_HEALTH_DEAD", "I"));
+
+ gConstants.healthOverVoltage = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_HEALTH_OVER_VOLTAGE", "I"));
+
+ gConstants.healthUnspecifiedFailure = env->GetStaticIntField(clazz,
+ env->GetStaticFieldID(clazz, "BATTERY_HEALTH_UNSPECIFIED_FAILURE", "I"));
+
+ return jniRegisterNativeMethods(env, "com/android/server/BatteryService", sMethods, NELEM(sMethods));
+}
+
+} /* namespace android */
diff --git a/core/jni/server/com_android_server_HardwareService.cpp b/core/jni/server/com_android_server_HardwareService.cpp
new file mode 100644
index 0000000..479e57d
--- /dev/null
+++ b/core/jni/server/com_android_server_HardwareService.cpp
@@ -0,0 +1,54 @@
+/* //device/libs/android_runtime/android_os_Vibrator.cpp
+**
+** Copyright 2006, 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 "Vibrator"
+
+#include "jni.h"
+#include "JNIHelp.h"
+#include <stdio.h>
+#include "android_runtime/AndroidRuntime.h"
+#include <utils/misc.h>
+#include <utils/Log.h>
+#include <hardware/vibrator.h>
+
+namespace android
+{
+
+static void on(JNIEnv *env, jobject clazz)
+{
+ // LOGI("on\n");
+ vibrator_on();
+}
+
+static void off(JNIEnv *env, jobject clazz)
+{
+ // LOGI("off\n");
+ vibrator_off();
+}
+
+static JNINativeMethod method_table[] = {
+ { "on", "()V", (void*)on },
+ { "off", "()V", (void*)off }
+};
+
+int register_android_os_Vibrator(JNIEnv *env)
+{
+ return jniRegisterNativeMethods(env, "com/android/server/HardwareService",
+ method_table, NELEM(method_table));
+}
+
+};
diff --git a/core/jni/server/com_android_server_KeyInputQueue.cpp b/core/jni/server/com_android_server_KeyInputQueue.cpp
new file mode 100644
index 0000000..4e9ffb1
--- /dev/null
+++ b/core/jni/server/com_android_server_KeyInputQueue.cpp
@@ -0,0 +1,299 @@
+/*
+ * Copyright (C) 2007 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 "Input"
+
+#include "jni.h"
+#include "JNIHelp.h"
+#include <utils/misc.h>
+#include <utils/Log.h>
+
+#include <ui/EventHub.h>
+#include <utils/threads.h>
+
+#include <stdio.h>
+
+namespace android {
+
+// ----------------------------------------------------------------------------
+
+static struct input_offsets_t
+{
+ jfieldID mMinValue;
+ jfieldID mMaxValue;
+ jfieldID mFlat;
+ jfieldID mFuzz;
+
+ jfieldID mDeviceId;
+ jfieldID mType;
+ jfieldID mScancode;
+ jfieldID mKeycode;
+ jfieldID mFlags;
+ jfieldID mValue;
+ jfieldID mWhen;
+} gInputOffsets;
+
+// ----------------------------------------------------------------------------
+
+static Mutex gLock;
+static sp<EventHub> gHub;
+
+static jboolean
+android_server_KeyInputQueue_readEvent(JNIEnv* env, jobject clazz,
+ jobject event)
+{
+ gLock.lock();
+ sp<EventHub> hub = gHub;
+ if (hub == NULL) {
+ hub = new EventHub;
+ gHub = hub;
+ }
+ gLock.unlock();
+
+ int32_t deviceId;
+ int32_t type;
+ int32_t scancode, keycode;
+ uint32_t flags;
+ int32_t value;
+ nsecs_t when;
+ bool res = hub->getEvent(&deviceId, &type, &scancode, &keycode,
+ &flags, &value, &when);
+
+ env->SetIntField(event, gInputOffsets.mDeviceId, (jint)deviceId);
+ env->SetIntField(event, gInputOffsets.mType, (jint)type);
+ env->SetIntField(event, gInputOffsets.mScancode, (jint)scancode);
+ env->SetIntField(event, gInputOffsets.mKeycode, (jint)keycode);
+ env->SetIntField(event, gInputOffsets.mFlags, (jint)flags);
+ env->SetIntField(event, gInputOffsets.mValue, value);
+ env->SetLongField(event, gInputOffsets.mWhen,
+ (jlong)(nanoseconds_to_milliseconds(when)));
+
+ return res;
+}
+
+static jint
+android_server_KeyInputQueue_getDeviceClasses(JNIEnv* env, jobject clazz,
+ jint deviceId)
+{
+ jint classes = 0;
+ gLock.lock();
+ if (gHub != NULL) classes = gHub->getDeviceClasses(deviceId);
+ gLock.unlock();
+ return classes;
+}
+
+static jstring
+android_server_KeyInputQueue_getDeviceName(JNIEnv* env, jobject clazz,
+ jint deviceId)
+{
+ String8 name;
+ gLock.lock();
+ if (gHub != NULL) name = gHub->getDeviceName(deviceId);
+ gLock.unlock();
+
+ if (name.size() > 0) {
+ return env->NewStringUTF(name.string());
+ }
+ return NULL;
+}
+
+static jboolean
+android_server_KeyInputQueue_getAbsoluteInfo(JNIEnv* env, jobject clazz,
+ jint deviceId, jint axis,
+ jobject info)
+{
+ int32_t minValue, maxValue, flat, fuzz;
+ int res = -1;
+ gLock.lock();
+ if (gHub != NULL) {
+ res = gHub->getAbsoluteInfo(deviceId, axis,
+ &minValue, &maxValue, &flat, &fuzz);
+ }
+ gLock.unlock();
+
+ if (res < 0) return JNI_FALSE;
+
+ env->SetIntField(info, gInputOffsets.mMinValue, (jint)minValue);
+ env->SetIntField(info, gInputOffsets.mMaxValue, (jint)maxValue);
+ env->SetIntField(info, gInputOffsets.mFlat, (jint)flat);
+ env->SetIntField(info, gInputOffsets.mFuzz, (jint)fuzz);
+ return JNI_TRUE;
+}
+
+static jint
+android_server_KeyInputQueue_getSwitchState(JNIEnv* env, jobject clazz,
+ jint sw)
+{
+ jint st = -1;
+ gLock.lock();
+ if (gHub != NULL) st = gHub->getSwitchState(sw);
+ gLock.unlock();
+
+ return st;
+}
+
+static jint
+android_server_KeyInputQueue_getSwitchStateDevice(JNIEnv* env, jobject clazz,
+ jint deviceId, jint sw)
+{
+ jint st = -1;
+ gLock.lock();
+ if (gHub != NULL) st = gHub->getSwitchState(deviceId, sw);
+ gLock.unlock();
+
+ return st;
+}
+
+static jint
+android_server_KeyInputQueue_getScancodeState(JNIEnv* env, jobject clazz,
+ jint sw)
+{
+ jint st = -1;
+ gLock.lock();
+ if (gHub != NULL) st = gHub->getScancodeState(sw);
+ gLock.unlock();
+
+ return st;
+}
+
+static jint
+android_server_KeyInputQueue_getScancodeStateDevice(JNIEnv* env, jobject clazz,
+ jint deviceId, jint sw)
+{
+ jint st = -1;
+ gLock.lock();
+ if (gHub != NULL) st = gHub->getScancodeState(deviceId, sw);
+ gLock.unlock();
+
+ return st;
+}
+
+static jint
+android_server_KeyInputQueue_getKeycodeState(JNIEnv* env, jobject clazz,
+ jint sw)
+{
+ jint st = -1;
+ gLock.lock();
+ if (gHub != NULL) st = gHub->getKeycodeState(sw);
+ gLock.unlock();
+
+ return st;
+}
+
+static jint
+android_server_KeyInputQueue_getKeycodeStateDevice(JNIEnv* env, jobject clazz,
+ jint deviceId, jint sw)
+{
+ jint st = -1;
+ gLock.lock();
+ if (gHub != NULL) st = gHub->getKeycodeState(deviceId, sw);
+ gLock.unlock();
+
+ return st;
+}
+
+
+// ----------------------------------------------------------------------------
+
+/*
+ * JNI registration.
+ */
+static JNINativeMethod gInputMethods[] = {
+ /* name, signature, funcPtr */
+ { "readEvent", "(Landroid/view/RawInputEvent;)Z",
+ (void*) android_server_KeyInputQueue_readEvent },
+ { "getDeviceClasses", "(I)I",
+ (void*) android_server_KeyInputQueue_getDeviceClasses },
+ { "getDeviceName", "(I)Ljava/lang/String;",
+ (void*) android_server_KeyInputQueue_getDeviceName },
+ { "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",
+ (void*) android_server_KeyInputQueue_getScancodeState },
+ { "getScancodeState", "(II)I",
+ (void*) android_server_KeyInputQueue_getScancodeStateDevice },
+ { "getKeycodeState", "(I)I",
+ (void*) android_server_KeyInputQueue_getKeycodeState },
+ { "getKeycodeState", "(II)I",
+ (void*) android_server_KeyInputQueue_getKeycodeStateDevice },
+};
+
+int register_android_server_KeyInputQueue(JNIEnv* env)
+{
+ jclass input = env->FindClass("com/android/server/KeyInputQueue");
+ LOG_FATAL_IF(input == NULL, "Unable to find class com/android/server/KeyInputQueue");
+ int res = jniRegisterNativeMethods(env, "com/android/server/KeyInputQueue",
+ gInputMethods, NELEM(gInputMethods));
+
+ jclass absoluteInfo = env->FindClass("com/android/server/InputDevice$AbsoluteInfo");
+ LOG_FATAL_IF(absoluteInfo == NULL, "Unable to find class com/android/server/InputDevice$AbsoluteInfo");
+
+ gInputOffsets.mMinValue
+ = env->GetFieldID(absoluteInfo, "minValue", "I");
+ LOG_FATAL_IF(gInputOffsets.mMinValue == NULL, "Unable to find InputDevice.AbsoluteInfo.minValue");
+
+ gInputOffsets.mMaxValue
+ = env->GetFieldID(absoluteInfo, "maxValue", "I");
+ LOG_FATAL_IF(gInputOffsets.mMaxValue == NULL, "Unable to find InputDevice.AbsoluteInfo.maxValue");
+
+ gInputOffsets.mFlat
+ = env->GetFieldID(absoluteInfo, "flat", "I");
+ LOG_FATAL_IF(gInputOffsets.mFlat == NULL, "Unable to find InputDevice.AbsoluteInfo.flat");
+
+ gInputOffsets.mFuzz
+ = env->GetFieldID(absoluteInfo, "fuzz", "I");
+ LOG_FATAL_IF(gInputOffsets.mFuzz == NULL, "Unable to find InputDevice.AbsoluteInfo.fuzz");
+
+ jclass inputEvent = env->FindClass("android/view/RawInputEvent");
+ LOG_FATAL_IF(inputEvent == NULL, "Unable to find class android/view/RawInputEvent");
+
+ gInputOffsets.mDeviceId
+ = env->GetFieldID(inputEvent, "deviceId", "I");
+ LOG_FATAL_IF(gInputOffsets.mDeviceId == NULL, "Unable to find RawInputEvent.deviceId");
+
+ gInputOffsets.mType
+ = env->GetFieldID(inputEvent, "type", "I");
+ LOG_FATAL_IF(gInputOffsets.mType == NULL, "Unable to find RawInputEvent.type");
+
+ gInputOffsets.mScancode
+ = env->GetFieldID(inputEvent, "scancode", "I");
+ LOG_FATAL_IF(gInputOffsets.mScancode == NULL, "Unable to find RawInputEvent.scancode");
+
+ gInputOffsets.mKeycode
+ = env->GetFieldID(inputEvent, "keycode", "I");
+ LOG_FATAL_IF(gInputOffsets.mKeycode == NULL, "Unable to find RawInputEvent.keycode");
+
+ gInputOffsets.mFlags
+ = env->GetFieldID(inputEvent, "flags", "I");
+ LOG_FATAL_IF(gInputOffsets.mFlags == NULL, "Unable to find RawInputEvent.flags");
+
+ gInputOffsets.mValue
+ = env->GetFieldID(inputEvent, "value", "I");
+ LOG_FATAL_IF(gInputOffsets.mValue == NULL, "Unable to find RawInputEvent.value");
+
+ gInputOffsets.mWhen
+ = env->GetFieldID(inputEvent, "when", "J");
+ LOG_FATAL_IF(gInputOffsets.mWhen == NULL, "Unable to find RawInputEvent.when");
+
+ return res;
+}
+
+}; // namespace android
+
diff --git a/core/jni/server/com_android_server_SensorService.cpp b/core/jni/server/com_android_server_SensorService.cpp
new file mode 100644
index 0000000..37f6231
--- /dev/null
+++ b/core/jni/server/com_android_server_SensorService.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2008, 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 "Sensors"
+
+#include <hardware/sensors.h>
+
+#include "jni.h"
+#include "JNIHelp.h"
+
+namespace android {
+
+
+static struct file_descriptor_offsets_t
+{
+ jclass mClass;
+ jmethodID mConstructor;
+ jfieldID mDescriptor;
+} gFileDescriptorOffsets;
+
+static struct parcel_file_descriptor_offsets_t
+{
+ jclass mClass;
+ jmethodID mConstructor;
+} gParcelFileDescriptorOffsets;
+
+/*
+ * The method below are not thread-safe and not intended to be
+ */
+
+static jint
+android_init(JNIEnv *env, jclass clazz)
+{
+ return sensors_control_init();
+}
+
+static jobject
+android_open(JNIEnv *env, jclass clazz)
+{
+ int fd = sensors_control_open();
+ // new FileDescriptor()
+ jobject filedescriptor = env->NewObject(
+ gFileDescriptorOffsets.mClass,
+ gFileDescriptorOffsets.mConstructor);
+
+ if (filedescriptor != NULL) {
+ env->SetIntField(filedescriptor, gFileDescriptorOffsets.mDescriptor, fd);
+ // new ParcelFileDescriptor()
+ return env->NewObject(gParcelFileDescriptorOffsets.mClass,
+ gParcelFileDescriptorOffsets.mConstructor,
+ filedescriptor);
+ }
+ close(fd);
+ return NULL;
+}
+
+static jboolean
+android_activate(JNIEnv *env, jclass clazz, jint sensor, jboolean activate)
+{
+ uint32_t active = sensors_control_activate(activate ? sensor : 0, sensor);
+ return (activate && !active) ? false : true;
+}
+
+static jint
+android_set_delay(JNIEnv *env, jclass clazz, jint ms)
+{
+ return sensors_control_delay(ms);
+}
+
+static JNINativeMethod gMethods[] = {
+ {"_sensors_control_init", "()I", (void*) android_init },
+ {"_sensors_control_open", "()Landroid/os/ParcelFileDescriptor;", (void*) android_open },
+ {"_sensors_control_activate", "(IZ)Z", (void*) android_activate },
+ {"_sensors_control_set_delay","(I)I", (void*) android_set_delay },
+};
+
+int register_android_server_SensorService(JNIEnv *env)
+{
+ jclass clazz;
+
+ clazz = env->FindClass("java/io/FileDescriptor");
+ gFileDescriptorOffsets.mClass = (jclass)env->NewGlobalRef(clazz);
+ gFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "()V");
+ gFileDescriptorOffsets.mDescriptor = env->GetFieldID(clazz, "descriptor", "I");
+
+ clazz = env->FindClass("android/os/ParcelFileDescriptor");
+ gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
+ gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V");
+
+ return jniRegisterNativeMethods(env, "com/android/server/SensorService",
+ gMethods, NELEM(gMethods));
+}
+
+}; // namespace android
diff --git a/core/jni/server/com_android_server_SystemServer.cpp b/core/jni/server/com_android_server_SystemServer.cpp
new file mode 100644
index 0000000..ae29405
--- /dev/null
+++ b/core/jni/server/com_android_server_SystemServer.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2007 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.
+ */
+#include <utils/Log.h>
+#include <utils/misc.h>
+
+#include "jni.h"
+#include "JNIHelp.h"
+
+namespace android {
+
+extern "C" int system_init();
+
+static void android_server_SystemServer_init1(JNIEnv* env, jobject clazz)
+{
+ system_init();
+}
+
+/*
+ * JNI registration.
+ */
+static JNINativeMethod gMethods[] = {
+ /* name, signature, funcPtr */
+ { "init1", "([Ljava/lang/String;)V", (void*) android_server_SystemServer_init1 },
+};
+
+int register_android_server_SystemServer(JNIEnv* env)
+{
+ return jniRegisterNativeMethods(env, "com/android/server/SystemServer",
+ gMethods, NELEM(gMethods));
+}
+
+}; // namespace android
+
+
diff --git a/core/jni/server/onload.cpp b/core/jni/server/onload.cpp
new file mode 100644
index 0000000..3d68cfb
--- /dev/null
+++ b/core/jni/server/onload.cpp
@@ -0,0 +1,36 @@
+#include "JNIHelp.h"
+#include "jni.h"
+#include "utils/Log.h"
+#include "utils/misc.h"
+
+namespace android {
+int register_android_server_AlarmManagerService(JNIEnv* env);
+int register_android_server_BatteryService(JNIEnv* env);
+int register_android_server_KeyInputQueue(JNIEnv* env);
+int register_android_os_Vibrator(JNIEnv* env);
+int register_android_server_SensorService(JNIEnv* env);
+int register_android_server_SystemServer(JNIEnv* env);
+};
+
+using namespace android;
+
+extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
+{
+ JNIEnv* env = NULL;
+ jint result = -1;
+
+ if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
+ LOGE("GetEnv failed!");
+ return result;
+ }
+ LOG_ASSERT(env, "Could not retrieve the env!");
+
+ register_android_server_KeyInputQueue(env);
+ register_android_os_Vibrator(env);
+ register_android_server_AlarmManagerService(env);
+ register_android_server_BatteryService(env);
+ register_android_server_SensorService(env);
+ register_android_server_SystemServer(env);
+
+ return JNI_VERSION_1_4;
+}