1 /**
2 * Copyright (C) 2020 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 <stdbool.h>
18 #include <stdint.h>
19
20 #include "chpp/common/gnss.h"
21 #include "chpp/macros.h"
22 #include "chre/pal/gnss.h"
23
24 static const struct chrePalSystemApi *gSystemApi;
25 static const struct chrePalGnssCallbacks *gCallbacks;
26
gnssPalOpen(const struct chrePalSystemApi * systemApi,const struct chrePalGnssCallbacks * callbacks)27 static bool gnssPalOpen(const struct chrePalSystemApi *systemApi,
28 const struct chrePalGnssCallbacks *callbacks) {
29 gSystemApi = systemApi;
30 gCallbacks = callbacks;
31
32 return true;
33 }
34
gnssPalClose(void)35 static void gnssPalClose(void) {}
36
gnssPalGetCapabilities(void)37 static uint32_t gnssPalGetCapabilities(void) {
38 return CHRE_GNSS_CAPABILITIES_LOCATION | CHRE_GNSS_CAPABILITIES_MEASUREMENTS |
39 CHRE_GNSS_CAPABILITIES_GNSS_ENGINE_BASED_PASSIVE_LISTENER;
40 }
41
gnssPalControlLocationSession(bool enable,uint32_t minIntervalMs,uint32_t minTimeToNextFixMs)42 static bool gnssPalControlLocationSession(bool enable, uint32_t minIntervalMs,
43 uint32_t minTimeToNextFixMs) {
44 // TODO
45 UNUSED_VAR(enable);
46 UNUSED_VAR(minIntervalMs);
47 UNUSED_VAR(minTimeToNextFixMs);
48
49 return true; // If successful
50 }
51
gnssPalReleaseLocationEvent(struct chreGnssLocationEvent * event)52 static void gnssPalReleaseLocationEvent(struct chreGnssLocationEvent *event) {
53 gSystemApi->memoryFree(event);
54 }
55
gnssPalControlMeasurementSessiont(bool enable,uint32_t minIntervalMs)56 static bool gnssPalControlMeasurementSessiont(bool enable,
57 uint32_t minIntervalMs) {
58 // TODO
59 UNUSED_VAR(enable);
60 UNUSED_VAR(minIntervalMs);
61
62 return true; // If successful
63 }
64
gnssPalReleaseMeasurementDataEvent(struct chreGnssDataEvent * event)65 static void gnssPalReleaseMeasurementDataEvent(
66 struct chreGnssDataEvent *event) {
67 gSystemApi->memoryFree(CHPP_CONST_CAST_POINTER(event->measurements));
68 gSystemApi->memoryFree(event);
69 }
70
gnssPalConfigurePassiveLocationListener(bool enable)71 static bool gnssPalConfigurePassiveLocationListener(bool enable) {
72 // TODO
73 UNUSED_VAR(enable);
74
75 return true; // If successful
76 }
77
78 #ifdef CHPP_SERVICE_ENABLED_GNSS
chrePalGnssGetApi(uint32_t requestedApiVersion)79 const struct chrePalGnssApi *chrePalGnssGetApi(uint32_t requestedApiVersion) {
80 static const struct chrePalGnssApi api = {
81 .moduleVersion = CHPP_PAL_GNSS_API_VERSION,
82 .open = gnssPalOpen,
83 .close = gnssPalClose,
84 .getCapabilities = gnssPalGetCapabilities,
85 .controlLocationSession = gnssPalControlLocationSession,
86 .releaseLocationEvent = gnssPalReleaseLocationEvent,
87 .controlMeasurementSession = gnssPalControlMeasurementSessiont,
88 .releaseMeasurementDataEvent = gnssPalReleaseMeasurementDataEvent,
89 .configurePassiveLocationListener =
90 gnssPalConfigurePassiveLocationListener,
91 };
92
93 CHPP_STATIC_ASSERT(
94 CHRE_PAL_GNSS_API_CURRENT_VERSION == CHPP_PAL_GNSS_API_VERSION,
95 "A newer CHRE PAL API version is available. Please update.");
96
97 if (!CHRE_PAL_VERSIONS_ARE_COMPATIBLE(api.moduleVersion,
98 requestedApiVersion)) {
99 return NULL;
100 } else {
101 return &api;
102 }
103 }
104 #endif
105