1 /* 2 * Copyright (C) 2020 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_HARDWARE_SENSORS_V2_1_H 18 #define ANDROID_HARDWARE_SENSORS_V2_1_H 19 20 #include "Sensors.h" 21 22 #include "EventMessageQueueWrapper.h" 23 24 #include <android/hardware/sensors/2.1/ISensors.h> 25 26 namespace android { 27 namespace hardware { 28 namespace sensors { 29 namespace V2_1 { 30 namespace implementation { 31 32 using Result = ::android::hardware::sensors::V1_0::Result; 33 using Sensors = ::android::hardware::sensors::V2_X::implementation::Sensors<ISensors>; 34 35 class ISensorsCallbackWrapper : public V2_0::ISensorsCallback { 36 public: ISensorsCallbackWrapper(const sp<V2_1::ISensorsCallback> & callback)37 ISensorsCallbackWrapper(const sp<V2_1::ISensorsCallback>& callback) : mCallback(callback) {} 38 onDynamicSensorsConnected(const hidl_vec<V1_0::SensorInfo> & sensorInfos)39 Return<void> onDynamicSensorsConnected(const hidl_vec<V1_0::SensorInfo>& sensorInfos) override { 40 return mCallback->onDynamicSensorsConnected_2_1(convertToNewSensorInfos(sensorInfos)); 41 } 42 onDynamicSensorsDisconnected(const hidl_vec<int32_t> & sensorHandles)43 Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& sensorHandles) override { 44 return mCallback->onDynamicSensorsDisconnected(sensorHandles); 45 } 46 47 private: 48 sp<V2_1::ISensorsCallback> mCallback; 49 }; 50 51 struct SensorsV2_1 : public Sensors { 52 SensorsV2_1(); 53 54 // Methods from ::android::hardware::sensors::V2_1::ISensors follow. 55 Return<void> getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) override; 56 57 Return<void> getSensorsListSensorsV2_158 getSensorsList(V2_0::ISensors::getSensorsList_cb _hidl_cb) override { 59 std::vector<V1_0::SensorInfo> sensors; 60 for (const auto &sensor : mSensors) { 61 auto &info = sensor.second->getSensorInfo(); 62 if (info.type != SensorType::HINGE_ANGLE) { 63 sensors.push_back(V2_1::implementation::convertToOldSensorInfo( 64 sensor.second->getSensorInfo())); 65 } 66 } 67 68 // Call the HIDL callback with the SensorInfo 69 _hidl_cb(sensors); 70 71 return Void(); 72 } 73 74 Return<Result> initialize_2_1( 75 const ::android::hardware::MQDescriptorSync<V2_1::Event>& eventQueueDescriptor, 76 const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor, 77 const sp<V2_1::ISensorsCallback>& sensorsCallback) override; 78 79 Return<Result> injectSensorData_2_1(const V2_1::Event& event) override; 80 81 private: 82 sp<ISensorsCallbackWrapper> mCallbackWrapper; 83 }; 84 85 } // namespace implementation 86 } // namespace V2_1 87 } // namespace sensors 88 } // namespace hardware 89 } // namespace android 90 91 #endif // ANDROID_HARDWARE_SENSORS_V2_1_H 92