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

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

Merge "1/ Change all "name" to id in statsD. 2/ Handle Subscription for alert....

Merge "1/ Change all "name" to id in statsD. 2/ Handle Subscription for alert. 3/ Support no_report_metric"
parents 5e798fe2 94e197cc
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -4368,10 +4368,10 @@ package android.util {
  }

  public final class StatsManager {
    method public boolean addConfiguration(java.lang.String, byte[], java.lang.String, java.lang.String);
    method public byte[] getData(java.lang.String);
    method public boolean addConfiguration(long, byte[], java.lang.String, java.lang.String);
    method public byte[] getData(long);
    method public byte[] getMetadata();
    method public boolean removeConfiguration(java.lang.String);
    method public boolean removeConfiguration(long);
  }

}
+6 −2
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ namespace android {
namespace os {
namespace statsd {

android::hash_t hashDimensionsValue(const DimensionsValue& value) {
    android::hash_t hash = 0;
android::hash_t hashDimensionsValue(int64_t seed, const DimensionsValue& value) {
    android::hash_t hash = seed;
    hash = android::JenkinsHashMix(hash, android::hash_type(value.field()));

    hash = android::JenkinsHashMix(hash, android::hash_type((int)value.value_case()));
@@ -63,6 +63,10 @@ android::hash_t hashDimensionsValue(const DimensionsValue& value) {
    return JenkinsHashWhiten(hash);
}

android::hash_t hashDimensionsValue(const DimensionsValue& value) {
    return hashDimensionsValue(0, value);
}

using std::string;


+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ private:
    DimensionsValue mDimensionsValue;
};

android::hash_t hashDimensionsValue(int64_t seed, const DimensionsValue& value);
android::hash_t hashDimensionsValue(const DimensionsValue& value);

}  // namespace statsd
+5 −5
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ const int FIELD_ID_CONFIG_KEY = 1;
const int FIELD_ID_REPORTS = 2;
// for ConfigKey
const int FIELD_ID_UID = 1;
const int FIELD_ID_NAME = 2;
const int FIELD_ID_ID = 2;
// for ConfigMetricsReport
const int FIELD_ID_METRICS = 1;
const int FIELD_ID_UID_MAP = 2;
@@ -157,7 +157,7 @@ void StatsLogProcessor::onDumpReport(const ConfigKey& key, const uint64_t& dumpT
        return;
    }
    report->mutable_config_key()->set_uid(key.GetUid());
    report->mutable_config_key()->set_name(key.GetName());
    report->mutable_config_key()->set_id(key.GetId());
    ConfigMetricsReport* configMetricsReport = report->add_reports();
    it->second->onDumpReport(dumpTimeStampNs, configMetricsReport);
    // TODO: dump uid mapping.
@@ -181,7 +181,7 @@ void StatsLogProcessor::onDumpReport(const ConfigKey& key, vector<uint8_t>* outD
    // Start of ConfigKey.
    long long configKeyToken = proto.start(FIELD_TYPE_MESSAGE | FIELD_ID_CONFIG_KEY);
    proto.write(FIELD_TYPE_INT32 | FIELD_ID_UID, key.GetUid());
    proto.write(FIELD_TYPE_STRING | FIELD_ID_NAME, key.GetName());
    proto.write(FIELD_TYPE_INT64 | FIELD_ID_ID, (long long)key.GetId());
    proto.end(configKeyToken);
    // End of ConfigKey.

@@ -278,8 +278,8 @@ void StatsLogProcessor::WriteDataToDisk() {
        vector<uint8_t> data;
        onDumpReport(key, &data);
        // TODO: Add a guardrail to prevent accumulation of file on disk.
        string file_name = StringPrintf("%s/%d-%s-%ld", STATS_DATA_DIR, key.GetUid(),
                                        key.GetName().c_str(), time(nullptr));
        string file_name = StringPrintf("%s/%d-%lld-%ld", STATS_DATA_DIR, key.GetUid(),
                                        (long long)key.GetId(), time(nullptr));
        StorageManager::writeFile(file_name.c_str(), &data[0], data.size());
    }
}
+10 −13
Original line number Diff line number Diff line
@@ -335,7 +335,7 @@ status_t StatsService::cmd_trigger_broadcast(FILE* out, Vector<String8>& args) {
        print_cmd_help(out);
        return UNKNOWN_ERROR;
    }
    auto receiver = mConfigManager->GetConfigReceiver(ConfigKey(uid, name));
    auto receiver = mConfigManager->GetConfigReceiver(ConfigKey(uid, StrToInt64(name)));
    sp<IStatsCompanionService> sc = getStatsCompanionService();
    if (sc != nullptr) {
        sc->sendBroadcast(String16(receiver.first.c_str()), String16(receiver.second.c_str()));
@@ -404,13 +404,13 @@ status_t StatsService::cmd_config(FILE* in, FILE* out, FILE* err, Vector<String8
                }

                // Add / update the config.
                mConfigManager->UpdateConfig(ConfigKey(uid, name), config);
                mConfigManager->UpdateConfig(ConfigKey(uid, StrToInt64(name)), config);
            } else {
                if (argCount == 2) {
                    cmd_remove_all_configs(out);
                } else {
                    // Remove the config.
                    mConfigManager->RemoveConfig(ConfigKey(uid, name));
                    mConfigManager->RemoveConfig(ConfigKey(uid, StrToInt64(name)));
                }
            }

@@ -459,7 +459,7 @@ status_t StatsService::cmd_dump_report(FILE* out, FILE* err, const Vector<String
        }
        if (good) {
            vector<uint8_t> data;
            mProcessor->onDumpReport(ConfigKey(uid, name), &data);
            mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), &data);
            // TODO: print the returned StatsLogReport to file instead of printing to logcat.
            if (proto) {
                for (size_t i = 0; i < data.size(); i ++) {
@@ -699,12 +699,11 @@ void StatsService::OnLogEvent(const LogEvent& event) {
    mProcessor->OnLogEvent(event);
}

Status StatsService::getData(const String16& key, vector<uint8_t>* output) {
Status StatsService::getData(int64_t key, vector<uint8_t>* output) {
    IPCThreadState* ipc = IPCThreadState::self();
    VLOG("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), ipc->getCallingUid());
    if (checkCallingPermission(String16(kPermissionDump))) {
        string keyStr = string(String8(key).string());
        ConfigKey configKey(ipc->getCallingUid(), keyStr);
        ConfigKey configKey(ipc->getCallingUid(), key);
        mProcessor->onDumpReport(configKey, output);
        return Status::ok();
    } else {
@@ -724,14 +723,13 @@ Status StatsService::getMetadata(vector<uint8_t>* output) {
    }
}

Status StatsService::addConfiguration(const String16& key,
Status StatsService::addConfiguration(int64_t key,
                                      const vector <uint8_t>& config,
                                      const String16& package, const String16& cls,
                                      bool* success) {
    IPCThreadState* ipc = IPCThreadState::self();
    if (checkCallingPermission(String16(kPermissionDump))) {
        string keyString = string(String8(key).string());
        ConfigKey configKey(ipc->getCallingUid(), keyString);
        ConfigKey configKey(ipc->getCallingUid(), key);
        StatsdConfig cfg;
        if (!cfg.ParseFromArray(&config[0], config.size())) {
            *success = false;
@@ -748,11 +746,10 @@ Status StatsService::addConfiguration(const String16& key,
    }
}

Status StatsService::removeConfiguration(const String16& key, bool* success) {
Status StatsService::removeConfiguration(int64_t key, bool* success) {
    IPCThreadState* ipc = IPCThreadState::self();
    if (checkCallingPermission(String16(kPermissionDump))) {
        string keyStr = string(String8(key).string());
        mConfigManager->RemoveConfig(ConfigKey(ipc->getCallingUid(), keyStr));
        mConfigManager->RemoveConfig(ConfigKey(ipc->getCallingUid(), key));
        *success = true;
        return Status::ok();
    } else {
Loading