blob: fd4800efadebcb6b9517dd6418bd4a2a81f81860 [file] [log] [blame]
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -07001/*
2 * Copyright (C) 2012-2015 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#ifndef _LOGD_LOG_UTILS_H__
18#define _LOGD_LOG_UTILS_H__
19
20#include <sys/types.h>
21
22#include <log/log.h>
Mark Salyzyn083b0372015-12-04 10:59:45 -080023#include <sysutils/SocketClient.h>
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070024
25// Hijack this header as a common include file used by most all sources
26// to report some utilities defined here and there.
27
28namespace android {
29
30// Furnished in main.cpp. Caller must own and free returned value
31char *uidToName(uid_t uid);
32
33// Furnished in LogStatistics.cpp. Caller must own and free returned value
34char *pidToName(pid_t pid);
35char *tidToName(pid_t tid);
36
37// Furnished in main.cpp. Thread safe.
38const char *tagToName(uint32_t tag);
39
40}
41
Mark Salyzyn083b0372015-12-04 10:59:45 -080042// Furnished in LogCommand.cpp
43bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid);
44bool clientHasLogCredentials(SocketClient *cli);
45
Mark Salyzyncdda62b2015-12-14 13:07:12 -080046// Furnished in main.cpp
Mark Salyzyn9c66a582015-12-14 16:40:12 -080047#define BOOL_DEFAULT_FLAG_TRUE_FALSE 0x1
48#define BOOL_DEFAULT_FALSE 0x0 // false if property not present
49#define BOOL_DEFAULT_TRUE 0x1 // true if property not present
50#define BOOL_DEFAULT_FLAG_PERSIST 0x2 // <key>, persist.<key>, ro.<key>
51#define BOOL_DEFAULT_FLAG_ENG 0x4 // off for user
52#define BOOL_DEFAULT_FLAG_SVELTE 0x8 // off for low_ram
53
54bool property_get_bool(const char *key, int def);
Mark Salyzyncdda62b2015-12-14 13:07:12 -080055
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070056static inline bool worstUidEnabledForLogid(log_id_t id) {
Mark Salyzyn083b0372015-12-04 10:59:45 -080057 return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) || (id == LOG_ID_RADIO);
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070058}
59
Mark Salyzynddda2122015-10-02 09:22:52 -070060template <int (*cmp)(const char *l, const char *r, const size_t s)>
61static inline int fast(const char *l, const char *r, const size_t s) {
62 return (*l != *r) || cmp(l + 1, r + 1, s - 1);
63}
64
65template <int (*cmp)(const void *l, const void *r, const size_t s)>
66static inline int fast(const void *lv, const void *rv, const size_t s) {
67 const char *l = static_cast<const char *>(lv);
68 const char *r = static_cast<const char *>(rv);
69 return (*l != *r) || cmp(l + 1, r + 1, s - 1);
70}
71
72template <int (*cmp)(const char *l, const char *r)>
73static inline int fast(const char *l, const char *r) {
74 return (*l != *r) || cmp(l + 1, r + 1);
75}
76
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070077#endif // _LOGD_LOG_UTILS_H__