wvcdm: filter logs by app uid

This commit is a combination of the following:
* http://go/wvgerrit/117003
* http://go/wvgerrit/118303

Bug: 162255728
Test: MediaDrmTest#testGetLogMessages
Change-Id: I5699b64d5c4bab463e5b587595fa7d324dc1d93f
This commit is contained in:
Robert Shih
2021-03-01 08:53:15 -08:00
parent 1ffc6ab16a
commit 7cb52c1ccf
19 changed files with 127 additions and 16 deletions

View File

@@ -33,6 +33,7 @@ typedef enum {
extern LogPriority g_cutoff;
struct LogMessage {
uint32_t uid_;
int64_t time_ms_;
LogPriority priority_;
std::string message_;
@@ -51,6 +52,26 @@ class LogBuffer {
extern LogBuffer g_logbuf;
static const uint32_t UNKNOWN_UID = ~0;
#ifdef __ANDROID__
void SetLoggingUid(const uint32_t);
void ClearLoggingUid();
uint32_t GetLoggingUid();
uint32_t GetIpcCallingUid();
#else
static inline void SetLoggingUid(const uint32_t) {}
static inline void ClearLoggingUid() {}
static inline uint32_t GetLoggingUid() { return UNKNOWN_UID; }
static inline uint32_t GetIpcCallingUid() { return UNKNOWN_UID; }
#endif
struct LoggingUidSetter {
LoggingUidSetter() {}
LoggingUidSetter(uint32_t uid) { SetLoggingUid(uid); }
virtual ~LoggingUidSetter() { ClearLoggingUid(); }
};
// Enable/disable verbose logging (LOGV).
// This function is supplied for cases where the system layer does not
// initialize logging. This is also needed to initialize logging in

View File

@@ -22,6 +22,7 @@
#define LOG_BUF_SIZE 1024
#include "log.h"
#include <hwbinder/IPCThreadState.h>
#include <utils/Log.h>
#include <stdarg.h>
@@ -54,6 +55,27 @@ LogPriority g_cutoff = LOG_VERBOSE;
LogBuffer g_logbuf;
thread_local bool tl_logging_uid_set_ = false;
thread_local uint32_t tl_logging_uid_ = UNKNOWN_UID;
void SetLoggingUid(const uint32_t uid) {
tl_logging_uid_set_ = true;
tl_logging_uid_ = uid;
}
void ClearLoggingUid() {
tl_logging_uid_set_ = false;
tl_logging_uid_ = UNKNOWN_UID;
}
uint32_t GetLoggingUid() { return tl_logging_uid_; }
uint32_t GetIpcCallingUid() {
const auto self = android::hardware::IPCThreadState::selfOrNull();
return self ? self->getCallingUid() : UNKNOWN_UID;
}
void InitLogging() {}
void Log(const char* file, const char* function, int line, LogPriority level,
@@ -101,7 +123,8 @@ void Log(const char* file, const char* function, int line, LogPriority level,
__android_log_write(prio, LOG_TAG, buf);
if (level <= LOG_INFO) {
g_logbuf.addLog({GetCurrentTimeMs(), level, buf});
uint32_t uid = tl_logging_uid_set_ ? tl_logging_uid_ : GetIpcCallingUid();
g_logbuf.addLog({uid, GetCurrentTimeMs(), level, buf});
}
}