| 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 |  | 
| Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 20 | #include "SensorList.h" | 
| Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 21 | #include "RecentEventLogger.h" | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 22 |  | 
|  | 23 | #include <binder/BinderService.h> | 
| Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 24 | #include <binder/IUidObserver.h> | 
| Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 25 | #include <cutils/compiler.h> | 
| Mathias Agopian | 801ea09 | 2017-03-06 15:05:04 -0800 | [diff] [blame] | 26 | #include <sensor/ISensorServer.h> | 
|  | 27 | #include <sensor/ISensorEventConnection.h> | 
|  | 28 | #include <sensor/Sensor.h> | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 29 |  | 
| Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 30 | #include <utils/AndroidThreads.h> | 
|  | 31 | #include <utils/KeyedVector.h> | 
|  | 32 | #include <utils/Looper.h> | 
|  | 33 | #include <utils/SortedVector.h> | 
|  | 34 | #include <utils/String8.h> | 
|  | 35 | #include <utils/Vector.h> | 
|  | 36 | #include <utils/threads.h> | 
|  | 37 |  | 
|  | 38 | #include <stdint.h> | 
|  | 39 | #include <sys/types.h> | 
| Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 40 | #include <unordered_map> | 
| Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 41 | #include <unordered_set> | 
| Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 42 |  | 
| Bernhard Rosenkränzer | 72952ef | 2014-11-17 21:03:39 +0100 | [diff] [blame] | 43 | #if __clang__ | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 44 | // Clang warns about SensorEventConnection::dump hiding BBinder::dump. The cause isn't fixable | 
|  | 45 | // without changing the API, so let's tell clang this is indeed intentional. | 
| Bernhard Rosenkränzer | 72952ef | 2014-11-17 21:03:39 +0100 | [diff] [blame] | 46 | #pragma clang diagnostic ignored "-Woverloaded-virtual" | 
|  | 47 | #endif | 
|  | 48 |  | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 49 | // --------------------------------------------------------------------------- | 
| Peng Xu | f66684a | 2015-07-23 11:41:53 -0700 | [diff] [blame] | 50 | #define IGNORE_HARDWARE_FUSION  false | 
| Mathias Agopian | a1b7db9 | 2011-05-27 16:23:58 -0700 | [diff] [blame] | 51 | #define DEBUG_CONNECTIONS   false | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 52 | // Max size is 100 KB which is enough to accept a batch of about 1000 events. | 
| Chih-Hung Hsieh | a389c7a | 2016-05-20 11:40:04 -0700 | [diff] [blame] | 53 | #define MAX_SOCKET_BUFFER_SIZE_BATCHED (100 * 1024) | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 54 | // For older HALs which don't support batching, use a smaller socket buffer size. | 
| Chih-Hung Hsieh | a389c7a | 2016-05-20 11:40:04 -0700 | [diff] [blame] | 55 | #define SOCKET_BUFFER_SIZE_NON_BATCHED (4 * 1024) | 
| Mathias Agopian | a1b7db9 | 2011-05-27 16:23:58 -0700 | [diff] [blame] | 56 |  | 
| Peng Xu | 363b3fd | 2016-07-07 15:40:08 -0700 | [diff] [blame] | 57 | #define SENSOR_REGISTRATIONS_BUF_SIZE 200 | 
| Aravind Akella | 444f267 | 2015-05-07 12:40:52 -0700 | [diff] [blame] | 58 |  | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 59 | namespace android { | 
|  | 60 | // --------------------------------------------------------------------------- | 
| Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 61 | class SensorInterface; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 62 |  | 
|  | 63 | class SensorService : | 
|  | 64 | public BinderService<SensorService>, | 
|  | 65 | public BnSensorServer, | 
|  | 66 | protected Thread | 
|  | 67 | { | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 68 | // nested class/struct for internal use | 
|  | 69 | class SensorEventConnection; | 
| Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 70 | class SensorDirectConnection; | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 71 |  | 
|  | 72 | public: | 
|  | 73 | void cleanupConnection(SensorEventConnection* connection); | 
| Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 74 | void cleanupConnection(SensorDirectConnection* c); | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 75 |  | 
|  | 76 | status_t enable(const sp<SensorEventConnection>& connection, int handle, | 
|  | 77 | nsecs_t samplingPeriodNs,  nsecs_t maxBatchReportLatencyNs, int reservedFlags, | 
|  | 78 | const String16& opPackageName); | 
|  | 79 |  | 
|  | 80 | status_t disable(const sp<SensorEventConnection>& connection, int handle); | 
|  | 81 |  | 
|  | 82 | status_t setEventRate(const sp<SensorEventConnection>& connection, int handle, nsecs_t ns, | 
|  | 83 | const String16& opPackageName); | 
|  | 84 |  | 
|  | 85 | status_t flushSensor(const sp<SensorEventConnection>& connection, | 
|  | 86 | const String16& opPackageName); | 
|  | 87 |  | 
| Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 88 |  | 
|  | 89 | virtual status_t shellCommand(int in, int out, int err, Vector<String16>& args); | 
|  | 90 |  | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 91 | private: | 
| Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 92 | friend class BinderService<SensorService>; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 93 |  | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 94 | // nested class/struct for internal use | 
|  | 95 | class SensorRecord; | 
|  | 96 | class SensorEventAckReceiver; | 
| Peng Xu | 5122468 | 2017-03-10 16:57:27 -0800 | [diff] [blame] | 97 | class SensorRegistrationInfo; | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 98 |  | 
| Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 99 | // If accessing a sensor we need to make sure the UID has access to it. If | 
|  | 100 | // the app UID is idle then it cannot access sensors and gets no trigger | 
|  | 101 | // events, no on-change events, flush event behavior does not change, and | 
|  | 102 | // recurring events are the same as the first one delivered in idle state | 
|  | 103 | // emulating no sensor change. As soon as the app UID transitions to an | 
|  | 104 | // active state we will start reporting events as usual and vise versa. This | 
|  | 105 | // approach transparently handles observing sensors while the app UID transitions | 
|  | 106 | // between idle/active state avoiding to get stuck in a state receiving sensor | 
|  | 107 | // data while idle or not receiving sensor data while active. | 
|  | 108 | class UidPolicy : public BnUidObserver { | 
|  | 109 | public: | 
|  | 110 | explicit UidPolicy(wp<SensorService> service) | 
|  | 111 | : mService(service) {} | 
|  | 112 | void registerSelf(); | 
|  | 113 | void unregisterSelf(); | 
|  | 114 |  | 
|  | 115 | bool isUidActive(uid_t uid); | 
|  | 116 |  | 
|  | 117 | void onUidGone(uid_t uid, bool disabled); | 
|  | 118 | void onUidActive(uid_t uid); | 
|  | 119 | void onUidIdle(uid_t uid, bool disabled); | 
|  | 120 |  | 
|  | 121 | void addOverrideUid(uid_t uid, bool active); | 
|  | 122 | void removeOverrideUid(uid_t uid); | 
|  | 123 | private: | 
|  | 124 | bool isUidActiveLocked(uid_t uid); | 
|  | 125 | void updateOverrideUid(uid_t uid, bool active, bool insert); | 
|  | 126 |  | 
|  | 127 | Mutex mUidLock; | 
|  | 128 | wp<SensorService> mService; | 
|  | 129 | std::unordered_set<uid_t> mActiveUids; | 
|  | 130 | std::unordered_map<uid_t, bool> mOverrideUids; | 
|  | 131 | }; | 
|  | 132 |  | 
| Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 133 | enum Mode { | 
|  | 134 | // The regular operating mode where any application can register/unregister/call flush on | 
|  | 135 | // sensors. | 
|  | 136 | NORMAL = 0, | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 137 | // This mode is only used for testing purposes. Not all HALs support this mode. In this mode, | 
|  | 138 | // the HAL ignores the sensor data provided by physical sensors and accepts the data that is | 
|  | 139 | // injected from the SensorService as if it were the real sensor data. This mode is primarily | 
|  | 140 | // used for testing various algorithms like vendor provided SensorFusion, Step Counter and | 
|  | 141 | // Step Detector etc. Typically in this mode, there will be a client (a | 
|  | 142 | // SensorEventConnection) which will be injecting sensor data into the HAL. Normal apps can | 
|  | 143 | // unregister and register for any sensor that supports injection. Registering to sensors | 
|  | 144 | // that do not support injection will give an error.  TODO(aakella) : Allow exactly one | 
|  | 145 | // client to inject sensor data at a time. | 
| Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 146 | DATA_INJECTION = 1, | 
| Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 147 | // This mode is used only for testing sensors. Each sensor can be tested in isolation with | 
|  | 148 | // the required sampling_rate and maxReportLatency parameters without having to think about | 
|  | 149 | // the data rates requested by other applications. End user devices are always expected to be | 
|  | 150 | // in NORMAL mode. When this mode is first activated, all active sensors from all connections | 
|  | 151 | // are disabled. Calling flush() will return an error. In this mode, only the requests from | 
|  | 152 | // selected apps whose package names are whitelisted are allowed (typically CTS apps).  Only | 
| Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 153 | // these apps can register/unregister/call flush() on sensors. If SensorService switches to | 
| Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 154 | // NORMAL mode again, all sensors that were previously registered to are activated with the | 
|  | 155 | // corresponding paramaters if the application hasn't unregistered for sensors in the mean | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 156 | // time.  NOTE: Non whitelisted app whose sensors were previously deactivated may still | 
|  | 157 | // receive events if a whitelisted app requests data from the same sensor. | 
| Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 158 | RESTRICTED = 2 | 
|  | 159 |  | 
|  | 160 | // State Transitions supported. | 
|  | 161 | //     RESTRICTED   <---  NORMAL   ---> DATA_INJECTION | 
|  | 162 | //                  --->           <--- | 
| Aravind Akella | 5c53805 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 163 |  | 
|  | 164 | // Shell commands to switch modes in SensorService. | 
|  | 165 | // 1) Put SensorService in RESTRICTED mode with packageName .cts. If it is already in | 
|  | 166 | // restricted mode it is treated as a NO_OP (and packageName is NOT changed). | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 167 | // | 
|  | 168 | //     $ adb shell dumpsys sensorservice restrict .cts. | 
| Aravind Akella | 5c53805 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 169 | // | 
|  | 170 | // 2) Put SensorService in DATA_INJECTION mode with packageName .xts. If it is already in | 
|  | 171 | // data_injection mode it is treated as a NO_OP (and packageName is NOT changed). | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 172 | // | 
|  | 173 | //     $ adb shell dumpsys sensorservice data_injection .xts. | 
| Aravind Akella | 5c53805 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 174 | // | 
|  | 175 | // 3) Reset sensorservice back to NORMAL mode. | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 176 | //     $ adb shell dumpsys sensorservice enable | 
| Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 177 | }; | 
|  | 178 |  | 
| Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 179 | static const char* WAKE_LOCK_NAME; | 
| Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 180 | static char const* getServiceName() ANDROID_API { return "sensorservice"; } | 
|  | 181 | SensorService() ANDROID_API; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 182 | virtual ~SensorService(); | 
|  | 183 |  | 
|  | 184 | virtual void onFirstRef(); | 
|  | 185 |  | 
|  | 186 | // Thread interface | 
|  | 187 | virtual bool threadLoop(); | 
|  | 188 |  | 
|  | 189 | // ISensorServer interface | 
| Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 190 | virtual Vector<Sensor> getSensorList(const String16& opPackageName); | 
| Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 191 | virtual Vector<Sensor> getDynamicSensorList(const String16& opPackageName); | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 192 | virtual sp<ISensorEventConnection> createSensorEventConnection( | 
|  | 193 | const String8& packageName, | 
|  | 194 | int requestedMode, const String16& opPackageName); | 
| Aravind Akella | 5c53805 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 195 | virtual int isDataInjectionEnabled(); | 
| Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 196 | virtual sp<ISensorEventConnection> createSensorDirectConnection(const String16& opPackageName, | 
|  | 197 | uint32_t size, int32_t type, int32_t format, const native_handle *resource); | 
| Peng Xu | dd5c5cb | 2017-03-16 17:39:43 -0700 | [diff] [blame] | 198 | virtual int setOperationParameter( | 
| Alexey Polyudov | 88711e8 | 2017-05-23 19:54:04 -0700 | [diff] [blame] | 199 | int32_t handle, int32_t type, const Vector<float> &floats, const Vector<int32_t> &ints); | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 200 | virtual status_t dump(int fd, const Vector<String16>& args); | 
| Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 201 | String8 getSensorName(int handle) const; | 
| Aravind Akella | b4099e7 | 2013-10-15 15:43:10 -0700 | [diff] [blame] | 202 | bool isVirtualSensor(int handle) const; | 
| Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 203 | sp<SensorInterface> getSensorInterfaceFromHandle(int handle) const; | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 204 | bool isWakeUpSensor(int type) const; | 
| Aravind Akella | 0ec2066 | 2014-09-14 17:29:48 -0700 | [diff] [blame] | 205 | void recordLastValueLocked(sensors_event_t const* buffer, size_t count); | 
| Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 206 | static void sortEventBuffer(sensors_event_t* buffer, size_t count); | 
| Peng Xu | 0cc8f80 | 2016-04-05 23:46:03 -0700 | [diff] [blame] | 207 | const Sensor& registerSensor(SensorInterface* sensor, | 
|  | 208 | bool isDebug = false, bool isVirtual = false); | 
|  | 209 | const Sensor& registerVirtualSensor(SensorInterface* sensor, bool isDebug = false); | 
| Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 210 | const Sensor& registerDynamicSensorLocked(SensorInterface* sensor, bool isDebug = false); | 
|  | 211 | bool unregisterDynamicSensorLocked(int handle); | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 212 | status_t cleanupWithoutDisable(const sp<SensorEventConnection>& connection, int handle); | 
|  | 213 | status_t cleanupWithoutDisableLocked(const sp<SensorEventConnection>& connection, int handle); | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 214 | void cleanupAutoDisabledSensorLocked(const sp<SensorEventConnection>& connection, | 
| Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 215 | sensors_event_t const* buffer, const int count); | 
| Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 216 | static bool canAccessSensor(const Sensor& sensor, const char* operation, | 
|  | 217 | const String16& opPackageName); | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 218 | // SensorService acquires a partial wakelock for delivering events from wake up sensors. This | 
|  | 219 | // method checks whether all the events from these wake up sensors have been delivered to the | 
|  | 220 | // corresponding applications, if yes the wakelock is released. | 
|  | 221 | void checkWakeLockState(); | 
|  | 222 | void checkWakeLockStateLocked(); | 
| Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 223 | bool isWakeLockAcquired(); | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 224 | bool isWakeUpSensorEvent(const sensors_event_t& event) const; | 
| Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 225 |  | 
|  | 226 | sp<Looper> getLooper() const; | 
|  | 227 |  | 
| Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 228 | // Reset mWakeLockRefCounts for all SensorEventConnections to zero. This may happen if | 
|  | 229 | // SensorService did not receive any acknowledgements from apps which have registered for | 
|  | 230 | // wake_up sensors. | 
|  | 231 | void resetAllWakeLockRefCounts(); | 
|  | 232 |  | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 233 | // Acquire or release wake_lock. If wake_lock is acquired, set the timeout in the looper to 5 | 
|  | 234 | // seconds and wake the looper. | 
| Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 235 | void setWakeLockAcquiredLocked(bool acquire); | 
|  | 236 |  | 
|  | 237 | // Send events from the event cache for this particular connection. | 
|  | 238 | void sendEventsFromCache(const sp<SensorEventConnection>& connection); | 
|  | 239 |  | 
|  | 240 | // Promote all weak referecences in mActiveConnections vector to strong references and add them | 
|  | 241 | // to the output vector. | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 242 | void populateActiveConnections( SortedVector< sp<SensorEventConnection> >* activeConnections); | 
| Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 243 |  | 
| Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 244 | // If SensorService is operating in RESTRICTED mode, only select whitelisted packages are | 
|  | 245 | // allowed to register for or call flush on sensors. Typically only cts test packages are | 
|  | 246 | // allowed. | 
|  | 247 | bool isWhiteListedPackage(const String8& packageName); | 
| Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 248 | bool isOperationRestricted(const String16& opPackageName); | 
| Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 249 |  | 
| Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 250 | // Reset the state of SensorService to NORMAL mode. | 
|  | 251 | status_t resetToNormalMode(); | 
|  | 252 | status_t resetToNormalModeLocked(); | 
|  | 253 |  | 
| Greg Kaiser | 53ca2e0 | 2016-06-21 16:11:14 -0700 | [diff] [blame] | 254 | // Transforms the UUIDs for all the sensors into proper IDs. | 
|  | 255 | void makeUuidsIntoIdsForSensorList(Vector<Sensor> &sensorList) const; | 
|  | 256 | // Gets the appropriate ID from the given UUID. | 
|  | 257 | int32_t getIdFromUuid(const Sensor::uuid_t &uuid) const; | 
|  | 258 | // Either read from storage or create a new one. | 
|  | 259 | static bool initializeHmacKey(); | 
|  | 260 |  | 
| Peng Xu | 98d30f6 | 2016-08-01 18:12:11 -0700 | [diff] [blame] | 261 | // Enable SCHED_FIFO priority for thread | 
|  | 262 | void enableSchedFifoMode(); | 
| Greg Kaiser | 53ca2e0 | 2016-06-21 16:11:14 -0700 | [diff] [blame] | 263 |  | 
| Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 264 | // Sets whether the given UID can get sensor data | 
|  | 265 | void setSensorAccess(uid_t uid, bool hasAccess); | 
|  | 266 |  | 
|  | 267 | // Overrides the UID state as if it is idle | 
|  | 268 | status_t handleSetUidState(Vector<String16>& args, int err); | 
|  | 269 | // Clears the override for the UID state | 
|  | 270 | status_t handleResetUidState(Vector<String16>& args, int err); | 
|  | 271 | // Gets the UID state | 
|  | 272 | status_t handleGetUidState(Vector<String16>& args, int out, int err); | 
|  | 273 | // Prints the shell command help | 
|  | 274 | status_t printHelp(int out); | 
|  | 275 |  | 
| Greg Kaiser | 53ca2e0 | 2016-06-21 16:11:14 -0700 | [diff] [blame] | 276 | static uint8_t sHmacGlobalKey[128]; | 
|  | 277 | static bool sHmacGlobalKeyIsValid; | 
|  | 278 |  | 
| Brian Stack | 4baa5be | 2018-09-18 14:03:13 -0700 | [diff] [blame] | 279 | SensorServiceUtil::SensorList mSensors; | 
| Mathias Agopian | 50df295 | 2010-07-19 19:09:10 -0700 | [diff] [blame] | 280 | status_t mInitCheck; | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 281 |  | 
| Aravind Akella | 5466c3d | 2014-08-22 16:11:10 -0700 | [diff] [blame] | 282 | // Socket buffersize used to initialize BitTube. This size depends on whether batching is | 
|  | 283 | // supported or not. | 
| Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 284 | uint32_t mSocketBufferSize; | 
|  | 285 | sp<Looper> mLooper; | 
|  | 286 | sp<SensorEventAckReceiver> mAckReceiver; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 287 |  | 
|  | 288 | // protected by mLock | 
|  | 289 | mutable Mutex mLock; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 290 | DefaultKeyedVector<int, SensorRecord*> mActiveSensors; | 
| Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 291 | std::unordered_set<int> mActiveVirtualSensors; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 292 | SortedVector< wp<SensorEventConnection> > mActiveConnections; | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 293 | bool mWakeLockAcquired; | 
| Aravind Akella | 8493b79 | 2014-09-08 15:45:47 -0700 | [diff] [blame] | 294 | sensors_event_t *mSensorEventBuffer, *mSensorEventScratch; | 
| Peng Xu | ded526e | 2016-08-12 16:39:44 -0700 | [diff] [blame] | 295 | wp<const SensorEventConnection> * mMapFlushEventsToConnections; | 
| Brian Stack | 4baa5be | 2018-09-18 14:03:13 -0700 | [diff] [blame] | 296 | std::unordered_map<int, SensorServiceUtil::RecentEventLogger*> mRecentEvent; | 
| Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 297 | SortedVector< wp<SensorDirectConnection> > mDirectConnections; | 
| Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 298 | Mode mCurrentOperatingMode; | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 299 |  | 
| Aravind Akella | 5c53805 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 300 | // This packagaName is set when SensorService is in RESTRICTED or DATA_INJECTION mode. Only | 
|  | 301 | // applications with this packageName are allowed to activate/deactivate or call flush on | 
|  | 302 | // sensors. To run CTS this is can be set to ".cts." and only CTS tests will get access to | 
|  | 303 | // sensors. | 
|  | 304 | String8 mWhiteListedPackage; | 
| Aravind Akella | 8493b79 | 2014-09-08 15:45:47 -0700 | [diff] [blame] | 305 |  | 
| Aravind Akella | 18d6d51 | 2015-06-18 14:18:28 -0700 | [diff] [blame] | 306 | int mNextSensorRegIndex; | 
|  | 307 | Vector<SensorRegistrationInfo> mLastNSensorRegistrations; | 
| Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 308 |  | 
|  | 309 | sp<UidPolicy> mUidPolicy; | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 310 | }; | 
|  | 311 |  | 
| Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 312 | } // namespace android | 
| Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 313 | #endif // ANDROID_SENSOR_SERVICE_H |