xref: /aosp_15_r20/system/chre/platform/shared/chre_api_gnss.cc (revision 84e339476a462649f82315436d70fd732297a399)
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 #include "chre_api/chre/gnss.h"
18 
19 #include "chre/core/event_loop_manager.h"
20 #include "chre/util/macros.h"
21 #include "chre/util/system/napp_permissions.h"
22 #include "chre/util/time.h"
23 
24 using chre::EventLoopManager;
25 using chre::EventLoopManagerSingleton;
26 using chre::Milliseconds;
27 using chre::Nanoapp;
28 using chre::NanoappPermissions;
29 
chreGnssGetCapabilities()30 DLL_EXPORT uint32_t chreGnssGetCapabilities() {
31 #ifdef CHRE_GNSS_SUPPORT_ENABLED
32   return EventLoopManagerSingleton::get()->getGnssManager().getCapabilities();
33 #else
34   return CHRE_GNSS_CAPABILITIES_NONE;
35 #endif  // CHRE_GNSS_SUPPORT_ENABLED
36 }
37 
chreGnssLocationSessionStartAsync(uint32_t minIntervalMs,uint32_t minTimeToNextFixMs,const void * cookie)38 DLL_EXPORT bool chreGnssLocationSessionStartAsync(
39     [[maybe_unused]] uint32_t minIntervalMs,
40     [[maybe_unused]] uint32_t minTimeToNextFixMs,
41     [[maybe_unused]] const void *cookie) {
42 #ifdef CHRE_GNSS_SUPPORT_ENABLED
43   Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
44   return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_GNSS) &&
45          EventLoopManagerSingleton::get()
46              ->getGnssManager()
47              .getLocationSession()
48              .addRequest(nanoapp, Milliseconds(minIntervalMs),
49                          Milliseconds(minTimeToNextFixMs), cookie);
50 #else
51   return false;
52 #endif  // CHRE_GNSS_SUPPORT_ENABLED
53 }
54 
chreGnssLocationSessionStopAsync(const void * cookie)55 DLL_EXPORT bool chreGnssLocationSessionStopAsync(
56     [[maybe_unused]] const void *cookie) {
57 #ifdef CHRE_GNSS_SUPPORT_ENABLED
58   Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
59   return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_GNSS) &&
60          EventLoopManagerSingleton::get()
61              ->getGnssManager()
62              .getLocationSession()
63              .removeRequest(nanoapp, cookie);
64 #else
65   return false;
66 #endif  // CHRE_GNSS_SUPPORT_ENABLED
67 }
68 
chreGnssMeasurementSessionStartAsync(uint32_t minIntervalMs,const void * cookie)69 DLL_EXPORT bool chreGnssMeasurementSessionStartAsync(
70     [[maybe_unused]] uint32_t minIntervalMs, [[maybe_unused]] const void *cookie) {
71 #ifdef CHRE_GNSS_SUPPORT_ENABLED
72   Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
73   return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_GNSS) &&
74          EventLoopManagerSingleton::get()
75              ->getGnssManager()
76              .getMeasurementSession()
77              .addRequest(nanoapp, Milliseconds(minIntervalMs),
78                          Milliseconds(0) /* minTimeToNext */, cookie);
79 #else
80   return false;
81 #endif  // CHRE_GNSS_SUPPORT_ENABLED
82 }
83 
chreGnssMeasurementSessionStopAsync(const void * cookie)84 DLL_EXPORT bool chreGnssMeasurementSessionStopAsync(
85     [[maybe_unused]] const void *cookie) {
86 #ifdef CHRE_GNSS_SUPPORT_ENABLED
87   Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
88   return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_GNSS) &&
89          EventLoopManagerSingleton::get()
90              ->getGnssManager()
91              .getMeasurementSession()
92              .removeRequest(nanoapp, cookie);
93 #else
94   return false;
95 #endif  // CHRE_GNSS_SUPPORT_ENABLED
96 }
97 
chreGnssConfigurePassiveLocationListener(bool enable)98 DLL_EXPORT bool chreGnssConfigurePassiveLocationListener(
99     [[maybe_unused]] bool enable) {
100 #ifdef CHRE_GNSS_SUPPORT_ENABLED
101   Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
102   return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_GNSS) &&
103          EventLoopManagerSingleton::get()
104              ->getGnssManager()
105              .configurePassiveLocationListener(nanoapp, enable);
106 #else
107   return false;
108 #endif  // CHRE_GNSS_SUPPORT_ENABLED
109 }
110