1 /* Copyright (c) 2014, 2020 The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __LOC_PLA__
30 #define __LOC_PLA__
31
32 #ifdef __cplusplus
33 #ifndef FEATURE_EXTERNAL_AP
34 #include <utils/SystemClock.h>
35 #endif /* FEATURE_EXTERNAL_AP */
36 #include <inttypes.h>
37 #include <sys/time.h>
38 #include <time.h>
39
40 #if defined(__GNUC__) && defined(__GNUC_PREREQ)
41 #if __GNUC_PREREQ(6,0)
42 #pragma message "GNU C version is above 6"
43 #else
44 #pragma message "GNU C version is less than 6"
45 #define NO_UNORDERED_SET_OR_MAP
46 #endif
47 #endif
48
49 // use set/map instead of unordered_set/unordered_map for
50 // older GCC versions
51 #ifdef NO_UNORDERED_SET_OR_MAP
52 #define unordered_set set
53 #define unordered_map map
54 #endif
55
sysTimeMillis(int clock)56 inline int64_t sysTimeMillis(int clock)
57 {
58 struct timespec ts;
59 int64_t time_ms = 0;
60 clock_gettime(clock, &ts);
61 time_ms += (ts.tv_sec * 1000000000LL);
62 time_ms += ts.tv_nsec + 500000LL;
63 return time_ms / 1000000LL;
64 }
65
uptimeMillis()66 inline int64_t uptimeMillis() {
67 return sysTimeMillis(CLOCK_MONOTONIC);
68 }
elapsedRealtime()69 inline int64_t elapsedRealtime() {
70 return sysTimeMillis(CLOCK_BOOTTIME);
71 }
72
73 extern "C" {
74 #endif
75
76 #ifndef FEATURE_EXTERNAL_AP
77 #include <cutils/properties.h>
78 #include <cutils/sched_policy.h>
79 #else
80 #define set_sched_policy(a, b)
81 #endif /* FEATURE_EXTERNAL_AP */
82 #include <pthread.h>
83 #include <sys/time.h>
84 #include <sys/types.h>
85 #include <string.h>
86 #include <stdlib.h>
87 #include <stdio.h>
88 #include <stdarg.h>
89 #define MAX_COMMAND_STR_LEN (255)
90 #define BOOT_KPI_FILE "/sys/kernel/debug/bootkpi/kpi_values"
91 #ifndef OFF_TARGET
92 #include <glib.h>
93 #define strlcat g_strlcat
94 #define strlcpy g_strlcpy
95 #else
96 #define strlcat strncat
97 #define strlcpy strncpy
98 #endif
99
100 #define UID_GPS (1021)
101 #define GID_GPS (1021)
102 #define UID_LOCCLIENT (4021)
103 #define GID_LOCCLIENT (4021)
104
105 #define LOC_PATH_GPS_CONF_STR "/etc/gps.conf"
106 #define LOC_PATH_IZAT_CONF_STR "/etc/izat.conf"
107 #define LOC_PATH_FLP_CONF_STR "/etc/flp.conf"
108 #define LOC_PATH_LOWI_CONF_STR "/etc/lowi.conf"
109 #define LOC_PATH_SAP_CONF_STR "/etc/sap.conf"
110 #define LOC_PATH_APDR_CONF_STR "/etc/apdr.conf"
111 #define LOC_PATH_XTWIFI_CONF_STR "/etc/xtwifi.conf"
112 #define LOC_PATH_QUIPC_CONF_STR "/etc/quipc.conf"
113 #define LOC_PATH_ANT_CORR_STR "/etc/gnss_antenna_info.conf"
114 #define LOC_PATH_SLIM_CONF_STR "/etc/slim.conf"
115 #define LOC_PATH_VPE_CONF_STR "/etc/vpeglue.conf"
116
117 #ifdef FEATURE_EXTERNAL_AP
118 #define PROPERTY_VALUE_MAX 92
119
property_get(const char * key,char * value,const char * default_value)120 inline int property_get(const char* key, char* value, const char* default_value)
121 {
122 strlcpy(value, default_value, PROPERTY_VALUE_MAX - 1);
123 return strlen(value);
124 }
125 #endif /* FEATURE_EXTERNAL_AP */
126
127 /*!
128 * @brief Function for memory block copy
129 *
130 * @param[out] p_Dest Destination buffer.
131 * @param[in] q_DestSize Destination buffer size.
132 * @param[in] p_Src Source buffer.
133 * @param[in] q_SrcSize Source buffer size.
134 *
135 * @return Number of bytes copied.
136 */
memscpy(void * p_Dest,size_t q_DestSize,const void * p_Src,size_t q_SrcSize)137 static inline size_t memscpy (void *p_Dest, size_t q_DestSize, const void *p_Src, size_t q_SrcSize)
138 {
139 size_t res = (q_DestSize < q_SrcSize) ? q_DestSize : q_SrcSize;
140 if (p_Dest && p_Src && q_DestSize > 0 && q_SrcSize > 0) {
141 memcpy(p_Dest, p_Src, res);
142 } else {
143 res = 0;
144 }
145 return res;
146 }
147
148 /*API for boot kpi marker prints */
loc_boot_kpi_marker(const char * pFmt,...)149 static inline int loc_boot_kpi_marker(const char * pFmt, ...)
150 {
151 int result = 0;
152 FILE *stream = NULL;
153 char data[MAX_COMMAND_STR_LEN] = {};
154 char buf[MAX_COMMAND_STR_LEN] = {};
155
156 va_list ap;
157 va_start(ap, pFmt);
158 vsnprintf(&buf[0], sizeof(buf), pFmt, ap);
159 snprintf(data, sizeof(data), "echo -n %s > %s", buf, BOOT_KPI_FILE);
160 stream = popen(data, "w" );
161 if (NULL == stream) {
162 result = -1;
163 } else {
164 pclose(stream);
165 }
166 va_end(ap);
167 return result;
168 }
169
170 #ifdef __cplusplus
171 }
172 #endif /*__cplusplus */
173
174 #endif /* __LOC_PLA__ */
175