blob: 9fea6479899593e70246560ffa73f55d1036289c [file] [log] [blame]
Brian Stack60fcdcf2018-10-16 14:51:34 -07001/*
2 * Copyright (C) 2018 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#include "Sensors.h"
18
Brian Stack475d4d42018-10-19 15:58:09 -070019#include <log/log.h>
20
Brian Stack60fcdcf2018-10-16 14:51:34 -070021namespace android {
22namespace hardware {
23namespace sensors {
24namespace V2_0 {
25namespace implementation {
26
27using ::android::hardware::sensors::V1_0::Event;
28using ::android::hardware::sensors::V1_0::OperationMode;
29using ::android::hardware::sensors::V1_0::RateLevel;
30using ::android::hardware::sensors::V1_0::Result;
31using ::android::hardware::sensors::V1_0::SharedMemInfo;
32
Brian Stack475d4d42018-10-19 15:58:09 -070033Sensors::Sensors() : mEventQueueFlag(nullptr) {}
34
35Sensors::~Sensors() {
36 deleteEventFlag();
37}
38
Brian Stack60fcdcf2018-10-16 14:51:34 -070039// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
40Return<void> Sensors::getSensorsList(getSensorsList_cb /* _hidl_cb */) {
41 // TODO implement
42 return Void();
43}
44
45Return<Result> Sensors::setOperationMode(OperationMode /* mode */) {
46 // TODO implement
47 return Result{};
48}
49
50Return<Result> Sensors::activate(int32_t /* sensorHandle */, bool /* enabled */) {
51 // TODO implement
52 return Result{};
53}
54
55Return<Result> Sensors::initialize(
Brian Stack475d4d42018-10-19 15:58:09 -070056 const ::android::hardware::MQDescriptorSync<Event>& eventQueueDescriptor,
57 const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
58 const sp<ISensorsCallback>& sensorsCallback) {
59 Result result = Result::OK;
60
61 // Save a reference to the callback
62 mCallback = sensorsCallback;
63
64 // Create the Event FMQ from the eventQueueDescriptor. Reset the read/write positions.
65 mEventQueue =
66 std::make_unique<EventMessageQueue>(eventQueueDescriptor, true /* resetPointers */);
67
68 // Ensure that any existing EventFlag is properly deleted
69 deleteEventFlag();
70
71 // Create the EventFlag that is used to signal to the framework that sensor events have been
72 // written to the Event FMQ
73 if (EventFlag::createEventFlag(mEventQueue->getEventFlagWord(), &mEventQueueFlag) != OK) {
74 result = Result::BAD_VALUE;
75 }
76
77 // Create the Wake Lock FMQ that is used by the framework to communicate whenever WAKE_UP
78 // events have been successfully read and handled by the framework.
79 mWakeLockQueue =
80 std::make_unique<WakeLockMessageQueue>(wakeLockDescriptor, true /* resetPointers */);
81
82 if (!mCallback || !mEventQueue || !mWakeLockQueue || mEventQueueFlag == nullptr) {
83 result = Result::BAD_VALUE;
84 }
85
86 return result;
Brian Stack60fcdcf2018-10-16 14:51:34 -070087}
88
89Return<Result> Sensors::batch(int32_t /* sensorHandle */, int64_t /* samplingPeriodNs */,
90 int64_t /* maxReportLatencyNs */) {
91 // TODO implement
92 return Result{};
93}
94
95Return<Result> Sensors::flush(int32_t /* sensorHandle */) {
96 // TODO implement
97 return Result{};
98}
99
100Return<Result> Sensors::injectSensorData(const Event& /* event */) {
101 // TODO implement
102 return Result{};
103}
104
105Return<void> Sensors::registerDirectChannel(const SharedMemInfo& /* mem */,
Brian Stack9a407f22018-10-19 16:04:11 -0700106 registerDirectChannel_cb _hidl_cb) {
107 _hidl_cb(Result::INVALID_OPERATION, 0 /* channelHandle */);
108 return Return<void>();
Brian Stack60fcdcf2018-10-16 14:51:34 -0700109}
110
111Return<Result> Sensors::unregisterDirectChannel(int32_t /* channelHandle */) {
Brian Stack9a407f22018-10-19 16:04:11 -0700112 return Result::INVALID_OPERATION;
Brian Stack60fcdcf2018-10-16 14:51:34 -0700113}
114
115Return<void> Sensors::configDirectReport(int32_t /* sensorHandle */, int32_t /* channelHandle */,
Brian Stack9a407f22018-10-19 16:04:11 -0700116 RateLevel /* rate */, configDirectReport_cb _hidl_cb) {
117 _hidl_cb(Result::INVALID_OPERATION, 0 /* reportToken */);
118 return Return<void>();
Brian Stack60fcdcf2018-10-16 14:51:34 -0700119}
120
Brian Stack475d4d42018-10-19 15:58:09 -0700121void Sensors::deleteEventFlag() {
122 status_t status = EventFlag::deleteEventFlag(&mEventQueueFlag);
123 if (status != OK) {
124 ALOGI("Failed to delete event flag: %d", status);
125 }
126}
127
Brian Stack60fcdcf2018-10-16 14:51:34 -0700128} // namespace implementation
129} // namespace V2_0
130} // namespace sensors
131} // namespace hardware
132} // namespace android