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

Commit 10978641 authored by tsaichristine's avatar tsaichristine
Browse files

Add StateTracker classes

One shared StateManager object will manage all StateTrackers across all configs, maintaining a map of atom ids to StateTrackers.

StateManager is responsible for initializing and removing StateTrackers and notifying them of event or StateListener changes.

Each StateTracker maintains a list of StateListeners and is responsible for tracking state values to primary keys and notifying StateListeners when a state change occurs.

Test: bit statsd_test:*
Bug: 136566566

Change-Id: Icb61c668a01b611aa75caa7bdc2a6801c650b119
parent ceb56c59
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -99,6 +99,8 @@ cc_defaults {
        "src/shell/shell_config.proto",
        "src/shell/ShellSubscriber.cpp",
        "src/socket/StatsSocketListener.cpp",
        "src/state/StateManager.cpp",
        "src/state/StateTracker.cpp",
        "src/stats_log_util.cpp",
        "src/statscompanion_util.cpp",
        "src/statsd_config.proto",
@@ -253,6 +255,7 @@ cc_test {
        "tests/metrics/ValueMetricProducer_test.cpp",
        "tests/MetricsManager_test.cpp",
        "tests/shell/ShellSubscriber_test.cpp",
        "tests/state/StateTracker_test.cpp",
        "tests/statsd_test_util.cpp",
        "tests/StatsLogProcessor_test.cpp",
        "tests/StatsService_test.cpp",
+10 −0
Original line number Diff line number Diff line
@@ -59,6 +59,16 @@ android::hash_t hashDimension(const HashableDimensionKey& value) {
    return JenkinsHashWhiten(hash);
}

bool filterValues(const Matcher& matcherField, const vector<FieldValue>& values, Value* output) {
    for (const auto& value : values) {
        if (value.mField.matches(matcherField)) {
            (*output) = value.mValue;
            return true;
        }
    }
    return false;
}

bool filterValues(const vector<Matcher>& matcherFields, const vector<FieldValue>& values,
                  HashableDimensionKey* output) {
    size_t num_matches = 0;
+8 −1
Original line number Diff line number Diff line
@@ -119,6 +119,13 @@ class MetricDimensionKey {

android::hash_t hashDimension(const HashableDimensionKey& key);

/**
 * Returns true if a FieldValue field matches the matcher field.
 * The value of the FieldValue is output.
 */
bool filterValues(const Matcher& matcherField, const std::vector<FieldValue>& values,
                  Value* output);

/**
 * Creating HashableDimensionKeys from FieldValues using matcher.
 *
+3 −3
Original line number Diff line number Diff line
@@ -3067,9 +3067,9 @@ message PictureInPictureStateChanged {
 *     services/core/java/com/android/server/wm/Session.java
 */
message OverlayStateChanged {
    optional int32 uid = 1 [(is_uid) = true];
    optional int32 uid = 1 [(state_field_option).option = PRIMARY, (is_uid) = true];

    optional string package_name = 2;
    optional string package_name = 2 [(state_field_option).option = PRIMARY];

    optional bool using_alert_window = 3;

@@ -3077,7 +3077,7 @@ message OverlayStateChanged {
        ENTERED = 1;
        EXITED = 2;
    }
    optional State state = 4;
    optional State state = 4 [(state_field_option).option = EXCLUSIVE];
}

/*
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <utils/RefBase.h>

#include "HashableDimensionKey.h"

namespace android {
namespace os {
namespace statsd {

class StateListener : public virtual RefBase {
public:
    StateListener(){};

    virtual ~StateListener(){};

    /**
     * Interface for handling a state change.
     *
     * The old and new state values map to the original state values.
     * StateTrackers only track the original state values and are unaware
     * of higher-level state groups. MetricProducers hold information on
     * state groups and are responsible for mapping original state values to
     * the correct state group.
     *
     * [atomId]: The id of the state atom
     * [primaryKey]: The primary field values of the state atom
     * [oldState]: Previous state value before state change
     * [newState]: Current state value after state change
     */
    virtual void onStateChanged(int atomId, const HashableDimensionKey& primaryKey, int oldState,
                                int newState) = 0;
};

}  // namespace statsd
}  // namespace os
}  // namespace android
Loading