/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MOCK_APP_MGR_SERVICE_H #define MOCK_APP_MGR_SERVICE_H #include #include "app_mgr_stub.h" #include #include "iremote_proxy.h" #include "iremote_stub.h" #include "semaphore_ex.h" namespace OHOS { namespace AppExecFwk { class MockAppMgrService : public AppMgrStub { public: MOCK_METHOD5(LoadAbility, void(const sptr &token, const sptr &preToken, const std::shared_ptr &abilityInfo, const std::shared_ptr &appInfo, const std::shared_ptr &want)); MOCK_METHOD2(TerminateAbility, void(const sptr &token, bool clearMissionFlag)); MOCK_METHOD2(UpdateAbilityState, void(const sptr &token, const AbilityState state)); MOCK_METHOD1(AttachApplication, void(const sptr &app)); MOCK_METHOD1(NotifyMemoryLevel, int(int32_t level)); MOCK_METHOD1(ApplicationForegrounded, void(const int32_t recordId)); MOCK_METHOD1(ApplicationBackgrounded, void(const int32_t recordId)); MOCK_METHOD1(ApplicationTerminated, void(const int32_t recordId)); MOCK_METHOD2(CheckPermission, int32_t(const int32_t recordId, const std::string &permission)); MOCK_METHOD1(AbilityCleaned, void(const sptr &token)); MOCK_METHOD1(KillApplication, int32_t(const std::string &appName)); MOCK_METHOD2(KillApplicationByUid, int(const std::string &, const int uid)); MOCK_METHOD1(IsBackgroundRunningRestricted, int(const std::string &bundleName)); MOCK_METHOD1(GetAllRunningProcesses, int(std::vector &info)); MOCK_METHOD2(GetProcessRunningInfosByUserId, int(std::vector &info, int32_t userId)); MOCK_METHOD0(GetAmsMgr, sptr()); MOCK_METHOD1(GetAppFreezingTime, void(int &time)); MOCK_METHOD1(SetAppFreezingTime, void(int time)); MOCK_METHOD3(ClearUpApplicationData, int32_t(const std::string&, int32_t appCloneIndex, int32_t userId)); MOCK_METHOD1(StartupResidentProcess, void(const std::vector &bundleInfos)); MOCK_METHOD1(AddAbilityStageDone, void(const int32_t recordId)); MOCK_METHOD0(PreStartNWebSpawnProcess, int()); MOCK_METHOD4(StartRenderProcess, int(const std::string&, int32_t, int32_t, pid_t&)); MOCK_METHOD1(AttachRenderProcess, void(const sptr &renderScheduler)); MOCK_METHOD2(GetRenderProcessTerminationStatus, int(pid_t renderPid, int &status)); MOCK_METHOD3(ScheduleAcceptWantDone, void(const int32_t recordId, const AAFwk::Want &want, const std::string &flag)); MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector> &tokens)); MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config)); MOCK_METHOD1(UpdateConfiguration, int32_t(const Configuration &config)); MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr &observer)); MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr &observer)); #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAppService, int()); #endif MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string &bundleName)); MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string &bundleName, const sptr &callback)); MOCK_METHOD2(NotifyHotReloadPage, int32_t(const std::string &bundleName, const sptr &callback)); MOCK_METHOD2(NotifyUnLoadRepairPatch, int32_t(const std::string &bundleName, const sptr &callback)); int32_t GetForegroundApplications(std::vector &list) override; int32_t RegisterApplicationStateObserver(const sptr &observer, const std::vector &bundleNameList); int32_t UnregisterApplicationStateObserver(const sptr &observer); void SwitchForeOrBackGround(uint32_t tokenId, int32_t flag); virtual int StartUserTestProcess( const AAFwk::Want &want, const sptr &observer, const BundleInfo &bundleInfo, int32_t userId) { return 0; } virtual int FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName) { return 0; } virtual void RegisterAppStateCallback(const sptr &callback) { callback_ = callback; } int32_t CheckPermissionImpl([[maybe_unused]] const int32_t recordId, const std::string &data) { data_ = data; return 0; } void KillApplicationImpl(const std::string &data) { data_ = data; } const std::string &GetData() const { return data_; } void Wait() { sem_.Wait(); } void Post() { sem_.Post(); } void UpdateState() const { if (!callback_) { return; } AppProcessData processData; processData.pid = 1; processData.appState = ApplicationState::APP_STATE_BEGIN; callback_->OnAppStateChanged(processData); } void Terminate(const sptr &token) const { if (!callback_) { return; } AbilityState st = AbilityState::ABILITY_STATE_BEGIN; callback_->OnAbilityRequestDone(token, st); } MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); int InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { code_ = code; return 0; } int code_; private: Semaphore sem_; std::string data_; sptr callback_; sptr observer_; }; } } #endif // MOCK_APP_MGR_SERVICE_H