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 #pragma once 18 19 #include "WatchdogProcessService.h" 20 #include "WatchdogServiceHelper.h" 21 22 #include <aidl/android/automotive/watchdog/TimeoutLength.h> 23 #include <aidl/android/automotive/watchdog/internal/ICarWatchdogServiceForSystem.h> 24 #include <aidl/android/automotive/watchdog/internal/PackageIoOveruseStats.h> 25 #include <android-base/result.h> 26 #include <binder/Status.h> 27 #include <gmock/gmock.h> 28 #include <utils/StrongPointer.h> 29 30 namespace android { 31 namespace automotive { 32 namespace watchdog { 33 34 class MockWatchdogServiceHelper : public WatchdogServiceHelperInterface { 35 public: MockWatchdogServiceHelper()36 MockWatchdogServiceHelper() { 37 ON_CALL(*this, isServiceConnected()).WillByDefault(::testing::Return(false)); 38 ON_CALL(*this, requestAidlVhalPid()).WillByDefault([]() { 39 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); 40 }); 41 } ~MockWatchdogServiceHelper()42 ~MockWatchdogServiceHelper() {} 43 44 MOCK_METHOD(bool, isServiceConnected, (), (override)); 45 MOCK_METHOD(android::base::Result<void>, init, 46 (const android::sp<WatchdogProcessServiceInterface>&), (override)); 47 MOCK_METHOD( 48 ndk::ScopedAStatus, registerService, 49 (const std::shared_ptr< 50 aidl::android::automotive::watchdog::internal::ICarWatchdogServiceForSystem>&), 51 (override)); 52 MOCK_METHOD( 53 ndk::ScopedAStatus, unregisterService, 54 (const std::shared_ptr< 55 aidl::android::automotive::watchdog::internal::ICarWatchdogServiceForSystem>&), 56 (override)); 57 MOCK_METHOD(void, handleBinderDeath, (void*), (override)); 58 MOCK_METHOD(ndk::ScopedAStatus, checkIfAlive, 59 (const ndk::SpAIBinder&, int32_t, 60 aidl::android::automotive::watchdog::TimeoutLength), 61 (const, override)); 62 MOCK_METHOD(ndk::ScopedAStatus, prepareProcessTermination, (const ndk::SpAIBinder&), 63 (override)); 64 MOCK_METHOD(ndk::ScopedAStatus, getPackageInfosForUids, 65 (const std::vector<int32_t>&, const std::vector<std::string>&, 66 std::vector<aidl::android::automotive::watchdog::internal::PackageInfo>*), 67 (const, override)); 68 MOCK_METHOD(ndk::ScopedAStatus, resetResourceOveruseStats, (const std::vector<std::string>&), 69 (const, override)); 70 MOCK_METHOD(ndk::ScopedAStatus, onLatestResourceStats, 71 (const std::vector<aidl::android::automotive::watchdog::internal::ResourceStats>&), 72 (const, override)); 73 MOCK_METHOD(ndk::ScopedAStatus, requestAidlVhalPid, (), (const, override)); 74 MOCK_METHOD(ndk::ScopedAStatus, requestTodayIoUsageStats, (), (const, override)); 75 MOCK_METHOD(void, terminate, (), (override)); 76 }; 77 78 } // namespace watchdog 79 } // namespace automotive 80 } // namespace android 81