Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 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 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 19 | #include <aidl/android/hardware/gnss/BnGnssCallback.h> |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 20 | #include <aidl/android/hardware/gnss/BnGnssConfiguration.h> |
| 21 | #include <android/hardware/gnss/2.1/IGnssCallback.h> |
| 22 | #include <mutex> |
| 23 | #include <unordered_set> |
| 24 | #include <vector> |
| 25 | |
| 26 | namespace aidl::android::hardware::gnss { |
| 27 | |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 28 | struct BlocklistedSourceHash { |
| 29 | inline int operator()(const BlocklistedSource& source) const { |
| 30 | return int(source.constellation) * 1000 + int(source.svid); |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | struct BlocklistedSourceEqual { |
| 35 | inline bool operator()(const BlocklistedSource& s1, const BlocklistedSource& s2) const { |
| 36 | return (s1.constellation == s2.constellation) && (s1.svid == s2.svid); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | using GnssSvInfoV2_1 = ::android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo; |
| 41 | using std::vector; |
| 42 | using BlocklistedSourceSet = |
| 43 | std::unordered_set<BlocklistedSource, BlocklistedSourceHash, BlocklistedSourceEqual>; |
Yu-Han Yang | 0483230 | 2020-11-20 09:51:18 -0800 | [diff] [blame] | 44 | using BlocklistedConstellationSet = |
| 45 | std::unordered_set<android::hardware::gnss::GnssConstellationType>; |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 46 | |
| 47 | struct GnssConfiguration : public BnGnssConfiguration { |
| 48 | public: |
| 49 | ndk::ScopedAStatus setSuplVersion(int) override { return ndk::ScopedAStatus::ok(); } |
| 50 | |
| 51 | ndk::ScopedAStatus setSuplMode(int) override { return ndk::ScopedAStatus::ok(); } |
| 52 | |
| 53 | ndk::ScopedAStatus setLppProfile(int) override { return ndk::ScopedAStatus::ok(); } |
| 54 | |
| 55 | ndk::ScopedAStatus setGlonassPositioningProtocol(int) override { |
| 56 | return ndk::ScopedAStatus::ok(); |
| 57 | } |
| 58 | |
| 59 | ndk::ScopedAStatus setEmergencySuplPdn(bool) override { return ndk::ScopedAStatus::ok(); } |
| 60 | |
| 61 | ndk::ScopedAStatus setEsExtensionSec(int) override { return ndk::ScopedAStatus::ok(); } |
| 62 | |
| 63 | ndk::ScopedAStatus setBlocklist(const vector<BlocklistedSource>& blocklist) override; |
| 64 | |
| 65 | bool isBlocklistedV2_1(const GnssSvInfoV2_1& gnssSvInfo) const; |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 66 | bool isBlocklisted(const IGnssCallback::GnssSvInfo& gnssSvInfo) const; |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 67 | |
| 68 | private: |
| 69 | BlocklistedSourceSet mBlocklistedSourceSet; |
| 70 | BlocklistedConstellationSet mBlocklistedConstellationSet; |
| 71 | mutable std::recursive_mutex mMutex; |
| 72 | }; |
| 73 | |
| 74 | } // namespace aidl::android::hardware::gnss |