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 #include <aidl/android/hardware/gnss/IGnss.h>
18 #include <debug.h>
19 #include "GnssConfiguration.h"
20 
21 namespace aidl {
22 namespace android {
23 namespace hardware {
24 namespace gnss {
25 namespace implementation {
26 
setSuplVersion(int)27 ndk::ScopedAStatus GnssConfiguration::setSuplVersion(int /*version*/) {
28     return ndk::ScopedAStatus::ok();
29 }
30 
setSuplMode(int)31 ndk::ScopedAStatus GnssConfiguration::setSuplMode(int /*mode*/) {
32     return ndk::ScopedAStatus::ok();
33 }
34 
setLppProfile(int)35 ndk::ScopedAStatus GnssConfiguration::setLppProfile(int /*lppProfile*/) {
36     return ndk::ScopedAStatus::ok();
37 }
38 
setGlonassPositioningProtocol(int)39 ndk::ScopedAStatus GnssConfiguration::setGlonassPositioningProtocol(int /*protocol*/) {
40     return ndk::ScopedAStatus::ok();
41 }
42 
setEmergencySuplPdn(bool)43 ndk::ScopedAStatus GnssConfiguration::setEmergencySuplPdn(bool /*enable*/) {
44     return ndk::ScopedAStatus::ok();
45 }
46 
setEsExtensionSec(int)47 ndk::ScopedAStatus GnssConfiguration::setEsExtensionSec(int /*emergencyExtensionSeconds*/) {
48     return ndk::ScopedAStatus::ok();
49 }
50 
setBlocklist(const std::vector<BlocklistedSource> & blocklist)51 ndk::ScopedAStatus GnssConfiguration::setBlocklist(const std::vector<BlocklistedSource>& blocklist) {
52     BlocklistedSources blockset;
53 
54     for (const BlocklistedSource& src : blocklist) {
55         if (!blockset.insert(src).second) {
56             return ndk::ScopedAStatus::fromExceptionCode(FAILURE(IGnss::ERROR_INVALID_ARGUMENT));
57         }
58     }
59 
60     std::lock_guard<std::mutex> lock(mMtx);
61     mBlocklistedSources = std::move(blockset);
62     return ndk::ScopedAStatus::ok();
63 }
64 
isBlocklisted(const GnssConstellationType constellation,const int svid) const65 bool GnssConfiguration::isBlocklisted(const GnssConstellationType constellation,
66                                       const int svid) const {
67     std::lock_guard<std::mutex> lock(mMtx);
68 
69     BlocklistedSource src;
70     src.constellation = constellation;
71     src.svid = svid;
72 
73     if (mBlocklistedSources.count(src) != 0) {
74         return true;
75     }
76 
77     src.svid = 0;
78     return mBlocklistedSources.count(src) != 0;
79 }
80 
operator ()(const BlocklistedSource & x) const81 size_t GnssConfiguration::BlocklistedSourceHasher::operator()(
82         const BlocklistedSource& x) const noexcept {
83     return size_t(x.constellation) * 999983 + size_t(x.svid) * 999979;
84 }
85 
operator ()(const BlocklistedSource & lhs,const BlocklistedSource & rhs) const86 bool GnssConfiguration::BlocklistedSourceEqual::operator()(
87         const BlocklistedSource& lhs, const BlocklistedSource& rhs) const noexcept {
88     return (lhs.constellation == rhs.constellation) && (lhs.svid == rhs.svid);
89 }
90 
91 }  // namespace implementation
92 }  // namespace gnss
93 }  // namespace hardware
94 }  // namespace android
95 }  // namespace aidl
96