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