blob: 96a1aa2a3ffca8e3ca5b81fb914e89c5cf5ce1a2 [file] [log] [blame]
Yu-Han Yang1e1a6762020-09-30 17:01:53 -07001/*
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 "GnssConfigurationAidl"
18
19#include "GnssConfiguration.h"
20#include <log/log.h>
21
22namespace aidl::android::hardware::gnss {
23
24ndk::ScopedAStatus GnssConfiguration::setBlocklist(const vector<BlocklistedSource>& sourceList) {
25 ALOGD("GnssConfiguration::setBlocklist");
26 std::unique_lock<std::recursive_mutex> lock(mMutex);
27 mBlocklistedConstellationSet.clear();
28 mBlocklistedSourceSet.clear();
29 for (const auto& source : sourceList) {
30 if (source.svid == 0) {
31 // Wildcard blocklist, i.e., blocklist entire constellation.
32 mBlocklistedConstellationSet.insert(source.constellation);
33 } else {
34 mBlocklistedSourceSet.insert(source);
35 }
36 }
37 return ndk::ScopedAStatus::ok();
38}
39
40bool GnssConfiguration::isBlocklistedV2_1(const GnssSvInfoV2_1& gnssSvInfo) const {
41 std::unique_lock<std::recursive_mutex> lock(mMutex);
42 if (mBlocklistedConstellationSet.find(static_cast<GnssConstellationType>(
43 gnssSvInfo.v2_0.constellation)) != mBlocklistedConstellationSet.end()) {
44 return true;
45 }
46 BlocklistedSource source = {
47 .constellation = static_cast<GnssConstellationType>(gnssSvInfo.v2_0.constellation),
48 .svid = gnssSvInfo.v2_0.v1_0.svid};
49 return (mBlocklistedSourceSet.find(source) != mBlocklistedSourceSet.end());
50}
51
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080052bool GnssConfiguration::isBlocklisted(const IGnssCallback::GnssSvInfo& gnssSvInfo) const {
53 std::unique_lock<std::recursive_mutex> lock(mMutex);
54 if (mBlocklistedConstellationSet.find(gnssSvInfo.constellation) !=
55 mBlocklistedConstellationSet.end()) {
56 return true;
57 }
58 BlocklistedSource source = {.constellation = gnssSvInfo.constellation, .svid = gnssSvInfo.svid};
59 return (mBlocklistedSourceSet.find(source) != mBlocklistedSourceSet.end());
60}
61
Yu-Han Yang1e1a6762020-09-30 17:01:53 -070062} // namespace aidl::android::hardware::gnss