• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 OHOS_ABILITY_RUNTIME_MOCK_ABILITY_MANAGER_STUB_H
17 #define OHOS_ABILITY_RUNTIME_MOCK_ABILITY_MANAGER_STUB_H
18 
19 #include "gmock/gmock.h"
20 
21 #include "string_ex.h"
22 #include "ability_manager_errors.h"
23 #include "ability_manager_stub.h"
24 #include "hilog_wrapper.h"
25 
26 namespace OHOS {
27 namespace AAFwk {
28 class MockAbilityManagerStub : public AbilityManagerStub {
29 public:
30     int StartAbility(const Want& want, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = -1);
31 
32     MOCK_METHOD4(StartAbility, int(const Want& want, const sptr<IRemoteObject>& callerToken,
33         int32_t userId, int requestCode));
34     MOCK_METHOD6(StartAbilityAsCaller, int(const Want &want, const sptr<IRemoteObject> &callerToken,
35         sptr<IRemoteObject> asCallerSourceToken, int32_t userId, int requestCode, bool isSendDialogResult));
36     MOCK_METHOD3(TerminateAbility, int(const sptr<IRemoteObject>& token, int resultCode, const Want* resultWant));
37     MOCK_METHOD3(TerminateUIExtensionAbility, int(const sptr<SessionInfo> &extensionSessionInfo, int resultCode,
38         const Want* resultWant));
39     int CloseAbility(const sptr<IRemoteObject>& token, int resultCode = DEFAULT_INVAL_VALUE,
40         const Want* resultWant = nullptr) override
41     {
42         return 0;
43     }
44     int MinimizeAbility(const sptr<IRemoteObject>& token, bool fromUser = false) override
45     {
46         return 0;
47     }
48     int MinimizeUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo, bool fromUser = false) override
49     {
50         return 0;
51     }
52     MOCK_METHOD4(ConnectAbility, int(const Want& want, const sptr<IAbilityConnection>& connect,
53         const sptr<IRemoteObject>& callerToken, int32_t userId));
54     MOCK_METHOD1(DisconnectAbility, int(sptr<IAbilityConnection> connect));
55     MOCK_METHOD3(AcquireDataAbility,
56         sptr<IAbilityScheduler>(const Uri& uri, bool tryBind, const sptr<IRemoteObject>& callerToken));
57     MOCK_METHOD2(
58         ReleaseDataAbility, int(sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject>& callerToken));
59     MOCK_METHOD2(AttachAbilityThread, int(const sptr<IAbilityScheduler>& scheduler, const sptr<IRemoteObject>& token));
60     MOCK_METHOD3(AbilityTransitionDone, int(const sptr<IRemoteObject>& token, int state, const PacMap&));
61     MOCK_METHOD2(
62         ScheduleConnectAbilityDone, int(const sptr<IRemoteObject>& token, const sptr<IRemoteObject>& remoteObject));
63     MOCK_METHOD1(ScheduleDisconnectAbilityDone, int(const sptr<IRemoteObject>& token));
64     MOCK_METHOD1(ScheduleCommandAbilityDone, int(const sptr<IRemoteObject>& token));
65     MOCK_METHOD4(ScheduleCommandAbilityWindowDone, int(const sptr<IRemoteObject> &token,
66         const sptr<SessionInfo> &sessionInfo, WindowCommand winCmd, AbilityCommand abilityCmd));
67 
68     void DumpState(const std::string& args, std::vector<std::string>& state);
69 
70     int StopServiceAbility(const Want& want, int32_t userId = DEFAULT_INVAL_VALUE,
71         const sptr<IRemoteObject> &token = nullptr);
72 
73     MOCK_METHOD1(KillProcess, int(const std::string& bundleName));
74     MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid));
75 
76     MOCK_METHOD2(
77         GetWantSender, sptr<IWantSender>(const WantSenderInfo& wantSenderInfo, const sptr<IRemoteObject>& callerToken));
78     MOCK_METHOD2(SendWantSender, int(sptr<IWantSender> target, const SenderInfo& senderInfo));
79     MOCK_METHOD1(CancelWantSender, void(const sptr<IWantSender>& sender));
80     MOCK_METHOD1(GetPendingWantUid, int(const sptr<IWantSender>& target));
81     MOCK_METHOD1(GetPendingWantUserId, int(const sptr<IWantSender>& target));
82     MOCK_METHOD1(GetPendingWantBundleName, std::string(const sptr<IWantSender>& target));
83     MOCK_METHOD1(GetPendingWantCode, int(const sptr<IWantSender>& target));
84     MOCK_METHOD1(GetPendingWantType, int(const sptr<IWantSender>& target));
85     MOCK_METHOD2(RegisterCancelListener, void(const sptr<IWantSender>& sender, const sptr<IWantReceiver>& receiver));
86     MOCK_METHOD2(UnregisterCancelListener, void(const sptr<IWantSender>& sender, const sptr<IWantReceiver>& receiver));
87     MOCK_METHOD2(GetPendingRequestWant, int(const sptr<IWantSender>& target, std::shared_ptr<Want>& want));
88     MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting,
89         const sptr<IRemoteObject>& callerToken, int32_t userId, int requestCode));
90     MOCK_METHOD4(StartAbilityByInsightIntent, int32_t(const Want& want, const sptr<IRemoteObject>& callerToken,
91         uint64_t intentId, int32_t userId));
92     MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr<IRemoteObject>& token));
93     MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id));
94     MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr<IRemoteObject>& abilityToken, int32_t status));
95     MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result));
96     MOCK_METHOD5(ContinueMission, int(const std::string& srcDeviceId, const std::string& dstDeviceId,
97         int32_t missionId, const sptr<IRemoteObject>& callBack, AAFwk::WantParams& wantParams));
98     MOCK_METHOD3(ContinueAbility, int(const std::string& deviceId, int32_t missionId, uint32_t versionCode));
99     MOCK_METHOD3(NotifyCompleteContinuation, void(const std::string& deviceId, int32_t sessionId, bool isSuccess));
100 
101     MOCK_METHOD1(LockMissionForCleanup, int(int32_t missionId));
102     MOCK_METHOD1(UnlockMissionForCleanup, int(int32_t missionId));
103     MOCK_METHOD1(RegisterMissionListener, int(const sptr<IMissionListener>& listener));
104     MOCK_METHOD1(UnRegisterMissionListener, int(const sptr<IMissionListener>& listener));
105     MOCK_METHOD3(
106         GetMissionInfos, int(const std::string& deviceId, int32_t numMax, std::vector<MissionInfo>& missionInfos));
107     MOCK_METHOD3(GetMissionInfo, int(const std::string& deviceId, int32_t missionId, MissionInfo& missionInfo));
108     MOCK_METHOD1(CleanMission, int(int32_t missionId));
109     MOCK_METHOD0(CleanAllMissions, int());
110     MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId));
111     MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions& startOptions));
112     MOCK_METHOD2(MoveMissionsToForeground, int(const std::vector<int32_t>& missionIds, int32_t topMissionId));
113     MOCK_METHOD2(MoveMissionsToBackground, int(const std::vector<int32_t>& missionIds, std::vector<int32_t>& result));
114     MOCK_METHOD2(SetMissionContinueState, int(const sptr<IRemoteObject>& token, const AAFwk::ContinueState& state));
115     MOCK_METHOD2(SetMissionLabel, int(const sptr<IRemoteObject>& token, const std::string& label));
116     MOCK_METHOD2(SetMissionIcon, int(const sptr<IRemoteObject>& token,
117         const std::shared_ptr<OHOS::Media::PixelMap>& icon));
118     MOCK_METHOD2(ClearUpApplicationData, int(const std::string&, int32_t userId));
119     MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
120     MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
121     MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
122     MOCK_METHOD2(GetWantSenderInfo, int(const sptr<IWantSender>& target, std::shared_ptr<WantSenderInfo>& info));
123     MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
124     MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
125         const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
126     MOCK_METHOD2(GetAbilityTokenByCalleeObj, void(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token));
127     virtual int StartAbility(
128         const Want& want,
129         const StartOptions& startOptions,
130         const sptr<IRemoteObject>& callerToken,
131         int32_t userId = DEFAULT_INVAL_VALUE,
132         int requestCode = DEFAULT_INVAL_VALUE)
133     {
134         return 0;
135     }
136 
137     virtual int StartAbilityAsCaller(
138         const Want& want,
139         const StartOptions& startOptions,
140         const sptr<IRemoteObject>& callerToken,
141         sptr<IRemoteObject> asCallerSourceToken,
142         int32_t userId = DEFAULT_INVAL_VALUE,
143         int requestCode = DEFAULT_INVAL_VALUE)
144     {
145         return 0;
146     }
147 
StartUser(int userId)148     int StartUser(int userId) override
149     {
150         return 0;
151     }
152 
StopUser(int userId,const sptr<IStopUserCallback> & callback)153     int StopUser(int userId, const sptr<IStopUserCallback>& callback) override
154     {
155         return 0;
156     }
157 
LogoutUser(int32_t userId)158     int LogoutUser(int32_t userId) override
159     {
160         return 0;
161     }
162 
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)163     int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
164     {
165         return 0;
166     }
StopSyncRemoteMissions(const std::string & devId)167     int StopSyncRemoteMissions(const std::string& devId) override
168     {
169         return 0;
170     }
RegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)171     int RegisterMissionListener(const std::string& deviceId,
172         const sptr<IRemoteMissionListener>& listener) override
173     {
174         return 0;
175     }
UnRegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)176     int UnRegisterMissionListener(const std::string& deviceId,
177         const sptr<IRemoteMissionListener>& listener) override
178     {
179         return 0;
180     }
181 
ReportDrawnCompleted(const sptr<IRemoteObject> & callerToken)182     int32_t ReportDrawnCompleted(const sptr<IRemoteObject>& callerToken) override
183     {
184         return 0;
185     }
186 
187     virtual int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
188         const sptr<IRemoteObject>& callerToken, int32_t userId = DEFAULT_INVAL_VALUE)
189     {
190         return 0;
191     }
ReleaseCall(const sptr<IAbilityConnection> & connect,const AppExecFwk::ElementName & element)192     virtual int ReleaseCall(const sptr<IAbilityConnection>& connect,
193         const AppExecFwk::ElementName& element)
194     {
195         return 0;
196     }
197 
GetMissionSnapshot(const std::string & deviceId,int32_t missionId,MissionSnapshot & snapshot,bool isLowResolution)198     virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
199         MissionSnapshot& snapshot, bool isLowResolution)
200     {
201         return 0;
202     }
203 
RegisterSnapshotHandler(const sptr<ISnapshotHandler> & handler)204     virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
205     {
206         return 0;
207     }
208 
RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler> & handler)209     int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler) override
210     {
211         return 0;
212     }
213 
GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> & list)214     virtual int32_t GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> &list)
215     {
216         return 0;
217     }
218 
CompleteFirstFrameDrawing(const sptr<IRemoteObject> & abilityToken)219     void CompleteFirstFrameDrawing(const sptr<IRemoteObject>& abilityToken) override {}
220 
SendANRProcessID(int pid)221     virtual int SendANRProcessID(int pid)
222     {
223         return 0;
224     }
225 
SetAbilityController(const sptr<AppExecFwk::IAbilityController> & abilityController,bool imAStabilityTest)226     int SetAbilityController(const sptr<AppExecFwk::IAbilityController>& abilityController,
227         bool imAStabilityTest) override
228     {
229         return 0;
230     }
IsRunningInStabilityTest()231     bool IsRunningInStabilityTest() override
232     {
233         return true;
234     }
DumpSysState(const std::string & args,std::vector<std::string> & info,bool isClient,bool isUserID,int UserID)235     void DumpSysState(
236         const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int UserID) override
237     {}
238 
239     MOCK_METHOD2(StartUserTest, int(const Want& want, const sptr<IRemoteObject>& observer));
240 
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)241     int FinishUserTest(
242         const std::string& msg, const int64_t& resultCode, const std::string& bundleName) override
243     {
244         return 0;
245     }
246 
GetTopAbility(sptr<IRemoteObject> & token)247     int GetTopAbility(sptr<IRemoteObject>& token) override
248     {
249         return 0;
250     }
251 
DelegatorDoAbilityForeground(const sptr<IRemoteObject> & token)252     int DelegatorDoAbilityForeground(const sptr<IRemoteObject>& token) override
253     {
254         return 0;
255     }
256 
DelegatorDoAbilityBackground(const sptr<IRemoteObject> & token)257     int DelegatorDoAbilityBackground(const sptr<IRemoteObject>& token) override
258     {
259         return 0;
260     }
261 
SetApplicationAutoStartupByEDM(const AutoStartupInfo & info,bool flag)262     int32_t SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override
263     {
264         return 0;
265     }
266 
CancelApplicationAutoStartupByEDM(const AutoStartupInfo & info,bool flag)267     int32_t CancelApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override
268     {
269         return 0;
270     }
271 
272 #ifdef ABILITY_COMMAND_FOR_TEST
273     MOCK_METHOD2(ForceTimeoutForTest, int(const std::string& abilityName, const std::string& state));
274 
BlockAmsService()275     virtual int BlockAmsService()
276     {
277         return 0;
278     }
279 
BlockAppService()280     virtual int BlockAppService()
281     {
282         return 0;
283     }
284 
BlockAbility(int32_t abilityRecordId)285     virtual int BlockAbility(int32_t abilityRecordId)
286     {
287         return 0;
288     }
289 #endif
290     MOCK_METHOD2(IsValidMissionIds, int32_t(const std::vector<int32_t>&, std::vector<MissionValidResult>&));
291     MOCK_METHOD1(RegisterAppDebugListener, int32_t(sptr<AppExecFwk::IAppDebugListener> listener));
292     MOCK_METHOD1(UnregisterAppDebugListener, int32_t(sptr<AppExecFwk::IAppDebugListener> listener));
293     MOCK_METHOD1(AttachAppDebug, int32_t(const std::string &bundleName));
294     MOCK_METHOD1(DetachAppDebug, int32_t(const std::string &bundleName));
295     MOCK_METHOD3(ExecuteIntent, int32_t(uint64_t key, const sptr<IRemoteObject> &callerToken,
296         const InsightIntentExecuteParam &param));
297     MOCK_METHOD3(ExecuteInsightIntentDone, int32_t(const sptr<IRemoteObject> &token, uint64_t intentId,
298         const InsightIntentExecuteResult &result));
299 
300 public:
301     std::string powerState_;
302 };
303 }  // namespace AAFwk
304 }  // namespace OHOS
305 
306 #endif  // OHOS_ABILITY_RUNTIME_MOCK_ABILITY_MANAGER_STUB_H
307