Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 1 | /* |
| 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 Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame] | 19 | #include <log/log.h> |
| 20 | |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 21 | namespace android { |
| 22 | namespace hardware { |
| 23 | namespace sensors { |
| 24 | namespace V2_0 { |
| 25 | namespace implementation { |
| 26 | |
| 27 | using ::android::hardware::sensors::V1_0::Event; |
| 28 | using ::android::hardware::sensors::V1_0::OperationMode; |
| 29 | using ::android::hardware::sensors::V1_0::RateLevel; |
| 30 | using ::android::hardware::sensors::V1_0::Result; |
| 31 | using ::android::hardware::sensors::V1_0::SharedMemInfo; |
| 32 | |
Brian Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame] | 33 | Sensors::Sensors() : mEventQueueFlag(nullptr) {} |
| 34 | |
| 35 | Sensors::~Sensors() { |
| 36 | deleteEventFlag(); |
| 37 | } |
| 38 | |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 39 | // Methods from ::android::hardware::sensors::V2_0::ISensors follow. |
| 40 | Return<void> Sensors::getSensorsList(getSensorsList_cb /* _hidl_cb */) { |
| 41 | // TODO implement |
| 42 | return Void(); |
| 43 | } |
| 44 | |
| 45 | Return<Result> Sensors::setOperationMode(OperationMode /* mode */) { |
| 46 | // TODO implement |
| 47 | return Result{}; |
| 48 | } |
| 49 | |
| 50 | Return<Result> Sensors::activate(int32_t /* sensorHandle */, bool /* enabled */) { |
| 51 | // TODO implement |
| 52 | return Result{}; |
| 53 | } |
| 54 | |
| 55 | Return<Result> Sensors::initialize( |
Brian Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame] | 56 | 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 Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | Return<Result> Sensors::batch(int32_t /* sensorHandle */, int64_t /* samplingPeriodNs */, |
| 90 | int64_t /* maxReportLatencyNs */) { |
| 91 | // TODO implement |
| 92 | return Result{}; |
| 93 | } |
| 94 | |
| 95 | Return<Result> Sensors::flush(int32_t /* sensorHandle */) { |
| 96 | // TODO implement |
| 97 | return Result{}; |
| 98 | } |
| 99 | |
| 100 | Return<Result> Sensors::injectSensorData(const Event& /* event */) { |
| 101 | // TODO implement |
| 102 | return Result{}; |
| 103 | } |
| 104 | |
| 105 | Return<void> Sensors::registerDirectChannel(const SharedMemInfo& /* mem */, |
Brian Stack | 9a407f2 | 2018-10-19 16:04:11 -0700 | [diff] [blame^] | 106 | registerDirectChannel_cb _hidl_cb) { |
| 107 | _hidl_cb(Result::INVALID_OPERATION, 0 /* channelHandle */); |
| 108 | return Return<void>(); |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | Return<Result> Sensors::unregisterDirectChannel(int32_t /* channelHandle */) { |
Brian Stack | 9a407f2 | 2018-10-19 16:04:11 -0700 | [diff] [blame^] | 112 | return Result::INVALID_OPERATION; |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | Return<void> Sensors::configDirectReport(int32_t /* sensorHandle */, int32_t /* channelHandle */, |
Brian Stack | 9a407f2 | 2018-10-19 16:04:11 -0700 | [diff] [blame^] | 116 | RateLevel /* rate */, configDirectReport_cb _hidl_cb) { |
| 117 | _hidl_cb(Result::INVALID_OPERATION, 0 /* reportToken */); |
| 118 | return Return<void>(); |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Brian Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame] | 121 | void 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 Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 128 | } // namespace implementation |
| 129 | } // namespace V2_0 |
| 130 | } // namespace sensors |
| 131 | } // namespace hardware |
| 132 | } // namespace android |