blob: a2c8676aff831ed125b091eb443abde853359e0b [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;
77 Return<void> getExtensionAGnssRil(getExtensionAGnssRil_cb _hidl_cb) override;
78 Return<void> getExtensionGnssGeofencing(getExtensionGnssGeofencing_cb _hidl_cb) override;
79 Return<void> getExtensionAGnss(getExtensionAGnss_cb _hidl_cb) override;
80 Return<void> getExtensionGnssNi(getExtensionGnssNi_cb _hidl_cb) override;
81 Return<void> getExtensionGnssMeasurement(getExtensionGnssMeasurement_cb _hidl_cb) override;
82 Return<void> getExtensionGnssNavigationMessage(
83 getExtensionGnssNavigationMessage_cb _hidl_cb) override;
84 Return<void> getExtensionXtra(getExtensionXtra_cb _hidl_cb) override;
85 Return<void> getExtensionGnssDebug(getExtensionGnssDebug_cb _hidl_cb) override;
86 Return<void> getExtensionGnssConfiguration(getExtensionGnssConfiguration_cb _hidl_cb) override;
87
88 /*
89 * Callback methods to be passed into the conventional GNSS HAL by the default
90 * implementation. These methods are not part of the IGnss base class.
91 */
92 static void locationCb(GpsLocation* location);
93 static void statusCb(GpsStatus* gnss_status);
94 static void nmeaCb(GpsUtcTime timestamp, const char* nmea, int length);
95 static void setCapabilitiesCb(uint32_t capabilities);
96 static void acquireWakelockCb();
97 static void releaseWakelockCb();
98 static void requestUtcTimeCb();
99 static pthread_t createThreadCb(const char* name, void (*start)(void*), void* arg);
100 static void gnssSvStatusCb(GnssSvStatus* status);
101 /*
102 * Deprecated callback added for backward compatibility to devices that do
103 * not support GnssSvStatus.
104 */
105 static void gpsSvStatusCb(GpsSvStatus* status);
106 static void setSystemInfoCb(const LegacyGnssSystemInfo* info);
107
108 /*
109 * Holds function pointers to the callback methods.
110 */
111 static GpsCallbacks sGnssCb;
112
113 private:
114 sp<GnssXtra> mGnssXtraIface = nullptr;
115 sp<AGnssRil> mGnssRil = nullptr;
116 sp<GnssGeofencing> mGnssGeofencingIface = nullptr;
117 sp<AGnss> mAGnssIface = nullptr;
118 sp<GnssNi> mGnssNi = nullptr;
119 sp<GnssMeasurement> mGnssMeasurement = nullptr;
120 sp<GnssNavigationMessage> mGnssNavigationMessage = nullptr;
121 sp<GnssDebug> mGnssDebug = nullptr;
122 sp<GnssConfiguration> mGnssConfig = nullptr;
123 const GpsInterface* mGnssIface = nullptr;
124 static sp<IGnssCallback> sGnssCbIface;
125 static std::vector<std::unique_ptr<ThreadFuncArgs>> sThreadFuncArgsList;
126 static bool sInterfaceExists;
127};
128
129extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
130
131} // namespace implementation
132} // namespace V1_0
133} // namespace gnss
134} // namespace hardware
135} // namespace android
136
137#endif // android_hardware_gnss_V1_0_Gnss_H_