diff options
author | Ruchir Rastogi <ruchirr@google.com> | 2020-07-06 15:48:45 -0700 |
---|---|---|
committer | Jeffrey Huang <jeffreyhuang@google.com> | 2020-10-09 10:39:59 -0700 |
commit | 1a6164c94a7277e6d3cef56b2a2041bdffff0dc0 (patch) | |
tree | 0336db318b3aba5aea75116e233e214240ba8884 | |
parent | c162886a3b4a56cfc1e6162c1b1e860f90a80475 (diff) | |
download | base-1a6164c94a7277e6d3cef56b2a2041bdffff0dc0.tar.gz |
Fix print-logs
The VERY_VERBOSE_PRINTING flag guards print-logs functionality but is
not present in the prebuilt version of the statsd module. To fix
print-logs, we remove the flag (thereby allowing print-logs to work on
user, userdebug, and eng builds), but require that the caller have root
privileges.
Test: adb shell cmd stats print-logs && adb logcat -s statsd:I (only works
once root privileges are granted)
Bug: 159982879
Change-Id: I2201fc0538876d1d6dfd6ab7abfac43cccc1102f
Merged-In: I2201fc0538876d1d6dfd6ab7abfac43cccc1102f
-rw-r--r-- | cmds/statsd/Android.bp | 4 | ||||
-rw-r--r-- | cmds/statsd/src/StatsLogProcessor.cpp | 2 | ||||
-rw-r--r-- | cmds/statsd/src/StatsLogProcessor.h | 4 | ||||
-rw-r--r-- | cmds/statsd/src/StatsService.cpp | 24 |
4 files changed, 13 insertions, 21 deletions
diff --git a/cmds/statsd/Android.bp b/cmds/statsd/Android.bp index 0617eb6c0e66..124f815f51f0 100644 --- a/cmds/statsd/Android.bp +++ b/cmds/statsd/Android.bp @@ -216,10 +216,6 @@ cc_binary { // address: true, //}, }, - debuggable: { - // Add a flag to enable stats log printing from statsd on debug builds. - cflags: ["-DVERY_VERBOSE_PRINTING"], - }, }, proto: { diff --git a/cmds/statsd/src/StatsLogProcessor.cpp b/cmds/statsd/src/StatsLogProcessor.cpp index e7b32c56551a..05e9ec3a1769 100644 --- a/cmds/statsd/src/StatsLogProcessor.cpp +++ b/cmds/statsd/src/StatsLogProcessor.cpp @@ -409,11 +409,9 @@ void StatsLogProcessor::OnLogEvent(LogEvent* event, int64_t elapsedRealtimeNs) { onWatchdogRollbackOccurredLocked(event); } -#ifdef VERY_VERBOSE_PRINTING if (mPrintAllLogs) { ALOGI("%s", event->ToString().c_str()); } -#endif resetIfConfigTtlExpiredLocked(eventElapsedTimeNs); // Hard-coded logic to update the isolated uid's in the uid-map. diff --git a/cmds/statsd/src/StatsLogProcessor.h b/cmds/statsd/src/StatsLogProcessor.h index 23f2584655b0..c0f54a0995ac 100644 --- a/cmds/statsd/src/StatsLogProcessor.h +++ b/cmds/statsd/src/StatsLogProcessor.h @@ -139,10 +139,8 @@ public: int64_t getLastReportTimeNs(const ConfigKey& key); inline void setPrintLogs(bool enabled) { -#ifdef VERY_VERBOSE_PRINTING std::lock_guard<std::mutex> lock(mMetricsMutex); mPrintAllLogs = enabled; -#endif } // Add a specific config key to the possible configs to dump ASAP. @@ -276,9 +274,7 @@ private: //Last time we wrote metadata to disk. int64_t mLastMetadataWriteNs = 0; -#ifdef VERY_VERBOSE_PRINTING bool mPrintAllLogs = false; -#endif FRIEND_TEST(StatsLogProcessorTest, TestOutOfOrderLogs); FRIEND_TEST(StatsLogProcessorTest, TestRateLimitByteSize); diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp index 6f952f637506..45043462a248 100644 --- a/cmds/statsd/src/StatsService.cpp +++ b/cmds/statsd/src/StatsService.cpp @@ -484,7 +484,8 @@ void StatsService::print_cmd_help(int out) { dprintf(out, " Clear cached puller data.\n"); dprintf(out, "\n"); dprintf(out, "usage: adb shell cmd stats print-logs\n"); - dprintf(out, " Only works on eng build\n"); + dprintf(out, " Requires root privileges.\n"); + dprintf(out, " Can be disabled by calling adb shell cmd stats print-logs 0\n"); } status_t StatsService::cmd_trigger_broadcast(int out, Vector<String8>& args) { @@ -865,18 +866,19 @@ status_t StatsService::cmd_clear_puller_cache(int out) { } status_t StatsService::cmd_print_logs(int out, const Vector<String8>& args) { - VLOG("StatsService::cmd_print_logs with Pid %i, Uid %i", AIBinder_getCallingPid(), - AIBinder_getCallingUid()); - if (checkPermission(kPermissionDump)) { - bool enabled = true; - if (args.size() >= 2) { - enabled = atoi(args[1].c_str()) != 0; - } - mProcessor->setPrintLogs(enabled); - return NO_ERROR; - } else { + Status status = checkUid(AID_ROOT); + if (!status.isOk()) { return PERMISSION_DENIED; } + + VLOG("StatsService::cmd_print_logs with pid %i, uid %i", AIBinder_getCallingPid(), + AIBinder_getCallingUid()); + bool enabled = true; + if (args.size() >= 2) { + enabled = atoi(args[1].c_str()) != 0; + } + mProcessor->setPrintLogs(enabled); + return NO_ERROR; } bool StatsService::getUidFromArgs(const Vector<String8>& args, size_t uidArgIndex, int32_t& uid) { |