blob: 560834f5f3de36a3169decfb73dc89c359e70b55 [file] [log] [blame]
Mathias Agopianf001c922010-11-11 17:58:51 -08001/*
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
Peng Xu755c4512016-04-07 23:15:14 -070017#include "SensorInterface.h"
18#include "SensorDevice.h"
19#include "SensorFusion.h"
Andrew Lehmer3a602572021-03-25 15:19:56 -070020#include "SensorService.h"
Peng Xu755c4512016-04-07 23:15:14 -070021
Mathias Agopianf001c922010-11-11 17:58:51 -080022#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopianf001c922010-11-11 17:58:51 -080025namespace android {
26// ---------------------------------------------------------------------------
27
Peng Xu755c4512016-04-07 23:15:14 -070028namespace {
29const sensor_t DUMMY_SENSOR = {
30 .name = "", .vendor = "", .stringType = "", .requiredPermission = ""};
31} //unnamed namespace
32
33BaseSensor::BaseSensor(const sensor_t& sensor) :
34 mSensorDevice(SensorDevice::getInstance()),
35 mSensor(&sensor, mSensorDevice.getHalDeviceVersion()) {
Mathias Agopianf001c922010-11-11 17:58:51 -080036}
37
Peng Xu6a2d3a02015-12-21 12:00:23 -080038BaseSensor::BaseSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]) :
39 mSensorDevice(SensorDevice::getInstance()),
40 mSensor(sensor, Sensor::uuid_t(uuid), mSensorDevice.getHalDeviceVersion()) {
41}
42
Mathias Agopianf001c922010-11-11 17:58:51 -080043// ---------------------------------------------------------------------------
44
Peng Xu755c4512016-04-07 23:15:14 -070045HardwareSensor::HardwareSensor(const sensor_t& sensor):
46 BaseSensor(sensor) {
Mathias Agopianf001c922010-11-11 17:58:51 -080047}
48
Peng Xu6a2d3a02015-12-21 12:00:23 -080049HardwareSensor::HardwareSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]):
50 BaseSensor(sensor, uuid) {
51}
52
Mathias Agopianf001c922010-11-11 17:58:51 -080053HardwareSensor::~HardwareSensor() {
54}
55
56bool HardwareSensor::process(sensors_event_t* outEvent,
57 const sensors_event_t& event) {
58 *outEvent = event;
59 return true;
60}
61
Mathias Agopian50b66762010-11-29 17:26:51 -080062status_t HardwareSensor::activate(void* ident, bool enabled) {
63 return mSensorDevice.activate(ident, mSensor.getHandle(), enabled);
Mathias Agopianf001c922010-11-11 17:58:51 -080064}
65
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070066status_t HardwareSensor::batch(void* ident, int /*handle*/, int flags,
Aravind Akella724d91d2013-06-27 12:04:23 -070067 int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs) {
68 return mSensorDevice.batch(ident, mSensor.getHandle(), flags, samplingPeriodNs,
69 maxBatchReportLatencyNs);
70}
71
72status_t HardwareSensor::flush(void* ident, int handle) {
73 return mSensorDevice.flush(ident, handle);
74}
75
Mathias Agopianf001c922010-11-11 17:58:51 -080076status_t HardwareSensor::setDelay(void* ident, int handle, int64_t ns) {
77 return mSensorDevice.setDelay(ident, handle, ns);
78}
79
Mathias Agopianac9a96d2013-07-12 02:01:16 -070080void HardwareSensor::autoDisable(void *ident, int handle) {
81 mSensorDevice.autoDisable(ident, handle);
Jaikumar Ganesh4c01b1a2013-04-16 15:52:23 -070082}
83
Peng Xu755c4512016-04-07 23:15:14 -070084VirtualSensor::VirtualSensor() :
85 BaseSensor(DUMMY_SENSOR), mSensorFusion(SensorFusion::getInstance()) {
Mathias Agopianf001c922010-11-11 17:58:51 -080086}
87
Mathias Agopianf001c922010-11-11 17:58:51 -080088// ---------------------------------------------------------------------------
Andrew Lehmer3a602572021-03-25 15:19:56 -070089
90ProximitySensor::ProximitySensor(const sensor_t& sensor, SensorService& service)
91 : HardwareSensor(sensor), mSensorService(service) {
92}
93
94status_t ProximitySensor::activate(void* ident, bool enabled) {
95 bool wasActive = mActive;
96 status_t status = HardwareSensor::activate(ident, enabled);
97 if (status != NO_ERROR) {
98 return status;
99 }
100 mActive = enabled;
101 if (wasActive != enabled) {
102 mSensorService.onProximityActiveLocked(enabled);
103 }
104 return NO_ERROR;
105}
106
107void ProximitySensor::willDisableAllSensors() {
108 if (mSensorDevice.isSensorActive(mSensor.getHandle())) {
109 mSensorService.onProximityActiveLocked(false);
110 }
111}
112
113void ProximitySensor::didEnableAllSensors() {
114 if (mSensorDevice.isSensorActive(mSensor.getHandle())) {
115 mSensorService.onProximityActiveLocked(true);
116 }
117}
118
119// ---------------------------------------------------------------------------
Mathias Agopianf001c922010-11-11 17:58:51 -0800120}; // namespace android