• 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_METHOD4(StartAbilityAsCaller, int(const Want &want, const sptr<IRemoteObject> &callerToken,
35         int32_t userId, int requestCode));
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(const 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(const 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_METHOD1(GetMissionIdByToken, int32_t(const sptr<IRemoteObject>& token));
91     MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id));
92     MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr<IRemoteObject>& abilityToken, int32_t status));
93     MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result));
94     MOCK_METHOD5(ContinueMission, int(const std::string& srcDeviceId, const std::string& dstDeviceId,
95         int32_t missionId, const sptr<IRemoteObject>& callBack, AAFwk::WantParams& wantParams));
96     MOCK_METHOD3(ContinueAbility, int(const std::string& deviceId, int32_t missionId, uint32_t versionCode));
97     MOCK_METHOD3(NotifyCompleteContinuation, void(const std::string& deviceId, int32_t sessionId, bool isSuccess));
98 
99     MOCK_METHOD1(LockMissionForCleanup, int(int32_t missionId));
100     MOCK_METHOD1(UnlockMissionForCleanup, int(int32_t missionId));
101     MOCK_METHOD1(RegisterMissionListener, int(const sptr<IMissionListener>& listener));
102     MOCK_METHOD1(UnRegisterMissionListener, int(const sptr<IMissionListener>& listener));
103     MOCK_METHOD3(
104         GetMissionInfos, int(const std::string& deviceId, int32_t numMax, std::vector<MissionInfo>& missionInfos));
105     MOCK_METHOD3(GetMissionInfo, int(const std::string& deviceId, int32_t missionId, MissionInfo& missionInfo));
106     MOCK_METHOD1(CleanMission, int(int32_t missionId));
107     MOCK_METHOD0(CleanAllMissions, int());
108     MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId));
109     MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions& startOptions));
110     MOCK_METHOD2(MoveMissionsToForeground, int(const std::vector<int32_t>& missionIds, int32_t topMissionId));
111     MOCK_METHOD2(MoveMissionsToBackground, int(const std::vector<int32_t>& missionIds, std::vector<int32_t>& result));
112     MOCK_METHOD2(SetMissionContinueState, int(const sptr<IRemoteObject>& token, const AAFwk::ContinueState& state));
113     MOCK_METHOD2(SetMissionLabel, int(const sptr<IRemoteObject>& token, const std::string& label));
114     MOCK_METHOD2(SetMissionIcon, int(const sptr<IRemoteObject>& token,
115         const std::shared_ptr<OHOS::Media::PixelMap>& icon));
116     MOCK_METHOD1(ClearUpApplicationData, int(const std::string&));
117     MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
118     MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
119     MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
120     MOCK_METHOD2(GetWantSenderInfo, int(const sptr<IWantSender>& target, std::shared_ptr<WantSenderInfo>& info));
121     MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
122     MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
123         const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
124     MOCK_METHOD2(GetAbilityTokenByCalleeObj, void(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token));
125     virtual int StartAbility(
126         const Want& want,
127         const StartOptions& startOptions,
128         const sptr<IRemoteObject>& callerToken,
129         int32_t userId = DEFAULT_INVAL_VALUE,
130         int requestCode = DEFAULT_INVAL_VALUE)
131     {
132         return 0;
133     }
134 
135     virtual int StartAbilityAsCaller(
136         const Want& want,
137         const StartOptions& startOptions,
138         const sptr<IRemoteObject>& callerToken,
139         int32_t userId = DEFAULT_INVAL_VALUE,
140         int requestCode = DEFAULT_INVAL_VALUE)
141     {
142         return 0;
143     }
144 
StartUser(int userId)145     int StartUser(int userId) override
146     {
147         return 0;
148     }
149 
StopUser(int userId,const sptr<IStopUserCallback> & callback)150     int StopUser(int userId, const sptr<IStopUserCallback>& callback) override
151     {
152         return 0;
153     }
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)154     int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override
155     {
156         return 0;
157     }
StopSyncRemoteMissions(const std::string & devId)158     int StopSyncRemoteMissions(const std::string& devId) override
159     {
160         return 0;
161     }
RegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)162     int RegisterMissionListener(const std::string& deviceId,
163         const sptr<IRemoteMissionListener>& listener) override
164     {
165         return 0;
166     }
UnRegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)167     int UnRegisterMissionListener(const std::string& deviceId,
168         const sptr<IRemoteMissionListener>& listener) override
169     {
170         return 0;
171     }
172 
ReportDrawnCompleted(const sptr<IRemoteObject> & callerToken)173     int32_t ReportDrawnCompleted(const sptr<IRemoteObject>& callerToken) override
174     {
175         return 0;
176     }
177 
178     virtual int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
179         const sptr<IRemoteObject>& callerToken, int32_t userId = DEFAULT_INVAL_VALUE)
180     {
181         return 0;
182     }
ReleaseCall(const sptr<IAbilityConnection> & connect,const AppExecFwk::ElementName & element)183     virtual int ReleaseCall(const sptr<IAbilityConnection>& connect,
184         const AppExecFwk::ElementName& element)
185     {
186         return 0;
187     }
188 
GetMissionSnapshot(const std::string & deviceId,int32_t missionId,MissionSnapshot & snapshot,bool isLowResolution)189     virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
190         MissionSnapshot& snapshot, bool isLowResolution)
191     {
192         return 0;
193     }
194 
RegisterSnapshotHandler(const sptr<ISnapshotHandler> & handler)195     virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
196     {
197         return 0;
198     }
199 
RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler> & handler)200     int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler) override
201     {
202         return 0;
203     }
204 
CompleteFirstFrameDrawing(const sptr<IRemoteObject> & abilityToken)205     void CompleteFirstFrameDrawing(const sptr<IRemoteObject>& abilityToken) override {}
206 
SendANRProcessID(int pid)207     virtual int SendANRProcessID(int pid)
208     {
209         return 0;
210     }
211 
SetAbilityController(const sptr<AppExecFwk::IAbilityController> & abilityController,bool imAStabilityTest)212     int SetAbilityController(const sptr<AppExecFwk::IAbilityController>& abilityController,
213         bool imAStabilityTest) override
214     {
215         return 0;
216     }
IsRunningInStabilityTest()217     bool IsRunningInStabilityTest() override
218     {
219         return true;
220     }
DumpSysState(const std::string & args,std::vector<std::string> & info,bool isClient,bool isUserID,int UserID)221     void DumpSysState(
222         const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int UserID) override
223     {}
224 
225     MOCK_METHOD2(StartUserTest, int(const Want& want, const sptr<IRemoteObject>& observer));
226 
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)227     int FinishUserTest(
228         const std::string& msg, const int64_t& resultCode, const std::string& bundleName) override
229     {
230         return 0;
231     }
232 
GetTopAbility(sptr<IRemoteObject> & token)233     int GetTopAbility(sptr<IRemoteObject>& token) override
234     {
235         return 0;
236     }
237 
DelegatorDoAbilityForeground(const sptr<IRemoteObject> & token)238     int DelegatorDoAbilityForeground(const sptr<IRemoteObject>& token) override
239     {
240         return 0;
241     }
242 
DelegatorDoAbilityBackground(const sptr<IRemoteObject> & token)243     int DelegatorDoAbilityBackground(const sptr<IRemoteObject>& token) override
244     {
245         return 0;
246     }
247 
248 #ifdef ABILITY_COMMAND_FOR_TEST
249     MOCK_METHOD2(ForceTimeoutForTest, int(const std::string& abilityName, const std::string& state));
250 
BlockAmsService()251     virtual int BlockAmsService()
252     {
253         return 0;
254     }
255 
BlockAppService()256     virtual int BlockAppService()
257     {
258         return 0;
259     }
260 
BlockAbility(int32_t abilityRecordId)261     virtual int BlockAbility(int32_t abilityRecordId)
262     {
263         return 0;
264     }
265 #endif
266     MOCK_METHOD2(IsValidMissionIds, int32_t(const std::vector<int32_t>&, std::vector<MissionVaildResult>&));
267 
268 public:
269     std::string powerState_;
270 };
271 }  // namespace AAFwk
272 }  // namespace OHOS
273 
274 #endif  // OHOS_ABILITY_RUNTIME_MOCK_ABILITY_MANAGER_STUB_H
275