• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020, 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 CPP_WATCHDOG_SERVER_SRC_WATCHDOGINTERNALHANDLER_H_
18 #define CPP_WATCHDOG_SERVER_SRC_WATCHDOGINTERNALHANDLER_H_
19 
20 #include "IoOveruseMonitor.h"
21 #include "WatchdogPerfService.h"
22 #include "WatchdogProcessService.h"
23 #include "WatchdogServiceHelper.h"
24 
25 #include <android/automotive/watchdog/internal/BnCarWatchdog.h>
26 #include <android/automotive/watchdog/internal/ComponentType.h>
27 #include <android/automotive/watchdog/internal/ICarWatchdogMonitor.h>
28 #include <android/automotive/watchdog/internal/ICarWatchdogServiceForSystem.h>
29 #include <android/automotive/watchdog/internal/PackageResourceOveruseAction.h>
30 #include <android/automotive/watchdog/internal/ResourceOveruseConfiguration.h>
31 #include <android/automotive/watchdog/internal/StateType.h>
32 #include <binder/Status.h>
33 #include <gtest/gtest_prod.h>
34 #include <utils/Errors.h>
35 #include <utils/String16.h>
36 #include <utils/Vector.h>
37 
38 namespace android {
39 namespace automotive {
40 namespace watchdog {
41 
42 class WatchdogBinderMediator;
43 
44 class WatchdogInternalHandler : public android::automotive::watchdog::internal::BnCarWatchdog {
45 public:
WatchdogInternalHandler(const android::sp<WatchdogBinderMediator> & binderMediator,const android::sp<IWatchdogServiceHelper> & watchdogServiceHelper,const android::sp<WatchdogProcessService> & watchdogProcessService,const android::sp<WatchdogPerfServiceInterface> & watchdogPerfService,const android::sp<IIoOveruseMonitor> & ioOveruseMonitor)46     explicit WatchdogInternalHandler(
47             const android::sp<WatchdogBinderMediator>& binderMediator,
48             const android::sp<IWatchdogServiceHelper>& watchdogServiceHelper,
49             const android::sp<WatchdogProcessService>& watchdogProcessService,
50             const android::sp<WatchdogPerfServiceInterface>& watchdogPerfService,
51             const android::sp<IIoOveruseMonitor>& ioOveruseMonitor) :
52           mBinderMediator(binderMediator),
53           mWatchdogServiceHelper(watchdogServiceHelper),
54           mWatchdogProcessService(watchdogProcessService),
55           mWatchdogPerfService(watchdogPerfService),
56           mIoOveruseMonitor(ioOveruseMonitor) {}
~WatchdogInternalHandler()57     ~WatchdogInternalHandler() { terminate(); }
58 
59     status_t dump(int fd, const Vector<android::String16>& args) override;
60     android::binder::Status registerCarWatchdogService(
61             const android::sp<
62                     android::automotive::watchdog::internal::ICarWatchdogServiceForSystem>& service)
63             override;
64     android::binder::Status unregisterCarWatchdogService(
65             const android::sp<
66                     android::automotive::watchdog::internal::ICarWatchdogServiceForSystem>& service)
67             override;
68     android::binder::Status registerMonitor(
69             const android::sp<android::automotive::watchdog::internal::ICarWatchdogMonitor>&
70                     monitor) override;
71     android::binder::Status unregisterMonitor(
72             const android::sp<android::automotive::watchdog::internal::ICarWatchdogMonitor>&
73                     monitor) override;
74     android::binder::Status tellCarWatchdogServiceAlive(
75             const android::sp<
76                     android::automotive::watchdog::internal::ICarWatchdogServiceForSystem>& service,
77             const std::vector<int32_t>& clientsNotResponding, int32_t sessionId) override;
78     android::binder::Status tellDumpFinished(
79             const android::sp<android::automotive::watchdog::internal::ICarWatchdogMonitor>&
80                     monitor,
81             int32_t pid) override;
82     android::binder::Status notifySystemStateChange(
83             android::automotive::watchdog::internal::StateType type, int32_t arg1,
84             int32_t arg2) override;
85     android::binder::Status updateResourceOveruseConfigurations(
86             const std::vector<
87                     android::automotive::watchdog::internal::ResourceOveruseConfiguration>& configs)
88             override;
89     android::binder::Status getResourceOveruseConfigurations(
90             std::vector<android::automotive::watchdog::internal::ResourceOveruseConfiguration>*
91                     configs) override;
92     android::binder::Status actionTakenOnResourceOveruse(
93             const std::vector<
94                     android::automotive::watchdog::internal::PackageResourceOveruseAction>&
95                     actions);
96 
97 protected:
terminate()98     void terminate() {
99         mBinderMediator.clear();
100         mWatchdogServiceHelper.clear();
101         mWatchdogProcessService.clear();
102         mWatchdogPerfService.clear();
103         mIoOveruseMonitor.clear();
104     }
105 
106 private:
107     void checkAndRegisterIoOveruseMonitor();
108 
109     android::binder::Status handlePowerCycleChange(
110             android::automotive::watchdog::internal::PowerCycle powerCycle);
111 
112     android::sp<WatchdogBinderMediator> mBinderMediator;
113     android::sp<IWatchdogServiceHelper> mWatchdogServiceHelper;
114     android::sp<WatchdogProcessService> mWatchdogProcessService;
115     android::sp<WatchdogPerfServiceInterface> mWatchdogPerfService;
116     android::sp<IIoOveruseMonitor> mIoOveruseMonitor;
117 
118     friend class WatchdogBinderMediator;
119 
120     FRIEND_TEST(WatchdogInternalHandlerTest, TestTerminate);
121 };
122 
123 }  // namespace watchdog
124 }  // namespace automotive
125 }  // namespace android
126 
127 #endif  // CPP_WATCHDOG_SERVER_SRC_WATCHDOGINTERNALHANDLER_H_
128