blob: c9e089e449923b944341e1626da5e437a45a7898 [file] [log] [blame]
Arthur Ishiguro5e3eaa82021-11-11 18:05:56 +00001/*
2 * Copyright (C) 2021 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_ISENSOR_HAL_WRAPPER_H
18#define ANDROID_ISENSOR_HAL_WRAPPER_H
19
20#include <hardware/sensors.h>
21#include <stdint.h>
22#include <sys/types.h>
23
24#include "SensorService.h"
25
26namespace android {
27
28/**
29 * A wrapper for various types of HAL implementation, e.g. to distinguish HIDL and AIDL versions.
30 */
31class ISensorHalWrapper {
32public:
33 class ICallback : public ISensorsCallback {
34
35 void onDynamicSensorsConnected(
36 const std::vector<sensor_t> &dynamicSensorsAdded) = 0;
37
38 void onDynamicSensorsDisconnected(
39 const std::vector<int32_t> &dynamicSensorHandlesRemoved) = 0;
40 };
41
42 /**
43 * Connects to the underlying sensors HAL. This should also be used for any reconnections
44 * due to HAL resets.
45 */
46 virtual bool connect(ICallback *callback) = 0;
47
48 /**
49 * Polls for available sensor events. This could be using the traditional sensors
50 * polling or from a FMQ.
51 */
52 virtual ssize_t poll(sensors_event_t* buffer, size_t count) = 0;
53
54 /**
55 * The below functions directly mirrors the sensors HAL definitions.
56 */
57 virtual std::vector<sensor_t> getSensorsList() = 0;
58
59 virtual status_t setOperationMode(SensorService::Mode mode) = 0;
60
61 virtual status_t activate(int32_t sensorHandle, bool enabled) = 0;
62
63 virtual status_t batch(int32_t sensorHandle, int64_t samplingPeriodNs,
64 int64_t maxReportLatencyNs) = 0;
65
66 virtual status_t flush(int32_t sensorHandle) = 0;
67
68 virtual status_t injectSensorData(const sensors_event_t *event) = 0;
69
70 virtual status_t registerDirectChannel(const sensors_direct_mem_t *memory,
71 int32_t *channelHandle) = 0;
72
73 virtual void unregisterDirectChannel(int32_t channelHandle) = 0;
74
75 virtual status_t configureDirectChannel(int32_t sensorHandle, int32_t channelHandle,
76 const struct sensors_direct_cfg_t *config) = 0;
77}
78
79} // namespace android
80
81#endif // ANDROID_ISENSOR_HAL_WRAPPER_H