The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Mike Lockwood | 270e87f | 2009-05-22 10:02:14 -0400 | [diff] [blame] | 16 | #define LOG_TAG "SensorManager" |
| 17 | |
Peng Xu | d5ec5f9 | 2016-04-27 14:49:25 -0700 | [diff] [blame] | 18 | #include "JNIHelp.h" |
| 19 | #include "android_os_MessageQueue.h" |
| 20 | #include "core_jni_helpers.h" |
| 21 | #include "jni.h" |
destradaa | 9ba7c1c | 2015-02-10 15:04:43 -0800 | [diff] [blame] | 22 | |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 23 | #include <ScopedUtfChars.h> |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 24 | #include <ScopedLocalRef.h> |
Peng Xu | d5ec5f9 | 2016-04-27 14:49:25 -0700 | [diff] [blame] | 25 | #include <android_runtime/AndroidRuntime.h> |
Peng Xu | 7d96fa0 | 2017-03-04 16:15:45 -0800 | [diff] [blame^] | 26 | #include <android_runtime/android_hardware_HardwareBuffer.h> |
Mathias Agopian | caf8930 | 2017-03-06 16:06:49 -0800 | [diff] [blame] | 27 | #include <sensor/Sensor.h> |
| 28 | #include <sensor/SensorEventQueue.h> |
| 29 | #include <sensor/SensorManager.h> |
Peng Xu | fa2672b | 2016-12-07 03:54:44 -0800 | [diff] [blame] | 30 | #include <cutils/native_handle.h> |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 31 | #include <utils/Log.h> |
| 32 | #include <utils/Looper.h> |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 33 | #include <utils/Vector.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Peng Xu | d5ec5f9 | 2016-04-27 14:49:25 -0700 | [diff] [blame] | 35 | #include <map> |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 36 | |
Peng Xu | 4a4baef | 2016-03-16 16:56:39 -0700 | [diff] [blame] | 37 | namespace { |
| 38 | |
| 39 | using namespace android; |
| 40 | |
| 41 | struct { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 42 | jclass clazz; |
| 43 | jmethodID dispatchSensorEvent; |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 44 | jmethodID dispatchFlushCompleteEvent; |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 45 | jmethodID dispatchAdditionalInfoEvent; |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 46 | } gBaseEventQueueClassInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | struct SensorOffsets |
| 49 | { |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 50 | jclass clazz; |
Peng Xu | b85b1fe | 2016-04-20 21:28:33 -0700 | [diff] [blame] | 51 | //fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | jfieldID name; |
| 53 | jfieldID vendor; |
| 54 | jfieldID version; |
| 55 | jfieldID handle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | jfieldID range; |
| 57 | jfieldID resolution; |
| 58 | jfieldID power; |
Mathias Agopian | 050b562 | 2010-07-29 16:51:38 -0700 | [diff] [blame] | 59 | jfieldID minDelay; |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 60 | jfieldID fifoReservedEventCount; |
| 61 | jfieldID fifoMaxEventCount; |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 62 | jfieldID stringType; |
| 63 | jfieldID requiredPermission; |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 64 | jfieldID maxDelay; |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 65 | jfieldID flags; |
Peng Xu | b85b1fe | 2016-04-20 21:28:33 -0700 | [diff] [blame] | 66 | //methods |
destradaa | 9ba7c1c | 2015-02-10 15:04:43 -0800 | [diff] [blame] | 67 | jmethodID setType; |
Peng Xu | b85b1fe | 2016-04-20 21:28:33 -0700 | [diff] [blame] | 68 | jmethodID setUuid; |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 69 | jmethodID init; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | } gSensorOffsets; |
| 71 | |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 72 | struct ListOffsets { |
| 73 | jclass clazz; |
| 74 | jmethodID add; |
| 75 | } gListOffsets; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | /* |
Peng Xu | 4a4baef | 2016-03-16 16:56:39 -0700 | [diff] [blame] | 78 | * nativeClassInit is not inteneded to be thread-safe. It should be called before other native... |
| 79 | * functions (except nativeCreate). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | */ |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 81 | static void |
| 82 | nativeClassInit (JNIEnv *_env, jclass _this) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | { |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 84 | //android.hardware.Sensor |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 85 | SensorOffsets& sensorOffsets = gSensorOffsets; |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 86 | jclass sensorClass = (jclass) _env->NewGlobalRef(_env->FindClass("android/hardware/Sensor")); |
| 87 | sensorOffsets.clazz = sensorClass; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 88 | sensorOffsets.name = _env->GetFieldID(sensorClass, "mName", "Ljava/lang/String;"); |
| 89 | sensorOffsets.vendor = _env->GetFieldID(sensorClass, "mVendor", "Ljava/lang/String;"); |
| 90 | sensorOffsets.version = _env->GetFieldID(sensorClass, "mVersion", "I"); |
| 91 | sensorOffsets.handle = _env->GetFieldID(sensorClass, "mHandle", "I"); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 92 | sensorOffsets.range = _env->GetFieldID(sensorClass, "mMaxRange", "F"); |
| 93 | sensorOffsets.resolution = _env->GetFieldID(sensorClass, "mResolution","F"); |
| 94 | sensorOffsets.power = _env->GetFieldID(sensorClass, "mPower", "F"); |
| 95 | sensorOffsets.minDelay = _env->GetFieldID(sensorClass, "mMinDelay", "I"); |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 96 | sensorOffsets.fifoReservedEventCount = |
| 97 | _env->GetFieldID(sensorClass, "mFifoReservedEventCount", "I"); |
| 98 | sensorOffsets.fifoMaxEventCount = _env->GetFieldID(sensorClass, "mFifoMaxEventCount", "I"); |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 99 | sensorOffsets.stringType = _env->GetFieldID(sensorClass, "mStringType", "Ljava/lang/String;"); |
| 100 | sensorOffsets.requiredPermission = _env->GetFieldID(sensorClass, "mRequiredPermission", |
| 101 | "Ljava/lang/String;"); |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 102 | sensorOffsets.maxDelay = _env->GetFieldID(sensorClass, "mMaxDelay", "I"); |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 103 | sensorOffsets.flags = _env->GetFieldID(sensorClass, "mFlags", "I"); |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 104 | |
destradaa | 9ba7c1c | 2015-02-10 15:04:43 -0800 | [diff] [blame] | 105 | sensorOffsets.setType = _env->GetMethodID(sensorClass, "setType", "(I)Z"); |
Peng Xu | b85b1fe | 2016-04-20 21:28:33 -0700 | [diff] [blame] | 106 | sensorOffsets.setUuid = _env->GetMethodID(sensorClass, "setUuid", "(JJ)V"); |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 107 | sensorOffsets.init = _env->GetMethodID(sensorClass, "<init>", "()V"); |
| 108 | |
| 109 | // java.util.List; |
| 110 | ListOffsets& listOffsets = gListOffsets; |
| 111 | jclass listClass = (jclass) _env->NewGlobalRef(_env->FindClass("java/util/List")); |
| 112 | listOffsets.clazz = listClass; |
| 113 | listOffsets.add = _env->GetMethodID(listClass, "add", "(Ljava/lang/Object;)Z"); |
destradaa | 9ba7c1c | 2015-02-10 15:04:43 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** |
| 117 | * A key comparator predicate. |
| 118 | * It is used to intern strings associated with Sensor data. |
| 119 | * It defines a 'Strict weak ordering' for the interned strings. |
| 120 | */ |
| 121 | class InternedStringCompare { |
| 122 | public: |
| 123 | bool operator()(const String8* string1, const String8* string2) const { |
| 124 | if (string1 == NULL) { |
| 125 | return string2 != NULL; |
| 126 | } |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 127 | if (string2 == NULL) { |
| 128 | return false; |
| 129 | } |
destradaa | 9ba7c1c | 2015-02-10 15:04:43 -0800 | [diff] [blame] | 130 | return string1->compare(*string2) < 0; |
| 131 | } |
| 132 | }; |
| 133 | |
| 134 | /** |
| 135 | * A localized interning mechanism for Sensor strings. |
| 136 | * We implement our own interning to avoid the overhead of using java.lang.String#intern(). |
| 137 | * It is common that Vendor, StringType, and RequirePermission data is common between many of the |
| 138 | * Sensors, by interning the memory usage to represent Sensors is optimized. |
| 139 | */ |
| 140 | static jstring |
| 141 | getInternedString(JNIEnv *env, const String8* string) { |
| 142 | static std::map<const String8*, jstring, InternedStringCompare> internedStrings; |
| 143 | |
| 144 | jstring internedString; |
| 145 | std::map<const String8*, jstring>::iterator iterator = internedStrings.find(string); |
| 146 | if (iterator != internedStrings.end()) { |
| 147 | internedString = iterator->second; |
| 148 | } else { |
| 149 | jstring localString = env->NewStringUTF(string->string()); |
| 150 | // we are implementing our own interning so expect these strings to be backed by global refs |
| 151 | internedString = (jstring) env->NewGlobalRef(localString); |
| 152 | internedStrings.insert(std::make_pair(string, internedString)); |
| 153 | env->DeleteLocalRef(localString); |
| 154 | } |
destradaa | 9ba7c1c | 2015-02-10 15:04:43 -0800 | [diff] [blame] | 155 | return internedString; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 158 | static jlong |
| 159 | nativeCreate |
| 160 | (JNIEnv *env, jclass clazz, jstring opPackageName) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | { |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 162 | ScopedUtfChars opPackageNameUtf(env, opPackageName); |
Aravind Akella | 2af91d0 | 2015-07-29 18:39:52 -0700 | [diff] [blame] | 163 | return (jlong) &SensorManager::getInstanceForPackage(String16(opPackageNameUtf.c_str())); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 166 | static jobject |
| 167 | translateNativeSensorToJavaSensor(JNIEnv *env, jobject sensor, const Sensor& nativeSensor) { |
| 168 | const SensorOffsets& sensorOffsets(gSensorOffsets); |
| 169 | |
| 170 | if (sensor == NULL) { |
| 171 | // Sensor sensor = new Sensor(); |
| 172 | sensor = env->NewObject(sensorOffsets.clazz, sensorOffsets.init, ""); |
| 173 | } |
| 174 | |
| 175 | if (sensor != NULL) { |
| 176 | jstring name = env->NewStringUTF(nativeSensor.getName().string()); |
| 177 | jstring vendor = env->NewStringUTF(nativeSensor.getVendor().string()); |
| 178 | jstring requiredPermission = |
| 179 | env->NewStringUTF(nativeSensor.getRequiredPermission().string()); |
| 180 | |
| 181 | env->SetObjectField(sensor, sensorOffsets.name, name); |
| 182 | env->SetObjectField(sensor, sensorOffsets.vendor, vendor); |
| 183 | env->SetIntField(sensor, sensorOffsets.version, nativeSensor.getVersion()); |
| 184 | env->SetIntField(sensor, sensorOffsets.handle, nativeSensor.getHandle()); |
| 185 | env->SetFloatField(sensor, sensorOffsets.range, nativeSensor.getMaxValue()); |
| 186 | env->SetFloatField(sensor, sensorOffsets.resolution, nativeSensor.getResolution()); |
| 187 | env->SetFloatField(sensor, sensorOffsets.power, nativeSensor.getPowerUsage()); |
| 188 | env->SetIntField(sensor, sensorOffsets.minDelay, nativeSensor.getMinDelay()); |
| 189 | env->SetIntField(sensor, sensorOffsets.fifoReservedEventCount, |
| 190 | nativeSensor.getFifoReservedEventCount()); |
| 191 | env->SetIntField(sensor, sensorOffsets.fifoMaxEventCount, |
| 192 | nativeSensor.getFifoMaxEventCount()); |
| 193 | env->SetObjectField(sensor, sensorOffsets.requiredPermission, |
| 194 | requiredPermission); |
| 195 | env->SetIntField(sensor, sensorOffsets.maxDelay, nativeSensor.getMaxDelay()); |
| 196 | env->SetIntField(sensor, sensorOffsets.flags, nativeSensor.getFlags()); |
Peng Xu | b85b1fe | 2016-04-20 21:28:33 -0700 | [diff] [blame] | 197 | |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 198 | if (env->CallBooleanMethod(sensor, sensorOffsets.setType, nativeSensor.getType()) |
| 199 | == JNI_FALSE) { |
| 200 | jstring stringType = getInternedString(env, &nativeSensor.getStringType()); |
| 201 | env->SetObjectField(sensor, sensorOffsets.stringType, stringType); |
| 202 | } |
Peng Xu | b85b1fe | 2016-04-20 21:28:33 -0700 | [diff] [blame] | 203 | |
Peng Xu | 716866d | 2016-05-25 21:10:00 -0700 | [diff] [blame] | 204 | // TODO(b/29547335): Rename "setUuid" method to "setId". |
| 205 | int64_t id = nativeSensor.getId(); |
| 206 | env->CallVoidMethod(sensor, sensorOffsets.setUuid, id, 0); |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 207 | } |
| 208 | return sensor; |
| 209 | } |
| 210 | |
Aravind Akella | 516e40e | 2015-07-01 16:54:24 -0700 | [diff] [blame] | 211 | static jboolean |
| 212 | nativeGetSensorAtIndex(JNIEnv *env, jclass clazz, jlong sensorManager, jobject sensor, jint index) |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 213 | { |
| 214 | SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 216 | Sensor const* const* sensorList; |
Peng Xu | a08c9f5 | 2016-02-04 22:27:20 -0800 | [diff] [blame] | 217 | ssize_t count = mgr->getSensorList(&sensorList); |
| 218 | if (ssize_t(index) >= count) { |
Aravind Akella | 516e40e | 2015-07-01 16:54:24 -0700 | [diff] [blame] | 219 | return false; |
destradaa | 9ba7c1c | 2015-02-10 15:04:43 -0800 | [diff] [blame] | 220 | } |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 221 | |
Peng Xu | b85b1fe | 2016-04-20 21:28:33 -0700 | [diff] [blame] | 222 | return translateNativeSensorToJavaSensor(env, sensor, *sensorList[index]) != NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 225 | static void |
| 226 | nativeGetDynamicSensors(JNIEnv *env, jclass clazz, jlong sensorManager, jobject sensorList) { |
| 227 | |
| 228 | SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager); |
| 229 | const ListOffsets& listOffsets(gListOffsets); |
| 230 | |
| 231 | Vector<Sensor> nativeList; |
| 232 | |
| 233 | mgr->getDynamicSensorList(nativeList); |
| 234 | |
Ben Wagner | 85ea32b | 2016-03-16 17:10:42 -0400 | [diff] [blame] | 235 | ALOGI("DYNS native SensorManager.getDynamicSensorList return %zu sensors", nativeList.size()); |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 236 | for (size_t i = 0; i < nativeList.size(); ++i) { |
| 237 | jobject sensor = translateNativeSensorToJavaSensor(env, NULL, nativeList[i]); |
| 238 | // add to list |
| 239 | env->CallBooleanMethod(sensorList, listOffsets.add, sensor); |
| 240 | } |
| 241 | } |
| 242 | |
Aravind Akella | d123b51 | 2015-06-29 12:35:51 -0700 | [diff] [blame] | 243 | static jboolean nativeIsDataInjectionEnabled(JNIEnv *_env, jclass _this, jlong sensorManager) { |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 244 | SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager); |
Aravind Akella | d123b51 | 2015-06-29 12:35:51 -0700 | [diff] [blame] | 245 | return mgr->isDataInjectionEnabled(); |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Peng Xu | fa2672b | 2016-12-07 03:54:44 -0800 | [diff] [blame] | 248 | static jint nativeCreateDirectChannel(JNIEnv *_env, jclass _this, jlong sensorManager, |
Peng Xu | 7d96fa0 | 2017-03-04 16:15:45 -0800 | [diff] [blame^] | 249 | jlong size, jint channelType, jint fd, jobject hardwareBufferObj) { |
| 250 | const native_handle_t *nativeHandle = nullptr; |
| 251 | NATIVE_HANDLE_DECLARE_STORAGE(ashmemHandle, 1, 0); |
Peng Xu | fa2672b | 2016-12-07 03:54:44 -0800 | [diff] [blame] | 252 | |
Peng Xu | 7d96fa0 | 2017-03-04 16:15:45 -0800 | [diff] [blame^] | 253 | if (channelType == SENSOR_DIRECT_MEM_TYPE_ASHMEM) { |
| 254 | native_handle_t *handle = native_handle_init(ashmemHandle, 1, 0); |
| 255 | handle->data[0] = fd; |
| 256 | nativeHandle = handle; |
| 257 | } else if (channelType == SENSOR_DIRECT_MEM_TYPE_GRALLOC) { |
| 258 | AHardwareBuffer *hardwareBuffer = |
| 259 | android_hardware_HardwareBuffer_getNativeHardwareBuffer(_env, hardwareBufferObj); |
| 260 | if (hardwareBuffer != nullptr) { |
| 261 | nativeHandle = AHardwareBuffer_getNativeHandle(hardwareBuffer); |
Peng Xu | fa2672b | 2016-12-07 03:54:44 -0800 | [diff] [blame] | 262 | } |
| 263 | } |
Peng Xu | 7d96fa0 | 2017-03-04 16:15:45 -0800 | [diff] [blame^] | 264 | |
| 265 | if (nativeHandle == nullptr) { |
| 266 | return BAD_VALUE; |
| 267 | } |
| 268 | |
| 269 | SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager); |
| 270 | return mgr->createDirectChannel(size, channelType, nativeHandle); |
Peng Xu | fa2672b | 2016-12-07 03:54:44 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static void nativeDestroyDirectChannel(JNIEnv *_env, jclass _this, jlong sensorManager, |
| 274 | jint channelHandle) { |
| 275 | SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager); |
| 276 | mgr->destroyDirectChannel(channelHandle); |
| 277 | } |
| 278 | |
| 279 | static jint nativeConfigDirectChannel(JNIEnv *_env, jclass _this, jlong sensorManager, |
| 280 | jint channelHandle, jint sensorHandle, jint rate) { |
| 281 | SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager); |
| 282 | return mgr->configureDirectChannel(channelHandle, sensorHandle, rate); |
| 283 | } |
| 284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | //---------------------------------------------------------------------------- |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 286 | |
| 287 | class Receiver : public LooperCallback { |
| 288 | sp<SensorEventQueue> mSensorQueue; |
| 289 | sp<MessageQueue> mMessageQueue; |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 290 | jobject mReceiverWeakGlobal; |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 291 | jfloatArray mFloatScratch; |
| 292 | jintArray mIntScratch; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 293 | public: |
| 294 | Receiver(const sp<SensorEventQueue>& sensorQueue, |
| 295 | const sp<MessageQueue>& messageQueue, |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 296 | jobject receiverWeak) { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 297 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 298 | mSensorQueue = sensorQueue; |
| 299 | mMessageQueue = messageQueue; |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 300 | mReceiverWeakGlobal = env->NewGlobalRef(receiverWeak); |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 301 | |
| 302 | mIntScratch = (jintArray) env->NewGlobalRef(env->NewIntArray(16)); |
| 303 | mFloatScratch = (jfloatArray) env->NewGlobalRef(env->NewFloatArray(16)); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 304 | } |
| 305 | ~Receiver() { |
| 306 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 307 | env->DeleteGlobalRef(mReceiverWeakGlobal); |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 308 | env->DeleteGlobalRef(mFloatScratch); |
| 309 | env->DeleteGlobalRef(mIntScratch); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 310 | } |
| 311 | sp<SensorEventQueue> getSensorEventQueue() const { |
| 312 | return mSensorQueue; |
| 313 | } |
| 314 | |
| 315 | void destroy() { |
| 316 | mMessageQueue->getLooper()->removeFd( mSensorQueue->getFd() ); |
| 317 | } |
| 318 | |
| 319 | private: |
| 320 | virtual void onFirstRef() { |
| 321 | LooperCallback::onFirstRef(); |
| 322 | mMessageQueue->getLooper()->addFd(mSensorQueue->getFd(), 0, |
| 323 | ALOOPER_EVENT_INPUT, this, mSensorQueue.get()); |
| 324 | } |
| 325 | |
| 326 | virtual int handleEvent(int fd, int events, void* data) { |
| 327 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 328 | sp<SensorEventQueue> q = reinterpret_cast<SensorEventQueue *>(data); |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 329 | ScopedLocalRef<jobject> receiverObj(env, jniGetReferent(env, mReceiverWeakGlobal)); |
| 330 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 331 | ssize_t n; |
| 332 | ASensorEvent buffer[16]; |
| 333 | while ((n = q->read(buffer, 16)) > 0) { |
| 334 | for (int i=0 ; i<n ; i++) { |
Aravind Akella | 0288ca6 | 2014-07-28 14:53:44 -0700 | [diff] [blame] | 335 | if (buffer[i].type == SENSOR_TYPE_STEP_COUNTER) { |
Jean-Baptiste Queru | 3c9c091 | 2013-08-05 11:03:28 -0700 | [diff] [blame] | 336 | // step-counter returns a uint64, but the java API only deals with floats |
| 337 | float value = float(buffer[i].u64.step_counter); |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 338 | env->SetFloatArrayRegion(mFloatScratch, 0, 1, &value); |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 339 | } else if (buffer[i].type == SENSOR_TYPE_DYNAMIC_SENSOR_META) { |
| 340 | float value[2]; |
| 341 | value[0] = buffer[i].dynamic_sensor_meta.connected ? 1.f: 0.f; |
| 342 | value[1] = float(buffer[i].dynamic_sensor_meta.handle); |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 343 | env->SetFloatArrayRegion(mFloatScratch, 0, 2, value); |
| 344 | } else if (buffer[i].type == SENSOR_TYPE_ADDITIONAL_INFO) { |
| 345 | env->SetIntArrayRegion(mIntScratch, 0, 14, |
| 346 | buffer[i].additional_info.data_int32); |
| 347 | env->SetFloatArrayRegion(mFloatScratch, 0, 14, |
| 348 | buffer[i].additional_info.data_float); |
Jean-Baptiste Queru | 3c9c091 | 2013-08-05 11:03:28 -0700 | [diff] [blame] | 349 | } else { |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 350 | env->SetFloatArrayRegion(mFloatScratch, 0, 16, buffer[i].data); |
Jean-Baptiste Queru | 3c9c091 | 2013-08-05 11:03:28 -0700 | [diff] [blame] | 351 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 352 | |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 353 | if (buffer[i].type == SENSOR_TYPE_META_DATA) { |
| 354 | // This is a flush complete sensor event. Call dispatchFlushCompleteEvent |
| 355 | // method. |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 356 | if (receiverObj.get()) { |
| 357 | env->CallVoidMethod(receiverObj.get(), |
| 358 | gBaseEventQueueClassInfo.dispatchFlushCompleteEvent, |
| 359 | buffer[i].meta_data.sensor); |
| 360 | } |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 361 | } else if (buffer[i].type == SENSOR_TYPE_ADDITIONAL_INFO) { |
| 362 | // This is a flush complete sensor event. Call dispatchAdditionalInfoEvent |
| 363 | // method. |
| 364 | if (receiverObj.get()) { |
| 365 | int type = buffer[i].additional_info.type; |
| 366 | int serial = buffer[i].additional_info.serial; |
| 367 | env->CallVoidMethod(receiverObj.get(), |
| 368 | gBaseEventQueueClassInfo.dispatchAdditionalInfoEvent, |
| 369 | buffer[i].sensor, |
| 370 | type, serial, |
| 371 | mFloatScratch, |
| 372 | mIntScratch, |
| 373 | buffer[i].timestamp); |
| 374 | } |
| 375 | }else { |
Etienne Le Grand | af80510 | 2014-05-16 12:21:41 -0700 | [diff] [blame] | 376 | int8_t status; |
| 377 | switch (buffer[i].type) { |
| 378 | case SENSOR_TYPE_ORIENTATION: |
| 379 | case SENSOR_TYPE_MAGNETIC_FIELD: |
| 380 | case SENSOR_TYPE_ACCELEROMETER: |
| 381 | case SENSOR_TYPE_GYROSCOPE: |
Aravind Akella | f38226a | 2015-06-23 10:32:16 -0700 | [diff] [blame] | 382 | case SENSOR_TYPE_GRAVITY: |
| 383 | case SENSOR_TYPE_LINEAR_ACCELERATION: |
Etienne Le Grand | af80510 | 2014-05-16 12:21:41 -0700 | [diff] [blame] | 384 | status = buffer[i].vector.status; |
| 385 | break; |
| 386 | case SENSOR_TYPE_HEART_RATE: |
| 387 | status = buffer[i].heart_rate.status; |
| 388 | break; |
| 389 | default: |
| 390 | status = SENSOR_STATUS_ACCURACY_HIGH; |
| 391 | break; |
| 392 | } |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 393 | if (receiverObj.get()) { |
| 394 | env->CallVoidMethod(receiverObj.get(), |
| 395 | gBaseEventQueueClassInfo.dispatchSensorEvent, |
| 396 | buffer[i].sensor, |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 397 | mFloatScratch, |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 398 | status, |
| 399 | buffer[i].timestamp); |
| 400 | } |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 401 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 402 | if (env->ExceptionCheck()) { |
Aravind Akella | 35187bd | 2014-02-11 18:44:42 -0800 | [diff] [blame] | 403 | mSensorQueue->sendAck(buffer, n); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 404 | ALOGE("Exception dispatching input event."); |
| 405 | return 1; |
| 406 | } |
| 407 | } |
Aravind Akella | 35187bd | 2014-02-11 18:44:42 -0800 | [diff] [blame] | 408 | mSensorQueue->sendAck(buffer, n); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 409 | } |
| 410 | if (n<0 && n != -EAGAIN) { |
| 411 | // FIXME: error receiving events, what to do in this case? |
| 412 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 413 | return 1; |
| 414 | } |
| 415 | }; |
| 416 | |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 417 | static jlong nativeInitSensorEventQueue(JNIEnv *env, jclass clazz, jlong sensorManager, |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 418 | jobject eventQWeak, jobject msgQ, jstring packageName, jint mode) { |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 419 | SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager); |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 420 | ScopedUtfChars packageUtf(env, packageName); |
| 421 | String8 clientName(packageUtf.c_str()); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 422 | sp<SensorEventQueue> queue(mgr->createEventQueue(clientName, mode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 424 | sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, msgQ); |
| 425 | if (messageQueue == NULL) { |
| 426 | jniThrowRuntimeException(env, "MessageQueue is not initialized."); |
| 427 | return 0; |
Mathias Agopian | 0b6d77b | 2012-05-07 18:27:06 -0700 | [diff] [blame] | 428 | } |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 429 | |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 430 | sp<Receiver> receiver = new Receiver(queue, messageQueue, eventQWeak); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 431 | receiver->incStrong((void*)nativeInitSensorEventQueue); |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 432 | return jlong(receiver.get()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 435 | static jint nativeEnableSensor(JNIEnv *env, jclass clazz, jlong eventQ, jint handle, jint rate_us, |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 436 | jint maxBatchReportLatency) { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 437 | sp<Receiver> receiver(reinterpret_cast<Receiver *>(eventQ)); |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 438 | return receiver->getSensorEventQueue()->enableSensor(handle, rate_us, maxBatchReportLatency, |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 439 | 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 442 | static jint nativeDisableSensor(JNIEnv *env, jclass clazz, jlong eventQ, jint handle) { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 443 | sp<Receiver> receiver(reinterpret_cast<Receiver *>(eventQ)); |
| 444 | return receiver->getSensorEventQueue()->disableSensor(handle); |
| 445 | } |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 446 | |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame] | 447 | static void nativeDestroySensorEventQueue(JNIEnv *env, jclass clazz, jlong eventQ) { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 448 | sp<Receiver> receiver(reinterpret_cast<Receiver *>(eventQ)); |
| 449 | receiver->destroy(); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 450 | receiver->decStrong((void*)nativeInitSensorEventQueue); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 451 | } |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 452 | |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 453 | static jint nativeFlushSensor(JNIEnv *env, jclass clazz, jlong eventQ) { |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 454 | sp<Receiver> receiver(reinterpret_cast<Receiver *>(eventQ)); |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 455 | return receiver->getSensorEventQueue()->flush(); |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 456 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 457 | |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame] | 458 | static jint nativeInjectSensorData(JNIEnv *env, jclass clazz, jlong eventQ, jint handle, |
| 459 | jfloatArray values, jint accuracy, jlong timestamp) { |
| 460 | sp<Receiver> receiver(reinterpret_cast<Receiver *>(eventQ)); |
| 461 | // Create a sensor_event from the above data which can be injected into the HAL. |
| 462 | ASensorEvent sensor_event; |
| 463 | memset(&sensor_event, 0, sizeof(sensor_event)); |
| 464 | sensor_event.sensor = handle; |
| 465 | sensor_event.timestamp = timestamp; |
| 466 | env->GetFloatArrayRegion(values, 0, env->GetArrayLength(values), sensor_event.data); |
| 467 | return receiver->getSensorEventQueue()->injectSensorEvent(sensor_event); |
| 468 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 469 | //---------------------------------------------------------------------------- |
| 470 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 471 | static const JNINativeMethod gSystemSensorManagerMethods[] = { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 472 | {"nativeClassInit", |
| 473 | "()V", |
| 474 | (void*)nativeClassInit }, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 475 | {"nativeCreate", |
| 476 | "(Ljava/lang/String;)J", |
| 477 | (void*)nativeCreate }, |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 478 | |
Aravind Akella | 516e40e | 2015-07-01 16:54:24 -0700 | [diff] [blame] | 479 | {"nativeGetSensorAtIndex", |
| 480 | "(JLandroid/hardware/Sensor;I)Z", |
| 481 | (void*)nativeGetSensorAtIndex }, |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame] | 482 | |
Peng Xu | a35b553 | 2016-01-20 00:05:45 -0800 | [diff] [blame] | 483 | {"nativeGetDynamicSensors", |
| 484 | "(JLjava/util/List;)V", |
| 485 | (void*)nativeGetDynamicSensors }, |
| 486 | |
Aravind Akella | d123b51 | 2015-06-29 12:35:51 -0700 | [diff] [blame] | 487 | {"nativeIsDataInjectionEnabled", |
| 488 | "(J)Z", |
Peng Xu | fa2672b | 2016-12-07 03:54:44 -0800 | [diff] [blame] | 489 | (void*)nativeIsDataInjectionEnabled }, |
| 490 | |
| 491 | {"nativeCreateDirectChannel", |
Peng Xu | 7d96fa0 | 2017-03-04 16:15:45 -0800 | [diff] [blame^] | 492 | "(JJIILandroid/hardware/HardwareBuffer;)I", |
Peng Xu | fa2672b | 2016-12-07 03:54:44 -0800 | [diff] [blame] | 493 | (void*)nativeCreateDirectChannel }, |
| 494 | |
| 495 | {"nativeDestroyDirectChannel", |
| 496 | "(JI)V", |
| 497 | (void*)nativeDestroyDirectChannel }, |
| 498 | |
| 499 | {"nativeConfigDirectChannel", |
| 500 | "(JIII)I", |
| 501 | (void*)nativeConfigDirectChannel }, |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 502 | }; |
| 503 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 504 | static const JNINativeMethod gBaseEventQueueMethods[] = { |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 505 | {"nativeInitBaseEventQueue", |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 506 | "(JLjava/lang/ref/WeakReference;Landroid/os/MessageQueue;Ljava/lang/String;ILjava/lang/String;)J", |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 507 | (void*)nativeInitSensorEventQueue }, |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 508 | |
| 509 | {"nativeEnableSensor", |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 510 | "(JIII)I", |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 511 | (void*)nativeEnableSensor }, |
| 512 | |
| 513 | {"nativeDisableSensor", |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 514 | "(JI)I", |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 515 | (void*)nativeDisableSensor }, |
| 516 | |
| 517 | {"nativeDestroySensorEventQueue", |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 518 | "(J)V", |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 519 | (void*)nativeDestroySensorEventQueue }, |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 520 | |
| 521 | {"nativeFlushSensor", |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 522 | "(J)I", |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 523 | (void*)nativeFlushSensor }, |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame] | 524 | |
| 525 | {"nativeInjectSensorData", |
| 526 | "(JI[FIJ)I", |
| 527 | (void*)nativeInjectSensorData }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | }; |
| 529 | |
Peng Xu | 4a4baef | 2016-03-16 16:56:39 -0700 | [diff] [blame] | 530 | } //unnamed namespace |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | |
| 532 | int register_android_hardware_SensorManager(JNIEnv *env) |
| 533 | { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 534 | RegisterMethodsOrDie(env, "android/hardware/SystemSensorManager", |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 535 | gSystemSensorManagerMethods, NELEM(gSystemSensorManagerMethods)); |
| 536 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 537 | RegisterMethodsOrDie(env, "android/hardware/SystemSensorManager$BaseEventQueue", |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 538 | gBaseEventQueueMethods, NELEM(gBaseEventQueueMethods)); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 539 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 540 | gBaseEventQueueClassInfo.clazz = FindClassOrDie(env, |
| 541 | "android/hardware/SystemSensorManager$BaseEventQueue"); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 542 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 543 | gBaseEventQueueClassInfo.dispatchSensorEvent = GetMethodIDOrDie(env, |
| 544 | gBaseEventQueueClassInfo.clazz, "dispatchSensorEvent", "(I[FIJ)V"); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 545 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 546 | gBaseEventQueueClassInfo.dispatchFlushCompleteEvent = GetMethodIDOrDie(env, |
| 547 | gBaseEventQueueClassInfo.clazz, "dispatchFlushCompleteEvent", "(I)V"); |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 548 | |
Peng Xu | a295835 | 2016-01-26 18:42:17 -0800 | [diff] [blame] | 549 | gBaseEventQueueClassInfo.dispatchAdditionalInfoEvent = GetMethodIDOrDie(env, |
| 550 | gBaseEventQueueClassInfo.clazz, "dispatchAdditionalInfoEvent", "(III[F[I)V"); |
| 551 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 552 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | } |