1 /*
2  * Copyright (C) 2019 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 "GnssConfiguration"
18 
19 #include "v2_1/GnssConfiguration.h"
20 #include <log/log.h>
21 
22 namespace android::hardware::gnss::V2_1::implementation {
23 
24 using GnssSvInfoV2_1 = V2_1::IGnssCallback::GnssSvInfo;
25 using BlacklistedSourceV2_1 = V2_1::IGnssConfiguration::BlacklistedSource;
26 
27 // Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow.
setSuplEs(bool enable)28 Return<bool> GnssConfiguration::setSuplEs(bool enable) {
29     ALOGD("setSuplEs enable: %d", enable);
30     // Method deprecated in 2.0 and not expected to be called by the framework.
31     return false;
32 }
33 
setSuplVersion(uint32_t)34 Return<bool> GnssConfiguration::setSuplVersion(uint32_t) {
35     return true;
36 }
37 
setSuplMode(hidl_bitfield<SuplMode>)38 Return<bool> GnssConfiguration::setSuplMode(hidl_bitfield<SuplMode>) {
39     return true;
40 }
41 
setGpsLock(hidl_bitfield<GpsLock> gpsLock)42 Return<bool> GnssConfiguration::setGpsLock(hidl_bitfield<GpsLock> gpsLock) {
43     ALOGD("setGpsLock gpsLock: %hhu", static_cast<GpsLock>(gpsLock));
44     // Method deprecated in 2.0 and not expected to be called by the framework.
45     return false;
46 }
47 
setLppProfile(hidl_bitfield<LppProfile>)48 Return<bool> GnssConfiguration::setLppProfile(hidl_bitfield<LppProfile>) {
49     return true;
50 }
51 
setGlonassPositioningProtocol(hidl_bitfield<GlonassPosProtocol>)52 Return<bool> GnssConfiguration::setGlonassPositioningProtocol(hidl_bitfield<GlonassPosProtocol>) {
53     return true;
54 }
55 
setEmergencySuplPdn(bool)56 Return<bool> GnssConfiguration::setEmergencySuplPdn(bool) {
57     return true;
58 }
59 
60 // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow.
setBlacklist(const hidl_vec<V1_1::IGnssConfiguration::BlacklistedSource> &)61 Return<bool> GnssConfiguration::setBlacklist(
62         const hidl_vec<V1_1::IGnssConfiguration::BlacklistedSource>&) {
63     // TODO (b/122463906): Reuse 1.1 implementation.
64     return bool{};
65 }
66 
67 // Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow.
setEsExtensionSec(uint32_t emergencyExtensionSeconds)68 Return<bool> GnssConfiguration::setEsExtensionSec(uint32_t emergencyExtensionSeconds) {
69     ALOGD("setEsExtensionSec emergencyExtensionSeconds: %d", emergencyExtensionSeconds);
70     return true;
71 }
72 
73 // Methods from ::android::hardware::gnss::V2_1::IGnssConfiguration follow.
setBlacklist_2_1(const hidl_vec<BlacklistedSourceV2_1> & sourceList)74 Return<bool> GnssConfiguration::setBlacklist_2_1(
75         const hidl_vec<BlacklistedSourceV2_1>& sourceList) {
76     std::unique_lock<std::recursive_mutex> lock(mMutex);
77     mBlacklistedConstellationSet.clear();
78     mBlacklistedSourceSet.clear();
79     for (auto source : sourceList) {
80         if (source.svid == 0) {
81             // Wildcard blacklist, i.e., blacklist entire constellation.
82             mBlacklistedConstellationSet.insert(source.constellation);
83         } else {
84             mBlacklistedSourceSet.insert(source);
85         }
86     }
87     return true;
88 }
89 
isBlacklistedV2_1(const GnssSvInfoV2_1 & gnssSvInfo) const90 Return<bool> GnssConfiguration::isBlacklistedV2_1(const GnssSvInfoV2_1& gnssSvInfo) const {
91     std::unique_lock<std::recursive_mutex> lock(mMutex);
92     if (mBlacklistedConstellationSet.find(gnssSvInfo.v2_0.constellation) !=
93         mBlacklistedConstellationSet.end()) {
94         return true;
95     }
96     BlacklistedSourceV2_1 source = {.constellation = gnssSvInfo.v2_0.constellation,
97                                     .svid = gnssSvInfo.v2_0.v1_0.svid};
98     return (mBlacklistedSourceSet.find(source) != mBlacklistedSourceSet.end());
99 }
100 
101 }  // namespace android::hardware::gnss::V2_1::implementation
102