blob: 63614fa7a3c58543ba6f8e450febbea50df5fdcf [file] [log] [blame]
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -07001/*
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 android_hardware_gnss_V1_0_Gnss_H_
18#define android_hardware_gnss_V1_0_Gnss_H_
19
20#include <AGnss.h>
21#include <AGnssRil.h>
Wyatt Rileyad03ab22016-12-14 14:54:29 -080022#include <GnssBatching.h>
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070023#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>
Wyatt Rileyad03ab22016-12-14 14:54:29 -080033#include <hardware/fused_location.h>
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070034#include <hardware/gps.h>
35#include <hidl/Status.h>
36
37namespace android {
38namespace hardware {
39namespace gnss {
40namespace V1_0 {
41namespace implementation {
42
43using ::android::hardware::Return;
44using ::android::hardware::Void;
45using ::android::hardware::hidl_vec;
46using ::android::hardware::hidl_string;
47using ::android::sp;
48
49using LegacyGnssSystemInfo = ::GnssSystemInfo;
50
51/*
52 * Represents the standard GNSS interface. Also contains wrapper methods to allow methods from
53 * IGnssCallback interface to be passed into the conventional implementation of the GNSS HAL.
54 */
55struct Gnss : public IGnss {
56 Gnss(gps_device_t* gnss_device);
57 ~Gnss();
58
59 /*
60 * Methods from ::android::hardware::gnss::V1_0::IGnss follow.
61 * These declarations were generated from Gnss.hal.
62 */
63 Return<bool> setCallback(const sp<IGnssCallback>& callback) override;
64 Return<bool> start() override;
65 Return<bool> stop() override;
66 Return<void> cleanup() override;
67 Return<bool> injectLocation(double latitudeDegrees,
68 double longitudeDegrees,
69 float accuracyMeters) override;
70 Return<bool> injectTime(int64_t timeMs,
71 int64_t timeReferenceMs,
72 int32_t uncertaintyMs) override;
73 Return<void> deleteAidingData(IGnss::GnssAidingData aidingDataFlags) override;
74 Return<bool> setPositionMode(IGnss::GnssPositionMode mode,
75 IGnss::GnssPositionRecurrence recurrence,
76 uint32_t minIntervalMs,
77 uint32_t preferredAccuracyMeters,
78 uint32_t preferredTimeMs) override;
Martijn Coenen527924a2017-01-04 12:59:48 +010079 Return<sp<IAGnssRil>> getExtensionAGnssRil() override;
80 Return<sp<IGnssGeofencing>> getExtensionGnssGeofencing() override;
81 Return<sp<IAGnss>> getExtensionAGnss() override;
82 Return<sp<IGnssNi>> getExtensionGnssNi() override;
83 Return<sp<IGnssMeasurement>> getExtensionGnssMeasurement() override;
84 Return<sp<IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override;
85 Return<sp<IGnssXtra>> getExtensionXtra() override;
86 Return<sp<IGnssConfiguration>> getExtensionGnssConfiguration() override;
87 Return<sp<IGnssDebug>> getExtensionGnssDebug() override;
Wyatt Rileyad03ab22016-12-14 14:54:29 -080088 Return<sp<IGnssBatching>> getExtensionGnssBatching() override;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070089
90 /*
91 * Callback methods to be passed into the conventional GNSS HAL by the default
92 * implementation. These methods are not part of the IGnss base class.
93 */
94 static void locationCb(GpsLocation* location);
95 static void statusCb(GpsStatus* gnss_status);
96 static void nmeaCb(GpsUtcTime timestamp, const char* nmea, int length);
97 static void setCapabilitiesCb(uint32_t capabilities);
98 static void acquireWakelockCb();
99 static void releaseWakelockCb();
100 static void requestUtcTimeCb();
101 static pthread_t createThreadCb(const char* name, void (*start)(void*), void* arg);
102 static void gnssSvStatusCb(GnssSvStatus* status);
103 /*
104 * Deprecated callback added for backward compatibility to devices that do
105 * not support GnssSvStatus.
106 */
107 static void gpsSvStatusCb(GpsSvStatus* status);
108 static void setSystemInfoCb(const LegacyGnssSystemInfo* info);
109
110 /*
Wyatt Riley8791e7b2017-01-17 12:12:25 -0800111 * Wakelock consolidation, only needed for dual use of a gps.h & fused_location.h HAL
112 *
113 * Ensures that if the last call from either legacy .h was to acquire a wakelock, that a
114 * wakelock is held. Otherwise releases it.
115 */
116 static void acquireWakelockFused();
117 static void releaseWakelockFused();
118
119 /*
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700120 * Holds function pointers to the callback methods.
121 */
122 static GpsCallbacks sGnssCb;
123
124 private:
Wyatt Riley8791e7b2017-01-17 12:12:25 -0800125 // for wakelock consolidation, see above
126 static void acquireWakelockGnss();
127 static void releaseWakelockGnss();
128 static void updateWakelock();
129 static bool sWakelockHeldGnss;
130 static bool sWakelockHeldFused;
131
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700132 sp<GnssXtra> mGnssXtraIface = nullptr;
133 sp<AGnssRil> mGnssRil = nullptr;
134 sp<GnssGeofencing> mGnssGeofencingIface = nullptr;
135 sp<AGnss> mAGnssIface = nullptr;
136 sp<GnssNi> mGnssNi = nullptr;
137 sp<GnssMeasurement> mGnssMeasurement = nullptr;
138 sp<GnssNavigationMessage> mGnssNavigationMessage = nullptr;
139 sp<GnssDebug> mGnssDebug = nullptr;
140 sp<GnssConfiguration> mGnssConfig = nullptr;
Wyatt Rileyad03ab22016-12-14 14:54:29 -0800141 sp<GnssBatching> mGnssBatching = nullptr;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700142 const GpsInterface* mGnssIface = nullptr;
143 static sp<IGnssCallback> sGnssCbIface;
144 static std::vector<std::unique_ptr<ThreadFuncArgs>> sThreadFuncArgsList;
145 static bool sInterfaceExists;
146};
147
148extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
149
150} // namespace implementation
151} // namespace V1_0
152} // namespace gnss
153} // namespace hardware
154} // namespace android
155
156#endif // android_hardware_gnss_V1_0_Gnss_H_