Loading cmds/statsd/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ cc_defaults { "src/external/SubsystemSleepStatePuller.cpp", "src/external/PowerStatsPuller.cpp", "src/external/ResourceHealthManagerPuller.cpp", "src/external/TrainInfoPuller.cpp", "src/external/StatsPullerManager.cpp", "src/external/puller_util.cpp", "src/logd/LogEvent.cpp", Loading cmds/statsd/src/StatsService.cpp +2 −5 Original line number Diff line number Diff line Loading @@ -55,9 +55,6 @@ namespace android { namespace os { namespace statsd { const int FIELD_ID_EXPERIMENT_ID = 1; const int FIELD_ID_EXPERIMENT_ID_MSG = 7; constexpr const char* kPermissionDump = "android.permission.DUMP"; constexpr const char* kPermissionUsage = "android.permission.PACKAGE_USAGE_STATS"; Loading @@ -67,6 +64,8 @@ constexpr const char* kOpUsage = "android:get_usage_stats"; // for StatsDataDumpProto const int FIELD_ID_REPORTS_LIST = 1; // for TrainInfo experiment id serialization const int FIELD_ID_EXPERIMENT_ID = 1; static binder::Status ok() { return binder::Status::ok(); Loading Loading @@ -1200,12 +1199,10 @@ Status StatsService::sendBinaryPushStateChangedAtom(const android::String16& tra bool requiresLowLatencyMonitor = options | IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR; ProtoOutputStream proto; uint64_t protoToken = proto.start(FIELD_TYPE_MESSAGE | FIELD_ID_EXPERIMENT_ID_MSG); for (const auto& expId : experimentIds) { proto.write(FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_EXPERIMENT_ID, (long long)expId); } proto.end(protoToken); vector<uint8_t> buffer; buffer.resize(proto.size()); Loading cmds/statsd/src/external/StatsPullerManager.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -29,10 +29,11 @@ #include "../statscompanion_util.h" #include "PowerStatsPuller.h" #include "ResourceHealthManagerPuller.h" #include "StatsCompanionServicePuller.h" #include "StatsCallbackPuller.h" #include "StatsCompanionServicePuller.h" #include "StatsPullerManager.h" #include "SubsystemSleepStatePuller.h" #include "TrainInfoPuller.h" #include "statslog.h" #include <iostream> Loading Loading @@ -231,6 +232,8 @@ std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = { // PermissionState. {android::util::DANGEROUS_PERMISSION_STATE, {.puller = new StatsCompanionServicePuller(android::util::DANGEROUS_PERMISSION_STATE)}}, // TrainInfo. {android::util::TRAIN_INFO, {.puller = new TrainInfoPuller()}}, }; StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) { Loading cmds/statsd/src/external/TrainInfoPuller.cpp 0 → 100644 +53 −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. */ #define DEBUG false // STOPSHIP if true #include "Log.h" #include "external/StatsPuller.h" #include "TrainInfoPuller.h" #include "logd/LogEvent.h" #include "stats_log_util.h" #include "statslog.h" #include "storage/StorageManager.h" using std::make_shared; using std::shared_ptr; namespace android { namespace os { namespace statsd { TrainInfoPuller::TrainInfoPuller() : StatsPuller(android::util::TRAIN_INFO) { } bool TrainInfoPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { InstallTrainInfo trainInfo; bool ret = StorageManager::readTrainInfo(trainInfo); if (!ret) { ALOGW("Failed to read train info."); return false; } auto event = make_shared<LogEvent>(getWallClockNs(), getElapsedRealtimeNs(), trainInfo); data->push_back(event); return true; } } // namespace statsd } // namespace os } // namespace android cmds/statsd/src/external/TrainInfoPuller.h 0 → 100644 +38 −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 "StatsPuller.h" namespace android { namespace os { namespace statsd { /** * Reads train info from disk. */ class TrainInfoPuller : public StatsPuller { public: TrainInfoPuller(); private: bool PullInternal(vector<std::shared_ptr<LogEvent>>* data) override; }; } // namespace statsd } // namespace os } // namespace android Loading
cmds/statsd/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ cc_defaults { "src/external/SubsystemSleepStatePuller.cpp", "src/external/PowerStatsPuller.cpp", "src/external/ResourceHealthManagerPuller.cpp", "src/external/TrainInfoPuller.cpp", "src/external/StatsPullerManager.cpp", "src/external/puller_util.cpp", "src/logd/LogEvent.cpp", Loading
cmds/statsd/src/StatsService.cpp +2 −5 Original line number Diff line number Diff line Loading @@ -55,9 +55,6 @@ namespace android { namespace os { namespace statsd { const int FIELD_ID_EXPERIMENT_ID = 1; const int FIELD_ID_EXPERIMENT_ID_MSG = 7; constexpr const char* kPermissionDump = "android.permission.DUMP"; constexpr const char* kPermissionUsage = "android.permission.PACKAGE_USAGE_STATS"; Loading @@ -67,6 +64,8 @@ constexpr const char* kOpUsage = "android:get_usage_stats"; // for StatsDataDumpProto const int FIELD_ID_REPORTS_LIST = 1; // for TrainInfo experiment id serialization const int FIELD_ID_EXPERIMENT_ID = 1; static binder::Status ok() { return binder::Status::ok(); Loading Loading @@ -1200,12 +1199,10 @@ Status StatsService::sendBinaryPushStateChangedAtom(const android::String16& tra bool requiresLowLatencyMonitor = options | IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR; ProtoOutputStream proto; uint64_t protoToken = proto.start(FIELD_TYPE_MESSAGE | FIELD_ID_EXPERIMENT_ID_MSG); for (const auto& expId : experimentIds) { proto.write(FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_EXPERIMENT_ID, (long long)expId); } proto.end(protoToken); vector<uint8_t> buffer; buffer.resize(proto.size()); Loading
cmds/statsd/src/external/StatsPullerManager.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -29,10 +29,11 @@ #include "../statscompanion_util.h" #include "PowerStatsPuller.h" #include "ResourceHealthManagerPuller.h" #include "StatsCompanionServicePuller.h" #include "StatsCallbackPuller.h" #include "StatsCompanionServicePuller.h" #include "StatsPullerManager.h" #include "SubsystemSleepStatePuller.h" #include "TrainInfoPuller.h" #include "statslog.h" #include <iostream> Loading Loading @@ -231,6 +232,8 @@ std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = { // PermissionState. {android::util::DANGEROUS_PERMISSION_STATE, {.puller = new StatsCompanionServicePuller(android::util::DANGEROUS_PERMISSION_STATE)}}, // TrainInfo. {android::util::TRAIN_INFO, {.puller = new TrainInfoPuller()}}, }; StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) { Loading
cmds/statsd/src/external/TrainInfoPuller.cpp 0 → 100644 +53 −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. */ #define DEBUG false // STOPSHIP if true #include "Log.h" #include "external/StatsPuller.h" #include "TrainInfoPuller.h" #include "logd/LogEvent.h" #include "stats_log_util.h" #include "statslog.h" #include "storage/StorageManager.h" using std::make_shared; using std::shared_ptr; namespace android { namespace os { namespace statsd { TrainInfoPuller::TrainInfoPuller() : StatsPuller(android::util::TRAIN_INFO) { } bool TrainInfoPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { InstallTrainInfo trainInfo; bool ret = StorageManager::readTrainInfo(trainInfo); if (!ret) { ALOGW("Failed to read train info."); return false; } auto event = make_shared<LogEvent>(getWallClockNs(), getElapsedRealtimeNs(), trainInfo); data->push_back(event); return true; } } // namespace statsd } // namespace os } // namespace android
cmds/statsd/src/external/TrainInfoPuller.h 0 → 100644 +38 −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 "StatsPuller.h" namespace android { namespace os { namespace statsd { /** * Reads train info from disk. */ class TrainInfoPuller : public StatsPuller { public: TrainInfoPuller(); private: bool PullInternal(vector<std::shared_ptr<LogEvent>>* data) override; }; } // namespace statsd } // namespace os } // namespace android