• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <android/hardware/gnss/2.1/IGnssMeasurement.h>
20 #include <hidl/MQDescriptor.h>
21 #include <hidl/Status.h>
22 #include <atomic>
23 #include <mutex>
24 #include <thread>
25 
26 namespace android {
27 namespace hardware {
28 namespace gnss {
29 namespace V2_1 {
30 namespace implementation {
31 
32 using GnssDataV2_1 = V2_1::IGnssMeasurementCallback::GnssData;
33 using GnssDataV2_0 = V2_0::IGnssMeasurementCallback::GnssData;
34 
35 using ::android::sp;
36 using ::android::hardware::hidl_array;
37 using ::android::hardware::hidl_memory;
38 using ::android::hardware::hidl_string;
39 using ::android::hardware::hidl_vec;
40 using ::android::hardware::Return;
41 using ::android::hardware::Void;
42 
43 struct GnssMeasurement : public IGnssMeasurement {
44     GnssMeasurement();
45     ~GnssMeasurement();
46     // Methods from V1_0::IGnssMeasurement follow.
47     Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback(
48             const sp<V1_0::IGnssMeasurementCallback>& callback) override;
49     Return<void> close() override;
50 
51     // Methods from V1_1::IGnssMeasurement follow.
52     Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_1_1(
53             const sp<V1_1::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
54 
55     // Methods from V2_0::IGnssMeasurement follow.
56     Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_2_0(
57             const sp<V2_0::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
58 
59     // Methods from V2_1::IGnssMeasurement follow.
60     Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_2_1(
61             const sp<V2_1::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
62 
63   private:
64     void start();
65     void stop();
66     void reportMeasurement(const GnssDataV2_0&);
67     void reportMeasurement(const GnssDataV2_1&);
68 
69     // Guarded by mMutex
70     static sp<V2_1::IGnssMeasurementCallback> sCallback_2_1;
71 
72     // Guarded by mMutex
73     static sp<V2_0::IGnssMeasurementCallback> sCallback_2_0;
74 
75     std::atomic<long> mMinIntervalMillis;
76     std::atomic<bool> mIsActive;
77     std::thread mThread;
78 
79     // Synchronization lock for sCallback_2_1 and sCallback_2_0
80     mutable std::mutex mMutex;
81 };
82 
83 }  // namespace implementation
84 }  // namespace V2_1
85 }  // namespace gnss
86 }  // namespace hardware
87 }  // namespace android
88