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 #pragma once 18 19 #include <android/hardware/gnss/2.1/IGnss.h> 20 #include "GnssCallbackEventQueue.h" 21 22 #include <gtest/gtest.h> 23 24 using android::hardware::hidl_vec; 25 using android::hardware::Return; 26 using android::hardware::Void; 27 28 using android::hardware::gnss::common::GnssCallbackEventQueue; 29 using android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrectionsCallback; 30 using android::hardware::gnss::V1_0::GnssLocationFlags; 31 using android::hardware::gnss::V2_0::GnssConstellationType; 32 33 using GnssLocation_1_0 = android::hardware::gnss::V1_0::GnssLocation; 34 using GnssLocation_2_0 = android::hardware::gnss::V2_0::GnssLocation; 35 36 using IGnssCallback_1_0 = android::hardware::gnss::V1_0::IGnssCallback; 37 using IGnssCallback_2_0 = android::hardware::gnss::V2_0::IGnssCallback; 38 using IGnssCallback_2_1 = android::hardware::gnss::V2_1::IGnssCallback; 39 40 using IGnssMeasurementCallback_1_0 = android::hardware::gnss::V1_0::IGnssMeasurementCallback; 41 using IGnssMeasurementCallback_1_1 = android::hardware::gnss::V1_1::IGnssMeasurementCallback; 42 using IGnssMeasurementCallback_2_0 = android::hardware::gnss::V2_0::IGnssMeasurementCallback; 43 using IGnssMeasurementCallback_2_1 = android::hardware::gnss::V2_1::IGnssMeasurementCallback; 44 45 using android::sp; 46 47 #define TIMEOUT_SEC 2 // for basic commands/responses 48 49 namespace android::hardware::gnss::common { 50 51 /* Callback class for data & Event. */ 52 class GnssCallback : public IGnssCallback_2_1 { 53 public: 54 IGnssCallback_1_0::GnssSystemInfo last_info_; 55 android::hardware::hidl_string last_name_; 56 uint32_t last_capabilities_; 57 GnssLocation_2_0 last_location_; 58 59 GnssCallbackEventQueue<IGnssCallback_1_0::GnssSystemInfo> info_cbq_; 60 GnssCallbackEventQueue<android::hardware::hidl_string> name_cbq_; 61 GnssCallbackEventQueue<uint32_t> capabilities_cbq_; 62 GnssCallbackEventQueue<GnssLocation_2_0> location_cbq_; 63 GnssCallbackEventQueue<hidl_vec<IGnssCallback_2_1::GnssSvInfo>> sv_info_list_cbq_; 64 65 GnssCallback(); 66 virtual ~GnssCallback() = default; 67 68 // Dummy callback handlers gnssStatusCb(const IGnssCallback_1_0::GnssStatusValue)69 Return<void> gnssStatusCb(const IGnssCallback_1_0::GnssStatusValue /* status */) override { 70 return Void(); 71 } gnssNmeaCb(int64_t,const android::hardware::hidl_string &)72 Return<void> gnssNmeaCb(int64_t /* timestamp */, 73 const android::hardware::hidl_string& /* nmea */) override { 74 return Void(); 75 } gnssAcquireWakelockCb()76 Return<void> gnssAcquireWakelockCb() override { return Void(); } gnssReleaseWakelockCb()77 Return<void> gnssReleaseWakelockCb() override { return Void(); } gnssRequestLocationCb(bool)78 Return<void> gnssRequestLocationCb(bool /* independentFromGnss */) override { return Void(); } gnssRequestTimeCb()79 Return<void> gnssRequestTimeCb() override { return Void(); } 80 // Actual (test) callback handlers 81 Return<void> gnssNameCb(const android::hardware::hidl_string& name) override; 82 Return<void> gnssLocationCb(const GnssLocation_1_0& location) override; 83 Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override; 84 Return<void> gnssSetSystemInfoCb(const IGnssCallback_1_0::GnssSystemInfo& info) override; 85 Return<void> gnssSvStatusCb(const IGnssCallback_1_0::GnssSvStatus& svStatus) override; 86 87 // New in v2.0 88 Return<void> gnssLocationCb_2_0(const GnssLocation_2_0& location) override; gnssRequestLocationCb_2_0(bool,bool)89 Return<void> gnssRequestLocationCb_2_0(bool /* independentFromGnss */, 90 bool /* isUserEmergency */) override { 91 return Void(); 92 } 93 Return<void> gnssSetCapabilitiesCb_2_0(uint32_t capabilities) override; gnssSvStatusCb_2_0(const hidl_vec<IGnssCallback_2_0::GnssSvInfo> &)94 Return<void> gnssSvStatusCb_2_0(const hidl_vec<IGnssCallback_2_0::GnssSvInfo>&) override { 95 return Void(); 96 } 97 98 // New in v2.1 99 Return<void> gnssSvStatusCb_2_1( 100 const hidl_vec<IGnssCallback_2_1::GnssSvInfo>& svInfoList) override; 101 Return<void> gnssSetCapabilitiesCb_2_1(uint32_t capabilities) override; 102 103 private: 104 Return<void> gnssLocationCbImpl(const GnssLocation_2_0& location); 105 }; 106 107 } // namespace android::hardware::gnss::common 108