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