1 /* 2 * Copyright (C) 2022 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 #ifndef SRC_TRACED_PROBES_ANDROID_GAME_INTERVENTION_LIST_ANDROID_GAME_INTERVENTION_LIST_DATA_SOURCE_H_ 18 #define SRC_TRACED_PROBES_ANDROID_GAME_INTERVENTION_LIST_ANDROID_GAME_INTERVENTION_LIST_DATA_SOURCE_H_ 19 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "perfetto/base/task_runner.h" 25 #include "perfetto/ext/base/pipe.h" 26 #include "perfetto/ext/base/scoped_file.h" 27 #include "perfetto/ext/tracing/core/basic_types.h" 28 29 #include "src/traced/probes/probes_data_source.h" 30 31 namespace perfetto { 32 33 // forward declaration of protos to be loaded 34 namespace protos { 35 namespace pbzero { 36 class AndroidGameInterventionList; 37 class AndroidGameInterventionList_GamePackageInfo; 38 } // namespace pbzero 39 } // namespace protos 40 41 class TraceWriter; 42 43 class AndroidGameInterventionListDataSource : public ProbesDataSource { 44 public: 45 static const ProbesDataSource::Descriptor descriptor; 46 47 AndroidGameInterventionListDataSource( 48 const DataSourceConfig& ds_config, 49 TracingSessionID session_id, 50 std::unique_ptr<TraceWriter> trace_writer); 51 52 ~AndroidGameInterventionListDataSource() override; 53 54 // ProbesDataSource implementaion. 55 void Start() override; 56 void Flush(FlushRequestID, std::function<void()> callback) override; 57 58 bool ParseAndroidGameInterventionListStream( 59 protos::pbzero::AndroidGameInterventionList* 60 android_game_intervention_list, 61 const base::ScopedFstream& fs, 62 const std::vector<std::string>& package_name_filter); 63 64 private: 65 bool ParseAndroidGameInterventionListLine( 66 char* line, 67 const std::vector<std::string>& package_name_filter, 68 protos::pbzero::AndroidGameInterventionList* packet); 69 70 std::vector<std::string> package_name_filter_; 71 std::unique_ptr<TraceWriter> trace_writer_; 72 }; 73 74 } // namespace perfetto 75 76 #endif // SRC_TRACED_PROBES_ANDROID_GAME_INTERVENTION_LIST_ANDROID_GAME_INTERVENTION_LIST_DATA_SOURCE_H_ 77