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

Commit 4e83de27 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make state_option top-level boolean annotations" into rvc-dev

parents 48079ba3 3f9c330e
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -22,13 +22,11 @@ namespace statsd {

const uint8_t ANNOTATION_ID_IS_UID = 1;
const uint8_t ANNOTATION_ID_TRUNCATE_TIMESTAMP = 2;
const uint8_t ANNOTATION_ID_STATE_OPTION = 3;
const uint8_t ANNOTATION_ID_RESET_STATE = 5;
const uint8_t ANNOTATION_ID_STATE_NESTED = 6;

const int32_t STATE_OPTION_PRIMARY_FIELD = 1;
const int32_t STATE_OPTION_EXCLUSIVE_STATE = 2;
const int32_t STATE_OPTION_PRIMARY_FIELD_FIRST_UID = 3;
const uint8_t ANNOTATION_ID_PRIMARY_FIELD = 3;
const uint8_t ANNOTATION_ID_EXCLUSIVE_STATE = 4;
const uint8_t ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID = 5;
const uint8_t ANNOTATION_ID_TRIGGER_STATE_RESET = 7;
const uint8_t ANNOTATION_ID_STATE_NESTED = 8;

} // namespace statsd
} // namespace os
+23 −27
Original line number Diff line number Diff line
@@ -23,25 +23,12 @@ option java_outer_classname = "AtomFieldOptions";

import "google/protobuf/descriptor.proto";

enum StateField {
    // Default value for fields that are not a primary or exclusive state field.
    STATE_FIELD_UNSET = 0;
    // Fields that represent the key that the state belongs to.
    // Used on simple proto fields. Do not use on attribution chains.
    PRIMARY_FIELD = 1;
    // The field that represents the state. It's an exclusive state.
    EXCLUSIVE_STATE = 2;
    // Used on an attribution chain field to indicate that the first uid is the
    // primary field.
    PRIMARY_FIELD_FIRST_UID = 3;
}

