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"
25 #include "statslog.h"
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 
TrainInfoPuller()35 TrainInfoPuller::TrainInfoPuller() :
36     StatsPuller(android::util::TRAIN_INFO) {
37 }
38 
PullInternal(vector<shared_ptr<LogEvent>> * data)39 bool TrainInfoPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) {
40     InstallTrainInfo trainInfo;
41     bool ret = StorageManager::readTrainInfo(trainInfo);
42     if (!ret) {
43         ALOGW("Failed to read train info.");
44         return false;
45     }
46     auto event = make_shared<LogEvent>(getWallClockNs(), getElapsedRealtimeNs(), trainInfo);
47     data->push_back(event);
48     return true;
49 }
50 
51 }  // namespace statsd
52 }  // namespace os
53 }  // namespace android
54