Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 1 | /* |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 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 | */ |
| 16 | |
| 17 | package android.hardware; |
| 18 | |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 19 | import android.Manifest; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 21 | import android.content.pm.PackageManager; |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 22 | import android.os.Handler; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 23 | import android.os.Looper; |
| 24 | import android.os.MessageQueue; |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 25 | import android.util.Log; |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 26 | import android.util.SparseArray; |
| 27 | import android.util.SparseBooleanArray; |
| 28 | import android.util.SparseIntArray; |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 29 | import dalvik.system.CloseGuard; |
| 30 | |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 31 | import java.lang.ref.WeakReference; |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 32 | import java.util.ArrayList; |
| 33 | import java.util.HashMap; |
| 34 | import java.util.List; |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 35 | |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Sensor manager implementation that communicates with the built-in |
| 38 | * system sensors. |
| 39 | * |
| 40 | * @hide |
| 41 | */ |
| 42 | public class SystemSensorManager extends SensorManager { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 43 | private static native void nativeClassInit(); |
| 44 | private static native int nativeGetNextSensor(Sensor sensor, int next); |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 45 | private static native int nativeEnableDataInjection(boolean enable); |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 46 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 47 | private static boolean sSensorModuleInitialized = false; |
| 48 | private static final Object sSensorModuleLock = new Object(); |
| 49 | private static final ArrayList<Sensor> sFullSensorsList = new ArrayList<Sensor>(); |
| 50 | private static final SparseArray<Sensor> sHandleToSensor = new SparseArray<Sensor>(); |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 51 | private static InjectEventQueue mInjectEventQueue = null; |
| 52 | private static boolean mDataInjectionMode = false; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 53 | |
| 54 | // Listener list |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 55 | private final HashMap<SensorEventListener, SensorEventQueue> mSensorListeners = |
| 56 | new HashMap<SensorEventListener, SensorEventQueue>(); |
| 57 | private final HashMap<TriggerEventListener, TriggerEventQueue> mTriggerListeners = |
| 58 | new HashMap<TriggerEventListener, TriggerEventQueue>(); |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 59 | |
Jeff Brown | 4481d9c | 2012-04-16 16:14:44 -0700 | [diff] [blame] | 60 | // Looper associated with the context in which this instance was created. |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 61 | private final Looper mMainLooper; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 62 | private final int mTargetSdkLevel; |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 63 | private final String mPackageName; |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 64 | private final boolean mHasDataInjectionPermissions; |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 65 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 66 | /** {@hide} */ |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 67 | public SystemSensorManager(Context context, Looper mainLooper) { |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 68 | mMainLooper = mainLooper; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 69 | mTargetSdkLevel = context.getApplicationInfo().targetSdkVersion; |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 70 | mPackageName = context.getPackageName(); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 71 | synchronized(sSensorModuleLock) { |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 72 | if (!sSensorModuleInitialized) { |
| 73 | sSensorModuleInitialized = true; |
| 74 | |
| 75 | nativeClassInit(); |
| 76 | |
| 77 | // initialize the sensor list |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 78 | final ArrayList<Sensor> fullList = sFullSensorsList; |
| 79 | int i = 0; |
| 80 | do { |
| 81 | Sensor sensor = new Sensor(); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 82 | i = nativeGetNextSensor(sensor, i); |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 83 | if (i>=0) { |
| 84 | //Log.d(TAG, "found sensor: " + sensor.getName() + |
| 85 | // ", handle=" + sensor.getHandle()); |
| 86 | fullList.add(sensor); |
| 87 | sHandleToSensor.append(sensor.getHandle(), sensor); |
| 88 | } |
| 89 | } while (i>0); |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 90 | } |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 91 | mHasDataInjectionPermissions = context.checkSelfPermission( |
| 92 | Manifest.permission.HARDWARE_TEST) == PackageManager.PERMISSION_GRANTED; |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 96 | |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 97 | /** @hide */ |
| 98 | @Override |
| 99 | protected List<Sensor> getFullSensorList() { |
| 100 | return sFullSensorsList; |
| 101 | } |
| 102 | |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 103 | |
| 104 | /** @hide */ |
Jeff Brown | 4481d9c | 2012-04-16 16:14:44 -0700 | [diff] [blame] | 105 | @Override |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 106 | protected boolean registerListenerImpl(SensorEventListener listener, Sensor sensor, |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 107 | int delayUs, Handler handler, int maxBatchReportLatencyUs, int reservedFlags) { |
| 108 | if (listener == null || sensor == null) { |
| 109 | Log.e(TAG, "sensor or listener is null"); |
| 110 | return false; |
| 111 | } |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 112 | // Trigger Sensors should use the requestTriggerSensor call. |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 113 | if (sensor.getReportingMode() == Sensor.REPORTING_MODE_ONE_SHOT) { |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 114 | Log.e(TAG, "Trigger Sensors should use the requestTriggerSensor."); |
| 115 | return false; |
| 116 | } |
| 117 | if (maxBatchReportLatencyUs < 0 || delayUs < 0) { |
| 118 | Log.e(TAG, "maxBatchReportLatencyUs and delayUs should be non-negative"); |
| 119 | return false; |
| 120 | } |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 121 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 122 | // Invariants to preserve: |
| 123 | // - one Looper per SensorEventListener |
| 124 | // - one Looper per SensorEventQueue |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 125 | // We map SensorEventListener to a SensorEventQueue, which holds the looper |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 126 | synchronized (mSensorListeners) { |
| 127 | SensorEventQueue queue = mSensorListeners.get(listener); |
| 128 | if (queue == null) { |
Jaikumar Ganesh | 1aab1db | 2013-03-13 15:00:21 -0700 | [diff] [blame] | 129 | Looper looper = (handler != null) ? handler.getLooper() : mMainLooper; |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 130 | queue = new SensorEventQueue(listener, looper, this); |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 131 | if (!queue.addSensor(sensor, delayUs, maxBatchReportLatencyUs)) { |
Jaikumar Ganesh | 1aab1db | 2013-03-13 15:00:21 -0700 | [diff] [blame] | 132 | queue.dispose(); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 133 | return false; |
Jaikumar Ganesh | 1aab1db | 2013-03-13 15:00:21 -0700 | [diff] [blame] | 134 | } |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 135 | mSensorListeners.put(listener, queue); |
| 136 | return true; |
| 137 | } else { |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 138 | return queue.addSensor(sensor, delayUs, maxBatchReportLatencyUs); |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /** @hide */ |
| 144 | @Override |
| 145 | protected void unregisterListenerImpl(SensorEventListener listener, Sensor sensor) { |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 146 | // Trigger Sensors should use the cancelTriggerSensor call. |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 147 | if (sensor != null && sensor.getReportingMode() == Sensor.REPORTING_MODE_ONE_SHOT) { |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 148 | return; |
| 149 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 150 | |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 151 | synchronized (mSensorListeners) { |
| 152 | SensorEventQueue queue = mSensorListeners.get(listener); |
Jaikumar Ganesh | 1aab1db | 2013-03-13 15:00:21 -0700 | [diff] [blame] | 153 | if (queue != null) { |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 154 | boolean result; |
| 155 | if (sensor == null) { |
| 156 | result = queue.removeAllSensors(); |
Jaikumar Ganesh | 1aab1db | 2013-03-13 15:00:21 -0700 | [diff] [blame] | 157 | } else { |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 158 | result = queue.removeSensor(sensor, true); |
Jaikumar Ganesh | 1aab1db | 2013-03-13 15:00:21 -0700 | [diff] [blame] | 159 | } |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 160 | if (result && !queue.hasSensors()) { |
| 161 | mSensorListeners.remove(listener); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 162 | queue.dispose(); |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 168 | /** @hide */ |
| 169 | @Override |
| 170 | protected boolean requestTriggerSensorImpl(TriggerEventListener listener, Sensor sensor) { |
| 171 | if (sensor == null) throw new IllegalArgumentException("sensor cannot be null"); |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 172 | |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 173 | if (sensor.getReportingMode() != Sensor.REPORTING_MODE_ONE_SHOT) return false; |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 174 | |
| 175 | synchronized (mTriggerListeners) { |
| 176 | TriggerEventQueue queue = mTriggerListeners.get(listener); |
| 177 | if (queue == null) { |
| 178 | queue = new TriggerEventQueue(listener, mMainLooper, this); |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 179 | if (!queue.addSensor(sensor, 0, 0)) { |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 180 | queue.dispose(); |
| 181 | return false; |
| 182 | } |
| 183 | mTriggerListeners.put(listener, queue); |
| 184 | return true; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 185 | } else { |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 186 | return queue.addSensor(sensor, 0, 0); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | } |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 190 | |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 191 | /** @hide */ |
| 192 | @Override |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 193 | protected boolean cancelTriggerSensorImpl(TriggerEventListener listener, Sensor sensor, |
| 194 | boolean disable) { |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 195 | if (sensor != null && sensor.getReportingMode() != Sensor.REPORTING_MODE_ONE_SHOT) { |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 196 | return false; |
| 197 | } |
| 198 | synchronized (mTriggerListeners) { |
| 199 | TriggerEventQueue queue = mTriggerListeners.get(listener); |
| 200 | if (queue != null) { |
| 201 | boolean result; |
| 202 | if (sensor == null) { |
| 203 | result = queue.removeAllSensors(); |
| 204 | } else { |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 205 | result = queue.removeSensor(sensor, disable); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 206 | } |
| 207 | if (result && !queue.hasSensors()) { |
| 208 | mTriggerListeners.remove(listener); |
| 209 | queue.dispose(); |
| 210 | } |
| 211 | return result; |
| 212 | } |
| 213 | return false; |
| 214 | } |
| 215 | } |
| 216 | |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 217 | protected boolean flushImpl(SensorEventListener listener) { |
| 218 | if (listener == null) throw new IllegalArgumentException("listener cannot be null"); |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 219 | |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 220 | synchronized (mSensorListeners) { |
| 221 | SensorEventQueue queue = mSensorListeners.get(listener); |
| 222 | if (queue == null) { |
| 223 | return false; |
| 224 | } else { |
| 225 | return (queue.flush() == 0); |
| 226 | } |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 227 | } |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 230 | protected boolean enableDataInjectionImpl(boolean enable) { |
| 231 | if (!mHasDataInjectionPermissions) { |
| 232 | throw new SecurityException("Permission denial. Calling enableDataInjection without " |
| 233 | + Manifest.permission.HARDWARE_TEST); |
| 234 | } |
| 235 | synchronized (sSensorModuleLock) { |
| 236 | int ret = nativeEnableDataInjection(enable); |
| 237 | // The HAL does not support injection. Ignore. |
| 238 | if (ret != 0) { |
| 239 | Log.e(TAG, "HAL does not support data injection"); |
| 240 | return false; |
| 241 | } |
| 242 | mDataInjectionMode = enable; |
| 243 | // If data injection is being disabled clean up the native resources. |
| 244 | if (!enable && mInjectEventQueue != null) { |
| 245 | mInjectEventQueue.dispose(); |
| 246 | mInjectEventQueue = null; |
| 247 | } |
| 248 | return true; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | protected boolean injectSensorDataImpl(Sensor sensor, float[] values, int accuracy, |
| 253 | long timestamp) { |
| 254 | if (!mHasDataInjectionPermissions) { |
| 255 | throw new SecurityException("Permission denial. Calling injectSensorData without " |
| 256 | + Manifest.permission.HARDWARE_TEST); |
| 257 | } |
| 258 | synchronized (sSensorModuleLock) { |
| 259 | if (!mDataInjectionMode) { |
| 260 | Log.e(TAG, "Data injection mode not activated before calling injectSensorData"); |
| 261 | return false; |
| 262 | } |
| 263 | if (mInjectEventQueue == null) { |
| 264 | mInjectEventQueue = new InjectEventQueue(mMainLooper, this); |
| 265 | } |
| 266 | int ret = mInjectEventQueue.injectSensorData(sensor.getHandle(), values, accuracy, |
| 267 | timestamp); |
| 268 | // If there are any errors in data injection clean up the native resources. |
| 269 | if (ret != 0) { |
| 270 | mInjectEventQueue.dispose(); |
| 271 | mInjectEventQueue = null; |
| 272 | mDataInjectionMode = false; |
| 273 | } |
| 274 | return ret == 0; |
| 275 | } |
| 276 | } |
| 277 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 278 | /* |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 279 | * BaseEventQueue is the communication channel with the sensor service, |
| 280 | * SensorEventQueue, TriggerEventQueue are subclases and there is one-to-one mapping between |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 281 | * the queues and the listeners. InjectEventQueue is also a sub-class which is a special case |
| 282 | * where data is being injected into the sensor HAL through the sensor service. It is not |
| 283 | * associated with any listener and there is one InjectEventQueue associated with a |
| 284 | * SensorManager instance. |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 285 | */ |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 286 | private static abstract class BaseEventQueue { |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 287 | private native long nativeInitBaseEventQueue(WeakReference<BaseEventQueue> eventQWeak, |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 288 | MessageQueue msgQ, float[] scratch, String packageName, int mode); |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 289 | private static native int nativeEnableSensor(long eventQ, int handle, int rateUs, |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 290 | int maxBatchReportLatencyUs); |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 291 | private static native int nativeDisableSensor(long eventQ, int handle); |
| 292 | private static native void nativeDestroySensorEventQueue(long eventQ); |
| 293 | private static native int nativeFlushSensor(long eventQ); |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 294 | private static native int nativeInjectSensorData(long eventQ, int handle, |
| 295 | float[] values,int accuracy, long timestamp); |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 296 | private long nSensorEventQueue; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 297 | private final SparseBooleanArray mActiveSensors = new SparseBooleanArray(); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 298 | protected final SparseIntArray mSensorAccuracies = new SparseIntArray(); |
| 299 | protected final SparseBooleanArray mFirstEvent = new SparseBooleanArray(); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 300 | private final CloseGuard mCloseGuard = CloseGuard.get(); |
| 301 | private final float[] mScratch = new float[16]; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 302 | protected final SystemSensorManager mManager; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 303 | |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 304 | protected static final int OPERATING_MODE_NORMAL = 0; |
| 305 | protected static final int OPERATING_MODE_DATA_INJECTION = 1; |
| 306 | |
| 307 | BaseEventQueue(Looper looper, SystemSensorManager manager, int mode) { |
Jeff Brown | 3b4049e | 2015-04-17 15:22:27 -0700 | [diff] [blame] | 308 | nSensorEventQueue = nativeInitBaseEventQueue(new WeakReference<BaseEventQueue>(this), |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 309 | looper.getQueue(), mScratch, manager.mPackageName, mode); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 310 | mCloseGuard.open("dispose"); |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 311 | mManager = manager; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 312 | } |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 313 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 314 | public void dispose() { |
| 315 | dispose(false); |
| 316 | } |
| 317 | |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 318 | public boolean addSensor( |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 319 | Sensor sensor, int delayUs, int maxBatchReportLatencyUs) { |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 320 | // Check if already present. |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 321 | int handle = sensor.getHandle(); |
| 322 | if (mActiveSensors.get(handle)) return false; |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 323 | |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 324 | // Get ready to receive events before calling enable. |
| 325 | mActiveSensors.put(handle, true); |
| 326 | addSensorEvent(sensor); |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 327 | if (enableSensor(sensor, delayUs, maxBatchReportLatencyUs) != 0) { |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 328 | // Try continuous mode if batching fails. |
| 329 | if (maxBatchReportLatencyUs == 0 || |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 330 | maxBatchReportLatencyUs > 0 && enableSensor(sensor, delayUs, 0) != 0) { |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 331 | removeSensor(sensor, false); |
| 332 | return false; |
| 333 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 334 | } |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 335 | return true; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 338 | public boolean removeAllSensors() { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 339 | for (int i=0 ; i<mActiveSensors.size(); i++) { |
| 340 | if (mActiveSensors.valueAt(i) == true) { |
| 341 | int handle = mActiveSensors.keyAt(i); |
| 342 | Sensor sensor = sHandleToSensor.get(handle); |
| 343 | if (sensor != null) { |
| 344 | disableSensor(sensor); |
| 345 | mActiveSensors.put(handle, false); |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 346 | removeSensorEvent(sensor); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 347 | } else { |
| 348 | // it should never happen -- just ignore. |
| 349 | } |
| 350 | } |
| 351 | } |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 352 | return true; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 355 | public boolean removeSensor(Sensor sensor, boolean disable) { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 356 | final int handle = sensor.getHandle(); |
| 357 | if (mActiveSensors.get(handle)) { |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 358 | if (disable) disableSensor(sensor); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 359 | mActiveSensors.put(sensor.getHandle(), false); |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 360 | removeSensorEvent(sensor); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 361 | return true; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 362 | } |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 363 | return false; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 364 | } |
| 365 | |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 366 | public int flush() { |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 367 | if (nSensorEventQueue == 0) throw new NullPointerException(); |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 368 | return nativeFlushSensor(nSensorEventQueue); |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 371 | public boolean hasSensors() { |
| 372 | // no more sensors are set |
| 373 | return mActiveSensors.indexOfValue(true) >= 0; |
| 374 | } |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 375 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 376 | @Override |
| 377 | protected void finalize() throws Throwable { |
| 378 | try { |
| 379 | dispose(true); |
| 380 | } finally { |
| 381 | super.finalize(); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | private void dispose(boolean finalized) { |
| 386 | if (mCloseGuard != null) { |
| 387 | if (finalized) { |
| 388 | mCloseGuard.warnIfOpen(); |
| 389 | } |
| 390 | mCloseGuard.close(); |
| 391 | } |
| 392 | if (nSensorEventQueue != 0) { |
| 393 | nativeDestroySensorEventQueue(nSensorEventQueue); |
| 394 | nSensorEventQueue = 0; |
| 395 | } |
| 396 | } |
| 397 | |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 398 | private int enableSensor( |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 399 | Sensor sensor, int rateUs, int maxBatchReportLatencyUs) { |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 400 | if (nSensorEventQueue == 0) throw new NullPointerException(); |
| 401 | if (sensor == null) throw new NullPointerException(); |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 402 | return nativeEnableSensor(nSensorEventQueue, sensor.getHandle(), rateUs, |
Aravind Akella | 8844599 | 2015-02-26 17:05:28 -0800 | [diff] [blame] | 403 | maxBatchReportLatencyUs); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 404 | } |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 405 | |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 406 | protected int injectSensorDataBase(int handle, float[] values, int accuracy, |
| 407 | long timestamp) { |
| 408 | return nativeInjectSensorData(nSensorEventQueue, handle, values, accuracy, timestamp); |
| 409 | } |
| 410 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 411 | private int disableSensor(Sensor sensor) { |
| 412 | if (nSensorEventQueue == 0) throw new NullPointerException(); |
| 413 | if (sensor == null) throw new NullPointerException(); |
| 414 | return nativeDisableSensor(nSensorEventQueue, sensor.getHandle()); |
| 415 | } |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 416 | protected abstract void dispatchSensorEvent(int handle, float[] values, int accuracy, |
| 417 | long timestamp); |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 418 | protected abstract void dispatchFlushCompleteEvent(int handle); |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 419 | |
| 420 | protected abstract void addSensorEvent(Sensor sensor); |
| 421 | protected abstract void removeSensorEvent(Sensor sensor); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static final class SensorEventQueue extends BaseEventQueue { |
| 425 | private final SensorEventListener mListener; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 426 | private final SparseArray<SensorEvent> mSensorsEvents = new SparseArray<SensorEvent>(); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 427 | |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 428 | public SensorEventQueue(SensorEventListener listener, Looper looper, |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 429 | SystemSensorManager manager) { |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 430 | super(looper, manager, OPERATING_MODE_NORMAL); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 431 | mListener = listener; |
| 432 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 433 | |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 434 | @Override |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 435 | public void addSensorEvent(Sensor sensor) { |
| 436 | SensorEvent t = new SensorEvent(Sensor.getMaxLengthValuesArray(sensor, |
| 437 | mManager.mTargetSdkLevel)); |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 438 | synchronized (mSensorsEvents) { |
| 439 | mSensorsEvents.put(sensor.getHandle(), t); |
| 440 | } |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 443 | @Override |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 444 | public void removeSensorEvent(Sensor sensor) { |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 445 | synchronized (mSensorsEvents) { |
| 446 | mSensorsEvents.delete(sensor.getHandle()); |
| 447 | } |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 450 | // Called from native code. |
| 451 | @SuppressWarnings("unused") |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 452 | @Override |
| 453 | protected void dispatchSensorEvent(int handle, float[] values, int inAccuracy, |
| 454 | long timestamp) { |
| 455 | final Sensor sensor = sHandleToSensor.get(handle); |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 456 | SensorEvent t = null; |
| 457 | synchronized (mSensorsEvents) { |
| 458 | t = mSensorsEvents.get(handle); |
| 459 | } |
| 460 | |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 461 | if (t == null) { |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 462 | // This may happen if the client has unregistered and there are pending events in |
| 463 | // the queue waiting to be delivered. Ignore. |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 464 | return; |
| 465 | } |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 466 | // Copy from the values array. |
| 467 | System.arraycopy(values, 0, t.values, 0, t.values.length); |
| 468 | t.timestamp = timestamp; |
| 469 | t.accuracy = inAccuracy; |
| 470 | t.sensor = sensor; |
Etienne Le Grand | af80510 | 2014-05-16 12:21:41 -0700 | [diff] [blame] | 471 | |
| 472 | // call onAccuracyChanged() only if the value changes |
| 473 | final int accuracy = mSensorAccuracies.get(handle); |
| 474 | if ((t.accuracy >= 0) && (accuracy != t.accuracy)) { |
| 475 | mSensorAccuracies.put(handle, t.accuracy); |
| 476 | mListener.onAccuracyChanged(t.sensor, t.accuracy); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 477 | } |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 478 | mListener.onSensorChanged(t); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 479 | } |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 480 | |
| 481 | @SuppressWarnings("unused") |
| 482 | protected void dispatchFlushCompleteEvent(int handle) { |
Aravind Akella | 4bdc37d | 2013-10-01 17:58:35 -0700 | [diff] [blame] | 483 | if (mListener instanceof SensorEventListener2) { |
| 484 | final Sensor sensor = sHandleToSensor.get(handle); |
| 485 | ((SensorEventListener2)mListener).onFlushCompleted(sensor); |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 486 | } |
| 487 | return; |
| 488 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 489 | } |
| 490 | |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 491 | static final class TriggerEventQueue extends BaseEventQueue { |
| 492 | private final TriggerEventListener mListener; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 493 | private final SparseArray<TriggerEvent> mTriggerEvents = new SparseArray<TriggerEvent>(); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 494 | |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 495 | public TriggerEventQueue(TriggerEventListener listener, Looper looper, |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 496 | SystemSensorManager manager) { |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 497 | super(looper, manager, OPERATING_MODE_NORMAL); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 498 | mListener = listener; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 501 | @Override |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 502 | public void addSensorEvent(Sensor sensor) { |
| 503 | TriggerEvent t = new TriggerEvent(Sensor.getMaxLengthValuesArray(sensor, |
| 504 | mManager.mTargetSdkLevel)); |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 505 | synchronized (mTriggerEvents) { |
| 506 | mTriggerEvents.put(sensor.getHandle(), t); |
| 507 | } |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 510 | @Override |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 511 | public void removeSensorEvent(Sensor sensor) { |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 512 | synchronized (mTriggerEvents) { |
| 513 | mTriggerEvents.delete(sensor.getHandle()); |
| 514 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 515 | } |
| 516 | |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 517 | // Called from native code. |
| 518 | @SuppressWarnings("unused") |
| 519 | @Override |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 520 | protected void dispatchSensorEvent(int handle, float[] values, int accuracy, |
| 521 | long timestamp) { |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 522 | final Sensor sensor = sHandleToSensor.get(handle); |
Aravind Akella | 31d14ce | 2013-10-22 20:04:22 -0700 | [diff] [blame] | 523 | TriggerEvent t = null; |
| 524 | synchronized (mTriggerEvents) { |
| 525 | t = mTriggerEvents.get(handle); |
| 526 | } |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 527 | if (t == null) { |
| 528 | Log.e(TAG, "Error: Trigger Event is null for Sensor: " + sensor); |
| 529 | return; |
| 530 | } |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 531 | |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 532 | // Copy from the values array. |
| 533 | System.arraycopy(values, 0, t.values, 0, t.values.length); |
| 534 | t.timestamp = timestamp; |
| 535 | t.sensor = sensor; |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 536 | |
Jaikumar Ganesh | 2e90089 | 2013-04-11 10:40:33 -0700 | [diff] [blame] | 537 | // A trigger sensor is auto disabled. So just clean up and don't call native |
| 538 | // disable. |
| 539 | mManager.cancelTriggerSensorImpl(mListener, sensor, false); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 540 | |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 541 | mListener.onTrigger(t); |
Mathias Agopian | db772d8 | 2013-01-31 19:31:12 -0800 | [diff] [blame] | 542 | } |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 543 | |
| 544 | @SuppressWarnings("unused") |
| 545 | protected void dispatchFlushCompleteEvent(int handle) { |
| 546 | } |
| 547 | } |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame^] | 548 | |
| 549 | static final class InjectEventQueue extends BaseEventQueue { |
| 550 | public InjectEventQueue(Looper looper, SystemSensorManager manager) { |
| 551 | super(looper, manager, OPERATING_MODE_DATA_INJECTION); |
| 552 | } |
| 553 | |
| 554 | int injectSensorData(int handle, float[] values,int accuracy, long timestamp) { |
| 555 | return injectSensorDataBase(handle, values, accuracy, timestamp); |
| 556 | } |
| 557 | |
| 558 | @SuppressWarnings("unused") |
| 559 | protected void dispatchSensorEvent(int handle, float[] values, int accuracy, |
| 560 | long timestamp) { |
| 561 | } |
| 562 | |
| 563 | @SuppressWarnings("unused") |
| 564 | protected void dispatchFlushCompleteEvent(int handle) { |
| 565 | |
| 566 | } |
| 567 | |
| 568 | @SuppressWarnings("unused") |
| 569 | protected void addSensorEvent(Sensor sensor) { |
| 570 | |
| 571 | } |
| 572 | |
| 573 | @SuppressWarnings("unused") |
| 574 | protected void removeSensorEvent(Sensor sensor) { |
| 575 | |
| 576 | } |
| 577 | } |
Jeff Brown | 25157e4 | 2012-04-16 12:13:05 -0700 | [diff] [blame] | 578 | } |