blob: 36947c1044cde6df023bfee478203eb6f69af170 [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 {
Wyatt Rileyad03ab22016-12-14 14:54:29 -080056 // TODO: Add flp_device_t, either in ctor, or later attach?
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070057 Gnss(gps_device_t* gnss_device);
58 ~Gnss();
59
60 /*
61 * Methods from ::android::hardware::gnss::V1_0::IGnss follow.
62 * These declarations were generated from Gnss.hal.
63 */
64 Return<bool> setCallback(const sp<IGnssCallback>& callback) override;
65 Return<bool> start() override;
66 Return<bool> stop() override;
67 Return<void> cleanup() override;
68 Return<bool> injectLocation(double latitudeDegrees,
69 double longitudeDegrees,
70 float accuracyMeters) override;
71 Return<bool> injectTime(int64_t timeMs,
72 int64_t timeReferenceMs,
73 int32_t uncertaintyMs) override;
74 Return<void> deleteAidingData(IGnss::GnssAidingData aidingDataFlags) override;
75 Return<bool> setPositionMode(IGnss::GnssPositionMode mode,
76 IGnss::GnssPositionRecurrence recurrence,
77 uint32_t minIntervalMs,
78 uint32_t preferredAccuracyMeters,
79 uint32_t preferredTimeMs) override;
Martijn Coenen527924a2017-01-04 12:59:48 +010080 Return<sp<IAGnssRil>> getExtensionAGnssRil() override;
81 Return<sp<IGnssGeofencing>> getExtensionGnssGeofencing() override;
82 Return<sp<IAGnss>> getExtensionAGnss() override;
83 Return<sp<IGnssNi>> getExtensionGnssNi() override;
84 Return<sp<IGnssMeasurement>> getExtensionGnssMeasurement() override;
85 Return<sp<IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override;
86 Return<sp<IGnssXtra>> getExtensionXtra() override;
87 Return<sp<IGnssConfiguration>> getExtensionGnssConfiguration() override;
88 Return<sp<IGnssDebug>> getExtensionGnssDebug() override;
Wyatt Rileyad03ab22016-12-14 14:54:29 -080089 Return<sp<IGnssBatching>> getExtensionGnssBatching() override;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070090
91 /*
92 * Callback methods to be passed into the conventional GNSS HAL by the default
93 * implementation. These methods are not part of the IGnss base class.
94 */
95 static void locationCb(GpsLocation* location);
96 static void statusCb(GpsStatus* gnss_status);
97 static void nmeaCb(GpsUtcTime timestamp, const char* nmea, int length);
98 static void setCapabilitiesCb(uint32_t capabilities);
99 static void acquireWakelockCb();
100 static void releaseWakelockCb();
101 static void requestUtcTimeCb();
102 static pthread_t createThreadCb(const char* name, void (*start)(void*), void* arg);
103 static void gnssSvStatusCb(GnssSvStatus* status);
104 /*
105 * Deprecated callback added for backward compatibility to devices that do
106 * not support GnssSvStatus.
107 */
108 static void gpsSvStatusCb(GpsSvStatus* status);
109 static void setSystemInfoCb(const LegacyGnssSystemInfo* info);
110
111 /*
112 * Holds function pointers to the callback methods.
113 */
114 static GpsCallbacks sGnssCb;
115
116 private:
117 sp<GnssXtra> mGnssXtraIface = nullptr;
118 sp<AGnssRil> mGnssRil = nullptr;
119 sp<GnssGeofencing> mGnssGeofencingIface = nullptr;
120 sp<AGnss> mAGnssIface = nullptr;
121 sp<GnssNi> mGnssNi = nullptr;
122 sp<GnssMeasurement> mGnssMeasurement = nullptr;
123 sp<GnssNavigationMessage> mGnssNavigationMessage = nullptr;
124 sp<GnssDebug> mGnssDebug = nullptr;
125 sp<GnssConfiguration> mGnssConfig = nullptr;
Wyatt Rileyad03ab22016-12-14 14:54:29 -0800126 sp<GnssBatching> mGnssBatching = nullptr;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700127 const GpsInterface* mGnssIface = nullptr;
128 static sp<IGnssCallback> sGnssCbIface;
129 static std::vector<std::unique_ptr<ThreadFuncArgs>> sThreadFuncArgsList;
130 static bool sInterfaceExists;
131};
132
133extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
134
135} // namespace implementation
136} // namespace V1_0
137} // namespace gnss
138} // namespace hardware
139} // namespace android
140
141#endif // android_hardware_gnss_V1_0_Gnss_H_