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<Result> initialize_2_1( 58 const ::android::hardware::MQDescriptorSync<V2_1::Event>& eventQueueDescriptor, 59 const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor, 60 const sp<V2_1::ISensorsCallback>& sensorsCallback) override; 61 62 Return<Result> injectSensorData_2_1(const V2_1::Event& event) override; 63 64 private: 65 sp<ISensorsCallbackWrapper> mCallbackWrapper; 66 }; 67 68 } // namespace implementation 69 } // namespace V2_1 70 } // namespace sensors 71 } // namespace hardware 72 } // namespace android 73 74 #endif // ANDROID_HARDWARE_SENSORS_V2_1_H