/* * Copyright (c) 2021-2023 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 OHOS_FORM_FWK_MOCK_ABILITY_MANAGER_H #define OHOS_FORM_FWK_MOCK_ABILITY_MANAGER_H #include #include #include #include "ability_manager_interface.h" #include "mock_form_provider_client.h" #include "semaphore_ex.h" namespace OHOS { namespace AppExecFwk { class MockAbilityMgrProxy : public IRemoteProxy { public: explicit MockAbilityMgrProxy(const sptr &impl) : IRemoteProxy(impl) {} virtual~MockAbilityMgrProxy() = default; int StartAbility( const AAFwk::Want &want, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = -1) override { return 0; } int StartAbility(const AAFwk::Want &want, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = -1) override { return 0; } int StartAbility( const Want &want, const StartOptions &startOptions, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) override { return 0; } int TerminateAbility( const sptr &token, int resultCode, const AAFwk::Want *resultWant = nullptr) override { return 0; } int ConnectAbility(const AAFwk::Want &want, const sptr &connect, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } int DisconnectAbility(sptr connect) override { return 0; } sptr AcquireDataAbility( const Uri &uri, bool tryBind, const sptr &callerToken) override { return nullptr; } int ReleaseDataAbility( sptr dataAbilityScheduler, const sptr &callerToken) override { return 0; } int AttachAbilityThread( const sptr &scheduler, const sptr &token) override { return 0; } int AbilityTransitionDone(const sptr &token, int state, const PacMap &saveData) override { return 0; } sptr GetWantSender( const AAFwk::WantSenderInfo &wantSenderInfo, const sptr &callerToken, int32_t uid) override { return nullptr; } int SendWantSender(sptr target, const AAFwk::SenderInfo &senderInfo) override { return 0; } void CancelWantSender(const sptr &sender) override { return; } int GetPendingWantUid(const sptr &target) override { return 0; } int GetPendingWantUserId(const sptr &target) override { return 0; } std::string GetPendingWantBundleName(const sptr &target) override { return ""; } int GetPendingWantCode(const sptr &target) override { return 0; } int GetPendingWantType(const sptr &target) override { return 0; } void RegisterCancelListener( const sptr &sender, const sptr &receiver) override { return; } int32_t ReportDrawnCompleted(const sptr& callerToken) override { return 0; } void UnregisterCancelListener( const sptr &sender, const sptr &receiver) override { return; } int GetPendingRequestWant(const sptr &target, std::shared_ptr &want) override { return 0; } int ScheduleConnectAbilityDone(const sptr &token, const sptr &remoteObject) { return 0; } int ScheduleDisconnectAbilityDone(const sptr &token) override { return 0; } int ScheduleCommandAbilityDone(const sptr &token) override { return 0; } int ScheduleCommandAbilityWindowDone( const sptr &token, const sptr &sessionInfo, AAFwk::WindowCommand winCmd, AAFwk::AbilityCommand abilityCmd) override { return 0; } void DumpState(const std::string &args, std::vector &state) override { return; } int StopServiceAbility(const AAFwk::Want &want, int32_t userId = DEFAULT_INVAL_VALUE, const sptr &token = nullptr) override { return 0; } int32_t GetMissionIdByToken(const sptr &token) override { return 0; } void GetAbilityTokenByCalleeObj(const sptr &callStub, sptr &token) override { return; } int KillProcess(const std::string &bundleName, const bool clreaPageStack = true) override { return 0; } int UninstallApp(const std::string &bundleName, int32_t uid) override { return 0; } int TerminateAbilityByRecordId(const int64_t recordId = -1) { return 0; } int StartContinuation(const Want &want, const sptr &abilityToken, int32_t status) override { return 0; } int NotifyContinuationResult(int32_t missionId, int32_t result) override { return 0; } int ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams) override { return 0; } int ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode) override { return 0; } void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess) override {} int LockMissionForCleanup(int32_t missionId) override { return 0; } int UnlockMissionForCleanup(int32_t missionId) override { return 0; } int RegisterMissionListener(const sptr &listener) override { return 0; } int UnRegisterMissionListener(const sptr &listener) override { return 0; } int GetMissionInfos(const std::string& deviceId, int32_t numMax, std::vector &missionInfos) override { return 0; } int GetMissionInfo(const std::string& deviceId, int32_t missionId, MissionInfo &missionInfo) override { return 0; } int CleanMission(int32_t missionId) override { return 0; } int CleanAllMissions() override { return 0; } int MoveMissionToFront(int32_t missionId) override { return 0; } int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override { return 0; } #ifdef SUPPORT_GRAPHICS int SetMissionLabel(const sptr &token, const std::string &lable) override { return 0; } int SetMissionIcon(const sptr &token, const std::shared_ptr &icon) override { return 0; } void CompleteFirstFrameDrawing(const sptr &abilityToken) override {} #endif int StartUserTest(const Want &want, const sptr &observer) override { return 0; } int FinishUserTest( const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override { return 0; } int GetTopAbility(sptr &token) override { return 0; } int DelegatorDoAbilityForeground(const sptr &token) override { return 0; } int DelegatorDoAbilityBackground(const sptr &token) override { return 0; } int DoAbilityForeground(const sptr &token, uint32_t flag) override { return 0; } int DoAbilityBackground(const sptr &token, uint32_t flag) override { return 0; } int32_t IsValidMissionIds(const std::vector& missionIds, std::vector& results) { return 0; } int32_t ExecuteIntent(uint64_t key, const sptr &callerToken, const InsightIntentExecuteParam ¶m) { return 0; } int32_t ExecuteInsightIntentDone(const sptr &token, uint64_t intentId, const InsightIntentExecuteResult &result) { return 0; } int32_t GetForegroundUIAbilities(std::vector &list) override { return 0; } }; class MockAbilityMgrStub : public IRemoteStub { public: using Uri = OHOS::Uri; MockAbilityMgrStub() = default; virtual ~MockAbilityMgrStub() = default; int OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override { return 0; } int32_t SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override { return 0; } int32_t CancelApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override { return 0; } }; class MockAbilityMgrService : public MockAbilityMgrStub { public: void Wait() { sem_.Wait(); } int Post() { sem_.Post(); return 0; } void PostVoid() { sem_.Post(); } int StartAbility( const AAFwk::Want &want, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = -1) override { return startAbility_; } int StartAbility(const AAFwk::Want &want, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = -1) override { return startAbility_; } int32_t StartAbilityByInsightIntent(const Want &want, const sptr &callerToken, uint64_t intentId, int32_t userId) override { return 0; } int StartAbility( const Want &want, const StartOptions &startOptions, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) override { return startAbility_; } int TerminateAbility( const sptr &token, int resultCode, const AAFwk::Want *resultWant = nullptr) override { return 0; } int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, const Want *resultWant = nullptr) override { return 0; } int MinimizeAbility(const sptr &token, bool fromUser) override { return 0; } int ConnectAbility(const AAFwk::Want &want, const sptr &connect, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE) override { connect->OnAbilityConnectDone(want.GetElement(), new (std::nothrow) MockFormProviderClient(), 0); return 0; } int DisconnectAbility(sptr connect) override { return 0; } sptr AcquireDataAbility( const Uri &uri, bool tryBind, const sptr &callerToken) override { return nullptr; } int ReleaseDataAbility( sptr dataAbilityScheduler, const sptr &callerToken) override { return 0; } int AttachAbilityThread( const sptr &scheduler, const sptr &token) override { return 0; } int AbilityTransitionDone(const sptr &token, int state, const PacMap &saveData) override { return 0; } int ScheduleConnectAbilityDone( const sptr &token, const sptr &remoteObject) override { return 0; } int ScheduleDisconnectAbilityDone(const sptr &token) override { return 0; } int ScheduleCommandAbilityDone(const sptr &token) override { return 0; } int ScheduleCommandAbilityWindowDone( const sptr &token, const sptr &sessionInfo, AAFwk::WindowCommand winCmd, AAFwk::AbilityCommand abilityCmd) override { return 0; } void DumpState(const std::string &args, std::vector &state) override { return; } void DumpSysState( const std::string& args, std::vector& state, bool isClient, bool isUserID, int UserID) override { return; } int StopServiceAbility(const AAFwk::Want &want, int32_t userId = DEFAULT_INVAL_VALUE, const sptr &token = nullptr) override { return 0; } sptr GetWantSender( const AAFwk::WantSenderInfo &wantSenderInfo, const sptr &callerToken, int32_t uid) override { return nullptr; } int SendWantSender(sptr target, const AAFwk::SenderInfo &senderInfo) override { return 0; } void CancelWantSender(const sptr &sender) override { return; } int GetPendingWantUid(const sptr &target) override { return 0; } int GetPendingWantUserId(const sptr &target) override { return 0; } std::string GetPendingWantBundleName(const sptr &target) override { return ""; } int GetPendingWantCode(const sptr &target) override { return 0; } int GetPendingWantType(const sptr &target) override { return 0; } int32_t ReportDrawnCompleted(const sptr& callerToken) override { return 0; } void RegisterCancelListener( const sptr &sender, const sptr &receiver) override { return; } void UnregisterCancelListener( const sptr &sender, const sptr &receiver) override { return; } int GetPendingRequestWant(const sptr &target, std::shared_ptr &want) override { return 0; } int32_t GetMissionIdByToken(const sptr &token) override { return 0; } void GetAbilityTokenByCalleeObj(const sptr &callStub, sptr &token) override { return; } int KillProcess(const std::string &bundleName, const bool clreaPageStack = true) override { return 0; } int UninstallApp(const std::string &bundleName, int32_t uid) override { return 0; } int TerminateAbilityByRecordId(const int64_t recordId = -1) { return 0; } int StartAbility( const Want &want, const AbilityStartSetting &abilityStartSetting, const sptr &callerToken, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) override { return startAbility_; } int GetWantSenderInfo(const sptr &target, std::shared_ptr &info) override { return 0; } int LockMissionForCleanup(int32_t missionId) override { return 0; } int StartContinuation(const Want &want, const sptr &abilityToken, int32_t status) override { return 0; } int NotifyContinuationResult(int32_t missionId, int32_t result) override { return 0; } int ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams) override { return 0; } int ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode) override { return 0; } void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess) override {} int UnlockMissionForCleanup(int32_t missionId) override { return 0; } int RegisterMissionListener(const sptr &listener) override { return 0; } int UnRegisterMissionListener(const sptr &listener) override { return 0; } int GetMissionInfos(const std::string& deviceId, int32_t numMax, std::vector &missionInfos) override { return 0; } int GetMissionInfo(const std::string& deviceId, int32_t missionId, MissionInfo &missionInfo) override { return 0; } int CleanMission(int32_t missionId) override { return 0; } int CleanAllMissions() override { return 0; } #ifdef SUPPORT_GRAPHICS void CompleteFirstFrameDrawing(const sptr &abilityToken) override {} int SetMissionLabel(const sptr &token, const std::string &lable) override { return 0; } int SetMissionIcon(const sptr &token, const std::shared_ptr &icon) override { return 0; } #endif int StartUserTest(const Want &want, const sptr &observer) override { return 0; } int FinishUserTest( const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override { return 0; } int GetTopAbility(sptr &token) override { return 0; } int DelegatorDoAbilityForeground(const sptr &token) override { return 0; } int DelegatorDoAbilityBackground(const sptr &token) override { return 0; } int MoveMissionToFront(int32_t missionId) override { return 0; } int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override { return 0; } int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override { return 0; } int StopSyncRemoteMissions(const std::string& devId) override { return 0; } int RegisterMissionListener(const std::string &deviceId, const sptr &listener) override { return 0; } int UnRegisterMissionListener(const std::string &deviceId, const sptr &listener) override { return 0; } int GetAbilityRunningInfos(std::vector &info) override { return 0; } int GetExtensionRunningInfos(int upperLimit, std::vector &info) override { return 0; } int GetProcessRunningInfos(std::vector &info) override { return 0; } int SetAbilityController(const sptr &abilityController, bool imAStabilityTest) override { return 0; } bool IsRunningInStabilityTest() override { return true; } int StartUser(int userId, sptr callback) override { return 0; } int StopUser(int userId, const sptr &callback) override { return 0; } int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot, bool isLowResolution) override { return 0; } int RegisterSnapshotHandler(const sptr& handler) override { return 0; } #ifdef SUPPORT_GRAPHICS int RegisterWindowManagerServiceHandler(const sptr& handler, bool animationEnabled = true) override { return 0; } #endif int StartAbilityByCall(const Want &want, const sptr &connect, const sptr &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE) override { return startAbilityByCall_; } int ReleaseCall( const sptr &connect, const AppExecFwk::ElementName &element) override { return 0; } int DoAbilityForeground(const sptr &token, uint32_t flag) override { return 0; } int DoAbilityBackground(const sptr &token, uint32_t flag) override { return 0; } #ifdef ABILITY_COMMAND_FOR_TEST int ForceTimeoutForTest(const std::string &abilityName, const std::string &state) override { return 0; } int BlockAmsService() override { return 0; } int BlockAppService() override { return 0; } int BlockAbility(int32_t abilityRecordId) override { return 0; } #endif int32_t IsValidMissionIds(const std::vector& missionIds, std::vector& results) { return 0; } int32_t RegisterAppDebugListener(sptr listener) { return 0; } int32_t UnregisterAppDebugListener(sptr listener) { return 0; } int32_t AttachAppDebug(const std::string &bundleName) { return 0; } int32_t DetachAppDebug(const std::string &bundleName) { return 0; } int32_t ExecuteIntent(uint64_t key, const sptr &callerToken, const InsightIntentExecuteParam ¶m) { return 0; } int32_t ExecuteInsightIntentDone(const sptr &token, uint64_t intentId, const InsightIntentExecuteResult &result) { return 0; } int32_t GetForegroundUIAbilities(std::vector &list) override { return 0; } int StartAbilityWithSpecifyTokenId(const Want& want, const sptr& callerToken, uint32_t specifyTokenId, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) { return startAbilityWithSpecifyTokenId_; } int32_t startAbility_ = 0; int32_t startAbilityByCall_ = 0; int32_t startAbilityWithSpecifyTokenId_ = 0; private: Semaphore sem_; }; } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_FORM_FWK_MOCK_ABILITY_MANAGER_H