1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MODULETEST_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_MGR_SERVICE_H 17 #define MODULETEST_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_MGR_SERVICE_H 18 19 #include "gmock/gmock.h" 20 #include "semaphore_ex.h" 21 #include "ability_manager_stub.h" 22 23 namespace OHOS { 24 namespace AAFwk { 25 class MockAbilityMgrService : public AbilityManagerStub { 26 public: 27 MOCK_METHOD3(StartAbility, int(const Want& want, int32_t userId, int requestCode)); 28 MOCK_METHOD4(StartAbility, int(const Want& want, const sptr<IRemoteObject>& callerToken, 29 int32_t userId, int requestCode)); 30 MOCK_METHOD4(StartAbilityAsCaller, int(const Want& want, const sptr<IRemoteObject>& callerToken, 31 int32_t userId, int requestCode)); 32 MOCK_METHOD5(StartAbilityAsCaller, int(const Want &want, const StartOptions &startOptions, 33 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)); 34 MOCK_METHOD3(TerminateAbility, int(const sptr<IRemoteObject>& token, int resultCode, const Want* resultWant)); 35 virtual int CloseAbility(const sptr<IRemoteObject>& token, int resultCode = DEFAULT_INVAL_VALUE, 36 const Want* resultWant = nullptr) override 37 { 38 return 0; 39 } 40 41 virtual int MinimizeAbility(const sptr<IRemoteObject>& token, bool fromUser = false) override 42 { 43 return 0; 44 } 45 MOCK_METHOD4(ConnectAbility, int(const Want& want, const sptr<IAbilityConnection>& connect, 46 const sptr<IRemoteObject>& callerToken, int32_t userId)); 47 MOCK_METHOD1(DisconnectAbility, int(const sptr<IAbilityConnection>& connect)); 48 MOCK_METHOD3(AcquireDataAbility, sptr<IAbilityScheduler>(const Uri&, bool, const sptr<IRemoteObject>&)); 49 MOCK_METHOD2(ReleaseDataAbility, int(sptr<IAbilityScheduler>, const sptr<IRemoteObject>&)); 50 MOCK_METHOD2(AttachAbilityThread, int(const sptr<IAbilityScheduler>& scheduler, const sptr<IRemoteObject>& token)); 51 MOCK_METHOD3(AbilityTransitionDone, int(const sptr<IRemoteObject>& token, int state, const PacMap&)); 52 MOCK_METHOD2( 53 ScheduleConnectAbilityDone, int(const sptr<IRemoteObject>& token, const sptr<IRemoteObject>& remoteObject)); 54 MOCK_METHOD1(ScheduleDisconnectAbilityDone, int(const sptr<IRemoteObject>& token)); 55 MOCK_METHOD1(ScheduleCommandAbilityDone, int(const sptr<IRemoteObject>&)); 56 MOCK_METHOD4(ScheduleCommandAbilityWindowDone, int(const sptr<IRemoteObject> &token, 57 const sptr<SessionInfo> &sessionInfo, WindowCommand winCmd, AbilityCommand abilityCmd)); 58 MOCK_METHOD2(DumpState, void(const std::string& args, std::vector<std::string>& state)); 59 MOCK_METHOD5( 60 DumpSysState, 61 void(const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int UserID)); 62 MOCK_METHOD3(StopServiceAbility, int(const Want&, int32_t userId, const sptr<IRemoteObject> &token)); 63 MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr<IRemoteObject>& token)); 64 MOCK_METHOD2(GetAbilityTokenByCalleeObj, void(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token)); 65 MOCK_METHOD1(KillProcess, int(const std::string&)); 66 MOCK_METHOD2(UninstallApp, int(const std::string&, int32_t)); 67 MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); 68 MOCK_METHOD2( 69 GetWantSender, sptr<IWantSender>(const WantSenderInfo& wantSenderInfo, const sptr<IRemoteObject>& callerToken)); 70 MOCK_METHOD2(SendWantSender, int(const sptr<IWantSender>& target, const SenderInfo& senderInfo)); 71 MOCK_METHOD1(CancelWantSender, void(const sptr<IWantSender>& sender)); 72 MOCK_METHOD1(GetPendingWantUid, int(const sptr<IWantSender>& target)); 73 MOCK_METHOD1(GetPendingWantUserId, int(const sptr<IWantSender>& target)); 74 MOCK_METHOD1(GetPendingWantBundleName, std::string(const sptr<IWantSender>& target)); 75 MOCK_METHOD1(GetPendingWantCode, int(const sptr<IWantSender>& target)); 76 MOCK_METHOD1(GetPendingWantType, int(const sptr<IWantSender>& target)); 77 MOCK_METHOD2(RegisterCancelListener, void(const sptr<IWantSender>& sender, const sptr<IWantReceiver>& receiver)); 78 MOCK_METHOD2(UnregisterCancelListener, void(const sptr<IWantSender>& sender, const sptr<IWantReceiver>& receiver)); 79 MOCK_METHOD2(GetPendingRequestWant, int(const sptr<IWantSender>& target, std::shared_ptr<Want>& want)); 80 MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, 81 const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode)); 82 MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr<IRemoteObject>& abilityToken, int32_t status)); 83 MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); 84 MOCK_METHOD5(ContinueMission, int(const std::string& srcDeviceId, const std::string& dstDeviceId, 85 int32_t missionId, const sptr<IRemoteObject>& callBack, AAFwk::WantParams& wantParams)); 86 MOCK_METHOD3(ContinueAbility, int(const std::string& deviceId, int32_t missionId, uint32_t versionCode)); 87 MOCK_METHOD3(NotifyCompleteContinuation, void(const std::string& deviceId, int32_t sessionId, bool isSuccess)); 88 89 MOCK_METHOD1(LockMissionForCleanup, int(int32_t missionId)); 90 MOCK_METHOD1(UnlockMissionForCleanup, int(int32_t missionId)); 91 MOCK_METHOD1(RegisterMissionListener, int(const sptr<IMissionListener>& listener)); 92 MOCK_METHOD1(UnRegisterMissionListener, int(const sptr<IMissionListener>& listener)); 93 MOCK_METHOD3( 94 GetMissionInfos, int(const std::string& deviceId, int32_t numMax, std::vector<MissionInfo>& missionInfos)); 95 MOCK_METHOD3(GetMissionInfo, int(const std::string& deviceId, int32_t missionId, MissionInfo& missionInfo)); 96 MOCK_METHOD1(CleanMission, int(int32_t missionId)); 97 MOCK_METHOD0(CleanAllMissions, int()); 98 MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); 99 MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions& startOptions)); 100 MOCK_METHOD2(MoveMissionsToForeground, int(const std::vector<int32_t>& missionIds, int32_t topMissionId)); 101 MOCK_METHOD2(MoveMissionsToBackground, int(const std::vector<int32_t>& missionIds, std::vector<int32_t>& result)); 102 MOCK_METHOD2(SetMissionContinueState, int(const sptr<IRemoteObject>& token, const AAFwk::ContinueState& state)); 103 MOCK_METHOD2(SetMissionLabel, int(const sptr<IRemoteObject>& token, const std::string& label)); 104 MOCK_METHOD2(SetMissionIcon, int(const sptr<IRemoteObject>& token, 105 const std::shared_ptr<OHOS::Media::PixelMap>& icon)); 106 MOCK_METHOD1(ClearUpApplicationData, int(const std::string&)); 107 108 MOCK_METHOD2(GetWantSenderInfo, int(const sptr<IWantSender>& target, std::shared_ptr<WantSenderInfo>& info)); 109 110 MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info)); 111 MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info)); 112 MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info)); 113 MOCK_METHOD4(StartAbilityByCall, 114 int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t)); 115 MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData)); 116 MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token, 117 const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); 118 #ifdef ABILITY_COMMAND_FOR_TEST 119 MOCK_METHOD0(BlockAppService, int()); 120 MOCK_METHOD0(BlockAmsService, int()); 121 MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); 122 #endif 123 124 virtual int StartAbility( 125 const Want& want, 126 const StartOptions& startOptions, 127 const sptr<IRemoteObject>& callerToken, 128 int32_t userId = DEFAULT_INVAL_VALUE, 129 int requestCode = DEFAULT_INVAL_VALUE) 130 { 131 return 0; 132 } 133 StartUser(int userId)134 virtual int StartUser(int userId) override 135 { 136 return 0; 137 } 138 StopUser(int userId,const sptr<IStopUserCallback> & callback)139 virtual int StopUser(int userId, const sptr<IStopUserCallback>& callback) override 140 { 141 return 0; 142 } StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)143 virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override 144 { 145 return 0; 146 } StopSyncRemoteMissions(const std::string & devId)147 virtual int StopSyncRemoteMissions(const std::string& devId) override 148 { 149 return 0; 150 } RegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)151 virtual int RegisterMissionListener(const std::string& deviceId, 152 const sptr<IRemoteMissionListener>& listener) override 153 { 154 return 0; 155 } UnRegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)156 virtual int UnRegisterMissionListener(const std::string& deviceId, 157 const sptr<IRemoteMissionListener>& listener) override 158 { 159 return 0; 160 } CallRequestDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callStub)161 void CallRequestDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub) override 162 { 163 return; 164 } ReleaseCall(const sptr<IAbilityConnection> & connect,const AppExecFwk::ElementName & element)165 virtual int ReleaseCall(const sptr<IAbilityConnection> &connect, 166 const AppExecFwk::ElementName &element) override 167 { 168 return 0; 169 } GetMissionSnapshot(const std::string & deviceId,int32_t missionId,MissionSnapshot & snapshot,bool isLowResolution)170 virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, 171 MissionSnapshot& snapshot, bool isLowResolution) 172 { 173 return 0; 174 } RegisterSnapshotHandler(const sptr<ISnapshotHandler> & handler)175 virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler) 176 { 177 return 0; 178 } 179 RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler> & handler)180 virtual int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler) override 181 { 182 return 0; 183 } 184 CompleteFirstFrameDrawing(const sptr<IRemoteObject> & abilityToken)185 virtual void CompleteFirstFrameDrawing(const sptr<IRemoteObject>& abilityToken) override {} 186 SetAbilityController(const sptr<AppExecFwk::IAbilityController> & abilityController,bool imAStabilityTest)187 virtual int SetAbilityController(const sptr<AppExecFwk::IAbilityController>& abilityController, 188 bool imAStabilityTest) override 189 { 190 return 0; 191 } 192 IsRunningInStabilityTest()193 virtual bool IsRunningInStabilityTest() override 194 { 195 return true; 196 } 197 SendANRProcessID(int pid)198 virtual int SendANRProcessID(int pid) override 199 { 200 return 0; 201 } 202 StartUserTest(const Want & want,const sptr<IRemoteObject> & observer)203 virtual int StartUserTest(const Want& want, const sptr<IRemoteObject>& observer) override 204 { 205 return 0; 206 } 207 FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)208 virtual int FinishUserTest( 209 const std::string& msg, const int64_t& resultCode, const std::string& bundleName) override 210 { 211 return 0; 212 } 213 GetTopAbility(sptr<IRemoteObject> & token)214 virtual int GetTopAbility(sptr<IRemoteObject>& token) override 215 { 216 return 0; 217 } 218 DelegatorDoAbilityForeground(const sptr<IRemoteObject> & token)219 virtual int DelegatorDoAbilityForeground(const sptr<IRemoteObject>& token) override 220 { 221 return 0; 222 } 223 DelegatorDoAbilityBackground(const sptr<IRemoteObject> & token)224 virtual int DelegatorDoAbilityBackground(const sptr<IRemoteObject>& token) override 225 { 226 return 0; 227 } 228 ReportDrawnCompleted(const sptr<IRemoteObject> & callerToken)229 int32_t ReportDrawnCompleted(const sptr<IRemoteObject>& callerToken) override 230 { 231 return 0; 232 } 233 Wait()234 void Wait() 235 { 236 sem_.Wait(); 237 } 238 Post()239 int Post() 240 { 241 sem_.Post(); 242 return 0; 243 } 244 PostVoid()245 void PostVoid() 246 { 247 sem_.Post(); 248 } 249 250 #ifdef ABILITY_COMMAND_FOR_TEST ForceTimeoutForTest(const std::string & abilityName,const std::string & state)251 virtual int ForceTimeoutForTest(const std::string& abilityName, const std::string& state) override 252 { 253 return 0; 254 } 255 #endif 256 MOCK_METHOD2(IsValidMissionIds, int32_t(const std::vector<int32_t>&, std::vector<MissionVaildResult>&)); 257 258 private: 259 Semaphore sem_; 260 }; 261 } // namespace AAFwk 262 } // namespace OHOS 263 #endif // MODULETEST_OHOS_ABILITY_RUNTIME_MOCK_ABILITY_MGR_SERVICE_H 264