// Used to annotate an atom that represents a state change. A state change atom must have exactly
// ONE exclusive state field, and any number of primary key fields. For example, message
// UidProcessStateChanged {
//    optional int32 uid = 1 [(state_field_option).option = PRIMARY_FIELD];
//    optional android.app.ProcessStateEnum state = 2 [(state_field_option).option =
//    EXCLUSIVE_STATE];
//    optional int32 uid = 1 [(state_field_option).primary_field = true];
//    optional android.app.ProcessStateEnum state =
//            2 [(state_field_option).exclusive_state = true];
//  }
// Each UidProcessStateChanged atom event represents a state change for a specific uid.
// A new state automatically overrides the previous state.
@@ -50,23 +37,23 @@ enum StateField {
// primary fields are the primary key.
// For example:
// message ThreadStateChanged {
//    optional int32 pid = 1  [(state_field_option).option = PRIMARY_FIELD];
//    optional int32 tid = 2  [(state_field_option).option = PRIMARY_FIELD];
//    optional int32 state = 3 [(state_field_option).option = EXCLUSIVE_STATE];
//    optional int32 pid = 1  [(state_field_option).primary_field = true];
//    optional int32 tid = 2  [(state_field_option).primary_field = true];
//    optional int32 state = 3 [(state_field_option).exclusive_state = true];
// }
//
// Sometimes, there is no primary key field, when the state is GLOBAL.
// For example,
// message ScreenStateChanged {
//    optional android.view.DisplayStateEnum state = 1 [(state_field_option).option =
//    EXCLUSIVE_STATE];
//    optional android.view.DisplayStateEnum state =
//          1 [(state_field_option).exclusive_state = true];
// }
//
// For state atoms with attribution chain, sometimes the primary key is the first uid in the chain.
// For example:
// message AudioStateChanged {
//   repeated AttributionNode attribution_node = 1
//       [(stateFieldOption).option = PRIMARY_KEY_FIRST_UID];
//       [(stateFieldOption).primary_field_first_uid = true];
//
//    enum State {
//      OFF = 0;
@@ -74,10 +61,19 @@ enum StateField {
//      // RESET indicates all audio stopped. Used when it (re)starts (e.g. after it crashes).
//      RESET = 2;
//    }
//    optional State state = 2 [(stateFieldOption).option = EXCLUSIVE_STATE];
//    optional State state = 2 [(stateFieldOption).exclusive_state = true];
// }
message StateAtomFieldOption {
    optional StateField option = 1 [default = STATE_FIELD_UNSET];
    // Fields that represent the key that the state belongs to.
    // Used on simple proto fields. Do not use on attribution chains.
    optional bool primary_field = 1 [default = false];

    // The field that represents the state. It's an exclusive state.
    optional bool exclusive_state = 2 [default = false];

    // Used on an attribution chain field to indicate that the first uid is the
    // primary field.
    optional bool primary_field_first_uid = 3 [default = false];

    // Note: We cannot annotate directly on the enums because many enums are imported from other
    // proto files in the platform. proto-lite cc library does not support annotations unfortunately
@@ -85,14 +81,14 @@ message StateAtomFieldOption {
    // Knowing the default state value allows state trackers to remove entries that become the
    // default state. If there is no default value specified, the default value is unknown, and all
    // states will be tracked in memory.
    optional int32 default_state_value = 2;
    optional int32 default_state_value = 4;

    // A reset state signals all states go to default value. For example, BLE reset means all active
    // BLE scans are to be turned off.
    optional int32 reset_state_value = 3;
    optional int32 trigger_state_reset_value = 5;

    // If the state change needs to count nesting.
    optional bool nested = 4 [default = true];
    optional bool nested = 6 [default = true];
}

// Used to generate StatsLog.write APIs.
+20 −21
Original line number Diff line number Diff line
@@ -610,7 +610,7 @@ message ThermalThrottlingStateChanged {
message ScreenStateChanged {
    // New screen state, from frameworks/base/core/proto/android/view/enums.proto.
    optional android.view.DisplayStateEnum state = 1
            [(state_field_option).option = EXCLUSIVE_STATE, (state_field_option).nested = false];
            [(state_field_option).exclusive_state = true, (state_field_option).nested = false];
}

/**
@@ -621,11 +621,11 @@ message ScreenStateChanged {
 *   frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
 */
message UidProcessStateChanged {
    optional int32 uid = 1 [(state_field_option).option = PRIMARY_FIELD, (is_uid) = true];
    optional int32 uid = 1 [(state_field_option).primary_field = true, (is_uid) = true];

    // The state, from frameworks/base/core/proto/android/app/enums.proto.
    optional android.app.ProcessStateEnum state = 2
            [(state_field_option).option = EXCLUSIVE_STATE, (state_field_option).nested = false];
            [(state_field_option).exclusive_state = true, (state_field_option).nested = false];
}

/**
@@ -657,7 +657,7 @@ message ActivityManagerSleepStateChanged {
        ASLEEP = 1;
        AWAKE = 2;
    }
    optional State state = 1 [(state_field_option).option = EXCLUSIVE_STATE];
    optional State state = 1 [(state_field_option).exclusive_state = true];
}

/**
@@ -676,7 +676,7 @@ message MemoryFactorStateChanged {
        CRITICAL = 4;   // critical memory.

    }
    optional State factor = 1 [(state_field_option).option = EXCLUSIVE_STATE];
    optional State factor = 1 [(state_field_option).exclusive_state = true];
}

/**
@@ -854,7 +854,7 @@ message ProcessLifeCycleStateChanged {
 */
message BleScanStateChanged {
    repeated AttributionNode attribution_node = 1
            [(state_field_option).option = PRIMARY_FIELD_FIRST_UID];
            [(state_field_option).primary_field_first_uid = true];

    enum State {
        OFF = 0;
@@ -863,18 +863,18 @@ message BleScanStateChanged {
        RESET = 2;
    }
    optional State state = 2 [
        (state_field_option).option = EXCLUSIVE_STATE,
        (state_field_option).exclusive_state = true,
        (state_field_option).default_state_value = 0 /* State.OFF */,
        (state_field_option).reset_state_value = 2 /* State.RESET */,
        (state_field_option).trigger_state_reset_value = 2 /* State.RESET */,
        (state_field_option).nested = true
    ];

    // Does the scan have a filter.
    optional bool is_filtered = 3 [(state_field_option).option = PRIMARY_FIELD];
    optional bool is_filtered = 3 [(state_field_option).primary_field = true];
    // Whether the scan is a CALLBACK_TYPE_FIRST_MATCH scan. Called 'background' scan internally.
    optional bool is_first_match = 4 [(state_field_option).option = PRIMARY_FIELD];
    optional bool is_first_match = 4 [(state_field_option).primary_field = true];
    // Whether the scan set to piggy-back off the results of other scans (SCAN_MODE_OPPORTUNISTIC).
    optional bool is_opportunistic = 5 [(state_field_option).option = PRIMARY_FIELD];
    optional bool is_opportunistic = 5 [(state_field_option).primary_field = true];
}

/**
@@ -1105,15 +1105,14 @@ message CameraStateChanged {
 */
message WakelockStateChanged {
    repeated AttributionNode attribution_node = 1
            [(state_field_option).option = PRIMARY_FIELD_FIRST_UID];
            [(state_field_option).primary_field_first_uid = true];

    // The type (level) of the wakelock; e.g. a partial wakelock or a full wakelock.
    // From frameworks/base/core/proto/android/os/enums.proto.
    optional android.os.WakeLockLevelEnum type = 2 [(state_field_option).option = PRIMARY_FIELD];
    ;
    optional android.os.WakeLockLevelEnum type = 2 [(state_field_option).primary_field = true];

    // The wakelock tag (Called tag in the Java API, sometimes name elsewhere).
    optional string tag = 3 [(state_field_option).option = PRIMARY_FIELD];
    optional string tag = 3 [(state_field_option).primary_field = true];

    enum State {
        RELEASE = 0;
@@ -1122,7 +1121,7 @@ message WakelockStateChanged {
        CHANGE_ACQUIRE = 3;
    }
    optional State state = 4 [
        (state_field_option).option = EXCLUSIVE_STATE,
        (state_field_option).exclusive_state = true,
        (state_field_option).default_state_value = 0,
        (state_field_option).nested = true
    ];
@@ -3494,9 +3493,9 @@ message PictureInPictureStateChanged {
 *     services/core/java/com/android/server/wm/Session.java
 */
message OverlayStateChanged {
    optional int32 uid = 1 [(state_field_option).option = PRIMARY_FIELD, (is_uid) = true];
    optional int32 uid = 1 [(state_field_option).primary_field = true, (is_uid) = true];

    optional string package_name = 2 [(state_field_option).option = PRIMARY_FIELD];
    optional string package_name = 2 [(state_field_option).primary_field = true];

    optional bool using_alert_window = 3;

@@ -3505,7 +3504,7 @@ message OverlayStateChanged {
        EXITED = 2;
    }
    optional State state = 4 [
        (state_field_option).option = EXCLUSIVE_STATE,
        (state_field_option).exclusive_state = true,
        (state_field_option).nested = false,
        (state_field_option).default_state_value = 2
    ];
@@ -3713,7 +3712,7 @@ message LmkKillOccurred {
 */
message AppDied {
    // timestamp(elapsedRealtime) of record creation
    optional uint64 timestamp_millis = 1 [(state_field_option).option = EXCLUSIVE_STATE];
    optional uint64 timestamp_millis = 1 [(state_field_option).exclusive_state = true];
}

/**
@@ -4235,7 +4234,7 @@ message PrivacyIndicatorsInteracted {
        DIALOG_LINE_ITEM = 5;
    }

    optional Type type = 1 [(state_field_option).option = EXCLUSIVE_STATE];
    optional Type type = 1 [(state_field_option).exclusive_state = true];

    // Used if the type is LINE_ITEM
    optional string package_name = 2;
+55 −47
Original line number Diff line number Diff line
@@ -17,14 +17,14 @@
#define DEBUG false  // STOPSHIP if true
#include "logd/LogEvent.h"

#include <android-base/stringprintf.h>
#include <android/binder_ibinder.h>
#include <private/android_filesystem_config.h>

#include "annotations.h"
#include "stats_log_util.h"
#include "statslog_statsd.h"

#include <android/binder_ibinder.h>
#include <android-base/stringprintf.h>
#include <private/android_filesystem_config.h>

namespace android {
namespace os {
namespace statsd {
@@ -76,9 +76,7 @@ LogEvent::LogEvent(const LogEvent& event) {
}

LogEvent::LogEvent(int32_t uid, int32_t pid)
    : mLogdTimestampNs(time(nullptr)),
      mLogUid(uid),
      mLogPid(pid) {
    : mLogdTimestampNs(time(nullptr)), mLogUid(uid), mLogPid(pid) {
}

LogEvent::LogEvent(const string& trainName, int64_t trainVersionCode, bool requiresStaging,
@@ -261,33 +259,38 @@ void LogEvent::parseTruncateTimestampAnnotation(uint8_t annotationType) {
    mTruncateTimestamp = readNextValue<uint8_t>();
}

void LogEvent::parseStateOptionAnnotation(uint8_t annotationType, int firstUidInChainIndex) {
    if (mValues.empty() || annotationType != INT32_TYPE) {
void LogEvent::parsePrimaryFieldAnnotation(uint8_t annotationType) {
    if (mValues.empty() || annotationType != BOOL_TYPE) {
        mValid = false;
        return;
    }

    int32_t stateOption = readNextValue<int32_t>();
    switch (stateOption) {
        case STATE_OPTION_EXCLUSIVE_STATE:
            mValues[mValues.size() - 1].mAnnotations.setExclusiveState(true);
            break;
        case STATE_OPTION_PRIMARY_FIELD:
            mValues[mValues.size() - 1].mAnnotations.setPrimaryField(true);
            break;
        case STATE_OPTION_PRIMARY_FIELD_FIRST_UID:
            if (firstUidInChainIndex == -1) {
    const bool primaryField = readNextValue<uint8_t>();
    mValues[mValues.size() - 1].mAnnotations.setPrimaryField(primaryField);
}

void LogEvent::parsePrimaryFieldFirstUidAnnotation(uint8_t annotationType,
                                                   int firstUidInChainIndex) {
    if (mValues.empty() || annotationType != BOOL_TYPE || -1 == firstUidInChainIndex) {
        mValid = false;
            } else {
                mValues[firstUidInChainIndex].mAnnotations.setPrimaryField(true);
        return;
    }
            break;
        default:

    const bool primaryField = readNextValue<uint8_t>();
    mValues[firstUidInChainIndex].mAnnotations.setPrimaryField(primaryField);
}

void LogEvent::parseExclusiveStateAnnotation(uint8_t annotationType) {
    if (mValues.empty() || annotationType != BOOL_TYPE) {
        mValid = false;
        return;
    }

    const bool exclusiveState = readNextValue<uint8_t>();
    mValues[mValues.size() - 1].mAnnotations.setExclusiveState(exclusiveState);
}

void LogEvent::parseResetStateAnnotation(uint8_t annotationType) {
void LogEvent::parseTriggerStateResetAnnotation(uint8_t annotationType) {
    if (mValues.empty() || annotationType != INT32_TYPE) {
        mValid = false;
        return;
@@ -321,11 +324,17 @@ void LogEvent::parseAnnotations(uint8_t numAnnotations, int firstUidInChainIndex
            case ANNOTATION_ID_TRUNCATE_TIMESTAMP:
                parseTruncateTimestampAnnotation(annotationType);
                break;
            case ANNOTATION_ID_STATE_OPTION:
                parseStateOptionAnnotation(annotationType, firstUidInChainIndex);
            case ANNOTATION_ID_PRIMARY_FIELD:
                parsePrimaryFieldAnnotation(annotationType);
                break;
            case ANNOTATION_ID_RESET_STATE:
                parseResetStateAnnotation(annotationType);
            case ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID:
                parsePrimaryFieldFirstUidAnnotation(annotationType, firstUidInChainIndex);
                break;
            case ANNOTATION_ID_EXCLUSIVE_STATE:
                parseExclusiveStateAnnotation(annotationType);
                break;
            case ANNOTATION_ID_TRIGGER_STATE_RESET:
                parseTriggerStateResetAnnotation(annotationType);
                break;
            case ANNOTATION_ID_STATE_NESTED:
                parseStateNestedAnnotation(annotationType);
@@ -364,7 +373,6 @@ bool LogEvent::parseBuffer(uint8_t* buf, size_t len) {
    numElements--;
    parseAnnotations(getNumAnnotations(typeInfo));  // atom-level annotations


    for (pos[0] = 1; pos[0] <= numElements && mValid; pos[0]++) {
        last[0] = (pos[0] == numElements);

+4 −2
Original line number Diff line number Diff line
@@ -208,8 +208,10 @@ private:
    void parseAnnotations(uint8_t numAnnotations, int firstUidInChainIndex = -1);
    void parseIsUidAnnotation(uint8_t annotationType);
    void parseTruncateTimestampAnnotation(uint8_t annotationType);
    void parseStateOptionAnnotation(uint8_t annotationType, int firstUidInChainIndex);
    void parseResetStateAnnotation(uint8_t annotationType);
    void parsePrimaryFieldAnnotation(uint8_t annotationType);
    void parsePrimaryFieldFirstUidAnnotation(uint8_t annotationType, int firstUidInChainIndex);
    void parseExclusiveStateAnnotation(uint8_t annotationType);
    void parseTriggerStateResetAnnotation(uint8_t annotationType);
    void parseStateNestedAnnotation(uint8_t annotationType);

    /**
Loading