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 | |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 23 | #include <android-base/macros.h> |
Brian Stack | 793f464 | 2019-04-18 17:21:34 -0700 | [diff] [blame] | 24 | #include <binder/AppOpsManager.h> |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 25 | #include <binder/BinderService.h> |
Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 26 | #include <binder/IUidObserver.h> |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 27 | #include <cutils/compiler.h> |
Tanmay Patil | d33a182 | 2019-04-11 18:38:55 -0700 | [diff] [blame] | 28 | #include <cutils/multiuser.h> |
Eric Laurent | e3f27df | 2022-01-05 19:20:32 +0100 | [diff] [blame] | 29 | #include <private/android_filesystem_config.h> |
Mathias Agopian | 801ea09 | 2017-03-06 15:05:04 -0800 | [diff] [blame] | 30 | #include <sensor/ISensorServer.h> |
| 31 | #include <sensor/ISensorEventConnection.h> |
| 32 | #include <sensor/Sensor.h> |
Michael Groover | 5e1f60b | 2018-12-04 22:34:29 -0800 | [diff] [blame] | 33 | #include "android/hardware/BnSensorPrivacyListener.h" |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 34 | |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 35 | #include <utils/AndroidThreads.h> |
| 36 | #include <utils/KeyedVector.h> |
| 37 | #include <utils/Looper.h> |
| 38 | #include <utils/SortedVector.h> |
| 39 | #include <utils/String8.h> |
| 40 | #include <utils/Vector.h> |
| 41 | #include <utils/threads.h> |
| 42 | |
| 43 | #include <stdint.h> |
| 44 | #include <sys/types.h> |
Vladimir Komsiyski | f76bba5 | 2022-10-23 10:56:06 +0200 | [diff] [blame] | 45 | #include <queue> |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 46 | #include <unordered_map> |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 47 | #include <unordered_set> |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 48 | #include <vector> |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 49 | |
Bernhard Rosenkränzer | 72952ef | 2014-11-17 21:03:39 +0100 | [diff] [blame] | 50 | #if __clang__ |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 51 | // Clang warns about SensorEventConnection::dump hiding BBinder::dump. The cause isn't fixable |
| 52 | // 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] | 53 | #pragma clang diagnostic ignored "-Woverloaded-virtual" |
| 54 | #endif |
| 55 | |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 56 | // --------------------------------------------------------------------------- |
Peng Xu | f66684a | 2015-07-23 11:41:53 -0700 | [diff] [blame] | 57 | #define IGNORE_HARDWARE_FUSION false |
Mathias Agopian | a1b7db9 | 2011-05-27 16:23:58 -0700 | [diff] [blame] | 58 | #define DEBUG_CONNECTIONS false |
Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 59 | // 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] | 60 | #define MAX_SOCKET_BUFFER_SIZE_BATCHED (100 * 1024) |
Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 61 | // 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] | 62 | #define SOCKET_BUFFER_SIZE_NON_BATCHED (4 * 1024) |
Mathias Agopian | a1b7db9 | 2011-05-27 16:23:58 -0700 | [diff] [blame] | 63 | |
Peng Xu | 363b3fd | 2016-07-07 15:40:08 -0700 | [diff] [blame] | 64 | #define SENSOR_REGISTRATIONS_BUF_SIZE 200 |
Aravind Akella | 444f267 | 2015-05-07 12:40:52 -0700 | [diff] [blame] | 65 | |
Anh Pham | af91a91 | 2021-02-10 14:10:53 +0100 | [diff] [blame] | 66 | // Apps that targets S+ and do not have HIGH_SAMPLING_RATE_SENSORS permission will be capped |
Anh Pham | 5198c99 | 2021-02-10 14:15:30 +0100 | [diff] [blame] | 67 | // at 200 Hz. The cap also applies to all requests when the mic toggle is flipped to on, regardless |
| 68 | // of their target SDKs and permission. |
Anh Pham | af91a91 | 2021-02-10 14:10:53 +0100 | [diff] [blame] | 69 | // Capped sampling periods for apps that have non-direct sensor connections. |
| 70 | #define SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS (5 * 1000 * 1000) |
| 71 | // Capped sampling rate level for apps that have direct sensor connections. |
| 72 | // The enum SENSOR_DIRECT_RATE_NORMAL corresponds to a rate value of at most 110 Hz. |
| 73 | #define SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL SENSOR_DIRECT_RATE_NORMAL |
| 74 | |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 75 | namespace android { |
| 76 | // --------------------------------------------------------------------------- |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 77 | class SensorInterface; |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 78 | |
| 79 | class SensorService : |
| 80 | public BinderService<SensorService>, |
| 81 | public BnSensorServer, |
| 82 | protected Thread |
| 83 | { |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 84 | // nested class/struct for internal use |
| 85 | class SensorEventConnection; |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 86 | class SensorDirectConnection; |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 87 | |
| 88 | public: |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 89 | enum UidState { |
| 90 | UID_STATE_ACTIVE = 0, |
| 91 | UID_STATE_IDLE, |
| 92 | }; |
| 93 | |
Arthur Ishiguro | 5e3eaa8 | 2021-11-11 18:05:56 +0000 | [diff] [blame] | 94 | enum Mode { |
| 95 | // The regular operating mode where any application can register/unregister/call flush on |
| 96 | // sensors. |
| 97 | NORMAL = 0, |
| 98 | // This mode is only used for testing purposes. Not all HALs support this mode. In this mode, |
| 99 | // the HAL ignores the sensor data provided by physical sensors and accepts the data that is |
| 100 | // injected from the SensorService as if it were the real sensor data. This mode is primarily |
| 101 | // used for testing various algorithms like vendor provided SensorFusion, Step Counter and |
| 102 | // Step Detector etc. Typically in this mode, there will be a client (a |
| 103 | // SensorEventConnection) which will be injecting sensor data into the HAL. Normal apps can |
| 104 | // unregister and register for any sensor that supports injection. Registering to sensors |
| 105 | // that do not support injection will give an error. TODO: Allow exactly one |
| 106 | // client to inject sensor data at a time. |
| 107 | DATA_INJECTION = 1, |
| 108 | // This mode is used only for testing sensors. Each sensor can be tested in isolation with |
| 109 | // the required sampling_rate and maxReportLatency parameters without having to think about |
| 110 | // the data rates requested by other applications. End user devices are always expected to be |
| 111 | // in NORMAL mode. When this mode is first activated, all active sensors from all connections |
| 112 | // are disabled. Calling flush() will return an error. In this mode, only the requests from |
| 113 | // selected apps whose package names are allowlisted are allowed (typically CTS apps). Only |
| 114 | // these apps can register/unregister/call flush() on sensors. If SensorService switches to |
| 115 | // NORMAL mode again, all sensors that were previously registered to are activated with the |
| 116 | // corresponding parameters if the application hasn't unregistered for sensors in the mean |
| 117 | // time. NOTE: Non allowlisted app whose sensors were previously deactivated may still |
| 118 | // receive events if a allowlisted app requests data from the same sensor. |
| 119 | RESTRICTED = 2 |
| 120 | |
| 121 | // State Transitions supported. |
| 122 | // RESTRICTED <--- NORMAL ---> DATA_INJECTION |
| 123 | // ---> <--- |
| 124 | |
| 125 | // Shell commands to switch modes in SensorService. |
| 126 | // 1) Put SensorService in RESTRICTED mode with packageName .cts. If it is already in |
| 127 | // restricted mode it is treated as a NO_OP (and packageName is NOT changed). |
| 128 | // |
| 129 | // $ adb shell dumpsys sensorservice restrict .cts. |
| 130 | // |
| 131 | // 2) Put SensorService in DATA_INJECTION mode with packageName .xts. If it is already in |
| 132 | // data_injection mode it is treated as a NO_OP (and packageName is NOT changed). |
| 133 | // |
| 134 | // $ adb shell dumpsys sensorservice data_injection .xts. |
| 135 | // |
| 136 | // 3) Reset sensorservice back to NORMAL mode. |
| 137 | // $ adb shell dumpsys sensorservice enable |
| 138 | }; |
| 139 | |
Andrew Lehmer | 3a60257 | 2021-03-25 15:19:56 -0700 | [diff] [blame] | 140 | class ProximityActiveListener : public virtual RefBase { |
| 141 | public: |
| 142 | // Note that the callback is invoked from an async thread and can interact with the |
| 143 | // SensorService directly. |
| 144 | virtual void onProximityActive(bool isActive) = 0; |
| 145 | }; |
| 146 | |
Vladimir Komsiyski | f76bba5 | 2022-10-23 10:56:06 +0200 | [diff] [blame] | 147 | class RuntimeSensorStateChangeCallback : public virtual RefBase { |
| 148 | public: |
| 149 | // Note that the callback is invoked from an async thread and can interact with the |
| 150 | // SensorService directly. |
| 151 | virtual void onStateChanged(bool enabled, int64_t samplingPeriodNanos, |
| 152 | int64_t batchReportLatencyNanos) = 0; |
| 153 | }; |
| 154 | |
Andrew Lehmer | 3a60257 | 2021-03-25 15:19:56 -0700 | [diff] [blame] | 155 | static char const* getServiceName() ANDROID_API { return "sensorservice"; } |
| 156 | SensorService() ANDROID_API; |
| 157 | |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 158 | void cleanupConnection(SensorEventConnection* connection); |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 159 | void cleanupConnection(SensorDirectConnection* c); |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 160 | |
Andrew Lehmer | 3a60257 | 2021-03-25 15:19:56 -0700 | [diff] [blame] | 161 | // Call with mLock held. |
Chris Kuiper | df11ff2 | 2021-10-12 16:30:01 -0700 | [diff] [blame] | 162 | void checkAndReportProxStateChangeLocked(); |
| 163 | void notifyProximityStateLocked(const bool isActive, |
| 164 | const std::vector<sp<ProximityActiveListener>>& listeners); |
Andrew Lehmer | 3a60257 | 2021-03-25 15:19:56 -0700 | [diff] [blame] | 165 | |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 166 | status_t enable(const sp<SensorEventConnection>& connection, int handle, |
| 167 | nsecs_t samplingPeriodNs, nsecs_t maxBatchReportLatencyNs, int reservedFlags, |
| 168 | const String16& opPackageName); |
| 169 | |
| 170 | status_t disable(const sp<SensorEventConnection>& connection, int handle); |
| 171 | |
| 172 | status_t setEventRate(const sp<SensorEventConnection>& connection, int handle, nsecs_t ns, |
| 173 | const String16& opPackageName); |
| 174 | |
| 175 | status_t flushSensor(const sp<SensorEventConnection>& connection, |
| 176 | const String16& opPackageName); |
| 177 | |
Andrew Lehmer | 3a60257 | 2021-03-25 15:19:56 -0700 | [diff] [blame] | 178 | status_t addProximityActiveListener(const sp<ProximityActiveListener>& callback) ANDROID_API; |
| 179 | status_t removeProximityActiveListener(const sp<ProximityActiveListener>& callback) ANDROID_API; |
| 180 | |
Vladimir Komsiyski | f76bba5 | 2022-10-23 10:56:06 +0200 | [diff] [blame] | 181 | int registerRuntimeSensor(const sensor_t& sensor, int deviceId, |
| 182 | sp<RuntimeSensorStateChangeCallback> callback) ANDROID_API; |
| 183 | status_t unregisterRuntimeSensor(int handle) ANDROID_API; |
| 184 | status_t sendRuntimeSensorEvent(const sensors_event_t& event) ANDROID_API; |
| 185 | |
Anh Pham | af91a91 | 2021-02-10 14:10:53 +0100 | [diff] [blame] | 186 | // Returns true if a sensor should be throttled according to our rate-throttling rules. |
| 187 | static bool isSensorInCappedSet(int sensorType); |
Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 188 | |
| 189 | virtual status_t shellCommand(int in, int out, int err, Vector<String16>& args); |
| 190 | |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 191 | private: |
Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 192 | friend class BinderService<SensorService>; |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 193 | |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 194 | // nested class/struct for internal use |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 195 | class ConnectionSafeAutolock; |
| 196 | class SensorConnectionHolder; |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 197 | class SensorEventAckReceiver; |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 198 | class SensorRecord; |
Peng Xu | 5122468 | 2017-03-10 16:57:27 -0800 | [diff] [blame] | 199 | class SensorRegistrationInfo; |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 200 | |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 201 | // Promoting a SensorEventConnection or SensorDirectConnection from wp to sp must be done with |
| 202 | // mLock held, but destroying that sp must be done unlocked to avoid a race condition that |
| 203 | // causes a deadlock (remote dies while we hold a local sp, then our decStrong() call invokes |
| 204 | // the dtor -> cleanupConnection() tries to re-lock the mutex). This class ensures safe usage |
| 205 | // by wrapping a Mutex::Autolock on SensorService's mLock, plus vectors that hold promoted sp<> |
| 206 | // references until the lock is released, when they are safely destroyed. |
| 207 | // All read accesses to the connection lists in mConnectionHolder must be done via this class. |
| 208 | class ConnectionSafeAutolock final { |
| 209 | public: |
| 210 | // Returns a list of non-null promoted connection references |
| 211 | const std::vector<sp<SensorEventConnection>>& getActiveConnections(); |
| 212 | const std::vector<sp<SensorDirectConnection>>& getDirectConnections(); |
| 213 | |
| 214 | private: |
| 215 | // Constructed via SensorConnectionHolder::lock() |
| 216 | friend class SensorConnectionHolder; |
| 217 | explicit ConnectionSafeAutolock(SensorConnectionHolder& holder, Mutex& mutex); |
| 218 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConnectionSafeAutolock); |
| 219 | |
| 220 | // NOTE: Order of these members is important, as the destructor for non-static members |
| 221 | // get invoked in the reverse order of their declaration. Here we are relying on the |
| 222 | // Autolock to be destroyed *before* the vectors, so the sp<> objects are destroyed without |
| 223 | // the lock held, which avoids the deadlock. |
| 224 | SensorConnectionHolder& mConnectionHolder; |
| 225 | std::vector<std::vector<sp<SensorEventConnection>>> mReferencedActiveConnections; |
| 226 | std::vector<std::vector<sp<SensorDirectConnection>>> mReferencedDirectConnections; |
| 227 | Mutex::Autolock mAutolock; |
| 228 | |
| 229 | template<typename ConnectionType> |
| 230 | const std::vector<sp<ConnectionType>>& getConnectionsHelper( |
| 231 | const SortedVector<wp<ConnectionType>>& connectionList, |
| 232 | std::vector<std::vector<sp<ConnectionType>>>* referenceHolder); |
| 233 | }; |
| 234 | |
| 235 | // Encapsulates the collection of active SensorEventConection and SensorDirectConnection |
| 236 | // references. Write access is done through this class with mLock held, but all read access |
| 237 | // must be routed through ConnectionSafeAutolock. |
| 238 | class SensorConnectionHolder { |
| 239 | public: |
| 240 | void addEventConnectionIfNotPresent(const sp<SensorEventConnection>& connection); |
| 241 | void removeEventConnection(const wp<SensorEventConnection>& connection); |
| 242 | |
| 243 | void addDirectConnection(const sp<SensorDirectConnection>& connection); |
| 244 | void removeDirectConnection(const wp<SensorDirectConnection>& connection); |
| 245 | |
| 246 | // Pass in the mutex that protects this connection holder; acquires the lock and returns an |
| 247 | // object that can be used to safely read the lists of connections |
| 248 | ConnectionSafeAutolock lock(Mutex& mutex); |
| 249 | |
| 250 | private: |
| 251 | friend class ConnectionSafeAutolock; |
| 252 | SortedVector< wp<SensorEventConnection> > mActiveConnections; |
| 253 | SortedVector< wp<SensorDirectConnection> > mDirectConnections; |
| 254 | }; |
| 255 | |
Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 256 | // If accessing a sensor we need to make sure the UID has access to it. If |
| 257 | // the app UID is idle then it cannot access sensors and gets no trigger |
| 258 | // events, no on-change events, flush event behavior does not change, and |
| 259 | // recurring events are the same as the first one delivered in idle state |
| 260 | // emulating no sensor change. As soon as the app UID transitions to an |
| 261 | // active state we will start reporting events as usual and vise versa. This |
| 262 | // approach transparently handles observing sensors while the app UID transitions |
| 263 | // between idle/active state avoiding to get stuck in a state receiving sensor |
| 264 | // data while idle or not receiving sensor data while active. |
| 265 | class UidPolicy : public BnUidObserver { |
| 266 | public: |
| 267 | explicit UidPolicy(wp<SensorService> service) |
| 268 | : mService(service) {} |
| 269 | void registerSelf(); |
| 270 | void unregisterSelf(); |
| 271 | |
| 272 | bool isUidActive(uid_t uid); |
| 273 | |
Austin Borger | 5144233 | 2022-02-17 00:26:18 +0000 | [diff] [blame] | 274 | void onUidGone(uid_t uid, bool disabled) override; |
| 275 | void onUidActive(uid_t uid) override; |
| 276 | void onUidIdle(uid_t uid, bool disabled) override; |
Eric Laurent | 0559589 | 2018-10-18 14:56:24 -0700 | [diff] [blame] | 277 | void onUidStateChanged(uid_t uid __unused, int32_t procState __unused, |
Austin Borger | 5144233 | 2022-02-17 00:26:18 +0000 | [diff] [blame] | 278 | int64_t procStateSeq __unused, |
| 279 | int32_t capability __unused) override {} |
| 280 | void onUidProcAdjChanged(uid_t uid __unused) override {} |
Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 281 | |
| 282 | void addOverrideUid(uid_t uid, bool active); |
| 283 | void removeOverrideUid(uid_t uid); |
| 284 | private: |
| 285 | bool isUidActiveLocked(uid_t uid); |
| 286 | void updateOverrideUid(uid_t uid, bool active, bool insert); |
| 287 | |
| 288 | Mutex mUidLock; |
| 289 | wp<SensorService> mService; |
| 290 | std::unordered_set<uid_t> mActiveUids; |
| 291 | std::unordered_map<uid_t, bool> mOverrideUids; |
| 292 | }; |
| 293 | |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 294 | bool isUidActive(uid_t uid); |
| 295 | |
Michael Groover | 5e1f60b | 2018-12-04 22:34:29 -0800 | [diff] [blame] | 296 | // Sensor privacy allows a user to disable access to all sensors on the device. When |
| 297 | // enabled sensor privacy will prevent all apps, including active apps, from accessing |
| 298 | // sensors, they will not receive trigger nor on-change events, flush event behavior |
| 299 | // does not change, and recurring events are the same as the first one delivered when |
| 300 | // sensor privacy was enabled. All sensor direct connections will be stopped as well |
| 301 | // and new direct connections will not be allowed while sensor privacy is enabled. |
| 302 | // Once sensor privacy is disabled access to sensors will be restored for active |
| 303 | // apps, previously stopped direct connections will be restarted, and new direct |
| 304 | // connections will be allowed again. |
| 305 | class SensorPrivacyPolicy : public hardware::BnSensorPrivacyListener { |
| 306 | public: |
Greg Kaiser | 1706759 | 2021-02-17 22:05:25 -0800 | [diff] [blame] | 307 | explicit SensorPrivacyPolicy(wp<SensorService> service) |
Evan Severson | 4c19785 | 2022-01-27 10:44:27 -0800 | [diff] [blame] | 308 | : mService(service) {} |
Michael Groover | 5e1f60b | 2018-12-04 22:34:29 -0800 | [diff] [blame] | 309 | void registerSelf(); |
| 310 | void unregisterSelf(); |
| 311 | |
| 312 | bool isSensorPrivacyEnabled(); |
| 313 | |
Evan Severson | 4c19785 | 2022-01-27 10:44:27 -0800 | [diff] [blame] | 314 | binder::Status onSensorPrivacyChanged(int toggleType, int sensor, |
| 315 | bool enabled); |
| 316 | |
| 317 | protected: |
| 318 | std::atomic_bool mSensorPrivacyEnabled; |
| 319 | wp<SensorService> mService; |
Michael Groover | 5e1f60b | 2018-12-04 22:34:29 -0800 | [diff] [blame] | 320 | |
| 321 | private: |
Anh Pham | 5198c99 | 2021-02-10 14:15:30 +0100 | [diff] [blame] | 322 | Mutex mSensorPrivacyLock; |
Evan Severson | 4c19785 | 2022-01-27 10:44:27 -0800 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | class MicrophonePrivacyPolicy : public SensorPrivacyPolicy { |
| 326 | public: |
| 327 | explicit MicrophonePrivacyPolicy(wp<SensorService> service) |
| 328 | : SensorPrivacyPolicy(service) {} |
| 329 | void registerSelf(); |
| 330 | void unregisterSelf(); |
| 331 | |
| 332 | binder::Status onSensorPrivacyChanged(int toggleType, int sensor, |
| 333 | bool enabled); |
Michael Groover | 5e1f60b | 2018-12-04 22:34:29 -0800 | [diff] [blame] | 334 | }; |
| 335 | |
Anh Pham | b04658b | 2021-03-22 18:17:17 +0100 | [diff] [blame] | 336 | // A class automatically clearing and restoring binder caller identity inside |
| 337 | // a code block (scoped variable). |
| 338 | // Declare one systematically before calling SensorPrivacyManager methods so that they are |
| 339 | // executed with the same level of privilege as the SensorService process. |
| 340 | class AutoCallerClear { |
| 341 | public: |
| 342 | AutoCallerClear() : |
| 343 | mToken(IPCThreadState::self()->clearCallingIdentity()) {} |
| 344 | ~AutoCallerClear() { |
| 345 | IPCThreadState::self()->restoreCallingIdentity(mToken); |
| 346 | } |
| 347 | |
| 348 | private: |
| 349 | const int64_t mToken; |
| 350 | }; |
| 351 | |
Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 352 | static const char* WAKE_LOCK_NAME; |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 353 | virtual ~SensorService(); |
| 354 | |
| 355 | virtual void onFirstRef(); |
| 356 | |
| 357 | // Thread interface |
| 358 | virtual bool threadLoop(); |
| 359 | |
| 360 | // ISensorServer interface |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 361 | virtual Vector<Sensor> getSensorList(const String16& opPackageName); |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 362 | virtual Vector<Sensor> getDynamicSensorList(const String16& opPackageName); |
Vladimir Komsiyski | f76bba5 | 2022-10-23 10:56:06 +0200 | [diff] [blame] | 363 | virtual Vector<Sensor> getRuntimeSensorList(const String16& opPackageName, int deviceId); |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 364 | virtual sp<ISensorEventConnection> createSensorEventConnection( |
| 365 | const String8& packageName, |
Arthur Ishiguro | 340882c | 2021-02-18 15:17:44 -0800 | [diff] [blame] | 366 | int requestedMode, const String16& opPackageName, const String16& attributionTag); |
Aravind Akella | 5c53805 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 367 | virtual int isDataInjectionEnabled(); |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 368 | virtual sp<ISensorEventConnection> createSensorDirectConnection(const String16& opPackageName, |
| 369 | 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] | 370 | virtual int setOperationParameter( |
Alexey Polyudov | 88711e8 | 2017-05-23 19:54:04 -0700 | [diff] [blame] | 371 | 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] | 372 | virtual status_t dump(int fd, const Vector<String16>& args); |
Andrew Lehmer | 3a60257 | 2021-03-25 15:19:56 -0700 | [diff] [blame] | 373 | |
Mike Ma | 2474386 | 2020-01-29 00:36:55 -0800 | [diff] [blame] | 374 | status_t dumpProtoLocked(int fd, ConnectionSafeAutolock* connLock) const; |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 375 | String8 getSensorName(int handle) const; |
Arthur Ishiguro | 883748c | 2020-10-28 13:18:02 -0700 | [diff] [blame] | 376 | String8 getSensorStringType(int handle) const; |
Aravind Akella | b4099e7 | 2013-10-15 15:43:10 -0700 | [diff] [blame] | 377 | bool isVirtualSensor(int handle) const; |
Vladimir Komsiyski | 705e5ab | 2022-12-08 17:29:14 +0100 | [diff] [blame^] | 378 | std::shared_ptr<SensorInterface> getSensorInterfaceFromHandle(int handle) const; |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 379 | bool isWakeUpSensor(int type) const; |
Aravind Akella | 0ec2066 | 2014-09-14 17:29:48 -0700 | [diff] [blame] | 380 | void recordLastValueLocked(sensors_event_t const* buffer, size_t count); |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 381 | static void sortEventBuffer(sensors_event_t* buffer, size_t count); |
Vladimir Komsiyski | 705e5ab | 2022-12-08 17:29:14 +0100 | [diff] [blame^] | 382 | bool registerSensor(std::shared_ptr<SensorInterface> sensor, bool isDebug = false, |
| 383 | bool isVirtual = false, int deviceId = RuntimeSensor::DEFAULT_DEVICE_ID); |
| 384 | bool registerVirtualSensor(std::shared_ptr<SensorInterface> sensor, bool isDebug = false); |
| 385 | bool registerDynamicSensorLocked(std::shared_ptr<SensorInterface> sensor, bool isDebug = false); |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 386 | bool unregisterDynamicSensorLocked(int handle); |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 387 | status_t cleanupWithoutDisable(const sp<SensorEventConnection>& connection, int handle); |
| 388 | status_t cleanupWithoutDisableLocked(const sp<SensorEventConnection>& connection, int handle); |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 389 | void cleanupAutoDisabledSensorLocked(const sp<SensorEventConnection>& connection, |
Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 390 | sensors_event_t const* buffer, const int count); |
Brian Duddie | 4a4d046 | 2022-05-09 16:49:49 -0700 | [diff] [blame] | 391 | bool canAccessSensor(const Sensor& sensor, const char* operation, |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 392 | const String16& opPackageName); |
Vladimir Komsiyski | f76bba5 | 2022-10-23 10:56:06 +0200 | [diff] [blame] | 393 | void addSensorIfAccessible(const String16& opPackageName, const Sensor& sensor, |
| 394 | Vector<Sensor>& accessibleSensorList); |
Brian Stack | 793f464 | 2019-04-18 17:21:34 -0700 | [diff] [blame] | 395 | static bool hasPermissionForSensor(const Sensor& sensor); |
| 396 | static int getTargetSdkVersion(const String16& opPackageName); |
Brian Duddie | 0d4ac56 | 2022-05-23 17:47:50 -0700 | [diff] [blame] | 397 | static void resetTargetSdkVersionCache(const String16& opPackageName); |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 398 | // SensorService acquires a partial wakelock for delivering events from wake up sensors. This |
| 399 | // method checks whether all the events from these wake up sensors have been delivered to the |
| 400 | // corresponding applications, if yes the wakelock is released. |
| 401 | void checkWakeLockState(); |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 402 | void checkWakeLockStateLocked(ConnectionSafeAutolock* connLock); |
Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 403 | bool isWakeLockAcquired(); |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 404 | bool isWakeUpSensorEvent(const sensors_event_t& event) const; |
Aravind Akella | 56ae426 | 2014-07-10 16:01:10 -0700 | [diff] [blame] | 405 | |
| 406 | sp<Looper> getLooper() const; |
| 407 | |
Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 408 | // Reset mWakeLockRefCounts for all SensorEventConnections to zero. This may happen if |
| 409 | // SensorService did not receive any acknowledgements from apps which have registered for |
| 410 | // wake_up sensors. |
| 411 | void resetAllWakeLockRefCounts(); |
| 412 | |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 413 | // Acquire or release wake_lock. If wake_lock is acquired, set the timeout in the looper to 5 |
| 414 | // seconds and wake the looper. |
Aravind Akella | b4373ac | 2014-10-29 17:55:20 -0700 | [diff] [blame] | 415 | void setWakeLockAcquiredLocked(bool acquire); |
| 416 | |
| 417 | // Send events from the event cache for this particular connection. |
| 418 | void sendEventsFromCache(const sp<SensorEventConnection>& connection); |
| 419 | |
Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 420 | // If SensorService is operating in RESTRICTED mode, only select whitelisted packages are |
| 421 | // allowed to register for or call flush on sensors. Typically only cts test packages are |
| 422 | // allowed. |
| 423 | bool isWhiteListedPackage(const String8& packageName); |
Arthur Ishiguro | e3ed3d2 | 2020-04-13 10:29:44 -0700 | [diff] [blame] | 424 | |
| 425 | // Returns true if a connection with the specified opPackageName has no access to sensors |
| 426 | // in the RESTRICTED mode (i.e. the service is in RESTRICTED mode, and the package is not |
| 427 | // whitelisted). mLock must be held to invoke this method. |
| 428 | bool isOperationRestrictedLocked(const String16& opPackageName); |
Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 429 | |
Anh Pham | af91a91 | 2021-02-10 14:10:53 +0100 | [diff] [blame] | 430 | status_t adjustSamplingPeriodBasedOnMicAndPermission(nsecs_t* requestedPeriodNs, |
| 431 | const String16& opPackageName); |
| 432 | status_t adjustRateLevelBasedOnMicAndPermission(int* requestedRateLevel, |
| 433 | const String16& opPackageName); |
| 434 | bool isRateCappedBasedOnPermission(const String16& opPackageName); |
| 435 | bool isPackageDebuggable(const String16& opPackageName); |
| 436 | |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 437 | // Reset the state of SensorService to NORMAL mode. |
| 438 | status_t resetToNormalMode(); |
| 439 | status_t resetToNormalModeLocked(); |
| 440 | |
Greg Kaiser | 53ca2e0 | 2016-06-21 16:11:14 -0700 | [diff] [blame] | 441 | // Transforms the UUIDs for all the sensors into proper IDs. |
| 442 | void makeUuidsIntoIdsForSensorList(Vector<Sensor> &sensorList) const; |
| 443 | // Gets the appropriate ID from the given UUID. |
| 444 | int32_t getIdFromUuid(const Sensor::uuid_t &uuid) const; |
| 445 | // Either read from storage or create a new one. |
| 446 | static bool initializeHmacKey(); |
| 447 | |
Peng Xu | 98d30f6 | 2016-08-01 18:12:11 -0700 | [diff] [blame] | 448 | // Enable SCHED_FIFO priority for thread |
| 449 | void enableSchedFifoMode(); |
Greg Kaiser | 53ca2e0 | 2016-06-21 16:11:14 -0700 | [diff] [blame] | 450 | |
Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 451 | // Sets whether the given UID can get sensor data |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 452 | void onUidStateChanged(uid_t uid, UidState state); |
Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 453 | |
Arthur Ishiguro | e3ed3d2 | 2020-04-13 10:29:44 -0700 | [diff] [blame] | 454 | // Returns true if a connection with the given uid and opPackageName |
| 455 | // currently has access to sensors. |
| 456 | bool hasSensorAccess(uid_t uid, const String16& opPackageName); |
| 457 | // Same as hasSensorAccess but with mLock held. |
| 458 | bool hasSensorAccessLocked(uid_t uid, const String16& opPackageName); |
| 459 | |
Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 460 | // Overrides the UID state as if it is idle |
| 461 | status_t handleSetUidState(Vector<String16>& args, int err); |
| 462 | // Clears the override for the UID state |
| 463 | status_t handleResetUidState(Vector<String16>& args, int err); |
| 464 | // Gets the UID state |
| 465 | status_t handleGetUidState(Vector<String16>& args, int out, int err); |
| 466 | // Prints the shell command help |
| 467 | status_t printHelp(int out); |
| 468 | |
Michael Groover | 5e1f60b | 2018-12-04 22:34:29 -0800 | [diff] [blame] | 469 | // temporarily stops all active direct connections and disables all sensors |
| 470 | void disableAllSensors(); |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 471 | void disableAllSensorsLocked(ConnectionSafeAutolock* connLock); |
Michael Groover | 5e1f60b | 2018-12-04 22:34:29 -0800 | [diff] [blame] | 472 | // restarts the previously stopped direct connections and enables all sensors |
| 473 | void enableAllSensors(); |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 474 | void enableAllSensorsLocked(ConnectionSafeAutolock* connLock); |
Michael Groover | 5e1f60b | 2018-12-04 22:34:29 -0800 | [diff] [blame] | 475 | |
Anh Pham | 5198c99 | 2021-02-10 14:15:30 +0100 | [diff] [blame] | 476 | // Caps active direct connections (when the mic toggle is flipped to on) |
Evan Severson | 4c19785 | 2022-01-27 10:44:27 -0800 | [diff] [blame] | 477 | void capRates(); |
Anh Pham | 5198c99 | 2021-02-10 14:15:30 +0100 | [diff] [blame] | 478 | // Removes the capped rate on active direct connections (when the mic toggle is flipped to off) |
Evan Severson | 4c19785 | 2022-01-27 10:44:27 -0800 | [diff] [blame] | 479 | void uncapRates(); |
Anh Pham | 5198c99 | 2021-02-10 14:15:30 +0100 | [diff] [blame] | 480 | |
Eric Laurent | e3f27df | 2022-01-05 19:20:32 +0100 | [diff] [blame] | 481 | static inline bool isAudioServerOrSystemServerUid(uid_t uid) { |
| 482 | return multiuser_get_app_id(uid) == AID_SYSTEM || uid == AID_AUDIOSERVER; |
| 483 | } |
| 484 | |
Greg Kaiser | 53ca2e0 | 2016-06-21 16:11:14 -0700 | [diff] [blame] | 485 | static uint8_t sHmacGlobalKey[128]; |
| 486 | static bool sHmacGlobalKeyIsValid; |
| 487 | |
Andrew Lehmer | 3a60257 | 2021-03-25 15:19:56 -0700 | [diff] [blame] | 488 | static std::atomic_uint64_t curProxCallbackSeq; |
| 489 | static std::atomic_uint64_t completedCallbackSeq; |
| 490 | |
Brian Stack | 4baa5be | 2018-09-18 14:03:13 -0700 | [diff] [blame] | 491 | SensorServiceUtil::SensorList mSensors; |
Mathias Agopian | 50df295 | 2010-07-19 19:09:10 -0700 | [diff] [blame] | 492 | status_t mInitCheck; |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 493 | |
Aravind Akella | 5466c3d | 2014-08-22 16:11:10 -0700 | [diff] [blame] | 494 | // Socket buffersize used to initialize BitTube. This size depends on whether batching is |
| 495 | // supported or not. |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 496 | uint32_t mSocketBufferSize; |
| 497 | sp<Looper> mLooper; |
| 498 | sp<SensorEventAckReceiver> mAckReceiver; |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 499 | |
| 500 | // protected by mLock |
| 501 | mutable Mutex mLock; |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 502 | DefaultKeyedVector<int, SensorRecord*> mActiveSensors; |
Peng Xu | 755c451 | 2016-04-07 23:15:14 -0700 | [diff] [blame] | 503 | std::unordered_set<int> mActiveVirtualSensors; |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 504 | SensorConnectionHolder mConnectionHolder; |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 505 | bool mWakeLockAcquired; |
Aravind Akella | 8493b79 | 2014-09-08 15:45:47 -0700 | [diff] [blame] | 506 | sensors_event_t *mSensorEventBuffer, *mSensorEventScratch; |
Brian Duddie | 967ce17 | 2019-06-10 11:08:27 -0700 | [diff] [blame] | 507 | // WARNING: these SensorEventConnection instances must not be promoted to sp, except via |
| 508 | // modification to add support for them in ConnectionSafeAutolock |
Peng Xu | ded526e | 2016-08-12 16:39:44 -0700 | [diff] [blame] | 509 | wp<const SensorEventConnection> * mMapFlushEventsToConnections; |
Brian Stack | 4baa5be | 2018-09-18 14:03:13 -0700 | [diff] [blame] | 510 | std::unordered_map<int, SensorServiceUtil::RecentEventLogger*> mRecentEvent; |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 511 | Mode mCurrentOperatingMode; |
Vladimir Komsiyski | f76bba5 | 2022-10-23 10:56:06 +0200 | [diff] [blame] | 512 | std::queue<sensors_event_t> mRuntimeSensorEventQueue; |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 513 | |
Brian Duddie | 4a4d046 | 2022-05-09 16:49:49 -0700 | [diff] [blame] | 514 | // true if the head tracker sensor type is currently restricted to system usage only |
| 515 | // (can only be unrestricted for testing, via shell cmd) |
| 516 | bool mHtRestricted = true; |
| 517 | |
Aravind Akella | 5c53805 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 518 | // This packagaName is set when SensorService is in RESTRICTED or DATA_INJECTION mode. Only |
| 519 | // applications with this packageName are allowed to activate/deactivate or call flush on |
| 520 | // sensors. To run CTS this is can be set to ".cts." and only CTS tests will get access to |
| 521 | // sensors. |
| 522 | String8 mWhiteListedPackage; |
Aravind Akella | 8493b79 | 2014-09-08 15:45:47 -0700 | [diff] [blame] | 523 | |
Aravind Akella | 18d6d51 | 2015-06-18 14:18:28 -0700 | [diff] [blame] | 524 | int mNextSensorRegIndex; |
| 525 | Vector<SensorRegistrationInfo> mLastNSensorRegistrations; |
Svet Ganov | e752a5c | 2018-01-15 17:14:20 -0800 | [diff] [blame] | 526 | |
| 527 | sp<UidPolicy> mUidPolicy; |
Michael Groover | 5e1f60b | 2018-12-04 22:34:29 -0800 | [diff] [blame] | 528 | sp<SensorPrivacyPolicy> mSensorPrivacyPolicy; |
Brian Stack | 793f464 | 2019-04-18 17:21:34 -0700 | [diff] [blame] | 529 | |
| 530 | static AppOpsManager sAppOpsManager; |
| 531 | static std::map<String16, int> sPackageTargetVersion; |
| 532 | static Mutex sPackageTargetVersionLock; |
Anthony Stange | 07eb421 | 2020-08-28 14:50:28 -0400 | [diff] [blame] | 533 | static String16 sSensorInterfaceDescriptorPrefix; |
Anh Pham | 5198c99 | 2021-02-10 14:15:30 +0100 | [diff] [blame] | 534 | |
Evan Severson | 4c19785 | 2022-01-27 10:44:27 -0800 | [diff] [blame] | 535 | sp<MicrophonePrivacyPolicy> mMicSensorPrivacyPolicy; |
Andrew Lehmer | 3a60257 | 2021-03-25 15:19:56 -0700 | [diff] [blame] | 536 | |
Chris Kuiper | df11ff2 | 2021-10-12 16:30:01 -0700 | [diff] [blame] | 537 | // Keeps track of the handles of all proximity sensors in the system. |
| 538 | std::vector<int32_t> mProxSensorHandles; |
| 539 | // The last proximity sensor active state reported to listeners. |
| 540 | bool mLastReportedProxIsActive; |
| 541 | // Listeners subscribed to receive updates on the proximity sensor active state. |
Andrew Lehmer | 3a60257 | 2021-03-25 15:19:56 -0700 | [diff] [blame] | 542 | std::vector<sp<ProximityActiveListener>> mProximityActiveListeners; |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 543 | }; |
| 544 | |
Peng Xu | eb4d628 | 2015-12-10 18:02:41 -0800 | [diff] [blame] | 545 | } // namespace android |
Mathias Agopian | fc32881 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 546 | #endif // ANDROID_SENSOR_SERVICE_H |