Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define DEBUG false // STOPSHIP if true |
| 18 | #include "Log.h" |
| 19 | |
| 20 | #include "external/StatsPuller.h" |
| 21 | |
| 22 | #include "TrainInfoPuller.h" |
| 23 | #include "logd/LogEvent.h" |
| 24 | #include "stats_log_util.h" |
Jeffrey Huang | 74fc435 | 2020-03-06 15:18:33 -0800 | [diff] [blame] | 25 | #include "statslog_statsd.h" |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 26 | #include "storage/StorageManager.h" |
| 27 | |
| 28 | using std::make_shared; |
| 29 | using std::shared_ptr; |
| 30 | |
| 31 | namespace android { |
| 32 | namespace os { |
| 33 | namespace statsd { |
| 34 | |
| 35 | TrainInfoPuller::TrainInfoPuller() : |
Jeffrey Huang | 74fc435 | 2020-03-06 15:18:33 -0800 | [diff] [blame] | 36 | StatsPuller(util::TRAIN_INFO) { |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | bool TrainInfoPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { |
Jonathan Nguyen | 703c42f | 2020-02-04 15:54:26 -0800 | [diff] [blame] | 40 | vector<InstallTrainInfo> trainInfoList = |
| 41 | StorageManager::readAllTrainInfo(); |
| 42 | if (trainInfoList.empty()) { |
| 43 | ALOGW("Train info was empty."); |
| 44 | return true; |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 45 | } |
Jonathan Nguyen | 703c42f | 2020-02-04 15:54:26 -0800 | [diff] [blame] | 46 | for (InstallTrainInfo& trainInfo : trainInfoList) { |
| 47 | auto event = make_shared<LogEvent>(getWallClockNs(), getElapsedRealtimeNs(), trainInfo); |
| 48 | data->push_back(event); |
| 49 | } |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 50 | return true; |
| 51 | } |
| 52 | |
| 53 | } // namespace statsd |
| 54 | } // namespace os |
| 55 | } // namespace android |