blob: 8a254b953539dcf6f0e997d12507efd4b133c01b [file] [log] [blame]
Mathias Agopianfc328812010-07-14 23:41:37 -07001/*
2 * Copyright (C) 2010 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#ifndef ANDROID_SENSOR_SERVICE_H
18#define ANDROID_SENSOR_SERVICE_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/Vector.h>
24#include <utils/SortedVector.h>
25#include <utils/KeyedVector.h>
26#include <utils/threads.h>
Aravind Akella56ae4262014-07-10 16:01:10 -070027#include <utils/AndroidThreads.h>
Mathias Agopianfc328812010-07-14 23:41:37 -070028#include <utils/RefBase.h>
Aravind Akella56ae4262014-07-10 16:01:10 -070029#include <utils/Looper.h>
Aravind Akella4949c502015-02-11 15:54:35 -080030#include <utils/String8.h>
Mathias Agopianfc328812010-07-14 23:41:37 -070031
32#include <binder/BinderService.h>
Mathias Agopianfc328812010-07-14 23:41:37 -070033
34#include <gui/Sensor.h>
Mathias Agopianb3989272011-10-20 18:42:02 -070035#include <gui/BitTube.h>
Mathias Agopianfc328812010-07-14 23:41:37 -070036#include <gui/ISensorServer.h>
37#include <gui/ISensorEventConnection.h>
38
Mathias Agopianf001c922010-11-11 17:58:51 -080039#include "SensorInterface.h"
40
Bernhard Rosenkränzer72952ef2014-11-17 21:03:39 +010041#if __clang__
42// Clang warns about SensorEventConnection::dump hiding BBinder::dump
43// The cause isn't fixable without changing the API, so let's tell clang
44// this is indeed intentional.
45#pragma clang diagnostic ignored "-Woverloaded-virtual"
46#endif
47
Mathias Agopianfc328812010-07-14 23:41:37 -070048// ---------------------------------------------------------------------------
49
Mathias Agopiana1b7db92011-05-27 16:23:58 -070050#define DEBUG_CONNECTIONS false
Aravind Akella56ae4262014-07-10 16:01:10 -070051// Max size is 100 KB which is enough to accept a batch of about 1000 events.
52#define MAX_SOCKET_BUFFER_SIZE_BATCHED 100 * 1024
53// For older HALs which don't support batching, use a smaller socket buffer size.
Aravind Akella4c8b9512013-09-05 17:03:38 -070054#define SOCKET_BUFFER_SIZE_NON_BATCHED 4 * 1024
Mathias Agopiana1b7db92011-05-27 16:23:58 -070055
Aravind Akella444f2672015-05-07 12:40:52 -070056#define CIRCULAR_BUF_SIZE 10
57
Mathias Agopianfc328812010-07-14 23:41:37 -070058struct sensors_poll_device_t;
59struct sensors_module_t;
60
61namespace android {
62// ---------------------------------------------------------------------------
63
64class SensorService :
65 public BinderService<SensorService>,
66 public BnSensorServer,
67 protected Thread
68{
Mathias Agopianb6df7d02013-05-09 14:53:35 -070069 friend class BinderService<SensorService>;
Mathias Agopianfc328812010-07-14 23:41:37 -070070
Aravind Akella4949c502015-02-11 15:54:35 -080071 enum Mode {
72 // The regular operating mode where any application can register/unregister/call flush on
73 // sensors.
74 NORMAL = 0,
Aravind Akellaa9e6cc32015-04-16 18:57:31 -070075 // This mode is only used for testing purposes. Not all HALs support this mode. In this
76 // mode, the HAL ignores the sensor data provided by physical sensors and accepts the data
77 // that is injected from the SensorService as if it were the real sensor data. This mode
78 // is primarily used for testing various algorithms like vendor provided SensorFusion,
79 // Step Counter and Step Detector etc. Typically in this mode, there will be a client
80 // (a SensorEventConnection) which will be injecting sensor data into the HAL. Normal apps
81 // can unregister and register for any sensor that supports injection. Registering to sensors
82 // that do not support injection will give an error.
83 // TODO(aakella) : Allow exactly one client to inject sensor data at a time.
84 DATA_INJECTION = 1,
Aravind Akella4949c502015-02-11 15:54:35 -080085 // This mode is used only for testing sensors. Each sensor can be tested in isolation with
86 // the required sampling_rate and maxReportLatency parameters without having to think about
87 // the data rates requested by other applications. End user devices are always expected to be
88 // in NORMAL mode. When this mode is first activated, all active sensors from all connections
89 // are disabled. Calling flush() will return an error. In this mode, only the requests from
90 // selected apps whose package names are whitelisted are allowed (typically CTS apps). Only
Aravind Akellaa9e6cc32015-04-16 18:57:31 -070091 // these apps can register/unregister/call flush() on sensors. If SensorService switches to
Aravind Akella4949c502015-02-11 15:54:35 -080092 // NORMAL mode again, all sensors that were previously registered to are activated with the
93 // corresponding paramaters if the application hasn't unregistered for sensors in the mean
94 // time.
95 // NOTE: Non whitelisted app whose sensors were previously deactivated may still receive
96 // events if a whitelisted app requests data from the same sensor.
Aravind Akellaa9e6cc32015-04-16 18:57:31 -070097 RESTRICTED = 2
98
99 // State Transitions supported.
100 // RESTRICTED <--- NORMAL ---> DATA_INJECTION
101 // ---> <---
Aravind Akella4949c502015-02-11 15:54:35 -0800102 };
103
Mathias Agopianb6df7d02013-05-09 14:53:35 -0700104 static const char* WAKE_LOCK_NAME;
Mathias Agopian7c1c5312010-07-21 15:59:50 -0700105
Mathias Agopianb6df7d02013-05-09 14:53:35 -0700106 static char const* getServiceName() ANDROID_API { return "sensorservice"; }
107 SensorService() ANDROID_API;
Mathias Agopianfc328812010-07-14 23:41:37 -0700108 virtual ~SensorService();
109
110 virtual void onFirstRef();
111
112 // Thread interface
113 virtual bool threadLoop();
114
115 // ISensorServer interface
116 virtual Vector<Sensor> getSensorList();
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700117 virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName,
118 int requestedMode);
119 virtual status_t enableDataInjection(int enable);
Mathias Agopianfc328812010-07-14 23:41:37 -0700120 virtual status_t dump(int fd, const Vector<String16>& args);
121
Aravind Akella56ae4262014-07-10 16:01:10 -0700122 class SensorEventConnection : public BnSensorEventConnection, public LooperCallback {
123 friend class SensorService;
Mathias Agopian7c1c5312010-07-21 15:59:50 -0700124 virtual ~SensorEventConnection();
125 virtual void onFirstRef();
Mathias Agopianb3989272011-10-20 18:42:02 -0700126 virtual sp<BitTube> getSensorChannel() const;
Aravind Akella724d91d2013-06-27 12:04:23 -0700127 virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs,
128 nsecs_t maxBatchReportLatencyNs, int reservedFlags);
129 virtual status_t setEventRate(int handle, nsecs_t samplingPeriodNs);
Aravind Akella701166d2013-10-08 14:59:26 -0700130 virtual status_t flush();
Aravind Akella4c8b9512013-09-05 17:03:38 -0700131 // Count the number of flush complete events which are about to be dropped in the buffer.
132 // Increment mPendingFlushEventsToSend in mSensorInfo. These flush complete events will be
133 // sent separately before the next batch of events.
Aravind Akella0ec20662014-09-14 17:29:48 -0700134 void countFlushCompleteEventsLocked(sensors_event_t const* scratch, int numEventsDropped);
Mathias Agopian7c1c5312010-07-21 15:59:50 -0700135
Aravind Akella6c2664a2014-08-13 12:24:50 -0700136 // Check if there are any wake up events in the buffer. If yes, return the index of the
137 // first wake_up sensor event in the buffer else return -1. This wake_up sensor event will
138 // have the flag WAKE_UP_SENSOR_EVENT_NEEDS_ACK set. Exactly one event per packet will have
139 // the wake_up flag set. SOCK_SEQPACKET ensures that either the entire packet is read or
140 // dropped.
141 int findWakeUpSensorEventLocked(sensors_event_t const* scratch, int count);
142
143 // Send pending flush_complete events. There may have been flush_complete_events that are
144 // dropped which need to be sent separately before other events. On older HALs (1_0) this
145 // method emulates the behavior of flush().
146 void sendPendingFlushEventsLocked();
Aravind Akella56ae4262014-07-10 16:01:10 -0700147
148 // Writes events from mEventCache to the socket.
Aravind Akellab4373ac2014-10-29 17:55:20 -0700149 void writeToSocketFromCache();
Aravind Akella56ae4262014-07-10 16:01:10 -0700150
151 // Compute the approximate cache size from the FIFO sizes of various sensors registered for
152 // this connection. Wake up and non-wake up sensors have separate FIFOs but FIFO may be
153 // shared amongst wake-up sensors and non-wake up sensors.
154 int computeMaxCacheSizeLocked() const;
155
Aravind Akella6c2664a2014-08-13 12:24:50 -0700156 // When more sensors register, the maximum cache size desired may change. Compute max cache
157 // size, reallocate memory and copy over events from the older cache.
158 void reAllocateCacheLocked(sensors_event_t const* scratch, int count);
159
Aravind Akella56ae4262014-07-10 16:01:10 -0700160 // LooperCallback method. If there is data to read on this fd, it is an ack from the
161 // app that it has read events from a wake up sensor, decrement mWakeLockRefCount.
162 // If this fd is available for writing send the data from the cache.
163 virtual int handleEvent(int fd, int events, void* data);
Aravind Akella9a844cf2014-02-11 18:58:52 -0800164
Aravind Akella8a969552014-09-28 17:52:41 -0700165 // Increment mPendingFlushEventsToSend for the given sensor handle.
166 void incrementPendingFlushCount(int32_t handle);
167
168 // Add or remove the file descriptor associated with the BitTube to the looper. If mDead is
169 // set to true or there are no more sensors for this connection, the file descriptor is
170 // removed if it has been previously added to the Looper. Depending on the state of the
171 // connection FD may be added to the Looper. The flags to set are determined by the internal
172 // state of the connection. FDs are added to the looper when wake-up sensors are registered
173 // (to poll for acknowledgements) and when write fails on the socket when there are too many
Aravind Akella8a969552014-09-28 17:52:41 -0700174 // error and the other end hangs up or when this client unregisters for this connection.
175 void updateLooperRegistration(const sp<Looper>& looper);
176 void updateLooperRegistrationLocked(const sp<Looper>& looper);
177
Mathias Agopianfc328812010-07-14 23:41:37 -0700178 sp<SensorService> const mService;
Aravind Akella4c8b9512013-09-05 17:03:38 -0700179 sp<BitTube> mChannel;
Mathias Agopian5307d172012-09-18 17:02:43 -0700180 uid_t mUid;
Mathias Agopian71d7a5c2010-11-14 20:55:25 -0800181 mutable Mutex mConnectionLock;
Aravind Akella9a844cf2014-02-11 18:58:52 -0800182 // Number of events from wake up sensors which are still pending and haven't been delivered
183 // to the corresponding application. It is incremented by one unit for each write to the
184 // socket.
Aravind Akella8a969552014-09-28 17:52:41 -0700185 uint32_t mWakeLockRefCount;
Mathias Agopian7c1c5312010-07-21 15:59:50 -0700186
Aravind Akella8a969552014-09-28 17:52:41 -0700187 // If this flag is set to true, it means that the file descriptor associated with the
188 // BitTube has been added to the Looper in SensorService. This flag is typically set when
189 // this connection has wake-up sensors associated with it or when write has failed on this
190 // connection and we're storing some events in the cache.
191 bool mHasLooperCallbacks;
192 // If there are any errors associated with the Looper this flag is set to true and
193 // mWakeLockRefCount is reset to zero. needsWakeLock method will always return false, if
194 // this flag is set.
195 bool mDead;
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700196
197 bool mDataInjectionMode;
Aravind Akella4c8b9512013-09-05 17:03:38 -0700198 struct FlushInfo {
199 // The number of flush complete events dropped for this sensor is stored here.
200 // They are sent separately before the next batch of events.
201 int mPendingFlushEventsToSend;
202 // Every activate is preceded by a flush. Only after the first flush complete is
203 // received, the events for the sensor are sent on that *connection*.
204 bool mFirstFlushPending;
Aravind Akella6c2664a2014-08-13 12:24:50 -0700205 FlushInfo() : mPendingFlushEventsToSend(0), mFirstFlushPending(false) {}
Aravind Akella4c8b9512013-09-05 17:03:38 -0700206 };
207 // protected by SensorService::mLock. Key for this vector is the sensor handle.
208 KeyedVector<int, FlushInfo> mSensorInfo;
Aravind Akella56ae4262014-07-10 16:01:10 -0700209 sensors_event_t *mEventCache;
210 int mCacheSize, mMaxCacheSize;
Aravind Akella4949c502015-02-11 15:54:35 -0800211 String8 mPackageName;
Aravind Akella56ae4262014-07-10 16:01:10 -0700212#if DEBUG_CONNECTIONS
213 int mEventsReceived, mEventsSent, mEventsSentFromCache;
Aravind Akellae74baf62014-08-21 12:28:35 -0700214 int mTotalAcksNeeded, mTotalAcksReceived;
Aravind Akella56ae4262014-07-10 16:01:10 -0700215#endif
Mathias Agopian7c1c5312010-07-21 15:59:50 -0700216
Mathias Agopianfc328812010-07-14 23:41:37 -0700217 public:
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700218 SensorEventConnection(const sp<SensorService>& service, uid_t uid, String8 packageName,
219 bool isDataInjectionMode);
Mathias Agopian7c1c5312010-07-21 15:59:50 -0700220
Aravind Akella0ec20662014-09-14 17:29:48 -0700221 status_t sendEvents(sensors_event_t const* buffer, size_t count,
Aravind Akella8493b792014-09-08 15:45:47 -0700222 sensors_event_t* scratch,
223 SensorEventConnection const * const * mapFlushEventsToConnections = NULL);
Mathias Agopianfc328812010-07-14 23:41:37 -0700224 bool hasSensor(int32_t handle) const;
225 bool hasAnySensor() const;
Aravind Akella8493b792014-09-08 15:45:47 -0700226 bool hasOneShotSensors() const;
Mathias Agopian7c1c5312010-07-21 15:59:50 -0700227 bool addSensor(int32_t handle);
228 bool removeSensor(int32_t handle);
Aravind Akella4c8b9512013-09-05 17:03:38 -0700229 void setFirstFlushPending(int32_t handle, bool value);
Aravind Akella4c8b9512013-09-05 17:03:38 -0700230 void dump(String8& result);
Aravind Akella9a844cf2014-02-11 18:58:52 -0800231 bool needsWakeLock();
Aravind Akellab4373ac2014-10-29 17:55:20 -0700232 void resetWakeLockRefCount();
Aravind Akella4949c502015-02-11 15:54:35 -0800233 String8 getPackageName() const;
Mathias Agopian5307d172012-09-18 17:02:43 -0700234
235 uid_t getUid() const { return mUid; }
Mathias Agopianfc328812010-07-14 23:41:37 -0700236 };
237
238 class SensorRecord {
239 SortedVector< wp<SensorEventConnection> > mConnections;
Aravind Akella6c2664a2014-08-13 12:24:50 -0700240 // A queue of all flush() calls made on this sensor. Flush complete events will be
241 // sent in this order.
242 Vector< wp<SensorEventConnection> > mPendingFlushConnections;
Mathias Agopianfc328812010-07-14 23:41:37 -0700243 public:
244 SensorRecord(const sp<SensorEventConnection>& connection);
Mathias Agopian7c1c5312010-07-21 15:59:50 -0700245 bool addConnection(const sp<SensorEventConnection>& connection);
Mathias Agopianfc328812010-07-14 23:41:37 -0700246 bool removeConnection(const wp<SensorEventConnection>& connection);
247 size_t getNumConnections() const { return mConnections.size(); }
Aravind Akella6c2664a2014-08-13 12:24:50 -0700248
249 void addPendingFlushConnection(const sp<SensorEventConnection>& connection);
250 void removeFirstPendingFlushConnection();
251 SensorEventConnection * getFirstPendingFlushConnection();
Aravind Akella4949c502015-02-11 15:54:35 -0800252 void clearAllPendingFlushConnections();
Mathias Agopianfc328812010-07-14 23:41:37 -0700253 };
254
Aravind Akella56ae4262014-07-10 16:01:10 -0700255 class SensorEventAckReceiver : public Thread {
256 sp<SensorService> const mService;
257 public:
258 virtual bool threadLoop();
259 SensorEventAckReceiver(const sp<SensorService>& service): mService(service) {}
260 };
261
Aravind Akella444f2672015-05-07 12:40:52 -0700262 // sensor_event_t with only the data and the timestamp.
263 struct TrimmedSensorEvent {
264 union {
265 float *mData;
266 uint64_t mStepCounter;
267 };
268 // Timestamp from the sensor_event.
269 int64_t mTimestamp;
270 // HH:MM:SS local time at which this sensor event is read at SensorService. Useful
271 // for debugging.
272 int32_t mHour, mMin, mSec;
273
274 TrimmedSensorEvent(int numData, int sensorType) {
275 mTimestamp = -1;
276 if (sensorType == SENSOR_TYPE_STEP_COUNTER) {
277 mStepCounter = 0;
278 } else {
279 mData = new float[numData];
280 for (int i = 0; i < numData; ++i) {
281 mData[i] = -1.0;
282 }
283 }
284 mHour = mMin = mSec = 0;
285 }
286
287 ~TrimmedSensorEvent() {
288 delete [] mData;
289 }
290 };
291
292 // A circular buffer of TrimmedSensorEvents. The size of this buffer is typically 10. The
293 // last N events generated from the sensor are stored in this buffer. The buffer is NOT
294 // cleared when the sensor unregisters and as a result one may see very old data in the
295 // dumpsys output but this is WAI.
296 class CircularBuffer {
297 int mNextInd;
298 int mSensorType;
299 TrimmedSensorEvent ** mTrimmedSensorEventArr;
300 public:
301 CircularBuffer(int sensor_event_type);
302 void addEvent(const sensors_event_t& sensor_event);
303 void printBuffer(String8& buffer) const;
304 bool populateLastEvent(sensors_event_t *event);
305 ~CircularBuffer();
306 };
307
308 static int getNumEventsForSensorType(int sensor_event_type);
Mathias Agopianf001c922010-11-11 17:58:51 -0800309 String8 getSensorName(int handle) const;
Aravind Akellab4099e72013-10-15 15:43:10 -0700310 bool isVirtualSensor(int handle) const;
Aravind Akella70018042014-04-07 22:52:37 +0000311 Sensor getSensorFromHandle(int handle) const;
Aravind Akella9a844cf2014-02-11 18:58:52 -0800312 bool isWakeUpSensor(int type) const;
Aravind Akella0ec20662014-09-14 17:29:48 -0700313 void recordLastValueLocked(sensors_event_t const* buffer, size_t count);
Mathias Agopianf001c922010-11-11 17:58:51 -0800314 static void sortEventBuffer(sensors_event_t* buffer, size_t count);
Mathias Agopian03193062013-05-10 19:32:39 -0700315 Sensor registerSensor(SensorInterface* sensor);
316 Sensor registerVirtualSensor(SensorInterface* sensor);
Mathias Agopianac9a96d2013-07-12 02:01:16 -0700317 status_t cleanupWithoutDisable(
318 const sp<SensorEventConnection>& connection, int handle);
319 status_t cleanupWithoutDisableLocked(
320 const sp<SensorEventConnection>& connection, int handle);
Aravind Akella9a844cf2014-02-11 18:58:52 -0800321 void cleanupAutoDisabledSensorLocked(const sp<SensorEventConnection>& connection,
Mathias Agopianb6df7d02013-05-09 14:53:35 -0700322 sensors_event_t const* buffer, const int count);
Aravind Akella70018042014-04-07 22:52:37 +0000323 static bool canAccessSensor(const Sensor& sensor);
324 static bool verifyCanAccessSensor(const Sensor& sensor, const char* operation);
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700325 static bool hasDataInjectionPermissions();
Aravind Akella9a844cf2014-02-11 18:58:52 -0800326 // SensorService acquires a partial wakelock for delivering events from wake up sensors. This
327 // method checks whether all the events from these wake up sensors have been delivered to the
328 // corresponding applications, if yes the wakelock is released.
329 void checkWakeLockState();
330 void checkWakeLockStateLocked();
Aravind Akellab4373ac2014-10-29 17:55:20 -0700331 bool isWakeLockAcquired();
Aravind Akella9a844cf2014-02-11 18:58:52 -0800332 bool isWakeUpSensorEvent(const sensors_event_t& event) const;
Aravind Akella56ae4262014-07-10 16:01:10 -0700333
Aravind Akella6c2664a2014-08-13 12:24:50 -0700334 SensorRecord * getSensorRecord(int handle);
335
Aravind Akella56ae4262014-07-10 16:01:10 -0700336 sp<Looper> getLooper() const;
337
Aravind Akellab4373ac2014-10-29 17:55:20 -0700338 // Reset mWakeLockRefCounts for all SensorEventConnections to zero. This may happen if
339 // SensorService did not receive any acknowledgements from apps which have registered for
340 // wake_up sensors.
341 void resetAllWakeLockRefCounts();
342
343 // Acquire or release wake_lock. If wake_lock is acquired, set the timeout in the looper to
344 // 5 seconds and wake the looper.
345 void setWakeLockAcquiredLocked(bool acquire);
346
347 // Send events from the event cache for this particular connection.
348 void sendEventsFromCache(const sp<SensorEventConnection>& connection);
349
350 // Promote all weak referecences in mActiveConnections vector to strong references and add them
351 // to the output vector.
352 void populateActiveConnections(SortedVector< sp<SensorEventConnection> >* activeConnections);
353
Aravind Akella4949c502015-02-11 15:54:35 -0800354 // If SensorService is operating in RESTRICTED mode, only select whitelisted packages are
355 // allowed to register for or call flush on sensors. Typically only cts test packages are
356 // allowed.
357 bool isWhiteListedPackage(const String8& packageName);
358
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700359 // Reset the state of SensorService to NORMAL mode.
360 status_t resetToNormalMode();
361 status_t resetToNormalModeLocked();
362
Mathias Agopianfc328812010-07-14 23:41:37 -0700363 // constants
364 Vector<Sensor> mSensorList;
Mathias Agopian33264862012-06-28 19:46:54 -0700365 Vector<Sensor> mUserSensorListDebug;
Mathias Agopian010e4222011-06-08 20:06:50 -0700366 Vector<Sensor> mUserSensorList;
Mathias Agopianf001c922010-11-11 17:58:51 -0800367 DefaultKeyedVector<int, SensorInterface*> mSensorMap;
368 Vector<SensorInterface *> mVirtualSensorList;
Mathias Agopian50df2952010-07-19 19:09:10 -0700369 status_t mInitCheck;
Aravind Akella5466c3d2014-08-22 16:11:10 -0700370 // Socket buffersize used to initialize BitTube. This size depends on whether batching is
371 // supported or not.
Aravind Akella8a969552014-09-28 17:52:41 -0700372 uint32_t mSocketBufferSize;
Aravind Akella56ae4262014-07-10 16:01:10 -0700373 sp<Looper> mLooper;
Aravind Akellab4373ac2014-10-29 17:55:20 -0700374 sp<SensorEventAckReceiver> mAckReceiver;
Mathias Agopianfc328812010-07-14 23:41:37 -0700375
376 // protected by mLock
377 mutable Mutex mLock;
Mathias Agopianfc328812010-07-14 23:41:37 -0700378 DefaultKeyedVector<int, SensorRecord*> mActiveSensors;
Mathias Agopianf001c922010-11-11 17:58:51 -0800379 DefaultKeyedVector<int, SensorInterface*> mActiveVirtualSensors;
Mathias Agopianfc328812010-07-14 23:41:37 -0700380 SortedVector< wp<SensorEventConnection> > mActiveConnections;
Aravind Akella9a844cf2014-02-11 18:58:52 -0800381 bool mWakeLockAcquired;
Aravind Akella8493b792014-09-08 15:45:47 -0700382 sensors_event_t *mSensorEventBuffer, *mSensorEventScratch;
383 SensorEventConnection const **mMapFlushEventsToConnections;
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700384 Mode mCurrentOperatingMode;
Aravind Akella8493b792014-09-08 15:45:47 -0700385
Mathias Agopian3560fb22010-07-22 21:24:39 -0700386 // The size of this vector is constant, only the items are mutable
Aravind Akella444f2672015-05-07 12:40:52 -0700387 KeyedVector<int32_t, CircularBuffer *> mLastEventSeen;
Mathias Agopian3560fb22010-07-22 21:24:39 -0700388
Mathias Agopianfc328812010-07-14 23:41:37 -0700389public:
Mathias Agopiandb5b4bc2011-02-03 14:52:47 -0800390 void cleanupConnection(SensorEventConnection* connection);
Aravind Akella724d91d2013-06-27 12:04:23 -0700391 status_t enable(const sp<SensorEventConnection>& connection, int handle,
392 nsecs_t samplingPeriodNs, nsecs_t maxBatchReportLatencyNs, int reservedFlags);
Mathias Agopianfc328812010-07-14 23:41:37 -0700393 status_t disable(const sp<SensorEventConnection>& connection, int handle);
Mathias Agopian7c1c5312010-07-21 15:59:50 -0700394 status_t setEventRate(const sp<SensorEventConnection>& connection, int handle, nsecs_t ns);
Aravind Akella9e3adfc2014-09-03 15:48:05 -0700395 status_t flushSensor(const sp<SensorEventConnection>& connection);
Mathias Agopianfc328812010-07-14 23:41:37 -0700396};
397
398// ---------------------------------------------------------------------------
399}; // namespace android
400
401#endif // ANDROID_SENSOR_SERVICE_H