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 #pragma once
18 
19 #include <aidl/android/hardware/gnss/BnGnssConfiguration.h>
20 #include <android/hardware/gnss/2.1/IGnssCallback.h>
21 #include <mutex>
22 #include <unordered_set>
23 #include <vector>
24 
25 namespace aidl::android::hardware::gnss {
26 
27 struct BlocklistedSourceHash {
operatorBlocklistedSourceHash28     inline int operator()(const BlocklistedSource& source) const {
29         return int(source.constellation) * 1000 + int(source.svid);
30     }
31 };
32 
33 struct BlocklistedSourceEqual {
operatorBlocklistedSourceEqual34     inline bool operator()(const BlocklistedSource& s1, const BlocklistedSource& s2) const {
35         return (s1.constellation == s2.constellation) && (s1.svid == s2.svid);
36     }
37 };
38 
39 using GnssSvInfoV2_1 = ::android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo;
40 using std::vector;
41 using BlocklistedSourceSet =
42         std::unordered_set<BlocklistedSource, BlocklistedSourceHash, BlocklistedSourceEqual>;
43 using BlocklistedConstellationSet =
44         std::unordered_set<android::hardware::gnss::GnssConstellationType>;
45 
46 struct GnssConfiguration : public BnGnssConfiguration {
47   public:
setSuplVersionGnssConfiguration48     ndk::ScopedAStatus setSuplVersion(int) override { return ndk::ScopedAStatus::ok(); }
49 
setSuplModeGnssConfiguration50     ndk::ScopedAStatus setSuplMode(int) override { return ndk::ScopedAStatus::ok(); }
51 
setLppProfileGnssConfiguration52     ndk::ScopedAStatus setLppProfile(int) override { return ndk::ScopedAStatus::ok(); }
53 
setGlonassPositioningProtocolGnssConfiguration54     ndk::ScopedAStatus setGlonassPositioningProtocol(int) override {
55         return ndk::ScopedAStatus::ok();
56     }
57 
setEmergencySuplPdnGnssConfiguration58     ndk::ScopedAStatus setEmergencySuplPdn(bool) override { return ndk::ScopedAStatus::ok(); }
59 
setEsExtensionSecGnssConfiguration60     ndk::ScopedAStatus setEsExtensionSec(int) override { return ndk::ScopedAStatus::ok(); }
61 
62     ndk::ScopedAStatus setBlocklist(const vector<BlocklistedSource>& blocklist) override;
63 
64     bool isBlocklistedV2_1(const GnssSvInfoV2_1& gnssSvInfo) const;
65 
66   private:
67     BlocklistedSourceSet mBlocklistedSourceSet;
68     BlocklistedConstellationSet mBlocklistedConstellationSet;
69     mutable std::recursive_mutex mMutex;
70 };
71 
72 }  // namespace aidl::android::hardware::gnss
73