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 #define LOG_TAG "GnssCallback"
18 
19 #include "v2_1/GnssCallback.h"
20 #include <chrono>
21 #include "Utils.h"
22 
23 #include <gtest/gtest.h>
24 
25 using ::android::hardware::gnss::common::Utils;
26 
27 namespace android::hardware::gnss::common {
28 
GnssCallback()29 GnssCallback::GnssCallback()
30     : info_cbq_("system_info"),
31       name_cbq_("name"),
32       capabilities_cbq_("capabilities"),
33       location_cbq_("location"),
34       sv_info_list_cbq_("sv_info") {}
35 
gnssSetSystemInfoCb(const IGnssCallback_1_0::GnssSystemInfo & info)36 Return<void> GnssCallback::gnssSetSystemInfoCb(const IGnssCallback_1_0::GnssSystemInfo& info) {
37     ALOGI("Info received, year %d", info.yearOfHw);
38     info_cbq_.store(info);
39     return Void();
40 }
41 
gnssSetCapabilitesCb(uint32_t capabilities)42 Return<void> GnssCallback::gnssSetCapabilitesCb(uint32_t capabilities) {
43     ALOGI("Capabilities received %d", capabilities);
44     capabilities_cbq_.store(capabilities);
45     return Void();
46 }
47 
gnssSetCapabilitiesCb_2_0(uint32_t capabilities)48 Return<void> GnssCallback::gnssSetCapabilitiesCb_2_0(uint32_t capabilities) {
49     ALOGI("Capabilities (v2.0) received %d", capabilities);
50     capabilities_cbq_.store(capabilities);
51     return Void();
52 }
53 
gnssSetCapabilitiesCb_2_1(uint32_t capabilities)54 Return<void> GnssCallback::gnssSetCapabilitiesCb_2_1(uint32_t capabilities) {
55     ALOGI("Capabilities (v2.1) received %d", capabilities);
56     capabilities_cbq_.store(capabilities);
57     return Void();
58 }
59 
gnssNameCb(const android::hardware::hidl_string & name)60 Return<void> GnssCallback::gnssNameCb(const android::hardware::hidl_string& name) {
61     ALOGI("Name received: %s", name.c_str());
62     name_cbq_.store(name);
63     return Void();
64 }
65 
gnssLocationCb(const GnssLocation_1_0 & location)66 Return<void> GnssCallback::gnssLocationCb(const GnssLocation_1_0& location) {
67     ALOGI("Location received");
68     GnssLocation_2_0 location_v2_0;
69     location_v2_0.v1_0 = location;
70     return gnssLocationCbImpl(location_v2_0);
71 }
72 
gnssLocationCb_2_0(const GnssLocation_2_0 & location)73 Return<void> GnssCallback::gnssLocationCb_2_0(const GnssLocation_2_0& location) {
74     ALOGI("Location (v2.0) received");
75     return gnssLocationCbImpl(location);
76 }
77 
gnssLocationCbImpl(const GnssLocation_2_0 & location)78 Return<void> GnssCallback::gnssLocationCbImpl(const GnssLocation_2_0& location) {
79     location_cbq_.store(location);
80     return Void();
81 }
82 
gnssSvStatusCb(const IGnssCallback_1_0::GnssSvStatus &)83 Return<void> GnssCallback::gnssSvStatusCb(const IGnssCallback_1_0::GnssSvStatus&) {
84     ALOGI("gnssSvStatusCb");
85     return Void();
86 }
87 
gnssSvStatusCb_2_1(const hidl_vec<IGnssCallback::GnssSvInfo> & svInfoList)88 Return<void> GnssCallback::gnssSvStatusCb_2_1(
89         const hidl_vec<IGnssCallback::GnssSvInfo>& svInfoList) {
90     ALOGI("gnssSvStatusCb_2_1. Size = %d", (int)svInfoList.size());
91     sv_info_list_cbq_.store(svInfoList);
92     return Void();
93 }
94 
95 }  // namespace android::hardware::gnss::common
96