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