1 /*
2  * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3  * Not a Contribution
4  */
5 /*
6  * Copyright (C) 2016 The Android Open Source Project
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSS_H
22 #define ANDROID_HARDWARE_GNSS_V1_1_GNSS_H
23 
24 #include <AGnss.h>
25 #include <GnssBatching.h>
26 #include <GnssConfiguration.h>
27 #include <GnssGeofencing.h>
28 #include <GnssMeasurement.h>
29 #include <GnssNi.h>
30 
31 #include <android/hardware/gnss/1.0/IGnss.h>
32 #include <hidl/Status.h>
33 
34 #include <GnssAPIClient.h>
35 #include <location_interface.h>
36 
37 namespace android {
38 namespace hardware {
39 namespace gnss {
40 namespace V1_0 {
41 namespace implementation {
42 
43 using ::android::hardware::Return;
44 using ::android::hardware::Void;
45 using ::android::hardware::hidl_vec;
46 using ::android::hardware::hidl_string;
47 using ::android::sp;
48 
49 struct Gnss : public IGnss {
50     Gnss();
51     ~Gnss();
52 
53     // registerAsService will call interfaceChain to determine the version of service
54     /* comment this out until we know really how to manipulate hidl version
55     using interfaceChain_cb = std::function<
56         void(const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& descriptors)>;
57     virtual ::android::hardware::Return<void> interfaceChain(interfaceChain_cb _hidl_cb) override {
58         _hidl_cb({
59                 "android.hardware.gnss@1.1::IGnss",
60                 ::android::hidl::base::V1_0::IBase::descriptor,
61                 });
62         return ::android::hardware::Void();
63     }
64     */
65 
66     /*
67      * Methods from ::android::hardware::gnss::V1_0::IGnss follow.
68      * These declarations were generated from Gnss.hal.
69      */
70     Return<bool> setCallback(const sp<IGnssCallback>& callback)  override;
71     Return<bool> start()  override;
72     Return<bool> stop()  override;
73     Return<void> cleanup()  override;
74     Return<bool> injectLocation(double latitudeDegrees,
75                                 double longitudeDegrees,
76                                 float accuracyMeters)  override;
77     Return<bool> injectTime(int64_t timeMs,
78                             int64_t timeReferenceMs,
79                             int32_t uncertaintyMs) override;
80     Return<void> deleteAidingData(IGnss::GnssAidingData aidingDataFlags)  override;
81     Return<bool> setPositionMode(IGnss::GnssPositionMode mode,
82                                  IGnss::GnssPositionRecurrence recurrence,
83                                  uint32_t minIntervalMs,
84                                  uint32_t preferredAccuracyMeters,
85                                  uint32_t preferredTimeMs)  override;
86     Return<sp<IAGnss>> getExtensionAGnss() override;
87     Return<sp<IGnssNi>> getExtensionGnssNi() override;
88     Return<sp<IGnssMeasurement>> getExtensionGnssMeasurement() override;
89     Return<sp<IGnssConfiguration>> getExtensionGnssConfiguration() override;
90     Return<sp<IGnssGeofencing>> getExtensionGnssGeofencing() override;
91     Return<sp<IGnssBatching>> getExtensionGnssBatching() override;
92 
getExtensionAGnssRilGnss93     inline Return<sp<IAGnssRil>> getExtensionAGnssRil() override {
94         return nullptr;
95     }
96 
getExtensionGnssNavigationMessageGnss97     inline Return<sp<IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override {
98         return nullptr;
99     }
100 
getExtensionXtraGnss101     inline Return<sp<IGnssXtra>> getExtensionXtra() override {
102         return nullptr;
103     }
104 
getExtensionGnssDebugGnss105     inline Return<sp<IGnssDebug>> getExtensionGnssDebug() override {
106         return nullptr;
107     }
108 
109     // These methods are not part of the IGnss base class.
110     GnssAPIClient* getApi();
111     Return<bool> setGnssNiCb(const sp<IGnssNiCallback>& niCb);
112     Return<bool> updateConfiguration(GnssConfig& gnssConfig);
113     GnssInterface* getGnssInterface();
114 
115  private:
116     struct GnssDeathRecipient : hidl_death_recipient {
GnssDeathRecipientGnss::GnssDeathRecipient117         GnssDeathRecipient(sp<Gnss> gnss) : mGnss(gnss) {
118         }
119         ~GnssDeathRecipient() = default;
120         virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
121         sp<Gnss> mGnss;
122     };
123 
124  private:
125     sp<GnssDeathRecipient> mGnssDeathRecipient = nullptr;
126 
127     sp<AGnss> mAGnssIface = nullptr;
128     sp<GnssNi> mGnssNi = nullptr;
129     sp<GnssMeasurement> mGnssMeasurement = nullptr;
130     sp<GnssConfiguration> mGnssConfig = nullptr;
131     sp<GnssGeofencing> mGnssGeofencingIface = nullptr;
132     sp<GnssBatching> mGnssBatching = nullptr;
133 
134     GnssAPIClient* mApi = nullptr;
135     sp<IGnssCallback> mGnssCbIface = nullptr;
136     sp<IGnssNiCallback> mGnssNiCbIface = nullptr;
137     GnssConfig mPendingConfig;
138     GnssInterface* mGnssInterface = nullptr;
139 };
140 
141 extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
142 
143 }  // namespace implementation
144 }  // namespace V1_0
145 }  // namespace gnss
146 }  // namespace hardware
147 }  // namespace android
148 
149 #endif  // ANDROID_HARDWARE_GNSS_V1_1_GNSS_H
150