1 /*
2  * Copyright (C) 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 #include "log_fake.h"
18 
19 #include <errno.h>
20 #include <stdarg.h>
21 
22 #include <string>
23 
24 #include <android-base/stringprintf.h>
25 #include <log/log.h>
26 
27 // Forward declarations.
28 class Backtrace;
29 struct EventTagMap;
30 struct AndroidLogEntry;
31 
32 std::string g_fake_log_buf;
33 
34 std::string g_fake_log_print;
35 
resetLogs()36 void resetLogs() {
37   g_fake_log_buf = "";
38   g_fake_log_print = "";
39 }
40 
getFakeLogBuf()41 std::string getFakeLogBuf() {
42   return g_fake_log_buf;
43 }
44 
getFakeLogPrint()45 std::string getFakeLogPrint() {
46   return g_fake_log_print;
47 }
48 
__android_log_buf_write(int bufId,int prio,const char * tag,const char * msg)49 extern "C" int __android_log_buf_write(int bufId, int prio, const char* tag, const char* msg) {
50   g_fake_log_buf += std::to_string(bufId) + ' ' + std::to_string(prio) + ' ';
51   g_fake_log_buf += tag;
52   g_fake_log_buf += ' ';
53   g_fake_log_buf += msg;
54   return 1;
55 }
56 
__android_log_print(int prio,const char * tag,const char * fmt,...)57 extern "C" int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
58   g_fake_log_print += std::to_string(prio) + ' ';
59   g_fake_log_print += tag;
60   g_fake_log_print += ' ';
61 
62   va_list ap;
63   va_start(ap, fmt);
64   android::base::StringAppendV(&g_fake_log_print, fmt, ap);
65   va_end(ap);
66 
67   g_fake_log_print += '\n';
68 
69   return 1;
70 }
71 
android_name_to_log_id(const char *)72 extern "C" log_id_t android_name_to_log_id(const char*) {
73   return LOG_ID_SYSTEM;
74 }
75 
android_logger_list_open(log_id_t,int,unsigned int,pid_t)76 extern "C" struct logger_list* android_logger_list_open(log_id_t, int, unsigned int, pid_t) {
77   errno = EACCES;
78   return nullptr;
79 }
80 
android_logger_list_read(struct logger_list *,struct log_msg *)81 extern "C" int android_logger_list_read(struct logger_list*, struct log_msg*) {
82   return 0;
83 }
84 
android_openEventTagMap(const char *)85 extern "C" EventTagMap* android_openEventTagMap(const char*) {
86   return nullptr;
87 }
88 
android_log_processBinaryLogBuffer(struct logger_entry *,AndroidLogEntry *,const EventTagMap *,char *,int)89 extern "C" int android_log_processBinaryLogBuffer(
90     struct logger_entry*,
91     AndroidLogEntry*, const EventTagMap*, char*, int) {
92   return 0;
93 }
94 
android_logger_list_free(struct logger_list *)95 extern "C" void android_logger_list_free(struct logger_list*) {
96 }
97