1 /* Copyright (c) 2014, 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
sysTimeMillis(int clock)40 inline int64_t sysTimeMillis(int clock)
41 {
42 struct timespec ts;
43 int64_t time_ms = 0;
44 clock_gettime(clock, &ts);
45 time_ms += (ts.tv_sec * 1000000000LL);
46 time_ms += ts.tv_nsec + 500000LL;
47 return time_ms / 1000000LL;
48 }
49
uptimeMillis()50 inline int64_t uptimeMillis() {
51 return sysTimeMillis(CLOCK_MONOTONIC);
52 }
elapsedRealtime()53 inline int64_t elapsedRealtime() {
54 return sysTimeMillis(CLOCK_BOOTTIME);
55 }
56
57 extern "C" {
58 #endif
59
60 #ifndef FEATURE_EXTERNAL_AP
61 #include <cutils/properties.h>
62 #include <cutils/threads.h>
63 #include <cutils/sched_policy.h>
64 #endif /* FEATURE_EXTERNAL_AP */
65 #include <pthread.h>
66 #include <sys/time.h>
67 #include <sys/types.h>
68 #include <string.h>
69 #include <stdlib.h>
70 #ifndef OFF_TARGET
71 #include <glib.h>
72 #define strlcat g_strlcat
73 #define strlcpy g_strlcpy
74 #else
75 #define strlcat strncat
76 #define strlcpy strncpy
77 #endif
78
79 #define UID_GPS (1021)
80 #define GID_GPS (1021)
81 #define UID_LOCCLIENT (4021)
82 #define GID_LOCCLIENT (4021)
83
84 #define LOC_PATH_GPS_CONF_STR "/etc/gps.conf"
85 #define LOC_PATH_IZAT_CONF_STR "/etc/izat.conf"
86 #define LOC_PATH_FLP_CONF_STR "/etc/flp.conf"
87 #define LOC_PATH_LOWI_CONF_STR "/etc/lowi.conf"
88 #define LOC_PATH_SAP_CONF_STR "/etc/sap.conf"
89 #define LOC_PATH_APDR_CONF_STR "/etc/apdr.conf"
90 #define LOC_PATH_XTWIFI_CONF_STR "/etc/xtwifi.conf"
91 #define LOC_PATH_QUIPC_CONF_STR "/etc/quipc.conf"
92
93 #ifdef FEATURE_EXTERNAL_AP
94 #define PROPERTY_VALUE_MAX 92
95
property_get(const char * key,char * value,const char * default_value)96 inline int property_get(const char* key, char* value, const char* default_value)
97 {
98 strlcpy(value, default_value, PROPERTY_VALUE_MAX - 1);
99 return strlen(value);
100 }
101 #endif /* FEATURE_EXTERNAL_AP */
102
103 #ifdef __cplusplus
104 }
105 #endif /*__cplusplus */
106
107 #endif /* __LOC_PLA__ */
108