• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 // Define LOG_TAG before <log/log.h> to overwrite the default value.
18 #define LOG_TAG "GnssGeofenceJni"
19 
20 #include "GnssGeofence.h"
21 
22 #include "Utils.h"
23 
24 using android::hardware::hidl_bitfield;
25 using GeofenceTransition = android::hardware::gnss::V1_0::IGnssGeofenceCallback::GeofenceTransition;
26 using IGnssGeofenceAidl = android::hardware::gnss::IGnssGeofence;
27 using IGnssGeofenceHidl = android::hardware::gnss::V1_0::IGnssGeofencing;
28 
29 namespace android::gnss {
30 
31 // Implementation of GnssGeofence (AIDL HAL)
32 
GnssGeofenceAidl(const sp<IGnssGeofenceAidl> & iGnssGeofence)33 GnssGeofenceAidl::GnssGeofenceAidl(const sp<IGnssGeofenceAidl>& iGnssGeofence)
34       : mIGnssGeofenceAidl(iGnssGeofence) {
35     assert(mIGnssGeofenceAidl != nullptr);
36 }
37 
setCallback(const std::unique_ptr<GnssGeofenceCallback> & callback)38 jboolean GnssGeofenceAidl::setCallback(const std::unique_ptr<GnssGeofenceCallback>& callback) {
39     auto status = mIGnssGeofenceAidl->setCallback(callback->getAidl());
40     return checkAidlStatus(status, "IGnssGeofenceAidl init() failed.");
41 }
42 
addGeofence(int geofenceId,double latitudeDegrees,double longitudeDegrees,double radiusMeters,int lastTransition,int monitorTransitions,int notificationResponsivenessMs,int unknownTimerMs)43 jboolean GnssGeofenceAidl::addGeofence(int geofenceId, double latitudeDegrees,
44                                        double longitudeDegrees, double radiusMeters,
45                                        int lastTransition, int monitorTransitions,
46                                        int notificationResponsivenessMs, int unknownTimerMs) {
47     auto status = mIGnssGeofenceAidl->addGeofence(geofenceId, latitudeDegrees, longitudeDegrees,
48                                                   radiusMeters, lastTransition, monitorTransitions,
49                                                   notificationResponsivenessMs, unknownTimerMs);
50     return checkAidlStatus(status, "IGnssGeofenceAidl addGeofence() failed");
51 }
52 
removeGeofence(int geofenceId)53 jboolean GnssGeofenceAidl::removeGeofence(int geofenceId) {
54     auto status = mIGnssGeofenceAidl->removeGeofence(geofenceId);
55     return checkAidlStatus(status, "IGnssGeofenceAidl removeGeofence() failed.");
56 }
57 
pauseGeofence(int geofenceId)58 jboolean GnssGeofenceAidl::pauseGeofence(int geofenceId) {
59     auto status = mIGnssGeofenceAidl->pauseGeofence(geofenceId);
60     return checkAidlStatus(status, "IGnssGeofenceAidl pauseGeofence() failed.");
61 }
62 
resumeGeofence(int geofenceId,int monitorTransitions)63 jboolean GnssGeofenceAidl::resumeGeofence(int geofenceId, int monitorTransitions) {
64     auto status = mIGnssGeofenceAidl->resumeGeofence(geofenceId, monitorTransitions);
65     return checkAidlStatus(status, "IGnssGeofenceAidl resumeGeofence() failed.");
66 }
67 
68 // Implementation of GnssGeofenceHidl
69 
GnssGeofenceHidl(const sp<IGnssGeofenceHidl> & iGnssGeofence)70 GnssGeofenceHidl::GnssGeofenceHidl(const sp<IGnssGeofenceHidl>& iGnssGeofence)
71       : mIGnssGeofenceHidl(iGnssGeofence) {
72     assert(mIGnssGeofenceHidl != nullptr);
73 }
74 
setCallback(const std::unique_ptr<GnssGeofenceCallback> & callback)75 jboolean GnssGeofenceHidl::setCallback(const std::unique_ptr<GnssGeofenceCallback>& callback) {
76     auto result = mIGnssGeofenceHidl->setCallback(callback->getHidl());
77     return checkHidlReturn(result, "IGnssGeofenceHidl setCallback() failed.");
78 }
79 
addGeofence(int geofenceId,double latitudeDegrees,double longitudeDegrees,double radiusMeters,int lastTransition,int monitorTransitions,int notificationResponsivenessMs,int unknownTimerMs)80 jboolean GnssGeofenceHidl::addGeofence(int geofenceId, double latitudeDegrees,
81                                        double longitudeDegrees, double radiusMeters,
82                                        int lastTransition, int monitorTransitions,
83                                        int notificationResponsivenessMs, int unknownTimerMs) {
84     auto result = mIGnssGeofenceHidl->addGeofence(geofenceId, latitudeDegrees, longitudeDegrees,
85                                                   radiusMeters,
86                                                   static_cast<GeofenceTransition>(lastTransition),
87                                                   static_cast<hidl_bitfield<GeofenceTransition>>(
88                                                           monitorTransitions),
89                                                   notificationResponsivenessMs, unknownTimerMs);
90     return checkHidlReturn(result, "IGnssGeofence addGeofence() failed.");
91 }
92 
removeGeofence(int geofenceId)93 jboolean GnssGeofenceHidl::removeGeofence(int geofenceId) {
94     auto result = mIGnssGeofenceHidl->removeGeofence(geofenceId);
95     return checkHidlReturn(result, "IGnssGeofence removeGeofence() failed.");
96 }
97 
pauseGeofence(int geofenceId)98 jboolean GnssGeofenceHidl::pauseGeofence(int geofenceId) {
99     auto result = mIGnssGeofenceHidl->pauseGeofence(geofenceId);
100     return checkHidlReturn(result, "IGnssGeofence pauseGeofence() failed.");
101 }
102 
resumeGeofence(int geofenceId,int monitorTransitions)103 jboolean GnssGeofenceHidl::resumeGeofence(int geofenceId, int monitorTransitions) {
104     auto result = mIGnssGeofenceHidl->resumeGeofence(geofenceId, monitorTransitions);
105     return checkHidlReturn(result, "IGnssGeofence resumeGeofence() failed.");
106 }
107 
108 } // namespace android::gnss
109