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/threads.h>
79 #include <cutils/sched_policy.h>
80 #else
81 #define set_sched_policy(a, b)
82 #endif /* FEATURE_EXTERNAL_AP */
83 #include <pthread.h>
84 #include <sys/time.h>
85 #include <sys/types.h>
86 #include <string.h>
87 #include <stdlib.h>
88 #include <stdio.h>
89 #include <stdarg.h>
90 #define MAX_COMMAND_STR_LEN (255)
91 #define BOOT_KPI_FILE "/sys/kernel/debug/bootkpi/kpi_values"
92 #ifndef OFF_TARGET
93 #include <glib.h>
94 #define strlcat g_strlcat
95 #define strlcpy g_strlcpy
96 #else
97 #define strlcat strncat
98 #define strlcpy strncpy
99 #endif
100
101 #define UID_GPS (1021)
102 #define GID_GPS (1021)
103 #define UID_LOCCLIENT (4021)
104 #define GID_LOCCLIENT (4021)
105
106 #define LOC_PATH_GPS_CONF_STR "/etc/gps.conf"
107 #define LOC_PATH_IZAT_CONF_STR "/etc/izat.conf"
108 #define LOC_PATH_FLP_CONF_STR "/etc/flp.conf"
109 #define LOC_PATH_LOWI_CONF_STR "/etc/lowi.conf"
110 #define LOC_PATH_SAP_CONF_STR "/etc/sap.conf"
111 #define LOC_PATH_APDR_CONF_STR "/etc/apdr.conf"
112 #define LOC_PATH_XTWIFI_CONF_STR "/etc/xtwifi.conf"
113 #define LOC_PATH_QUIPC_CONF_STR "/etc/quipc.conf"
114 #define LOC_PATH_ANT_CORR_STR "/etc/gnss_antenna_info.conf"
115 #define LOC_PATH_SLIM_CONF_STR "/etc/slim.conf"
116 #define LOC_PATH_VPE_CONF_STR "/etc/vpeglue.conf"
117
118 #ifdef FEATURE_EXTERNAL_AP
119 #define PROPERTY_VALUE_MAX 92
120
property_get(const char * key,char * value,const char * default_value)121 inline int property_get(const char* key, char* value, const char* default_value)
122 {
123 strlcpy(value, default_value, PROPERTY_VALUE_MAX - 1);
124 return strlen(value);
125 }
126 #endif /* FEATURE_EXTERNAL_AP */
127
128 /*!
129 * @brief Function for memory block copy
130 *
131 * @param[out] p_Dest Destination buffer.
132 * @param[in] q_DestSize Destination buffer size.
133 * @param[in] p_Src Source buffer.
134 * @param[in] q_SrcSize Source buffer size.
135 *
136 * @return Number of bytes copied.
137 */
memscpy(void * p_Dest,size_t q_DestSize,const void * p_Src,size_t q_SrcSize)138 static inline size_t memscpy (void *p_Dest, size_t q_DestSize, const void *p_Src, size_t q_SrcSize)
139 {
140 size_t res = (q_DestSize < q_SrcSize) ? q_DestSize : q_SrcSize;
141 if (p_Dest && p_Src && q_DestSize > 0 && q_SrcSize > 0) {
142 memcpy(p_Dest, p_Src, res);
143 } else {
144 res = 0;
145 }
146 return res;
147 }
148
149 /*API for boot kpi marker prints */
loc_boot_kpi_marker(const char * pFmt,...)150 static inline int loc_boot_kpi_marker(const char * pFmt, ...)
151 {
152 int result = 0;
153 FILE *stream = NULL;
154 char data[MAX_COMMAND_STR_LEN] = {};
155 char buf[MAX_COMMAND_STR_LEN] = {};
156
157 va_list ap;
158 va_start(ap, pFmt);
159 vsnprintf(&buf[0], sizeof(buf), pFmt, ap);
160 snprintf(data, sizeof(data), "echo -n %s > %s", buf, BOOT_KPI_FILE);
161 stream = popen(data, "w" );
162 if (NULL == stream) {
163 result = -1;
164 } else {
165 pclose(stream);
166 }
167 va_end(ap);
168 return result;
169 }
170
171 #ifdef __cplusplus
172 }
173 #endif /*__cplusplus */
174
175 #endif /* __LOC_PLA__ */
176