blob: e12ac128c94af1f541aa425d47a7e4f33eaf3ef3 [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>
22#include <GnssConfiguration.h>
23#include <GnssDebug.h>
24#include <GnssGeofencing.h>
25#include <GnssMeasurement.h>
26#include <GnssNavigationMessage.h>
27#include <GnssNi.h>
28#include <GnssXtra.h>
29
30#include <ThreadCreationWrapper.h>
31#include <android/hardware/gnss/1.0/IGnss.h>
32#include <hardware/gps.h>
33#include <hidl/Status.h>
34
35namespace android {
36namespace hardware {
37namespace gnss {
38namespace V1_0 {
39namespace implementation {
40
41using ::android::hardware::Return;
42using ::android::hardware::Void;
43using ::android::hardware::hidl_vec;
44using ::android::hardware::hidl_string;
45using ::android::sp;
46
47using LegacyGnssSystemInfo = ::GnssSystemInfo;
48
49/*
50 * Represents the standard GNSS interface. Also contains wrapper methods to allow methods from
51 * IGnssCallback interface to be passed into the conventional implementation of the GNSS HAL.
52 */
53struct Gnss : public IGnss {
54 Gnss(gps_device_t* gnss_device);
55 ~Gnss();
56
57 /*
58 * Methods from ::android::hardware::gnss::V1_0::IGnss follow.
59 * These declarations were generated from Gnss.hal.
60 */
61 Return<bool> setCallback(const sp<IGnssCallback>& callback) override;
62 Return<bool> start() override;
63 Return<bool> stop() override;
64 Return<void> cleanup() override;
65 Return<bool> injectLocation(double latitudeDegrees,
66 double longitudeDegrees,
67 float accuracyMeters) override;
68 Return<bool> injectTime(int64_t timeMs,
69 int64_t timeReferenceMs,
70 int32_t uncertaintyMs) override;
71 Return<void> deleteAidingData(IGnss::GnssAidingData aidingDataFlags) override;
72 Return<bool> setPositionMode(IGnss::GnssPositionMode mode,
73 IGnss::GnssPositionRecurrence recurrence,
74 uint32_t minIntervalMs,
75 uint32_t preferredAccuracyMeters,
76 uint32_t preferredTimeMs) override;
Martijn Coenen527924a2017-01-04 12:59:48 +010077 Return<sp<IAGnssRil>> getExtensionAGnssRil() override;
78 Return<sp<IGnssGeofencing>> getExtensionGnssGeofencing() override;
79 Return<sp<IAGnss>> getExtensionAGnss() override;
80 Return<sp<IGnssNi>> getExtensionGnssNi() override;
81 Return<sp<IGnssMeasurement>> getExtensionGnssMeasurement() override;
82 Return<sp<IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override;
83 Return<sp<IGnssXtra>> getExtensionXtra() override;
84 Return<sp<IGnssConfiguration>> getExtensionGnssConfiguration() override;
85 Return<sp<IGnssDebug>> getExtensionGnssDebug() override;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -070086
87 /*
88 * Callback methods to be passed into the conventional GNSS HAL by the default
89 * implementation. These methods are not part of the IGnss base class.
90 */
91 static void locationCb(GpsLocation* location);
92 static void statusCb(GpsStatus* gnss_status);
93 static void nmeaCb(GpsUtcTime timestamp, const char* nmea, int length);
94 static void setCapabilitiesCb(uint32_t capabilities);
95 static void acquireWakelockCb();
96 static void releaseWakelockCb();
97 static void requestUtcTimeCb();
98 static pthread_t createThreadCb(const char* name, void (*start)(void*), void* arg);
99 static void gnssSvStatusCb(GnssSvStatus* status);
100 /*
101 * Deprecated callback added for backward compatibility to devices that do
102 * not support GnssSvStatus.
103 */
104 static void gpsSvStatusCb(GpsSvStatus* status);
105 static void setSystemInfoCb(const LegacyGnssSystemInfo* info);
106
107 /*
108 * Holds function pointers to the callback methods.
109 */
110 static GpsCallbacks sGnssCb;
111
112 private:
113 sp<GnssXtra> mGnssXtraIface = nullptr;
114 sp<AGnssRil> mGnssRil = nullptr;
115 sp<GnssGeofencing> mGnssGeofencingIface = nullptr;
116 sp<AGnss> mAGnssIface = nullptr;
117 sp<GnssNi> mGnssNi = nullptr;
118 sp<GnssMeasurement> mGnssMeasurement = nullptr;
119 sp<GnssNavigationMessage> mGnssNavigationMessage = nullptr;
120 sp<GnssDebug> mGnssDebug = nullptr;
121 sp<GnssConfiguration> mGnssConfig = nullptr;
122 const GpsInterface* mGnssIface = nullptr;
123 static sp<IGnssCallback> sGnssCbIface;
124 static std::vector<std::unique_ptr<ThreadFuncArgs>> sThreadFuncArgsList;
125 static bool sInterfaceExists;
126};
127
128extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
129
130} // namespace implementation
131} // namespace V1_0
132} // namespace gnss
133} // namespace hardware
134} // namespace android
135
136#endif // android_hardware_gnss_V1_0_Gnss_H_