Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a6164c9 authored by Ruchir Rastogi's avatar Ruchir Rastogi Committed by Jeffrey Huang
Browse files

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
parent c162886a
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -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: {
+0 −2
Original line number Diff line number Diff line
@@ -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.
+0 −4
Original line number Diff line number Diff line
@@ -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);
+13 −11
Original line number Diff line number Diff line
@@ -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(),
    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());
    if (checkPermission(kPermissionDump)) {
    bool enabled = true;
    if (args.size() >= 2) {
        enabled = atoi(args[1].c_str()) != 0;
    }
    mProcessor->setPrintLogs(enabled);
    return NO_ERROR;
    } else {
        return PERMISSION_DENIED;
    }
}

bool StatsService::getUidFromArgs(const Vector<String8>& args, size_t uidArgIndex, int32_t& uid) {