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

Commit 509d87c2 authored by Andrei-Valentin Onea's avatar Andrei-Valentin Onea Committed by Android (Google) Code Review
Browse files

Merge "Add whitelist atom field option Whitelisted atoms can be triggered from...

Merge "Add whitelist atom field option Whitelisted atoms can be triggered from any source Test: stats-log-api-gen-test Bug: 119217680 Change-Id: Ia5faed04d696b59ba4ffaab13f5046f943d8a8b7"
parents f0cdc787 da01ea5b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -82,4 +82,6 @@ extend google.protobuf.FieldOptions {
    optional bool is_uid = 50001 [default = false];

    optional LogMode log_mode = 50002 [default = MODE_AUTOMATIC];

    optional bool allow_from_any_uid = 50003 [default = false];
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ message Atom {
        PacketWakeupOccurred packet_wakeup_occurred = 44;
        WallClockTimeShifted wall_clock_time_shifted = 45;
        AnomalyDetected anomaly_detected = 46;
        AppBreadcrumbReported app_breadcrumb_reported = 47;
        AppBreadcrumbReported app_breadcrumb_reported = 47 [(allow_from_any_uid) = true];
        AppStartOccurred app_start_occurred = 48;
        AppStartCanceled app_start_canceled = 49;
        AppStartFullyDrawn app_start_fully_drawn = 50;
@@ -121,7 +121,7 @@ message Atom {
        AppStartMemoryStateCaptured app_start_memory_state_captured = 55;
        ShutdownSequenceReported shutdown_sequence_reported = 56;
        BootSequenceReported boot_sequence_reported = 57;
        DaveyOccurred davey_occurred = 58;
        DaveyOccurred davey_occurred = 58 [(allow_from_any_uid) = true];
        OverlayStateChanged overlay_state_changed = 59;
        ForegroundServiceStateChanged foreground_service_state_changed = 60;
        CallStateChanged call_state_changed = 61;
+39 −18
Original line number Diff line number Diff line
@@ -241,12 +241,22 @@ void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs,
    VLOG("=========================Metric Reports End==========================");
}

// Consume the stats log if it's interesting to this metric.
void MetricsManager::onLogEvent(const LogEvent& event) {
    if (!mConfigValid) {
        return;

bool MetricsManager::checkLogCredentials(const LogEvent& event) {
    if (android::util::AtomsInfo::kWhitelistedAtoms.find(event.GetTagId()) !=
      android::util::AtomsInfo::kWhitelistedAtoms.end()) 
    {
        return true;
    }
    std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
    if (mAllowedLogSources.find(event.GetUid()) == mAllowedLogSources.end()) {
        VLOG("log source %d not on the whitelist", event.GetUid());
        return false;
    }
    return true;
}

bool MetricsManager::eventSanityCheck(const LogEvent& event) {
    if (event.GetTagId() == android::util::APP_BREADCRUMB_REPORTED) {
        // Check that app breadcrumb reported fields are valid.
        status_t err = NO_ERROR;
@@ -256,23 +266,23 @@ void MetricsManager::onLogEvent(const LogEvent& event) {
        long appHookUid = event.GetLong(event.size()-2, &err);
        if (err != NO_ERROR ) {
            VLOG("APP_BREADCRUMB_REPORTED had error when parsing the uid");
            return;
            return false;
        }
        int32_t loggerUid = event.GetUid();
        if (loggerUid != appHookUid && loggerUid != AID_STATSD) {
            VLOG("APP_BREADCRUMB_REPORTED has invalid uid: claimed %ld but caller is %d",
                 appHookUid, loggerUid);
            return;
            return false;
        }

        // The state must be from 0,3. This part of code must be manually updated.
        long appHookState = event.GetLong(event.size(), &err);
        if (err != NO_ERROR ) {
            VLOG("APP_BREADCRUMB_REPORTED had error when parsing the state field");
            return;
            return false;
        } else if (appHookState < 0 || appHookState > 3) {
            VLOG("APP_BREADCRUMB_REPORTED does not have valid state %ld", appHookState);
            return;
            return false;
        }
    } else if (event.GetTagId() == android::util::DAVEY_OCCURRED) {
        // Daveys can be logged from any app since they are logged in libs/hwui/JankTracker.cpp.
@@ -283,29 +293,40 @@ void MetricsManager::onLogEvent(const LogEvent& event) {
        long jankUid = event.GetLong(1, &err);
        if (err != NO_ERROR ) {
            VLOG("Davey occurred had error when parsing the uid");
            return;
            return false;
        }
        int32_t loggerUid = event.GetUid();
        if (loggerUid != jankUid && loggerUid != AID_STATSD) {
            VLOG("DAVEY_OCCURRED has invalid uid: claimed %ld but caller is %d", jankUid,
                 loggerUid);
            return;
            return false;
        }

        long duration = event.GetLong(event.size(), &err);
        if (err != NO_ERROR ) {
            VLOG("Davey occurred had error when parsing the duration");
            return;
            return false;
        } else if (duration > 100000) {
            VLOG("Davey duration is unreasonably long: %ld", duration);
            return false;
        }
    }

    return true;
}

// Consume the stats log if it's interesting to this metric.
void MetricsManager::onLogEvent(const LogEvent& event) {
    if (!mConfigValid) {
        return;
    }
    } else {
        std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
        if (mAllowedLogSources.find(event.GetUid()) == mAllowedLogSources.end()) {
            VLOG("log source %d not on the whitelist", event.GetUid());

    if (!checkLogCredentials(event)) {
        return;
    }

    if (!eventSanityCheck(event)) {
        return;
    }

    int tagId = event.GetTagId();
+4 −0
Original line number Diff line number Diff line
@@ -49,6 +49,10 @@ public:
    // Return whether the configuration is valid.
    bool isConfigValid() const;

    bool checkLogCredentials(const LogEvent& event);

    bool eventSanityCheck(const LogEvent& event);

    void onLogEvent(const LogEvent& event);

    void onAnomalyAlarmFired(
+7 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ AtomDecl::AtomDecl(const AtomDecl& that)
      primaryFields(that.primaryFields),
      exclusiveField(that.exclusiveField),
      uidField(that.uidField),
      whitelisted(that.whitelisted),
      binaryFields(that.binaryFields) {}

AtomDecl::AtomDecl(int c, const string& n, const string& m)
@@ -162,6 +163,7 @@ int collate_atom(const Descriptor *atom, AtomDecl *atomDecl,
                 vector<java_type_t> *signature) {

  int errorCount = 0;

  // Build a sorted list of the fields. Descriptor has them in source file
  // order.
  map<int, const FieldDescriptor *> fields;
@@ -387,6 +389,11 @@ int collate_atoms(const Descriptor *descriptor, Atoms *atoms) {

    const Descriptor *atom = atomField->message_type();
    AtomDecl atomDecl(atomField->number(), atomField->name(), atom->name());

    if (atomField->options().GetExtension(os::statsd::allow_from_any_uid) == true) {
      atomDecl.whitelisted = true;
    }

    vector<java_type_t> signature;
    errorCount += collate_atom(atom, &atomDecl, &signature);
    if (atomDecl.primaryFields.size() != 0 && atomDecl.exclusiveField == 0) {
Loading