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