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