blob: ef93163abd58f8cde7e6eb24a870273a98db7fda [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
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_GnssGeofencing_H_
18#define android_hardware_gnss_V1_0_GnssGeofencing_H_
19
20#include <ThreadCreationWrapper.h>
21#include <android/hardware/gnss/1.0/IGnssGeofencing.h>
22#include <hidl/Status.h>
23#include <hardware/gps.h>
24#include "hardware/gps_mtk.h"
25
26namespace android {
27namespace hardware {
28namespace gnss {
29namespace V1_0 {
30namespace implementation {
31
32using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback;
33using ::android::hardware::gnss::V1_0::IGnssGeofencing;
34using ::android::hardware::Return;
35using ::android::hardware::Void;
36using ::android::hardware::hidl_vec;
37using ::android::hardware::hidl_string;
38using ::android::sp;
39
40/*
41 * Interface for GNSS Geofencing support. It also contains wrapper methods to allow
42 * methods from IGnssGeofenceCallback interface to be passed into the
43 * conventional implementation of the GNSS HAL.
44 */
45struct GnssGeofencing : public IGnssGeofencing {
46 GnssGeofencing(const GpsGeofencingInterface_ext* gpsGeofencingIface);
47 ~GnssGeofencing();
48
49 /*
50 * Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow.
51 * These declarations were generated from IGnssGeofencing.hal.
52 */
53 Return<void> setCallback(const sp<IGnssGeofenceCallback>& callback) override;
54 Return<void> addGeofence(int32_t geofenceId,
55 double latitudeDegrees,
56 double longitudeDegrees,
57 double radiusMeters,
58 IGnssGeofenceCallback::GeofenceTransition lastTransition,
59 int32_t monitorTransitions,
60 uint32_t notificationResponsivenessMs,
61 uint32_t unknownTimerMs) override;
62
63 Return<void> pauseGeofence(int32_t geofenceId) override;
64 Return<void> resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) override;
65 Return<void> removeGeofence(int32_t geofenceId) override;
66
67 /*
68 * Callback methods to be passed into the conventional GNSS HAL by the default
69 * implementation. These methods are not part of the IGnssGeofencing base class.
70 */
71 static void gnssGfTransitionCb(int32_t geofence_id, GpsLocation_ext* location,
72 int32_t transition, GpsUtcTime timestamp);
73 static void gnssGfStatusCb(int32_t status, GpsLocation_ext* last_location);
74 static void gnssGfAddCb(int32_t geofence_id, int32_t status);
75 static void gnssGfRemoveCb(int32_t geofence_id, int32_t status);
76 static void gnssGfPauseCb(int32_t geofence_id, int32_t status);
77 static void gnssGfResumeCb(int32_t geofence_id, int32_t status);
78 static pthread_t createThreadCb(const char* name, void (*start)(void*), void* arg);
79
80 /*
81 * Holds function pointers to the callback methods.
82 */
83 static GpsGeofenceCallbacks_ext sGnssGfCb;
84
85 private:
86 static std::vector<std::unique_ptr<ThreadFuncArgs>> sThreadFuncArgsList;
87 static sp<IGnssGeofenceCallback> mGnssGeofencingCbIface;
88 const GpsGeofencingInterface_ext* mGnssGeofencingIface = nullptr;
89 static bool sInterfaceExists;
90};
91
92} // namespace implementation
93} // namespace V1_0
94} // namespace gnss
95} // namespace hardware
96} // namespace android
97
98#endif // android_hardware_gnss_V1_0_GnssGeofencing_H_