| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 27 | #include <utils/AndroidThreads.h> | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 29 | #include <utils/Looper.h> | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 30 |  | 
|  | 31 | #include <binder/BinderService.h> | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 32 |  | 
|  | 33 | #include <gui/Sensor.h> | 
| Mathias Agopian | b398927 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 34 | #include <gui/BitTube.h> | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 35 | #include <gui/ISensorServer.h> | 
|  | 36 | #include <gui/ISensorEventConnection.h> | 
|  | 37 |  | 
| Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 38 | #include "SensorInterface.h" | 
|  | 39 |  | 
| Bernhard Rosenkränzer | 72952ef | 2014-11-17 21:03:39 +0100 | [diff] [blame] | 40 | #if __clang__ | 
|  | 41 | // Clang warns about SensorEventConnection::dump hiding BBinder::dump | 
|  | 42 | // The cause isn't fixable without changing the API, so let's tell clang | 
|  | 43 | // this is indeed intentional. | 
|  | 44 | #pragma clang diagnostic ignored "-Woverloaded-virtual" | 
|  | 45 | #endif | 
|  | 46 |  | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 47 | // --------------------------------------------------------------------------- | 
|  | 48 |  | 
| Mathias Agopian | a1b7db9 | 2011-05-27 16:23:58 -0700 | [diff] [blame] | 49 | #define DEBUG_CONNECTIONS   false | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 50 | // Max size is 100 KB which is enough to accept a batch of about 1000 events. | 
|  | 51 | #define MAX_SOCKET_BUFFER_SIZE_BATCHED 100 * 1024 | 
|  | 52 | // For older HALs which don't support batching, use a smaller socket buffer size. | 
| Aravind Akella | 4c8b951 | 2013-09-05 17:03:38 -0700 | [diff] [blame] | 53 | #define SOCKET_BUFFER_SIZE_NON_BATCHED 4 * 1024 | 
| Mathias Agopian | a1b7db9 | 2011-05-27 16:23:58 -0700 | [diff] [blame] | 54 |  | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 55 | struct sensors_poll_device_t; | 
|  | 56 | struct sensors_module_t; | 
|  | 57 |  | 
|  | 58 | namespace android { | 
|  | 59 | // --------------------------------------------------------------------------- | 
|  | 60 |  | 
|  | 61 | class SensorService : | 
|  | 62 | public BinderService<SensorService>, | 
|  | 63 | public BnSensorServer, | 
|  | 64 | protected Thread | 
|  | 65 | { | 
| Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 66 | friend class BinderService<SensorService>; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 67 |  | 
| Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 68 | static const char* WAKE_LOCK_NAME; | 
| Mathias Agopian | 7c1c531 | 2010-07-21 15:59:50 -0700 | [diff] [blame] | 69 |  | 
| Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 70 | static char const* getServiceName() ANDROID_API { return "sensorservice"; } | 
|  | 71 | SensorService() ANDROID_API; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 72 | virtual ~SensorService(); | 
|  | 73 |  | 
|  | 74 | virtual void onFirstRef(); | 
|  | 75 |  | 
|  | 76 | // Thread interface | 
|  | 77 | virtual bool threadLoop(); | 
|  | 78 |  | 
|  | 79 | // ISensorServer interface | 
|  | 80 | virtual Vector<Sensor> getSensorList(); | 
|  | 81 | virtual sp<ISensorEventConnection> createSensorEventConnection(); | 
|  | 82 | virtual status_t dump(int fd, const Vector<String16>& args); | 
|  | 83 |  | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 84 | class SensorEventConnection : public BnSensorEventConnection, public LooperCallback { | 
|  | 85 | friend class SensorService; | 
| Mathias Agopian | 7c1c531 | 2010-07-21 15:59:50 -0700 | [diff] [blame] | 86 | virtual ~SensorEventConnection(); | 
|  | 87 | virtual void onFirstRef(); | 
| Mathias Agopian | b398927 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 88 | virtual sp<BitTube> getSensorChannel() const; | 
| Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 89 | virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs, | 
|  | 90 | nsecs_t maxBatchReportLatencyNs, int reservedFlags); | 
|  | 91 | virtual status_t setEventRate(int handle, nsecs_t samplingPeriodNs); | 
| Aravind Akella | 701166d | 2013-10-08 14:59:26 -0700 | [diff] [blame] | 92 | virtual status_t flush(); | 
| Aravind Akella | 4c8b951 | 2013-09-05 17:03:38 -0700 | [diff] [blame] | 93 | // Count the number of flush complete events which are about to be dropped in the buffer. | 
|  | 94 | // Increment mPendingFlushEventsToSend in mSensorInfo. These flush complete events will be | 
|  | 95 | // sent separately before the next batch of events. | 
| Aravind Akella | 0ec2066 | 2014-09-14 17:29:48 -0700 | [diff] [blame] | 96 | void countFlushCompleteEventsLocked(sensors_event_t const* scratch, int numEventsDropped); | 
| Mathias Agopian | 7c1c531 | 2010-07-21 15:59:50 -0700 | [diff] [blame] | 97 |  | 
| Aravind Akella | 6c2664a | 2014-08-13 12:24:50 -0700 | [diff] [blame] | 98 | // Check if there are any wake up events in the buffer. If yes, return the index of the | 
|  | 99 | // first wake_up sensor event in the buffer else return -1. This wake_up sensor event will | 
|  | 100 | // have the flag WAKE_UP_SENSOR_EVENT_NEEDS_ACK set. Exactly one event per packet will have | 
|  | 101 | // the wake_up flag set. SOCK_SEQPACKET ensures that either the entire packet is read or | 
|  | 102 | // dropped. | 
|  | 103 | int findWakeUpSensorEventLocked(sensors_event_t const* scratch, int count); | 
|  | 104 |  | 
|  | 105 | // Send pending flush_complete events. There may have been flush_complete_events that are | 
|  | 106 | // dropped which need to be sent separately before other events. On older HALs (1_0) this | 
|  | 107 | // method emulates the behavior of flush(). | 
|  | 108 | void sendPendingFlushEventsLocked(); | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 109 |  | 
|  | 110 | // Writes events from mEventCache to the socket. | 
| Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 111 | void writeToSocketFromCache(); | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 112 |  | 
|  | 113 | // Compute the approximate cache size from the FIFO sizes of various sensors registered for | 
|  | 114 | // this connection. Wake up and non-wake up sensors have separate FIFOs but FIFO may be | 
|  | 115 | // shared amongst wake-up sensors and non-wake up sensors. | 
|  | 116 | int computeMaxCacheSizeLocked() const; | 
|  | 117 |  | 
| Aravind Akella | 6c2664a | 2014-08-13 12:24:50 -0700 | [diff] [blame] | 118 | // When more sensors register, the maximum cache size desired may change. Compute max cache | 
|  | 119 | // size, reallocate memory and copy over events from the older cache. | 
|  | 120 | void reAllocateCacheLocked(sensors_event_t const* scratch, int count); | 
|  | 121 |  | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 122 | // LooperCallback method. If there is data to read on this fd, it is an ack from the | 
|  | 123 | // app that it has read events from a wake up sensor, decrement mWakeLockRefCount. | 
|  | 124 | // If this fd is available for writing send the data from the cache. | 
|  | 125 | virtual int handleEvent(int fd, int events, void* data); | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 126 |  | 
| Aravind Akella | 8a96955 | 2014-09-28 17:52:41 -0700 | [diff] [blame] | 127 | // Increment mPendingFlushEventsToSend for the given sensor handle. | 
|  | 128 | void incrementPendingFlushCount(int32_t handle); | 
|  | 129 |  | 
|  | 130 | // Add or remove the file descriptor associated with the BitTube to the looper. If mDead is | 
|  | 131 | // set to true or there are no more sensors for this connection, the file descriptor is | 
|  | 132 | // removed if it has been previously added to the Looper. Depending on the state of the | 
|  | 133 | // connection FD may be added to the Looper. The flags to set are determined by the internal | 
|  | 134 | // state of the connection. FDs are added to the looper when wake-up sensors are registered | 
|  | 135 | // (to poll for acknowledgements) and when write fails on the socket when there are too many | 
|  | 136 | // events (to poll when the FD is available for writing). FDs are removed when there is an | 
|  | 137 | // error and the other end hangs up or when this client unregisters for this connection. | 
|  | 138 | void updateLooperRegistration(const sp<Looper>& looper); | 
|  | 139 | void updateLooperRegistrationLocked(const sp<Looper>& looper); | 
|  | 140 |  | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 141 | sp<SensorService> const mService; | 
| Aravind Akella | 4c8b951 | 2013-09-05 17:03:38 -0700 | [diff] [blame] | 142 | sp<BitTube> mChannel; | 
| Mathias Agopian | 5307d17 | 2012-09-18 17:02:43 -0700 | [diff] [blame] | 143 | uid_t mUid; | 
| Mathias Agopian | 71d7a5c | 2010-11-14 20:55:25 -0800 | [diff] [blame] | 144 | mutable Mutex mConnectionLock; | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 145 | // Number of events from wake up sensors which are still pending and haven't been delivered | 
|  | 146 | // to the corresponding application. It is incremented by one unit for each write to the | 
|  | 147 | // socket. | 
| Aravind Akella | 8a96955 | 2014-09-28 17:52:41 -0700 | [diff] [blame] | 148 | uint32_t mWakeLockRefCount; | 
| Mathias Agopian | 7c1c531 | 2010-07-21 15:59:50 -0700 | [diff] [blame] | 149 |  | 
| Aravind Akella | 8a96955 | 2014-09-28 17:52:41 -0700 | [diff] [blame] | 150 | // If this flag is set to true, it means that the file descriptor associated with the | 
|  | 151 | // BitTube has been added to the Looper in SensorService. This flag is typically set when | 
|  | 152 | // this connection has wake-up sensors associated with it or when write has failed on this | 
|  | 153 | // connection and we're storing some events in the cache. | 
|  | 154 | bool mHasLooperCallbacks; | 
|  | 155 | // If there are any errors associated with the Looper this flag is set to true and | 
|  | 156 | // mWakeLockRefCount is reset to zero. needsWakeLock method will always return false, if | 
|  | 157 | // this flag is set. | 
|  | 158 | bool mDead; | 
| Aravind Akella | 4c8b951 | 2013-09-05 17:03:38 -0700 | [diff] [blame] | 159 | struct FlushInfo { | 
|  | 160 | // The number of flush complete events dropped for this sensor is stored here. | 
|  | 161 | // They are sent separately before the next batch of events. | 
|  | 162 | int mPendingFlushEventsToSend; | 
|  | 163 | // Every activate is preceded by a flush. Only after the first flush complete is | 
|  | 164 | // received, the events for the sensor are sent on that *connection*. | 
|  | 165 | bool mFirstFlushPending; | 
| Aravind Akella | 6c2664a | 2014-08-13 12:24:50 -0700 | [diff] [blame] | 166 | FlushInfo() : mPendingFlushEventsToSend(0), mFirstFlushPending(false) {} | 
| Aravind Akella | 4c8b951 | 2013-09-05 17:03:38 -0700 | [diff] [blame] | 167 | }; | 
|  | 168 | // protected by SensorService::mLock. Key for this vector is the sensor handle. | 
|  | 169 | KeyedVector<int, FlushInfo> mSensorInfo; | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 170 | sensors_event_t *mEventCache; | 
|  | 171 | int mCacheSize, mMaxCacheSize; | 
|  | 172 |  | 
|  | 173 | #if DEBUG_CONNECTIONS | 
|  | 174 | int mEventsReceived, mEventsSent, mEventsSentFromCache; | 
| Aravind Akella | e74baf6 | 2014-08-21 12:28:35 -0700 | [diff] [blame] | 175 | int mTotalAcksNeeded, mTotalAcksReceived; | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 176 | #endif | 
| Mathias Agopian | 7c1c531 | 2010-07-21 15:59:50 -0700 | [diff] [blame] | 177 |  | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 178 | public: | 
| Mathias Agopian | 5307d17 | 2012-09-18 17:02:43 -0700 | [diff] [blame] | 179 | SensorEventConnection(const sp<SensorService>& service, uid_t uid); | 
| Mathias Agopian | 7c1c531 | 2010-07-21 15:59:50 -0700 | [diff] [blame] | 180 |  | 
| Aravind Akella | 0ec2066 | 2014-09-14 17:29:48 -0700 | [diff] [blame] | 181 | status_t sendEvents(sensors_event_t const* buffer, size_t count, | 
| Aravind Akella | 8493b79 | 2014-09-08 15:45:47 -0700 | [diff] [blame] | 182 | sensors_event_t* scratch, | 
|  | 183 | SensorEventConnection const * const * mapFlushEventsToConnections = NULL); | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 184 | bool hasSensor(int32_t handle) const; | 
|  | 185 | bool hasAnySensor() const; | 
| Aravind Akella | 8493b79 | 2014-09-08 15:45:47 -0700 | [diff] [blame] | 186 | bool hasOneShotSensors() const; | 
| Mathias Agopian | 7c1c531 | 2010-07-21 15:59:50 -0700 | [diff] [blame] | 187 | bool addSensor(int32_t handle); | 
|  | 188 | bool removeSensor(int32_t handle); | 
| Aravind Akella | 4c8b951 | 2013-09-05 17:03:38 -0700 | [diff] [blame] | 189 | void setFirstFlushPending(int32_t handle, bool value); | 
| Aravind Akella | 4c8b951 | 2013-09-05 17:03:38 -0700 | [diff] [blame] | 190 | void dump(String8& result); | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 191 | bool needsWakeLock(); | 
| Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 192 | void resetWakeLockRefCount(); | 
| Mathias Agopian | 5307d17 | 2012-09-18 17:02:43 -0700 | [diff] [blame] | 193 |  | 
|  | 194 | uid_t getUid() const { return mUid; } | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 195 | }; | 
|  | 196 |  | 
|  | 197 | class SensorRecord { | 
|  | 198 | SortedVector< wp<SensorEventConnection> > mConnections; | 
| Aravind Akella | 6c2664a | 2014-08-13 12:24:50 -0700 | [diff] [blame] | 199 | // A queue of all flush() calls made on this sensor. Flush complete events will be | 
|  | 200 | // sent in this order. | 
|  | 201 | Vector< wp<SensorEventConnection> > mPendingFlushConnections; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 202 | public: | 
|  | 203 | SensorRecord(const sp<SensorEventConnection>& connection); | 
| Mathias Agopian | 7c1c531 | 2010-07-21 15:59:50 -0700 | [diff] [blame] | 204 | bool addConnection(const sp<SensorEventConnection>& connection); | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 205 | bool removeConnection(const wp<SensorEventConnection>& connection); | 
|  | 206 | size_t getNumConnections() const { return mConnections.size(); } | 
| Aravind Akella | 6c2664a | 2014-08-13 12:24:50 -0700 | [diff] [blame] | 207 |  | 
|  | 208 | void addPendingFlushConnection(const sp<SensorEventConnection>& connection); | 
|  | 209 | void removeFirstPendingFlushConnection(); | 
|  | 210 | SensorEventConnection * getFirstPendingFlushConnection(); | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 211 | }; | 
|  | 212 |  | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 213 | class SensorEventAckReceiver : public Thread { | 
|  | 214 | sp<SensorService> const mService; | 
|  | 215 | public: | 
|  | 216 | virtual bool threadLoop(); | 
|  | 217 | SensorEventAckReceiver(const sp<SensorService>& service): mService(service) {} | 
|  | 218 | }; | 
|  | 219 |  | 
| Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 220 | String8 getSensorName(int handle) const; | 
| Aravind Akella | b4099e7 | 2013-10-15 15:43:10 -0700 | [diff] [blame] | 221 | bool isVirtualSensor(int handle) const; | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 222 | Sensor getSensorFromHandle(int handle) const; | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 223 | bool isWakeUpSensor(int type) const; | 
| Aravind Akella | 0ec2066 | 2014-09-14 17:29:48 -0700 | [diff] [blame] | 224 | void recordLastValueLocked(sensors_event_t const* buffer, size_t count); | 
| Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 225 | static void sortEventBuffer(sensors_event_t* buffer, size_t count); | 
| Mathias Agopian | 0319306 | 2013-05-10 19:32:39 -0700 | [diff] [blame] | 226 | Sensor registerSensor(SensorInterface* sensor); | 
|  | 227 | Sensor registerVirtualSensor(SensorInterface* sensor); | 
| Mathias Agopian | ac9a96d | 2013-07-12 02:01:16 -0700 | [diff] [blame] | 228 | status_t cleanupWithoutDisable( | 
|  | 229 | const sp<SensorEventConnection>& connection, int handle); | 
|  | 230 | status_t cleanupWithoutDisableLocked( | 
|  | 231 | const sp<SensorEventConnection>& connection, int handle); | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 232 | void cleanupAutoDisabledSensorLocked(const sp<SensorEventConnection>& connection, | 
| Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 233 | sensors_event_t const* buffer, const int count); | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 234 | static bool canAccessSensor(const Sensor& sensor); | 
|  | 235 | static bool verifyCanAccessSensor(const Sensor& sensor, const char* operation); | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 236 | // SensorService acquires a partial wakelock for delivering events from wake up sensors. This | 
|  | 237 | // method checks whether all the events from these wake up sensors have been delivered to the | 
|  | 238 | // corresponding applications, if yes the wakelock is released. | 
|  | 239 | void checkWakeLockState(); | 
|  | 240 | void checkWakeLockStateLocked(); | 
| Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 241 | bool isWakeLockAcquired(); | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 242 | bool isWakeUpSensorEvent(const sensors_event_t& event) const; | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 243 |  | 
| Aravind Akella | 6c2664a | 2014-08-13 12:24:50 -0700 | [diff] [blame] | 244 | SensorRecord * getSensorRecord(int handle); | 
|  | 245 |  | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 246 | sp<Looper> getLooper() const; | 
|  | 247 |  | 
| Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 248 | // Reset mWakeLockRefCounts for all SensorEventConnections to zero. This may happen if | 
|  | 249 | // SensorService did not receive any acknowledgements from apps which have registered for | 
|  | 250 | // wake_up sensors. | 
|  | 251 | void resetAllWakeLockRefCounts(); | 
|  | 252 |  | 
|  | 253 | // Acquire or release wake_lock. If wake_lock is acquired, set the timeout in the looper to | 
|  | 254 | // 5 seconds and wake the looper. | 
|  | 255 | void setWakeLockAcquiredLocked(bool acquire); | 
|  | 256 |  | 
|  | 257 | // Send events from the event cache for this particular connection. | 
|  | 258 | void sendEventsFromCache(const sp<SensorEventConnection>& connection); | 
|  | 259 |  | 
|  | 260 | // Promote all weak referecences in mActiveConnections vector to strong references and add them | 
|  | 261 | // to the output vector. | 
|  | 262 | void populateActiveConnections(SortedVector< sp<SensorEventConnection> >* activeConnections); | 
|  | 263 |  | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 264 | // constants | 
|  | 265 | Vector<Sensor> mSensorList; | 
| Mathias Agopian | 3326486 | 2012-06-28 19:46:54 -0700 | [diff] [blame] | 266 | Vector<Sensor> mUserSensorListDebug; | 
| Mathias Agopian | 010e422 | 2011-06-08 20:06:50 -0700 | [diff] [blame] | 267 | Vector<Sensor> mUserSensorList; | 
| Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 268 | DefaultKeyedVector<int, SensorInterface*> mSensorMap; | 
|  | 269 | Vector<SensorInterface *> mVirtualSensorList; | 
| Mathias Agopian | 50df295 | 2010-07-19 19:09:10 -0700 | [diff] [blame] | 270 | status_t mInitCheck; | 
| Aravind Akella | 5466c3d | 2014-08-22 16:11:10 -0700 | [diff] [blame] | 271 | // Socket buffersize used to initialize BitTube. This size depends on whether batching is | 
|  | 272 | // supported or not. | 
| Aravind Akella | 8a96955 | 2014-09-28 17:52:41 -0700 | [diff] [blame] | 273 | uint32_t mSocketBufferSize; | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 274 | sp<Looper> mLooper; | 
| Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 275 | sp<SensorEventAckReceiver> mAckReceiver; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 276 |  | 
|  | 277 | // protected by mLock | 
|  | 278 | mutable Mutex mLock; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 279 | DefaultKeyedVector<int, SensorRecord*> mActiveSensors; | 
| Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 280 | DefaultKeyedVector<int, SensorInterface*> mActiveVirtualSensors; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 281 | SortedVector< wp<SensorEventConnection> > mActiveConnections; | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 282 | bool mWakeLockAcquired; | 
| Aravind Akella | 8493b79 | 2014-09-08 15:45:47 -0700 | [diff] [blame] | 283 | sensors_event_t *mSensorEventBuffer, *mSensorEventScratch; | 
|  | 284 | SensorEventConnection const **mMapFlushEventsToConnections; | 
|  | 285 |  | 
| Mathias Agopian | 3560fb2 | 2010-07-22 21:24:39 -0700 | [diff] [blame] | 286 | // The size of this vector is constant, only the items are mutable | 
|  | 287 | KeyedVector<int32_t, sensors_event_t> mLastEventSeen; | 
|  | 288 |  | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 289 | public: | 
| Mathias Agopian | db5b4bc | 2011-02-03 14:52:47 -0800 | [diff] [blame] | 290 | void cleanupConnection(SensorEventConnection* connection); | 
| Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 291 | status_t enable(const sp<SensorEventConnection>& connection, int handle, | 
|  | 292 | nsecs_t samplingPeriodNs,  nsecs_t maxBatchReportLatencyNs, int reservedFlags); | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 293 | status_t disable(const sp<SensorEventConnection>& connection, int handle); | 
| Mathias Agopian | 7c1c531 | 2010-07-21 15:59:50 -0700 | [diff] [blame] | 294 | status_t setEventRate(const sp<SensorEventConnection>& connection, int handle, nsecs_t ns); | 
| Aravind Akella | 9e3adfc | 2014-09-03 15:48:05 -0700 | [diff] [blame] | 295 | status_t flushSensor(const sp<SensorEventConnection>& connection); | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 296 | }; | 
|  | 297 |  | 
|  | 298 | // --------------------------------------------------------------------------- | 
|  | 299 | }; // namespace android | 
|  | 300 |  | 
|  | 301 | #endif // ANDROID_SENSOR_SERVICE_H |