blob: b66542cd0949ef8c268ceb72559826323e4efa8d [file] [log] [blame]
Peng Xu1a00e2d2017-09-27 23:08:30 -07001/*
2 * Copyright (C) 2017 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_UTIL
18#define ANDROID_SENSOR_DEVICE_UTIL
19
20#include <android/hidl/manager/1.0/IServiceNotification.h>
Anthony Stange0ff158f2020-03-20 10:46:15 -040021#include <hardware/sensors.h>
Peng Xu1a00e2d2017-09-27 23:08:30 -070022
23#include <condition_variable>
24#include <thread>
25
26using ::android::hardware::hidl_string;
27using ::android::hardware::Return;
28using ::android::hidl::manager::V1_0::IServiceNotification;
29
30namespace android {
31namespace SensorDeviceUtils {
32
Anthony Stange0ff158f2020-03-20 10:46:15 -040033// Ensures a sensor event doesn't provide values finer grained than its sensor resolution allows.
34void quantizeSensorEventValues(sensors_event_t *event, float resolution);
35
36// Provides a default resolution for simple sensor types if one wasn't provided by the HAL.
37float defaultResolutionForType(int type);
38
Peng Xu1a00e2d2017-09-27 23:08:30 -070039class HidlServiceRegistrationWaiter : public IServiceNotification {
40public:
41
42 HidlServiceRegistrationWaiter();
43
44 Return<void> onRegistration(const hidl_string &fqName,
45 const hidl_string &name,
46 bool preexisting) override;
47
48 void reset();
49
50 /**
51 * Wait for service restart
52 *
53 * @return true if service is restart since last reset(); false otherwise.
54 */
55 bool wait();
Yifan Honga53e89d2017-11-02 16:19:19 -070056protected:
57 void onFirstRef() override;
Peng Xu1a00e2d2017-09-27 23:08:30 -070058private:
Martijn Coenenb41e87a2017-11-02 14:00:41 +010059 bool mRegistered;
Peng Xu1a00e2d2017-09-27 23:08:30 -070060
61 std::mutex mLock;
62 std::condition_variable mCondition;
63 bool mRestartObserved;
64};
65
66} // namespace SensorDeviceUtils
67} // namespace android;
68
69#endif // ANDROID_SENSOR_SERVICE_UTIL