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 #ifndef IORAP_MANAGER_EVENT_MANAGER_H_
18 #define IORAP_MANAGER_EVENT_MANAGER_H_
19 
20 #include "binder/app_launch_event.h"
21 #include "binder/request_id.h"
22 
23 #include <memory>
24 
25 namespace iorap::perfetto {
26   struct RxProducerFactory;
27 }  // namespace iorap::perfetto
28 
29 namespace iorap::manager {
30 
31 class EventManager {
32  public:
33   static std::shared_ptr<EventManager> Create();
34   static std::shared_ptr<EventManager> Create(
35       /*borrow*/perfetto::RxProducerFactory& perfetto_factory);
36 
37   // Handles an AppLaunchEvent:
38   //
39   // * Intent starts and app launch starts are treated critically
40   //   and will be handled immediately. This means the caller
41   //   (e.g. the binder pool thread) could be starved in the name
42   //   of low latency.
43   //
44   // * Other types are handled in a separate thread.
45   bool OnAppLaunchEvent(binder::RequestId request_id,
46                         const binder::AppLaunchEvent& event);
47 
48   class Impl;
49  private:
50   std::unique_ptr<Impl> impl_;
51 
52   EventManager(perfetto::RxProducerFactory& perfetto_factory);
53 };
54 
55 }  // namespace iorap::manager
56 
57 #endif  // IORAP_MANAGER_EVENT_MANAGER_H_
58