blob: bc211b4c3554c75a5407fd4a981fc1b75392aac2 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (C) 2016 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#ifndef VENDOR_MEDIATEK_HARDWARE_GNSS_V1_1_MTKGNSS_H
18#define VENDOR_MEDIATEK_HARDWARE_GNSS_V1_1_MTKGNSS_H
19
20#include <AGnss.h>
21#include <AGnssRil.h>
22#include <GnssBatching.h>
23#include <GnssConfiguration.h>
24#include <GnssDebug.h>
25#include <GnssGeofencing.h>
26#include <GnssMeasurement.h>
27#include <GnssNavigationMessage.h>
28#include <GnssNi.h>
29#include <GnssXtra.h>
30
31#include <ThreadCreationWrapper.h>
32//#include <android/hardware/gnss/1.0/IGnss.h>
33#include <vendor/mediatek/hardware/gnss/1.1/IMtkGnss.h>
34#include <hardware/fused_location.h>
35#include <hardware/gps.h>
36#include <hidl/Status.h>
37
38#include <VzwDebug.h>
39#include <semaphore.h>
40
41namespace vendor {
42namespace mediatek {
43namespace hardware {
44namespace gnss {
45namespace V1_1 {
46namespace implementation {
47
48/// Mtk added to include more namespaces
49using namespace android::hardware::gnss::V1_0;
50using namespace android::hardware::gnss::V1_0::implementation;
51using ::vendor::mediatek::hardware::gnss::V1_1::IMtkGnss;
52using ::vendor::mediatek::hardware::gnss::V1_1::IVzwDebug;
53using ::android::wp;
54/// Mtk add end
55using ::android::hardware::hidl_death_recipient;
56using ::android::hardware::Return;
57using ::android::hardware::Void;
58using ::android::hardware::hidl_vec;
59using ::android::hardware::hidl_string;
60using ::android::sp;
61
62using LegacyGnssSystemInfo = ::GnssSystemInfo;
63
64/*
65 * Represents the standard GNSS interface. Also contains wrapper methods to allow methods from
66 * IGnssCallback interface to be passed into the conventional implementation of the GNSS HAL.
67 */
68class MtkGnss : public IMtkGnss {
69 public:
70 MtkGnss(gps_device_t* gnss_device);
71 ~MtkGnss();
72
73 /*
74 * Methods from ::android::hardware::gnss::V1_0::IGnss follow.
75 * These declarations were generated from Gnss.hal.
76 */
77 Return<bool> setCallback(const sp<IGnssCallback>& callback) override;
78 Return<bool> start() override;
79 Return<bool> stop() override;
80 Return<void> cleanup() override;
81 Return<bool> injectLocation(double latitudeDegrees,
82 double longitudeDegrees,
83 float accuracyMeters) override;
84 Return<bool> injectTime(int64_t timeMs,
85 int64_t timeReferenceMs,
86 int32_t uncertaintyMs) override;
87 Return<void> deleteAidingData(IGnss::GnssAidingData aidingDataFlags) override;
88 Return<bool> setPositionMode(IGnss::GnssPositionMode mode,
89 IGnss::GnssPositionRecurrence recurrence,
90 uint32_t minIntervalMs,
91 uint32_t preferredAccuracyMeters,
92 uint32_t preferredTimeMs) override;
93 Return<sp<IAGnssRil>> getExtensionAGnssRil() override;
94 Return<sp<IGnssGeofencing>> getExtensionGnssGeofencing() override;
95 Return<sp<IAGnss>> getExtensionAGnss() override;
96 Return<sp<IGnssNi>> getExtensionGnssNi() override;
97 Return<sp<IGnssMeasurement>> getExtensionGnssMeasurement() override;
98 Return<sp<IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override;
99 Return<sp<IGnssXtra>> getExtensionXtra() override;
100 Return<sp<IGnssConfiguration>> getExtensionGnssConfiguration() override;
101 Return<sp<IGnssDebug>> getExtensionGnssDebug() override;
102 Return<sp<IGnssBatching>> getExtensionGnssBatching() override;
103 ///M: add to get and wrap hal vzw debug interface
104 Return<sp<IVzwDebug>> getExtensionVzwDebug() override;
105
106 /*
107 * Callback methods to be passed into the conventional GNSS HAL by the default
108 * implementation. These methods are not part of the IGnss base class.
109 */
110 static void locationCb(GpsLocation* location);
111 static void statusCb(GpsStatus* gnss_status);
112 static void nmeaCb(GpsUtcTime timestamp, const char* nmea, int length);
113 static void setCapabilitiesCb(uint32_t capabilities);
114 static void acquireWakelockCb();
115 static void releaseWakelockCb();
116 static void requestUtcTimeCb();
117 static pthread_t createThreadCb(const char* name, void (*start)(void*), void* arg);
118 static void gnssSvStatusCb(GnssSvStatus* status);
119 /*
120 * Deprecated callback added for backward compatibility to devices that do
121 * not support GnssSvStatus.
122 */
123 static void gpsSvStatusCb(GpsSvStatus* status);
124 static void setSystemInfoCb(const LegacyGnssSystemInfo* info);
125
126 /*
127 * Wakelock consolidation, only needed for dual use of a gps.h & fused_location.h HAL
128 *
129 * Ensures that if the last call from either legacy .h was to acquire a wakelock, that a
130 * wakelock is held. Otherwise releases it.
131 */
132 static void acquireWakelockFused();
133 static void releaseWakelockFused();
134
135 /*
136 * Holds function pointers to the callback methods.
137 */
138 static GpsCallbacks sGnssCb;
139
140 private:
141 /*
142 * For handling system-server death while GNSS service lives on.
143 */
144 class GnssHidlDeathRecipient : public hidl_death_recipient {
145 public:
146 GnssHidlDeathRecipient(const sp<MtkGnss> gnss) : mGnss(gnss) {
147 }
148
149 virtual void serviceDied(uint64_t /*cookie*/,
150 const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
151 mGnss->handleHidlDeath();
152 }
153 private:
154 sp<MtkGnss> mGnss;
155 };
156
157 // for wakelock consolidation, see above
158 static void acquireWakelockGnss();
159 static void releaseWakelockGnss();
160 static void updateWakelock();
161 static bool sWakelockHeldGnss;
162 static bool sWakelockHeldFused;
163
164 /*
165 * Cleanup for death notification
166 */
167 void handleHidlDeath();
168
169 sp<GnssXtra> mGnssXtraIface = nullptr;
170 sp<AGnssRil> mGnssRil = nullptr;
171 sp<GnssGeofencing> mGnssGeofencingIface = nullptr;
172 sp<AGnss> mAGnssIface = nullptr;
173 sp<GnssNi> mGnssNi = nullptr;
174 /// Mtk added to specify namespace
175 sp<implementation::GnssMeasurement> mGnssMeasurement = nullptr;
176 sp<implementation::GnssNavigationMessage> mGnssNavigationMessage = nullptr;
177 /// Mtk add end
178 sp<GnssDebug> mGnssDebug = nullptr;
179 sp<GnssConfiguration> mGnssConfig = nullptr;
180 sp<GnssBatching> mGnssBatching = nullptr;
181
182 ///M: add for vzw debug hidl imlementation instance
183 sp<VzwDebug> mVzwDebug = nullptr;
184 static sem_t sSem;
185
186 sp<GnssHidlDeathRecipient> mDeathRecipient;
187
188 const GpsInterface* mGnssIface = nullptr;
189 static sp<IGnssCallback> sGnssCbIface;
190 static std::vector<std::unique_ptr<ThreadFuncArgs>> sThreadFuncArgsList;
191 static bool sInterfaceExists;
192
193 // Values saved for resend
194 static uint32_t sCapabilitiesCached;
195 static uint16_t sYearOfHwCached;
196};
197
198extern "C" IMtkGnss* HIDL_FETCH_IMtkGnss(const char* name);
199
200} // namespace implementation
201} // namespace V1_1
202} // namespace gnss
203} // namespace hardware
204} // namespace mediatek
205} // namespace vendor
206
207#endif // VENDOR_MEDIATEK_HARDWARE_GNSS_V1_1_MTKGNSS_H