Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [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_DEVICE_H |
| 18 | #define ANDROID_SENSOR_DEVICE_H |
| 19 | |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 20 | #include "ISensorsWrapper.h" |
Peng Xu | 1a00e2d | 2017-09-27 23:08:30 -0700 | [diff] [blame] | 21 | #include "SensorDeviceUtils.h" |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 22 | #include "SensorService.h" |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 23 | #include "SensorServiceUtils.h" |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 24 | |
Brian Stack | 979887b | 2018-09-19 15:27:48 -0700 | [diff] [blame] | 25 | #include <fmq/MessageQueue.h> |
Mathias Agopian | 801ea09 | 2017-03-06 15:05:04 -0800 | [diff] [blame] | 26 | #include <sensor/Sensor.h> |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 27 | #include <sensor/SensorEventQueue.h> |
Steven Moreland | d15c030 | 2016-12-20 11:14:50 -0800 | [diff] [blame] | 28 | #include <stdint.h> |
| 29 | #include <sys/types.h> |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 30 | #include <utils/KeyedVector.h> |
| 31 | #include <utils/Singleton.h> |
| 32 | #include <utils/String8.h> |
Brian Stack | a28e921 | 2018-09-19 15:20:30 -0700 | [diff] [blame] | 33 | #include <utils/Timers.h> |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 34 | |
Peng Xu | 2bec623 | 2016-07-01 17:13:10 -0700 | [diff] [blame] | 35 | #include <algorithm> //std::max std::min |
Arthur Ishiguro | 4f1dd8a | 2021-11-12 17:21:24 +0000 | [diff] [blame] | 36 | #include <string> |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 37 | #include <unordered_map> |
Arthur Ishiguro | 4f1dd8a | 2021-11-12 17:21:24 +0000 | [diff] [blame] | 38 | #include <vector> |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 39 | |
Ashutosh Joshi | 96b12d8 | 2017-03-15 16:27:12 -0700 | [diff] [blame] | 40 | #include "RingBuffer.h" |
| 41 | |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 42 | // --------------------------------------------------------------------------- |
| 43 | |
| 44 | namespace android { |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 45 | |
Arthur Ishiguro | 71e78ac | 2021-11-14 01:18:47 +0000 | [diff] [blame^] | 46 | using Result = ::android::hardware::sensors::V1_0::Result; |
| 47 | |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 48 | // --------------------------------------------------------------------------- |
Brian Stack | 574cda3 | 2018-10-01 11:18:51 -0700 | [diff] [blame] | 49 | class SensorsHalDeathReceivier : public android::hardware::hidl_death_recipient { |
| 50 | virtual void serviceDied(uint64_t cookie, |
| 51 | const wp<::android::hidl::base::V1_0::IBase>& service) override; |
| 52 | }; |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 53 | |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 54 | class SensorDevice : public Singleton<SensorDevice>, public SensorServiceUtil::Dumpable { |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 55 | public: |
Ashutosh Joshi | 96b12d8 | 2017-03-15 16:27:12 -0700 | [diff] [blame] | 56 | class HidlTransportErrorLog { |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 57 | public: |
Ashutosh Joshi | 96b12d8 | 2017-03-15 16:27:12 -0700 | [diff] [blame] | 58 | HidlTransportErrorLog() { |
| 59 | mTs = 0; |
| 60 | mCount = 0; |
| 61 | } |
| 62 | |
| 63 | HidlTransportErrorLog(time_t ts, int count) { |
| 64 | mTs = ts; |
| 65 | mCount = count; |
| 66 | } |
| 67 | |
| 68 | String8 toString() const { |
| 69 | String8 result; |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 70 | struct tm* timeInfo = localtime(&mTs); |
Ashutosh Joshi | 96b12d8 | 2017-03-15 16:27:12 -0700 | [diff] [blame] | 71 | result.appendFormat("%02d:%02d:%02d :: %d", timeInfo->tm_hour, timeInfo->tm_min, |
| 72 | timeInfo->tm_sec, mCount); |
| 73 | return result; |
| 74 | } |
| 75 | |
| 76 | private: |
| 77 | time_t mTs; // timestamp of the error |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 78 | int mCount; // number of transport errors observed |
Ashutosh Joshi | 96b12d8 | 2017-03-15 16:27:12 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Brian Stack | a28e921 | 2018-09-19 15:20:30 -0700 | [diff] [blame] | 81 | ~SensorDevice(); |
Brian Stack | 156da08 | 2018-10-01 15:58:53 -0700 | [diff] [blame] | 82 | void prepareForReconnect(); |
| 83 | void reconnect(); |
Brian Stack | a28e921 | 2018-09-19 15:20:30 -0700 | [diff] [blame] | 84 | |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 85 | ssize_t getSensorList(sensor_t const** list); |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 86 | |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 87 | void handleDynamicSensorConnection(int handle, bool connected); |
| 88 | status_t initCheck() const; |
| 89 | int getHalDeviceVersion() const; |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 90 | |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 91 | ssize_t poll(sensors_event_t* buffer, size_t count); |
Brian Stack | b7bfc0f | 2018-09-25 09:41:16 -0700 | [diff] [blame] | 92 | void writeWakeLockHandled(uint32_t count); |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 93 | |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 94 | status_t activate(void* ident, int handle, int enabled); |
| 95 | status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs, |
| 96 | int64_t maxBatchReportLatencyNs); |
| 97 | // Call batch with timeout zero instead of calling setDelay() for newer devices. |
| 98 | status_t setDelay(void* ident, int handle, int64_t ns); |
| 99 | status_t flush(void* ident, int handle); |
| 100 | status_t setMode(uint32_t mode); |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 101 | |
Peng Xu | 5363254 | 2017-01-23 20:06:27 -0800 | [diff] [blame] | 102 | bool isDirectReportSupported() const; |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 103 | int32_t registerDirectChannel(const sensors_direct_mem_t* memory); |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 104 | void unregisterDirectChannel(int32_t channelHandle); |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 105 | int32_t configureDirectChannel(int32_t sensorHandle, int32_t channelHandle, |
| 106 | const struct sensors_direct_cfg_t* config); |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 107 | |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 108 | void disableAllSensors(); |
| 109 | void enableAllSensors(); |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 110 | void autoDisable(void* ident, int handle); |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 111 | |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 112 | status_t injectSensorData(const sensors_event_t* event); |
| 113 | void notifyConnectionDestroyed(void* ident); |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 114 | |
Arthur Ishiguro | 71e78ac | 2021-11-14 01:18:47 +0000 | [diff] [blame^] | 115 | void onDynamicSensorsConnected(const std::vector<sensor_t>& dynamicSensorsAdded); |
| 116 | void onDynamicSensorsDisconnected(const std::vector<int32_t>& dynamicSensorHandlesRemoved); |
Brian Stack | 6c49e6f | 2018-09-24 15:44:32 -0700 | [diff] [blame] | 117 | |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 118 | void setUidStateForConnection(void* ident, SensorService::UidState state); |
| 119 | |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 120 | bool isReconnecting() const { return mReconnecting; } |
Brian Stack | 156da08 | 2018-10-01 15:58:53 -0700 | [diff] [blame] | 121 | |
Brian Stack | bce04d7 | 2019-03-21 10:54:10 -0700 | [diff] [blame] | 122 | bool isSensorActive(int handle) const; |
| 123 | |
Anh Pham | 5198c99 | 2021-02-10 14:15:30 +0100 | [diff] [blame] | 124 | // To update the BatchParams of a SensorEventConnection when the mic toggle changes its state |
| 125 | // while the Sensors Off toggle is on. |
| 126 | void onMicSensorAccessChanged(void* ident, int handle, nsecs_t samplingPeriodNs); |
| 127 | |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 128 | // Dumpable |
Mike Ma | 2474386 | 2020-01-29 00:36:55 -0800 | [diff] [blame] | 129 | virtual std::string dump() const override; |
| 130 | virtual void dump(util::ProtoOutputStream* proto) const override; |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 131 | |
Peng Xu | 6a2d3a0 | 2015-12-21 12:00:23 -0800 | [diff] [blame] | 132 | private: |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 133 | friend class Singleton<SensorDevice>; |
Steven Moreland | d15c030 | 2016-12-20 11:14:50 -0800 | [diff] [blame] | 134 | |
Anthony Stange | e38a141 | 2020-02-13 21:28:37 -0500 | [diff] [blame] | 135 | sp<::android::hardware::sensors::V2_1::implementation::ISensorsWrapperBase> mSensors; |
Arthur Ishiguro | 71e78ac | 2021-11-14 01:18:47 +0000 | [diff] [blame^] | 136 | sp<::android::hardware::sensors::V2_1::ISensorsCallback> mCallback; |
Arthur Ishiguro | 4f1dd8a | 2021-11-12 17:21:24 +0000 | [diff] [blame] | 137 | std::vector<sensor_t> mSensorList; |
Arthur Ishiguro | 71e78ac | 2021-11-14 01:18:47 +0000 | [diff] [blame^] | 138 | std::unordered_map<int32_t, sensor_t> mConnectedDynamicSensors; |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 139 | |
Anthony Stange | fb4e33a | 2021-09-29 15:47:53 +0000 | [diff] [blame] | 140 | // A bug in the Sensors HIDL spec which marks onDynamicSensorsConnected as oneway causes dynamic |
| 141 | // meta events and onDynamicSensorsConnected to be received out of order. This mutex + CV are |
| 142 | // used to block meta event processing until onDynamicSensorsConnected is received to simplify |
| 143 | // HAL implementations. |
| 144 | std::mutex mDynamicSensorsMutex; |
| 145 | std::condition_variable mDynamicSensorsCv; |
| 146 | static constexpr std::chrono::seconds MAX_DYN_SENSOR_WAIT{5}; |
| 147 | |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 148 | static const nsecs_t MINIMUM_EVENTS_PERIOD = 1000000; // 1000 Hz |
| 149 | mutable Mutex mLock; // protect mActivationCount[].batchParams |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 150 | // fixed-size array after construction |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 151 | |
| 152 | // Struct to store all the parameters(samplingPeriod, maxBatchReportLatency and flags) from |
| 153 | // batch call. For continous mode clients, maxBatchReportLatency is set to zero. |
| 154 | struct BatchParams { |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 155 | nsecs_t mTSample, mTBatch; |
| 156 | BatchParams() : mTSample(INT64_MAX), mTBatch(INT64_MAX) {} |
| 157 | BatchParams(nsecs_t tSample, nsecs_t tBatch) : mTSample(tSample), mTBatch(tBatch) {} |
| 158 | bool operator!=(const BatchParams& other) { |
| 159 | return !(mTSample == other.mTSample && mTBatch == other.mTBatch); |
| 160 | } |
| 161 | // Merge another parameter with this one. The updated mTSample will be the min of the two. |
| 162 | // The update mTBatch will be the min of original mTBatch and the apparent batch period |
| 163 | // of the other. the apparent batch is the maximum of mTBatch and mTSample, |
| 164 | void merge(const BatchParams& other) { |
| 165 | mTSample = std::min(mTSample, other.mTSample); |
| 166 | mTBatch = std::min(mTBatch, std::max(other.mTBatch, other.mTSample)); |
| 167 | } |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | // Store batch parameters in the KeyedVector and the optimal batch_rate and timeout in |
| 171 | // bestBatchParams. For every batch() call corresponding params are stored in batchParams |
| 172 | // vector. A continuous mode request is batch(... timeout=0 ..) followed by activate(). A batch |
| 173 | // mode request is batch(... timeout > 0 ...) followed by activate(). |
| 174 | // Info is a per-sensor data structure which contains the batch parameters for each client that |
| 175 | // has registered for this sensor. |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 176 | struct Info { |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 177 | BatchParams bestBatchParams; |
| 178 | // Key is the unique identifier(ident) for each client, value is the batch parameters |
| 179 | // requested by the client. |
| 180 | KeyedVector<void*, BatchParams> batchParams; |
| 181 | |
Brian Stack | 0c305fe | 2019-04-09 12:49:24 -0700 | [diff] [blame] | 182 | // Flag to track if the sensor is active |
| 183 | bool isActive = false; |
| 184 | |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 185 | // Sets batch parameters for this ident. Returns error if this ident is not already present |
| 186 | // in the KeyedVector above. |
| 187 | status_t setBatchParamsForIdent(void* ident, int flags, int64_t samplingPeriodNs, |
| 188 | int64_t maxBatchReportLatencyNs); |
| 189 | // Finds the optimal parameters for batching and stores them in bestBatchParams variable. |
| 190 | void selectBatchParams(); |
| 191 | // Removes batchParams for an ident and re-computes bestBatchParams. Returns the index of |
| 192 | // the removed ident. If index >=0, ident is present and successfully removed. |
| 193 | ssize_t removeBatchParamsForIdent(void* ident); |
Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 194 | |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 195 | bool hasBatchParamsForIdent(void* ident) const { |
| 196 | return batchParams.indexOfKey(ident) >= 0; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * @return The number of active clients of this sensor. |
| 201 | */ |
Brian Stack | 156da08 | 2018-10-01 15:58:53 -0700 | [diff] [blame] | 202 | int numActiveClients() const; |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 203 | }; |
| 204 | DefaultKeyedVector<int, Info> mActivationCount; |
| 205 | |
Ashutosh Joshi | 96b12d8 | 2017-03-15 16:27:12 -0700 | [diff] [blame] | 206 | // Keep track of any hidl transport failures |
| 207 | SensorServiceUtil::RingBuffer<HidlTransportErrorLog> mHidlTransportErrors; |
| 208 | int mTotalHidlTransportErrors; |
| 209 | |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 210 | /** |
| 211 | * Enums describing the reason why a client was disabled. |
| 212 | */ |
| 213 | enum DisabledReason : uint8_t { |
| 214 | // UID becomes idle (e.g. app goes to background). |
| 215 | DISABLED_REASON_UID_IDLE = 0, |
| 216 | |
| 217 | // Sensors are restricted for all clients. |
| 218 | DISABLED_REASON_SERVICE_RESTRICTED, |
| 219 | DISABLED_REASON_MAX, |
| 220 | }; |
| 221 | |
| 222 | static_assert(DisabledReason::DISABLED_REASON_MAX < sizeof(uint8_t) * CHAR_BIT); |
| 223 | |
| 224 | // Use this map to determine which client is activated or deactivated. |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 225 | std::unordered_map<void*, uint8_t> mDisabledClients; |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 226 | |
| 227 | void addDisabledReasonForIdentLocked(void* ident, DisabledReason reason); |
| 228 | void removeDisabledReasonForIdentLocked(void* ident, DisabledReason reason); |
| 229 | |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 230 | SensorDevice(); |
Peng Xu | a8fad9b | 2017-03-17 12:20:27 -0700 | [diff] [blame] | 231 | bool connectHidlService(); |
Brian Stack | 156da08 | 2018-10-01 15:58:53 -0700 | [diff] [blame] | 232 | void initializeSensorList(); |
| 233 | void reactivateSensors(const DefaultKeyedVector<int, Info>& previousActivations); |
Arthur Ishiguro | 4f1dd8a | 2021-11-12 17:21:24 +0000 | [diff] [blame] | 234 | static bool sensorHandlesChanged(const std::vector<sensor_t>& oldSensorList, |
| 235 | const std::vector<sensor_t>& newSensorList); |
Brian Stack | 156da08 | 2018-10-01 15:58:53 -0700 | [diff] [blame] | 236 | static bool sensorIsEquivalent(const sensor_t& prevSensor, const sensor_t& newSensor); |
Brian Stack | 979887b | 2018-09-19 15:27:48 -0700 | [diff] [blame] | 237 | |
| 238 | enum HalConnectionStatus { |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 239 | CONNECTED, // Successfully connected to the HAL |
| 240 | DOES_NOT_EXIST, // Could not find the HAL |
Brian Stack | 979887b | 2018-09-19 15:27:48 -0700 | [diff] [blame] | 241 | FAILED_TO_CONNECT, // Found the HAL but failed to connect/initialize |
| 242 | UNKNOWN, |
| 243 | }; |
| 244 | HalConnectionStatus connectHidlServiceV1_0(); |
| 245 | HalConnectionStatus connectHidlServiceV2_0(); |
Anthony Stange | e38a141 | 2020-02-13 21:28:37 -0500 | [diff] [blame] | 246 | HalConnectionStatus connectHidlServiceV2_1(); |
| 247 | HalConnectionStatus initializeHidlServiceV2_X(); |
Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 248 | |
Brian Stack | a28e921 | 2018-09-19 15:20:30 -0700 | [diff] [blame] | 249 | ssize_t pollHal(sensors_event_t* buffer, size_t count); |
| 250 | ssize_t pollFmq(sensors_event_t* buffer, size_t count); |
Brian Stack | 156da08 | 2018-10-01 15:58:53 -0700 | [diff] [blame] | 251 | status_t activateLocked(void* ident, int handle, int enabled); |
| 252 | status_t batchLocked(void* ident, int handle, int flags, int64_t samplingPeriodNs, |
| 253 | int64_t maxBatchReportLatencyNs); |
Brian Stack | a28e921 | 2018-09-19 15:20:30 -0700 | [diff] [blame] | 254 | |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 255 | status_t updateBatchParamsLocked(int handle, Info& info); |
| 256 | status_t doActivateHardwareLocked(int handle, bool enable); |
| 257 | |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 258 | void handleHidlDeath(const std::string& detail); |
| 259 | template <typename T> |
Brian Duddie | 6d2e375 | 2019-05-30 09:52:28 -0700 | [diff] [blame] | 260 | void checkReturn(const Return<T>& ret) { |
Peng Xu | 3889e6e | 2017-03-02 19:10:38 -0800 | [diff] [blame] | 261 | if (!ret.isOk()) { |
| 262 | handleHidlDeath(ret.description()); |
| 263 | } |
Peng Xu | 3889e6e | 2017-03-02 19:10:38 -0800 | [diff] [blame] | 264 | } |
Arthur Ishiguro | 71e78ac | 2021-11-14 01:18:47 +0000 | [diff] [blame^] | 265 | |
Brian Duddie | 6d2e375 | 2019-05-30 09:52:28 -0700 | [diff] [blame] | 266 | status_t checkReturnAndGetStatus(const Return<Result>& ret); |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 267 | // TODO(b/67425500): remove waiter after bug is resolved. |
Peng Xu | 1a00e2d | 2017-09-27 23:08:30 -0700 | [diff] [blame] | 268 | sp<SensorDeviceUtils::HidlServiceRegistrationWaiter> mRestartWaiter; |
Peng Xu | 3889e6e | 2017-03-02 19:10:38 -0800 | [diff] [blame] | 269 | |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 270 | bool isClientDisabled(void* ident) const; |
| 271 | bool isClientDisabledLocked(void* ident) const; |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 272 | std::vector<void*> getDisabledClientsLocked() const; |
Arthur Ishiguro | 539c27c | 2020-04-13 09:47:59 -0700 | [diff] [blame] | 273 | |
| 274 | bool clientHasNoAccessLocked(void* ident) const; |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 275 | |
Anthony Stange | e38a141 | 2020-02-13 21:28:37 -0500 | [diff] [blame] | 276 | using Event = hardware::sensors::V2_1::Event; |
| 277 | using SensorInfo = hardware::sensors::V2_1::SensorInfo; |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 278 | |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 279 | void convertToSensorEvent(const Event& src, sensors_event_t* dst); |
Andreas Huber | 99fdbb5 | 2016-10-10 13:22:58 -0700 | [diff] [blame] | 280 | |
Arthur Ishiguro | d6b9e21 | 2021-11-14 01:20:55 +0000 | [diff] [blame] | 281 | void convertToSensorEventsAndQuantize(const hardware::hidl_vec<Event>& src, |
| 282 | const hardware::hidl_vec<SensorInfo>& dynamicSensorsAdded, |
| 283 | sensors_event_t* dst); |
Peng Xu | 5363254 | 2017-01-23 20:06:27 -0800 | [diff] [blame] | 284 | |
Anthony Stange | 1292486 | 2020-03-20 10:46:15 -0400 | [diff] [blame] | 285 | float getResolutionForSensor(int sensorHandle); |
| 286 | |
Peng Xu | 5363254 | 2017-01-23 20:06:27 -0800 | [diff] [blame] | 287 | bool mIsDirectReportSupported; |
Brian Stack | 979887b | 2018-09-19 15:27:48 -0700 | [diff] [blame] | 288 | |
Brian Stack | 979887b | 2018-09-19 15:27:48 -0700 | [diff] [blame] | 289 | typedef hardware::MessageQueue<uint32_t, hardware::kSynchronizedReadWrite> WakeLockQueue; |
Brian Stack | 979887b | 2018-09-19 15:27:48 -0700 | [diff] [blame] | 290 | std::unique_ptr<WakeLockQueue> mWakeLockQueue; |
Brian Stack | a28e921 | 2018-09-19 15:20:30 -0700 | [diff] [blame] | 291 | |
| 292 | hardware::EventFlag* mEventQueueFlag; |
Brian Stack | a24e7d4 | 2019-01-08 12:56:09 -0800 | [diff] [blame] | 293 | hardware::EventFlag* mWakeLockQueueFlag; |
Brian Stack | a28e921 | 2018-09-19 15:20:30 -0700 | [diff] [blame] | 294 | |
| 295 | std::array<Event, SensorEventQueue::MAX_RECEIVE_BUFFER_EVENT_COUNT> mEventBuffer; |
Brian Stack | 574cda3 | 2018-10-01 11:18:51 -0700 | [diff] [blame] | 296 | |
| 297 | sp<SensorsHalDeathReceivier> mSensorsHalDeathReceiver; |
Brian Stack | 156da08 | 2018-10-01 15:58:53 -0700 | [diff] [blame] | 298 | std::atomic_bool mReconnecting; |
Mathias Agopian | f001c92 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | // --------------------------------------------------------------------------- |
| 302 | }; // namespace android |
| 303 | |
| 304 | #endif // ANDROID_SENSOR_DEVICE_H |