| Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
| Mark Salyzyn | d048f11 | 2016-02-08 10:28:12 -0800 | [diff] [blame] | 20 | #include <sys/cdefs.h> | 
| Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 21 | #include <sys/types.h> | 
|  | 22 |  | 
|  | 23 | #include <log/log.h> | 
| Mark Salyzyn | 083b037 | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 24 | #include <sysutils/SocketClient.h> | 
| Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 25 |  | 
|  | 26 | // Hijack this header as a common include file used by most all sources | 
|  | 27 | // to report some utilities defined here and there. | 
|  | 28 |  | 
|  | 29 | namespace android { | 
|  | 30 |  | 
|  | 31 | // Furnished in main.cpp. Caller must own and free returned value | 
|  | 32 | char *uidToName(uid_t uid); | 
| Mark Salyzyn | d048f11 | 2016-02-08 10:28:12 -0800 | [diff] [blame] | 33 | void prdebug(const char *fmt, ...) __printflike(1, 2); | 
| Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 34 |  | 
|  | 35 | // Furnished in LogStatistics.cpp. Caller must own and free returned value | 
|  | 36 | char *pidToName(pid_t pid); | 
|  | 37 | char *tidToName(pid_t tid); | 
|  | 38 |  | 
|  | 39 | // Furnished in main.cpp. Thread safe. | 
|  | 40 | const char *tagToName(uint32_t tag); | 
|  | 41 |  | 
|  | 42 | } | 
|  | 43 |  | 
| Mark Salyzyn | 083b037 | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 44 | // Furnished in LogCommand.cpp | 
|  | 45 | bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid); | 
|  | 46 | bool clientHasLogCredentials(SocketClient *cli); | 
|  | 47 |  | 
| Mark Salyzyn | cdda62b | 2015-12-14 13:07:12 -0800 | [diff] [blame] | 48 | // Furnished in main.cpp | 
| Mark Salyzyn | 9c66a58 | 2015-12-14 16:40:12 -0800 | [diff] [blame] | 49 | #define BOOL_DEFAULT_FLAG_TRUE_FALSE 0x1 | 
|  | 50 | #define BOOL_DEFAULT_FALSE       0x0     // false if property not present | 
|  | 51 | #define BOOL_DEFAULT_TRUE        0x1     // true if property not present | 
|  | 52 | #define BOOL_DEFAULT_FLAG_PERSIST    0x2 // <key>, persist.<key>, ro.<key> | 
|  | 53 | #define BOOL_DEFAULT_FLAG_ENG        0x4 // off for user | 
|  | 54 | #define BOOL_DEFAULT_FLAG_SVELTE     0x8 // off for low_ram | 
|  | 55 |  | 
|  | 56 | bool property_get_bool(const char *key, int def); | 
| Mark Salyzyn | cdda62b | 2015-12-14 13:07:12 -0800 | [diff] [blame] | 57 |  | 
| Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 58 | static inline bool worstUidEnabledForLogid(log_id_t id) { | 
| Mark Salyzyn | 6a06694 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 59 | return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) || | 
|  | 60 | (id == LOG_ID_RADIO) || (id == LOG_ID_EVENTS); | 
| Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 61 | } | 
|  | 62 |  | 
| Mark Salyzyn | ddda212 | 2015-10-02 09:22:52 -0700 | [diff] [blame] | 63 | template <int (*cmp)(const char *l, const char *r, const size_t s)> | 
|  | 64 | static inline int fast(const char *l, const char *r, const size_t s) { | 
|  | 65 | return (*l != *r) || cmp(l + 1, r + 1, s - 1); | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | template <int (*cmp)(const void *l, const void *r, const size_t s)> | 
|  | 69 | static inline int fast(const void *lv, const void *rv, const size_t s) { | 
|  | 70 | const char *l = static_cast<const char *>(lv); | 
|  | 71 | const char *r = static_cast<const char *>(rv); | 
|  | 72 | return (*l != *r) || cmp(l + 1, r + 1, s - 1); | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | template <int (*cmp)(const char *l, const char *r)> | 
|  | 76 | static inline int fast(const char *l, const char *r) { | 
|  | 77 | return (*l != *r) || cmp(l + 1, r + 1); | 
|  | 78 | } | 
|  | 79 |  | 
| Mark Salyzyn | 5ac5c6b | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 80 | #endif // _LOGD_LOG_UTILS_H__ |