1 /*
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_AGnss_H_
18 #define android_hardware_gnss_V1_0_AGnss_H_
19 
20 #include <ThreadCreationWrapper.h>
21 #include <android/hardware/gnss/1.0/IAGnss.h>
22 #include <hardware/gps_internal.h>
23 #include <hidl/Status.h>
24 #include <netinet/in.h>
25 
26 namespace android {
27 namespace hardware {
28 namespace gnss {
29 namespace V1_0 {
30 namespace implementation {
31 
32 using ::android::hardware::gnss::V1_0::IAGnss;
33 using ::android::hardware::gnss::V1_0::IAGnssCallback;
34 using ::android::hardware::Return;
35 using ::android::hardware::Void;
36 using ::android::hardware::hidl_vec;
37 using ::android::hardware::hidl_string;
38 using ::android::sp;
39 
40 /*
41  * Extended interface for AGNSS support. Also contains wrapper methods to allow
42  * methods from IAGnssCallback interface to be passed into the conventional
43  * implementation of the GNSS HAL.
44  */
45 struct AGnss : public IAGnss {
46     AGnss(const AGpsInterface* agpsIface);
47     ~AGnss();
48     /*
49      * Methods from ::android::hardware::gnss::V1_0::IAGnss interface follow.
50      * These declarations were generated from IAGnss.hal.
51      */
52     Return<void> setCallback(const sp<IAGnssCallback>& callback) override;
53     Return<bool> dataConnClosed() override;
54     Return<bool> dataConnFailed() override;
55     Return<bool> setServer(IAGnssCallback::AGnssType type,
56                          const hidl_string& hostname, int32_t port) override;
57     Return<bool> dataConnOpen(const hidl_string& apn,
58                                            IAGnss::ApnIpType apnIpType) override;
59 
60     /*
61      * Callback methods to be passed into the conventional GNSS HAL by the default
62      * implementation. These methods are not part of the IAGnss base class.
63      */
64     static pthread_t createThreadCb(const char* name, void (*start)(void*), void* arg);
65     static void statusCb(AGpsStatus* status);
66 
67     /*
68      * Holds function pointers to the callback methods.
69      */
70     static AGpsCallbacks sAGnssCb;
71 
72  private:
73     const AGpsInterface* mAGnssIface = nullptr;
74     static sp<IAGnssCallback> sAGnssCbIface;
75     static std::vector<std::unique_ptr<ThreadFuncArgs>> sThreadFuncArgsList;
76     static bool sInterfaceExists;
77 };
78 
79 }  // namespace implementation
80 }  // namespace V1_0
81 }  // namespace gnss
82 }  // namespace hardware
83 }  // namespace android
84 
85 #endif  // android_hardware_gnss_V1_0_AGnss_H_
86