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/sched_policy.h>
63 #endif /* FEATURE_EXTERNAL_AP */
64 #include <pthread.h>
65 #include <sys/time.h>
66 #include <sys/types.h>
67 #include <string.h>
68 #include <stdlib.h>
69 #ifndef OFF_TARGET
70 #include <glib.h>
71 #define strlcat g_strlcat
72 #define strlcpy g_strlcpy
73 #else
74 #define strlcat strncat
75 #define strlcpy strncpy
76 #endif
77 
78 #define UID_GPS (1021)
79 #define GID_GPS (1021)
80 #define UID_LOCCLIENT (4021)
81 #define GID_LOCCLIENT (4021)
82 
83 #define LOC_PATH_GPS_CONF_STR      "/etc/gps.conf"
84 #define LOC_PATH_IZAT_CONF_STR     "/etc/izat.conf"
85 #define LOC_PATH_FLP_CONF_STR      "/etc/flp.conf"
86 #define LOC_PATH_LOWI_CONF_STR     "/etc/lowi.conf"
87 #define LOC_PATH_SAP_CONF_STR      "/etc/sap.conf"
88 #define LOC_PATH_APDR_CONF_STR     "/etc/apdr.conf"
89 #define LOC_PATH_XTWIFI_CONF_STR   "/etc/xtwifi.conf"
90 #define LOC_PATH_QUIPC_CONF_STR    "/etc/quipc.conf"
91 
92 #ifdef FEATURE_EXTERNAL_AP
93 #define PROPERTY_VALUE_MAX 92
94 
property_get(const char * key,char * value,const char * default_value)95 inline int property_get(const char* key, char* value, const char* default_value)
96 {
97     strlcpy(value, default_value, PROPERTY_VALUE_MAX - 1);
98     return strlen(value);
99 }
100 #endif /* FEATURE_EXTERNAL_AP */
101 
102 #ifdef __cplusplus
103 }
104 #endif /*__cplusplus */
105 
106 #endif /* __LOC_PLA__ */
107