• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "ability_manager_stub.h"
17 
18 #include "errors.h"
19 #include "string_ex.h"
20 
21 #include "ability_connect_callback_proxy.h"
22 #include "ability_connect_callback_stub.h"
23 #include "ability_manager_errors.h"
24 #include "ability_scheduler_proxy.h"
25 #include "ability_scheduler_stub.h"
26 
27 namespace OHOS {
28 namespace AAFwk {
29 
AbilityManagerStub()30 AbilityManagerStub::AbilityManagerStub()
31 {
32     FirstStepInit();
33     SecondStepInit();
34     ThirdStepInit();
35 }
36 
~AbilityManagerStub()37 AbilityManagerStub::~AbilityManagerStub()
38 {
39     requestFuncMap_.clear();
40 }
41 
FirstStepInit()42 void AbilityManagerStub::FirstStepInit()
43 {
44     requestFuncMap_[TERMINATE_ABILITY] = &AbilityManagerStub::TerminateAbilityInner;
45     requestFuncMap_[TERMINATE_ABILITY_BY_CALLER] = &AbilityManagerStub::TerminateAbilityByCallerInner;
46     requestFuncMap_[MINIMIZE_ABILITY] = &AbilityManagerStub::MinimizeAbilityInner;
47     requestFuncMap_[ATTACH_ABILITY_THREAD] = &AbilityManagerStub::AttachAbilityThreadInner;
48     requestFuncMap_[ABILITY_TRANSITION_DONE] = &AbilityManagerStub::AbilityTransitionDoneInner;
49     requestFuncMap_[CONNECT_ABILITY_DONE] = &AbilityManagerStub::ScheduleConnectAbilityDoneInner;
50     requestFuncMap_[DISCONNECT_ABILITY_DONE] = &AbilityManagerStub::ScheduleDisconnectAbilityDoneInner;
51     requestFuncMap_[ADD_WINDOW_INFO] = &AbilityManagerStub::AddWindowInfoInner;
52     requestFuncMap_[TERMINATE_ABILITY_RESULT] = &AbilityManagerStub::TerminateAbilityResultInner;
53     requestFuncMap_[LIST_STACK_INFO] = &AbilityManagerStub::GetAllStackInfoInner;
54     requestFuncMap_[GET_RECENT_MISSION] = &AbilityManagerStub::GetRecentMissionsInner;
55     requestFuncMap_[REMOVE_MISSION] = &AbilityManagerStub::RemoveMissionInner;
56     requestFuncMap_[COMMAND_ABILITY_DONE] = &AbilityManagerStub::ScheduleCommandAbilityDoneInner;
57     requestFuncMap_[GET_MISSION_SNAPSHOT] = &AbilityManagerStub::GetMissionSnapshotInner;
58     requestFuncMap_[ACQUIRE_DATA_ABILITY] = &AbilityManagerStub::AcquireDataAbilityInner;
59     requestFuncMap_[RELEASE_DATA_ABILITY] = &AbilityManagerStub::ReleaseDataAbilityInner;
60     requestFuncMap_[MOVE_MISSION_TO_TOP] = &AbilityManagerStub::MoveMissionToTopInner;
61     requestFuncMap_[MOVE_MISSION_TO_END] = &AbilityManagerStub::MoveMissionToEndInner;
62     requestFuncMap_[KILL_PROCESS] = &AbilityManagerStub::KillProcessInner;
63     requestFuncMap_[UNINSTALL_APP] = &AbilityManagerStub::UninstallAppInner;
64     requestFuncMap_[START_ABILITY] = &AbilityManagerStub::StartAbilityInner;
65     requestFuncMap_[START_ABILITY_ADD_CALLER] = &AbilityManagerStub::StartAbilityAddCallerInner;
66     requestFuncMap_[CONNECT_ABILITY] = &AbilityManagerStub::ConnectAbilityInner;
67     requestFuncMap_[DISCONNECT_ABILITY] = &AbilityManagerStub::DisconnectAbilityInner;
68     requestFuncMap_[STOP_SERVICE_ABILITY] = &AbilityManagerStub::StopServiceAbilityInner;
69     requestFuncMap_[DUMP_STATE] = &AbilityManagerStub::DumpStateInner;
70     requestFuncMap_[DUMPSYS_STATE] = &AbilityManagerStub::DumpSysStateInner;
71     requestFuncMap_[START_ABILITY_FOR_SETTINGS] = &AbilityManagerStub::StartAbilityForSettingsInner;
72     requestFuncMap_[CONTINUE_MISSION] = &AbilityManagerStub::ContinueMissionInner;
73     requestFuncMap_[CONTINUE_ABILITY] = &AbilityManagerStub::ContinueAbilityInner;
74     requestFuncMap_[START_CONTINUATION] = &AbilityManagerStub::StartContinuationInner;
75     requestFuncMap_[NOTIFY_COMPLETE_CONTINUATION] = &AbilityManagerStub::NotifyCompleteContinuationInner;
76     requestFuncMap_[NOTIFY_CONTINUATION_RESULT] = &AbilityManagerStub::NotifyContinuationResultInner;
77     requestFuncMap_[REGISTER_REMOTE_MISSION_LISTENER] = &AbilityManagerStub::RegisterRemoteMissionListenerInner;
78     requestFuncMap_[UNREGISTER_REMOTE_MISSION_LISTENER] = &AbilityManagerStub::UnRegisterRemoteMissionListenerInner;
79     requestFuncMap_[MOVE_MISSION_TO_FLOATING_STACK] = &AbilityManagerStub::MoveMissionToFloatingStackInner;
80     requestFuncMap_[MOVE_MISSION_TO_SPLITSCREEN_STACK] = &AbilityManagerStub::MoveMissionToSplitScreenStackInner;
81     requestFuncMap_[CHANGE_FOCUS_ABILITY] = &AbilityManagerStub::ChangeFocusAbilityInner;
82     requestFuncMap_[MINIMIZE_MULTI_WINDOW] = &AbilityManagerStub::MinimizeMultiWindowInner;
83     requestFuncMap_[START_ABILITY_FOR_OPTIONS] = &AbilityManagerStub::StartAbilityForOptionsInner;
84     requestFuncMap_[START_SYNC_MISSIONS] = &AbilityManagerStub::StartSyncRemoteMissionsInner;
85     requestFuncMap_[STOP_SYNC_MISSIONS] = &AbilityManagerStub::StopSyncRemoteMissionsInner;
86     requestFuncMap_[FORCE_TIMEOUT] = &AbilityManagerStub::ForceTimeoutForTestInner;
87 }
88 
SecondStepInit()89 void AbilityManagerStub::SecondStepInit()
90 {
91     requestFuncMap_[MAXIMIZE_MULTI_WINDOW] = &AbilityManagerStub::MaximizeMultiWindowInner;
92     requestFuncMap_[GET_FLOATING_MISSIONS] = &AbilityManagerStub::GetFloatingMissionsInner;
93     requestFuncMap_[CLOSE_MULTI_WINDOW] = &AbilityManagerStub::CloseMultiWindowInner;
94     requestFuncMap_[SET_STACK_SETTING] = &AbilityManagerStub::SetMissionStackSettingInner;
95     requestFuncMap_[IS_FIRST_IN_MISSION] = &AbilityManagerStub::IsFirstInMissionInner;
96     requestFuncMap_[POWER_OFF] = &AbilityManagerStub::PowerOffInner;
97     requestFuncMap_[POWER_ON] = &AbilityManagerStub::PowerOnInner;
98     requestFuncMap_[LUCK_MISSION] = &AbilityManagerStub::LockMissionInner;
99     requestFuncMap_[UNLUCK_MISSION] = &AbilityManagerStub::UnlockMissionInner;
100     requestFuncMap_[GET_PENDING_WANT_SENDER] = &AbilityManagerStub::GetWantSenderInner;
101     requestFuncMap_[SEND_PENDING_WANT_SENDER] = &AbilityManagerStub::SendWantSenderInner;
102     requestFuncMap_[CANCEL_PENDING_WANT_SENDER] = &AbilityManagerStub::CancelWantSenderInner;
103     requestFuncMap_[GET_PENDING_WANT_UID] = &AbilityManagerStub::GetPendingWantUidInner;
104     requestFuncMap_[GET_PENDING_WANT_USERID] = &AbilityManagerStub::GetPendingWantUserIdInner;
105     requestFuncMap_[GET_PENDING_WANT_BUNDLENAME] = &AbilityManagerStub::GetPendingWantBundleNameInner;
106     requestFuncMap_[GET_PENDING_WANT_CODE] = &AbilityManagerStub::GetPendingWantCodeInner;
107     requestFuncMap_[GET_PENDING_WANT_TYPE] = &AbilityManagerStub::GetPendingWantTypeInner;
108     requestFuncMap_[REGISTER_CANCEL_LISTENER] = &AbilityManagerStub::RegisterCancelListenerInner;
109     requestFuncMap_[UNREGISTER_CANCEL_LISTENER] = &AbilityManagerStub::UnregisterCancelListenerInner;
110     requestFuncMap_[GET_PENDING_REQUEST_WANT] = &AbilityManagerStub::GetPendingRequestWantInner;
111     requestFuncMap_[GET_PENDING_WANT_SENDER_INFO] = &AbilityManagerStub::GetPendingRequestWantInner;
112     requestFuncMap_[SET_MISSION_INFO] = &AbilityManagerStub::SetMissionDescriptionInfoInner;
113     requestFuncMap_[GET_MISSION_LOCK_MODE_STATE] = &AbilityManagerStub::GetMissionLockModeStateInner;
114     requestFuncMap_[UPDATE_CONFIGURATION] = &AbilityManagerStub::UpdateConfigurationInner;
115     requestFuncMap_[SET_SHOW_ON_LOCK_SCREEN] = &AbilityManagerStub::SetShowOnLockScreenInner;
116     requestFuncMap_[GET_SYSTEM_MEMORY_ATTR] = &AbilityManagerStub::GetSystemMemoryAttrInner;
117     requestFuncMap_[GET_APP_MEMORY_SIZE] = &AbilityManagerStub::GetAppMemorySizeInner;
118     requestFuncMap_[IS_RAM_CONSTRAINED_DEVICE] = &AbilityManagerStub::IsRamConstrainedDeviceInner;
119     requestFuncMap_[CLEAR_UP_APPLICATION_DATA] = &AbilityManagerStub::ClearUpApplicationDataInner;
120     requestFuncMap_[LOCK_MISSION_FOR_CLEANUP] = &AbilityManagerStub::LockMissionForCleanupInner;
121     requestFuncMap_[UNLOCK_MISSION_FOR_CLEANUP] = &AbilityManagerStub::UnlockMissionForCleanupInner;
122     requestFuncMap_[REGISTER_MISSION_LISTENER] = &AbilityManagerStub::RegisterMissionListenerInner;
123     requestFuncMap_[UNREGISTER_MISSION_LISTENER] = &AbilityManagerStub::UnRegisterMissionListenerInner;
124     requestFuncMap_[GET_MISSION_INFOS] = &AbilityManagerStub::GetMissionInfosInner;
125     requestFuncMap_[GET_MISSION_INFO_BY_ID] = &AbilityManagerStub::GetMissionInfoInner;
126     requestFuncMap_[CLEAN_MISSION] = &AbilityManagerStub::CleanMissionInner;
127     requestFuncMap_[CLEAN_ALL_MISSIONS] = &AbilityManagerStub::CleanAllMissionsInner;
128     requestFuncMap_[MOVE_MISSION_TO_FRONT] = &AbilityManagerStub::MoveMissionToFrontInner;
129     requestFuncMap_[MOVE_MISSION_TO_FRONT_BY_OPTIONS] = &AbilityManagerStub::MoveMissionToFrontByOptionsInner;
130     requestFuncMap_[START_CALL_ABILITY] = &AbilityManagerStub::StartAbilityByCallInner;
131     requestFuncMap_[RELEASE_CALL_ABILITY] = &AbilityManagerStub::ReleaseInner;
132     requestFuncMap_[SET_MISSION_LABEL] = &AbilityManagerStub::SetMissionLabelInner;
133     requestFuncMap_[START_USER] = &AbilityManagerStub::StartUserInner;
134     requestFuncMap_[STOP_USER] = &AbilityManagerStub::StopUserInner;
135     requestFuncMap_[GET_ABILITY_RUNNING_INFO] = &AbilityManagerStub::GetAbilityRunningInfosInner;
136     requestFuncMap_[GET_EXTENSION_RUNNING_INFO] = &AbilityManagerStub::GetExtensionRunningInfosInner;
137     requestFuncMap_[GET_PROCESS_RUNNING_INFO] = &AbilityManagerStub::GetProcessRunningInfosInner;
138     requestFuncMap_[SET_ABILITY_CONTROLLER] = &AbilityManagerStub::SetAbilityControllerInner;
139     requestFuncMap_[GET_MISSION_SNAPSHOT_INFO] = &AbilityManagerStub::GetMissionSnapshotInfoInner;
140     requestFuncMap_[IS_USER_A_STABILITY_TEST] = &AbilityManagerStub::IsRunningInStabilityTestInner;
141     requestFuncMap_[SEND_APP_NOT_RESPONSE_PROCESS_ID] = &AbilityManagerStub::SendANRProcessIDInner;
142 }
143 
ThirdStepInit()144 void AbilityManagerStub::ThirdStepInit()
145 {
146     requestFuncMap_[START_USER_TEST] = &AbilityManagerStub::StartUserTestInner;
147     requestFuncMap_[FINISH_USER_TEST] = &AbilityManagerStub::FinishUserTestInner;
148     requestFuncMap_[GET_CURRENT_TOP_ABILITY] = &AbilityManagerStub::GetCurrentTopAbilityInner;
149     requestFuncMap_[DELEGATOR_DO_ABILITY_FOREGROUND] = &AbilityManagerStub::DelegatorDoAbilityForegroundInner;
150     requestFuncMap_[DELEGATOR_DO_ABILITY_BACKGROUND] = &AbilityManagerStub::DelegatorDoAbilityBackgroundInner;
151     requestFuncMap_[DO_ABILITY_FOREGROUND] = &AbilityManagerStub::DoAbilityForegroundInner;
152     requestFuncMap_[DO_ABILITY_BACKGROUND] = &AbilityManagerStub::DoAbilityBackgroundInner;
153     requestFuncMap_[GET_MISSION_ID_BY_ABILITY_TOKEN] = &AbilityManagerStub::GetMissionIdByTokenInner;
154     requestFuncMap_[GET_TOP_ABILITY] = &AbilityManagerStub::GetTopAbilityInner;
155     requestFuncMap_[SET_MISSION_ICON] = &AbilityManagerStub::SetMissionIconInner;
156     requestFuncMap_[DUMP_ABILITY_INFO_DONE] = &AbilityManagerStub::DumpAbilityInfoDoneInner;
157 }
158 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)159 int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
160 {
161     HILOG_DEBUG("cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
162     std::u16string descriptor = AbilityManagerStub::GetDescriptor();
163     std::u16string remoteDescriptor = data.ReadInterfaceToken();
164     if (descriptor != remoteDescriptor) {
165         HILOG_INFO("local descriptor is not equal to remote");
166         return ERR_INVALID_STATE;
167     }
168 
169     auto itFunc = requestFuncMap_.find(code);
170     if (itFunc != requestFuncMap_.end()) {
171         auto requestFunc = itFunc->second;
172         if (requestFunc != nullptr) {
173             return (this->*requestFunc)(data, reply);
174         }
175     }
176     HILOG_WARN("default case, need check.");
177     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
178 }
179 
GetTopAbilityInner(MessageParcel & data,MessageParcel & reply)180 int AbilityManagerStub::GetTopAbilityInner(MessageParcel &data, MessageParcel &reply)
181 {
182     AppExecFwk::ElementName result = GetTopAbility();
183     if (result.GetDeviceID().empty()) {
184         HILOG_DEBUG("GetTopAbilityInner is nullptr");
185     }
186     reply.WriteParcelable(&result);
187     return NO_ERROR;
188 }
189 
TerminateAbilityInner(MessageParcel & data,MessageParcel & reply)190 int AbilityManagerStub::TerminateAbilityInner(MessageParcel &data, MessageParcel &reply)
191 {
192     sptr<IRemoteObject> token = nullptr;
193     if (data.ReadBool()) {
194         token = data.ReadRemoteObject();
195     }
196     int resultCode = data.ReadInt32();
197     Want *resultWant = data.ReadParcelable<Want>();
198     bool flag = data.ReadBool();
199     int32_t result;
200     if (flag) {
201         result = TerminateAbility(token, resultCode, resultWant);
202     } else {
203         result = CloseAbility(token, resultCode, resultWant);
204     }
205     reply.WriteInt32(result);
206     if (resultWant != nullptr) {
207         delete resultWant;
208     }
209     return NO_ERROR;
210 }
211 
TerminateAbilityByCallerInner(MessageParcel & data,MessageParcel & reply)212 int AbilityManagerStub::TerminateAbilityByCallerInner(MessageParcel &data, MessageParcel &reply)
213 {
214     sptr<IRemoteObject> callerToken = nullptr;
215     if (data.ReadBool()) {
216         callerToken = data.ReadRemoteObject();
217     }
218     int requestCode = data.ReadInt32();
219     int32_t result = TerminateAbilityByCaller(callerToken, requestCode);
220     reply.WriteInt32(result);
221     return NO_ERROR;
222 }
223 
MinimizeAbilityInner(MessageParcel & data,MessageParcel & reply)224 int AbilityManagerStub::MinimizeAbilityInner(MessageParcel &data, MessageParcel &reply)
225 {
226     auto token = data.ReadRemoteObject();
227     auto fromUser = data.ReadBool();
228     int32_t result = MinimizeAbility(token, fromUser);
229     reply.WriteInt32(result);
230     return NO_ERROR;
231 }
232 
AttachAbilityThreadInner(MessageParcel & data,MessageParcel & reply)233 int AbilityManagerStub::AttachAbilityThreadInner(MessageParcel &data, MessageParcel &reply)
234 {
235     auto scheduler = iface_cast<IAbilityScheduler>(data.ReadRemoteObject());
236     auto token = data.ReadRemoteObject();
237     int32_t result = AttachAbilityThread(scheduler, token);
238     reply.WriteInt32(result);
239     return NO_ERROR;
240 }
241 
AbilityTransitionDoneInner(MessageParcel & data,MessageParcel & reply)242 int AbilityManagerStub::AbilityTransitionDoneInner(MessageParcel &data, MessageParcel &reply)
243 {
244     auto token = data.ReadRemoteObject();
245     int targetState = data.ReadInt32();
246     std::unique_ptr<PacMap> saveData(data.ReadParcelable<PacMap>());
247     if (!saveData) {
248         HILOG_INFO("save data is nullptr");
249         return ERR_INVALID_VALUE;
250     }
251     int32_t result = AbilityTransitionDone(token, targetState, *saveData);
252     reply.WriteInt32(result);
253     return NO_ERROR;
254 }
255 
ScheduleConnectAbilityDoneInner(MessageParcel & data,MessageParcel & reply)256 int AbilityManagerStub::ScheduleConnectAbilityDoneInner(MessageParcel &data, MessageParcel &reply)
257 {
258     sptr<IRemoteObject> token = nullptr;
259     sptr<IRemoteObject> remoteObject = nullptr;
260     if (data.ReadBool()) {
261         token = data.ReadRemoteObject();
262     }
263     if (data.ReadBool()) {
264         remoteObject = data.ReadRemoteObject();
265     }
266     int32_t result = ScheduleConnectAbilityDone(token, remoteObject);
267     reply.WriteInt32(result);
268     return NO_ERROR;
269 }
270 
ScheduleDisconnectAbilityDoneInner(MessageParcel & data,MessageParcel & reply)271 int AbilityManagerStub::ScheduleDisconnectAbilityDoneInner(MessageParcel &data, MessageParcel &reply)
272 {
273     auto token = data.ReadRemoteObject();
274     int32_t result = ScheduleDisconnectAbilityDone(token);
275     reply.WriteInt32(result);
276     return NO_ERROR;
277 }
278 
AddWindowInfoInner(MessageParcel & data,MessageParcel & reply)279 int AbilityManagerStub::AddWindowInfoInner(MessageParcel &data, MessageParcel &reply)
280 {
281     sptr<IRemoteObject> token = data.ReadRemoteObject();
282     int windowToken = data.ReadInt32();
283     AddWindowInfo(token, windowToken);
284     return NO_ERROR;
285 }
286 
TerminateAbilityResultInner(MessageParcel & data,MessageParcel & reply)287 int AbilityManagerStub::TerminateAbilityResultInner(MessageParcel &data, MessageParcel &reply)
288 {
289     sptr<IRemoteObject> token = data.ReadRemoteObject();
290     int startId = data.ReadInt32();
291     int32_t result = TerminateAbilityResult(token, startId);
292     reply.WriteInt32(result);
293     return NO_ERROR;
294 }
295 
GetAllStackInfoInner(MessageParcel & data,MessageParcel & reply)296 int AbilityManagerStub::GetAllStackInfoInner(MessageParcel &data, MessageParcel &reply)
297 {
298     StackInfo stackInfo;
299     int32_t result = GetAllStackInfo(stackInfo);
300     if (!reply.WriteInt32(result)) {
301         HILOG_ERROR("GetAllStackInfo result error");
302         return ERR_INVALID_VALUE;
303     }
304     if (!reply.WriteParcelable(&stackInfo)) {
305         HILOG_ERROR("GetAllStackInfo error");
306         return ERR_INVALID_VALUE;
307     }
308     return NO_ERROR;
309 }
310 
GetRecentMissionsInner(MessageParcel & data,MessageParcel & reply)311 int AbilityManagerStub::GetRecentMissionsInner(MessageParcel &data, MessageParcel &reply)
312 {
313     int numMax = data.ReadInt32();
314     int flags = data.ReadInt32();
315     std::vector<AbilityMissionInfo> missionInfos;
316     int32_t result = GetRecentMissions(numMax, flags, missionInfos);
317     reply.WriteInt32(missionInfos.size());
318     for (auto &it : missionInfos) {
319         if (!reply.WriteParcelable(&it)) {
320             return ERR_INVALID_VALUE;
321         }
322     }
323     if (!reply.WriteInt32(result)) {
324         return ERR_INVALID_VALUE;
325     }
326     return result;
327 }
328 
RemoveMissionInner(MessageParcel & data,MessageParcel & reply)329 int AbilityManagerStub::RemoveMissionInner(MessageParcel &data, MessageParcel &reply)
330 {
331     int id = data.ReadInt32();
332     int32_t result = RemoveMission(id);
333     if (!reply.WriteInt32(result)) {
334         HILOG_ERROR("remove mission error.");
335         return ERR_INVALID_VALUE;
336     }
337     return NO_ERROR;
338 }
339 
ScheduleCommandAbilityDoneInner(MessageParcel & data,MessageParcel & reply)340 int AbilityManagerStub::ScheduleCommandAbilityDoneInner(MessageParcel &data, MessageParcel &reply)
341 {
342     auto token = data.ReadRemoteObject();
343     int32_t result = ScheduleCommandAbilityDone(token);
344     reply.WriteInt32(result);
345     return NO_ERROR;
346 }
347 
GetMissionSnapshotInner(MessageParcel & data,MessageParcel & reply)348 int AbilityManagerStub::GetMissionSnapshotInner(MessageParcel &data, MessageParcel &reply)
349 {
350     MissionPixelMap missionPixelMap;
351     int32_t missionId = data.ReadInt32();
352     int32_t result = GetMissionSnapshot(missionId, missionPixelMap);
353     if (!reply.WriteParcelable(&missionPixelMap)) {
354         HILOG_ERROR("GetMissionSnapshot error");
355         return ERR_INVALID_VALUE;
356     }
357 
358     if (!reply.WriteInt32(result)) {
359         HILOG_ERROR("GetMissionSnapshot result error");
360         return ERR_INVALID_VALUE;
361     }
362     return NO_ERROR;
363 }
364 
AcquireDataAbilityInner(MessageParcel & data,MessageParcel & reply)365 int AbilityManagerStub::AcquireDataAbilityInner(MessageParcel &data, MessageParcel &reply)
366 {
367     std::unique_ptr<Uri> uri(new Uri(data.ReadString()));
368     bool tryBind = data.ReadBool();
369     sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
370     sptr<IAbilityScheduler> result = AcquireDataAbility(*uri, tryBind, callerToken);
371     HILOG_DEBUG("acquire data ability %{public}s", result ? "ok" : "failed");
372     if (result) {
373         reply.WriteRemoteObject(result->AsObject());
374     } else {
375         reply.WriteParcelable(nullptr);
376     }
377     return NO_ERROR;
378 }
379 
ReleaseDataAbilityInner(MessageParcel & data,MessageParcel & reply)380 int AbilityManagerStub::ReleaseDataAbilityInner(MessageParcel &data, MessageParcel &reply)
381 {
382     auto scheduler = iface_cast<IAbilityScheduler>(data.ReadRemoteObject());
383     auto callerToken = data.ReadRemoteObject();
384     int32_t result = ReleaseDataAbility(scheduler, callerToken);
385     HILOG_DEBUG("release data ability ret = %d", result);
386     reply.WriteInt32(result);
387     return NO_ERROR;
388 }
389 
MoveMissionToTopInner(MessageParcel & data,MessageParcel & reply)390 int AbilityManagerStub::MoveMissionToTopInner(MessageParcel &data, MessageParcel &reply)
391 {
392     int32_t id = data.ReadInt32();
393     int result = MoveMissionToTop(id);
394     if (!reply.WriteInt32(result)) {
395         HILOG_ERROR("move mission to top error");
396         return ERR_INVALID_VALUE;
397     }
398     return NO_ERROR;
399 }
400 
MoveMissionToEndInner(MessageParcel & data,MessageParcel & reply)401 int AbilityManagerStub::MoveMissionToEndInner(MessageParcel &data, MessageParcel &reply)
402 {
403     auto token = data.ReadRemoteObject();
404     auto nonFirst = data.ReadBool();
405     int result = MoveMissionToEnd(token, nonFirst);
406     if (!reply.WriteInt32(result)) {
407         HILOG_ERROR("move mission to top error");
408         return ERR_INVALID_VALUE;
409     }
410     return NO_ERROR;
411 }
412 
KillProcessInner(MessageParcel & data,MessageParcel & reply)413 int AbilityManagerStub::KillProcessInner(MessageParcel &data, MessageParcel &reply)
414 {
415     std::string bundleName = Str16ToStr8(data.ReadString16());
416     int result = KillProcess(bundleName);
417     if (!reply.WriteInt32(result)) {
418         HILOG_ERROR("remove stack error");
419         return ERR_INVALID_VALUE;
420     }
421     return NO_ERROR;
422 }
423 
ClearUpApplicationDataInner(MessageParcel & data,MessageParcel & reply)424 int AbilityManagerStub::ClearUpApplicationDataInner(MessageParcel &data, MessageParcel &reply)
425 {
426     std::string bundleName = Str16ToStr8(data.ReadString16());
427     int result = ClearUpApplicationData(bundleName);
428     if (!reply.WriteInt32(result)) {
429         HILOG_ERROR("ClearUpApplicationData error");
430         return ERR_INVALID_VALUE;
431     }
432     return NO_ERROR;
433 }
434 
UninstallAppInner(MessageParcel & data,MessageParcel & reply)435 int AbilityManagerStub::UninstallAppInner(MessageParcel &data, MessageParcel &reply)
436 {
437     std::string bundleName = Str16ToStr8(data.ReadString16());
438     int32_t uid = data.ReadInt32();
439     int result = UninstallApp(bundleName, uid);
440     if (!reply.WriteInt32(result)) {
441         HILOG_ERROR("remove stack error");
442         return ERR_INVALID_VALUE;
443     }
444     return NO_ERROR;
445 }
446 
StartAbilityInner(MessageParcel & data,MessageParcel & reply)447 int AbilityManagerStub::StartAbilityInner(MessageParcel &data, MessageParcel &reply)
448 {
449     Want *want = data.ReadParcelable<Want>();
450     if (want == nullptr) {
451         HILOG_ERROR("want is nullptr");
452         return ERR_INVALID_VALUE;
453     }
454     int32_t userId = data.ReadInt32();
455     int requestCode = data.ReadInt32();
456     int32_t result = StartAbility(*want, userId, requestCode);
457     reply.WriteInt32(result);
458     delete want;
459     return NO_ERROR;
460 }
461 
StartAbilityAddCallerInner(MessageParcel & data,MessageParcel & reply)462 int AbilityManagerStub::StartAbilityAddCallerInner(MessageParcel &data, MessageParcel &reply)
463 {
464     Want *want = data.ReadParcelable<Want>();
465     if (want == nullptr) {
466         HILOG_ERROR("want is nullptr");
467         return ERR_INVALID_VALUE;
468     }
469 
470     sptr<IRemoteObject> callerToken = nullptr;
471     if (data.ReadBool()) {
472         callerToken = data.ReadRemoteObject();
473     }
474 
475     int32_t userId = data.ReadInt32();
476     int requestCode = data.ReadInt32();
477     int32_t result = StartAbility(*want, callerToken, userId, requestCode);
478     reply.WriteInt32(result);
479     delete want;
480     return NO_ERROR;
481 }
482 
ConnectAbilityInner(MessageParcel & data,MessageParcel & reply)483 int AbilityManagerStub::ConnectAbilityInner(MessageParcel &data, MessageParcel &reply)
484 {
485     Want *want = data.ReadParcelable<Want>();
486     if (want == nullptr) {
487         HILOG_ERROR("want is nullptr");
488         return ERR_INVALID_VALUE;
489     }
490     sptr<IAbilityConnection> callback = nullptr;
491     sptr<IRemoteObject> token = nullptr;
492     if (data.ReadBool()) {
493         callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
494     }
495     if (data.ReadBool()) {
496         token = data.ReadRemoteObject();
497     }
498     int32_t userId = data.ReadInt32();
499     int32_t result = ConnectAbility(*want, callback, token, userId);
500     reply.WriteInt32(result);
501     delete want;
502     return NO_ERROR;
503 }
504 
DisconnectAbilityInner(MessageParcel & data,MessageParcel & reply)505 int AbilityManagerStub::DisconnectAbilityInner(MessageParcel &data, MessageParcel &reply)
506 {
507     auto callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
508     int32_t result = DisconnectAbility(callback);
509     HILOG_DEBUG("disconnect ability ret = %d", result);
510     reply.WriteInt32(result);
511     return NO_ERROR;
512 }
513 
StopServiceAbilityInner(MessageParcel & data,MessageParcel & reply)514 int AbilityManagerStub::StopServiceAbilityInner(MessageParcel &data, MessageParcel &reply)
515 {
516     Want *want = data.ReadParcelable<Want>();
517     if (want == nullptr) {
518         HILOG_ERROR("want is nullptr");
519         return ERR_INVALID_VALUE;
520     }
521     int32_t userId = data.ReadInt32();
522     int32_t result = StopServiceAbility(*want, userId);
523     reply.WriteInt32(result);
524     delete want;
525     return NO_ERROR;
526 }
527 
DumpSysStateInner(MessageParcel & data,MessageParcel & reply)528 int AbilityManagerStub::DumpSysStateInner(MessageParcel &data, MessageParcel &reply)
529 {
530     std::vector<std::string> result;
531     std::string args = Str16ToStr8(data.ReadString16());
532     std::vector<std::string> argList;
533 
534     auto isClient = data.ReadBool();
535     auto isUserID = data.ReadBool();
536     auto UserID = data.ReadInt32();
537     SplitStr(args, " ", argList);
538     if (argList.empty()) {
539         return ERR_INVALID_VALUE;
540     }
541     DumpSysState(args, result, isClient, isUserID, UserID);
542     reply.WriteInt32(result.size());
543     for (auto stack : result) {
544         reply.WriteString16(Str8ToStr16(stack));
545     }
546     return NO_ERROR;
547 }
548 
DumpStateInner(MessageParcel & data,MessageParcel & reply)549 int AbilityManagerStub::DumpStateInner(MessageParcel &data, MessageParcel &reply)
550 {
551     std::vector<std::string> result;
552     std::string args = Str16ToStr8(data.ReadString16());
553     std::vector<std::string> argList;
554     SplitStr(args, " ", argList);
555     if (argList.empty()) {
556         return ERR_INVALID_VALUE;
557     }
558     DumpState(args, result);
559     reply.WriteInt32(result.size());
560     for (auto stack : result) {
561         reply.WriteString16(Str8ToStr16(stack));
562     }
563     return NO_ERROR;
564 }
565 
StartAbilityForSettingsInner(MessageParcel & data,MessageParcel & reply)566 int AbilityManagerStub::StartAbilityForSettingsInner(MessageParcel &data, MessageParcel &reply)
567 {
568     Want *want = data.ReadParcelable<Want>();
569     if (want == nullptr) {
570         HILOG_ERROR("want is nullptr");
571         return ERR_INVALID_VALUE;
572     }
573     AbilityStartSetting *abilityStartSetting = data.ReadParcelable<AbilityStartSetting>();
574     if (abilityStartSetting == nullptr) {
575         HILOG_ERROR("abilityStartSetting is nullptr");
576         delete want;
577         return ERR_INVALID_VALUE;
578     }
579     sptr<IRemoteObject> callerToken = nullptr;
580     if (data.ReadBool()) {
581         callerToken = data.ReadRemoteObject();
582     }
583     int32_t userId = data.ReadInt32();
584     int requestCode = data.ReadInt32();
585     int32_t result = StartAbility(*want, *abilityStartSetting, callerToken, userId, requestCode);
586     reply.WriteInt32(result);
587     delete want;
588     delete abilityStartSetting;
589     return NO_ERROR;
590 }
591 
StartAbilityForOptionsInner(MessageParcel & data,MessageParcel & reply)592 int AbilityManagerStub::StartAbilityForOptionsInner(MessageParcel &data, MessageParcel &reply)
593 {
594     Want *want = data.ReadParcelable<Want>();
595     if (want == nullptr) {
596         HILOG_ERROR("want is nullptr");
597         return ERR_INVALID_VALUE;
598     }
599     StartOptions *startOptions = data.ReadParcelable<StartOptions>();
600     if (startOptions == nullptr) {
601         HILOG_ERROR("startOptions is nullptr");
602         delete want;
603         return ERR_INVALID_VALUE;
604     }
605     sptr<IRemoteObject> callerToken = nullptr;
606     if (data.ReadBool()) {
607         callerToken = data.ReadRemoteObject();
608     }
609     int32_t userId = data.ReadInt32();
610     int requestCode = data.ReadInt32();
611     int32_t result = StartAbility(*want, *startOptions, callerToken, userId, requestCode);
612     reply.WriteInt32(result);
613     delete want;
614     delete startOptions;
615     return NO_ERROR;
616 }
617 
MoveMissionToFloatingStackInner(MessageParcel & data,MessageParcel & reply)618 int AbilityManagerStub::MoveMissionToFloatingStackInner(MessageParcel &data, MessageParcel &reply)
619 {
620     MissionOption *missionOption = data.ReadParcelable<MissionOption>();
621     if (missionOption == nullptr) {
622         HILOG_ERROR("missionOption is nullptr");
623         return ERR_INVALID_VALUE;
624     }
625 
626     auto result = MoveMissionToFloatingStack(*missionOption);
627     reply.WriteInt32(result);
628     delete missionOption;
629     return NO_ERROR;
630 }
631 
MoveMissionToSplitScreenStackInner(MessageParcel & data,MessageParcel & reply)632 int AbilityManagerStub::MoveMissionToSplitScreenStackInner(MessageParcel &data, MessageParcel &reply)
633 {
634     MissionOption *primary = data.ReadParcelable<MissionOption>();
635     if (primary == nullptr) {
636         HILOG_ERROR("missionOption is nullptr");
637         return ERR_INVALID_VALUE;
638     }
639     MissionOption *secondary = data.ReadParcelable<MissionOption>();
640     if (secondary == nullptr) {
641         HILOG_ERROR("missionOption is nullptr");
642         delete primary;
643         return ERR_INVALID_VALUE;
644     }
645     auto result = MoveMissionToSplitScreenStack(*primary, *secondary);
646     reply.WriteInt32(result);
647     delete primary;
648     delete secondary;
649     return NO_ERROR;
650 }
651 
ChangeFocusAbilityInner(MessageParcel & data,MessageParcel & reply)652 int AbilityManagerStub::ChangeFocusAbilityInner(MessageParcel &data, MessageParcel &reply)
653 {
654     auto loseToken = data.ReadRemoteObject();
655     auto getToken = data.ReadRemoteObject();
656     auto result = ChangeFocusAbility(loseToken, getToken);
657     reply.WriteInt32(result);
658     return NO_ERROR;
659 }
660 
MinimizeMultiWindowInner(MessageParcel & data,MessageParcel & reply)661 int AbilityManagerStub::MinimizeMultiWindowInner(MessageParcel &data, MessageParcel &reply)
662 {
663     auto missionId = data.ReadInt32();
664     auto result = MinimizeMultiWindow(missionId);
665     reply.WriteInt32(result);
666     return NO_ERROR;
667 }
668 
MaximizeMultiWindowInner(MessageParcel & data,MessageParcel & reply)669 int AbilityManagerStub::MaximizeMultiWindowInner(MessageParcel &data, MessageParcel &reply)
670 {
671     auto missionId = data.ReadInt32();
672     auto result = MaximizeMultiWindow(missionId);
673     reply.WriteInt32(result);
674     return NO_ERROR;
675 }
676 
GetFloatingMissionsInner(MessageParcel & data,MessageParcel & reply)677 int AbilityManagerStub::GetFloatingMissionsInner(MessageParcel &data, MessageParcel &reply)
678 {
679     std::vector<AbilityMissionInfo> missionInfos;
680     auto result = GetFloatingMissions(missionInfos);
681     reply.WriteInt32(missionInfos.size());
682     for (auto &it : missionInfos) {
683         if (!reply.WriteParcelable(&it)) {
684             return ERR_INVALID_VALUE;
685         }
686     }
687     if (!reply.WriteInt32(result)) {
688         return ERR_INVALID_VALUE;
689     }
690     return NO_ERROR;
691 }
692 
CloseMultiWindowInner(MessageParcel & data,MessageParcel & reply)693 int AbilityManagerStub::CloseMultiWindowInner(MessageParcel &data, MessageParcel &reply)
694 {
695     auto missionId = data.ReadInt32();
696     auto result = CloseMultiWindow(missionId);
697     reply.WriteInt32(result);
698     return NO_ERROR;
699 }
700 
SetMissionStackSettingInner(MessageParcel & data,MessageParcel & reply)701 int AbilityManagerStub::SetMissionStackSettingInner(MessageParcel &data, MessageParcel &reply)
702 {
703     StackSetting *stackSetting = data.ReadParcelable<StackSetting>();
704     if (stackSetting == nullptr) {
705         HILOG_ERROR("stackSetting is nullptr");
706         return ERR_INVALID_VALUE;
707     }
708     auto result = SetMissionStackSetting(*stackSetting);
709     reply.WriteInt32(result);
710     delete stackSetting;
711     return NO_ERROR;
712 }
713 
IsFirstInMissionInner(MessageParcel & data,MessageParcel & reply)714 int AbilityManagerStub::IsFirstInMissionInner(MessageParcel &data, MessageParcel &reply)
715 {
716     auto token = data.ReadRemoteObject();
717     auto result = IsFirstInMission(token);
718     if (!reply.WriteBool(result)) {
719         HILOG_ERROR("reply write failed.");
720         return ERR_INVALID_VALUE;
721     }
722     return NO_ERROR;
723 }
724 
PowerOffInner(MessageParcel & data,MessageParcel & reply)725 int AbilityManagerStub::PowerOffInner(MessageParcel &data, MessageParcel &reply)
726 {
727     auto result = PowerOff();
728     reply.WriteInt32(result);
729     return NO_ERROR;
730 }
731 
PowerOnInner(MessageParcel & data,MessageParcel & reply)732 int AbilityManagerStub::PowerOnInner(MessageParcel &data, MessageParcel &reply)
733 {
734     auto result = PowerOn();
735     reply.WriteInt32(result);
736     return NO_ERROR;
737 }
738 
LockMissionInner(MessageParcel & data,MessageParcel & reply)739 int AbilityManagerStub::LockMissionInner(MessageParcel &data, MessageParcel &reply)
740 {
741     int32_t id = data.ReadInt32();
742     int result = LockMission(id);
743     if (!reply.WriteInt32(result)) {
744         HILOG_ERROR("AbilityManagerStub: lock mission failed.");
745         return ERR_INVALID_VALUE;
746     }
747     return NO_ERROR;
748 }
749 
UnlockMissionInner(MessageParcel & data,MessageParcel & reply)750 int AbilityManagerStub::UnlockMissionInner(MessageParcel &data, MessageParcel &reply)
751 {
752     int32_t id = data.ReadInt32();
753     int result = UnlockMission(id);
754     if (!reply.WriteInt32(result)) {
755         HILOG_ERROR("AbilityManagerStub: lock mission failed.");
756         return ERR_INVALID_VALUE;
757     }
758     return NO_ERROR;
759 }
760 
SetMissionDescriptionInfoInner(MessageParcel & data,MessageParcel & reply)761 int AbilityManagerStub::SetMissionDescriptionInfoInner(MessageParcel &data, MessageParcel &reply)
762 {
763     auto token = data.ReadRemoteObject();
764     std::unique_ptr<MissionDescriptionInfo> missionInfo(data.ReadParcelable<MissionDescriptionInfo>());
765     int result = SetMissionDescriptionInfo(token, *missionInfo);
766     if (!reply.WriteInt32(result)) {
767         HILOG_ERROR("AbilityManagerStub: set mission info failed.");
768         return ERR_INVALID_VALUE;
769     }
770     return NO_ERROR;
771 }
772 
GetMissionLockModeStateInner(MessageParcel & data,MessageParcel & reply)773 int AbilityManagerStub::GetMissionLockModeStateInner(MessageParcel &data, MessageParcel &reply)
774 {
775     int result = GetMissionLockModeState();
776     if (!reply.WriteInt32(result)) {
777         HILOG_ERROR("AbilityManagerStub: get mission lock mode state failed.");
778         return ERR_INVALID_VALUE;
779     }
780     return NO_ERROR;
781 }
782 
UpdateConfigurationInner(MessageParcel & data,MessageParcel & reply)783 int AbilityManagerStub::UpdateConfigurationInner(MessageParcel &data, MessageParcel &reply)
784 {
785     std::unique_ptr<AppExecFwk::Configuration> config(data.ReadParcelable<AppExecFwk::Configuration>());
786     if (config == nullptr) {
787         HILOG_ERROR("AbilityManagerStub: config is nullptr");
788         return ERR_INVALID_VALUE;
789     }
790     int result = UpdateConfiguration(*config);
791     if (!reply.WriteInt32(result)) {
792         HILOG_ERROR("AbilityManagerStub: update configuration failed.");
793         return ERR_INVALID_VALUE;
794     }
795     return NO_ERROR;
796 }
797 
GetWantSenderInner(MessageParcel & data,MessageParcel & reply)798 int AbilityManagerStub::GetWantSenderInner(MessageParcel &data, MessageParcel &reply)
799 {
800     std::unique_ptr<WantSenderInfo> wantSenderInfo(data.ReadParcelable<WantSenderInfo>());
801     if (wantSenderInfo == nullptr) {
802         HILOG_ERROR("wantSenderInfo is nullptr");
803         return ERR_INVALID_VALUE;
804     }
805     sptr<IRemoteObject> callerToken = nullptr;
806     if (data.ReadBool()) {
807         callerToken = data.ReadRemoteObject();
808     }
809     sptr<IWantSender> wantSender = GetWantSender(*wantSenderInfo, callerToken);
810     if (!reply.WriteRemoteObject(((wantSender == nullptr) ? nullptr : wantSender->AsObject()))) {
811         HILOG_ERROR("failed to reply wantSender instance to client, for write parcel error");
812         return ERR_INVALID_VALUE;
813     }
814     return NO_ERROR;
815 }
816 
SendWantSenderInner(MessageParcel & data,MessageParcel & reply)817 int AbilityManagerStub::SendWantSenderInner(MessageParcel &data, MessageParcel &reply)
818 {
819     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
820     if (wantSender == nullptr) {
821         HILOG_ERROR("wantSender is nullptr");
822         return ERR_INVALID_VALUE;
823     }
824     std::unique_ptr<SenderInfo> senderInfo(data.ReadParcelable<SenderInfo>());
825     if (senderInfo == nullptr) {
826         HILOG_ERROR("senderInfo is nullptr");
827         return ERR_INVALID_VALUE;
828     }
829     int32_t result = SendWantSender(wantSender, *senderInfo);
830     reply.WriteInt32(result);
831     return NO_ERROR;
832 }
833 
CancelWantSenderInner(MessageParcel & data,MessageParcel & reply)834 int AbilityManagerStub::CancelWantSenderInner(MessageParcel &data, MessageParcel &reply)
835 {
836     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
837     if (wantSender == nullptr) {
838         HILOG_ERROR("wantSender is nullptr");
839         return ERR_INVALID_VALUE;
840     }
841     CancelWantSender(wantSender);
842     return NO_ERROR;
843 }
844 
GetPendingWantUidInner(MessageParcel & data,MessageParcel & reply)845 int AbilityManagerStub::GetPendingWantUidInner(MessageParcel &data, MessageParcel &reply)
846 {
847     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
848     if (wantSender == nullptr) {
849         HILOG_ERROR("wantSender is nullptr");
850         return ERR_INVALID_VALUE;
851     }
852 
853     int32_t uid = GetPendingWantUid(wantSender);
854     reply.WriteInt32(uid);
855     return NO_ERROR;
856 }
857 
GetPendingWantUserIdInner(MessageParcel & data,MessageParcel & reply)858 int AbilityManagerStub::GetPendingWantUserIdInner(MessageParcel &data, MessageParcel &reply)
859 {
860     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
861     if (wantSender == nullptr) {
862         HILOG_ERROR("wantSender is nullptr");
863         return ERR_INVALID_VALUE;
864     }
865 
866     int32_t userId = GetPendingWantUserId(wantSender);
867     reply.WriteInt32(userId);
868     return NO_ERROR;
869 }
870 
GetPendingWantBundleNameInner(MessageParcel & data,MessageParcel & reply)871 int AbilityManagerStub::GetPendingWantBundleNameInner(MessageParcel &data, MessageParcel &reply)
872 {
873     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
874     if (wantSender == nullptr) {
875         HILOG_ERROR("wantSender is nullptr");
876         return ERR_INVALID_VALUE;
877     }
878 
879     std::string bundleName = GetPendingWantBundleName(wantSender);
880     reply.WriteString16(Str8ToStr16(bundleName));
881     return NO_ERROR;
882 }
883 
GetPendingWantCodeInner(MessageParcel & data,MessageParcel & reply)884 int AbilityManagerStub::GetPendingWantCodeInner(MessageParcel &data, MessageParcel &reply)
885 {
886     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
887     if (wantSender == nullptr) {
888         HILOG_ERROR("wantSender is nullptr");
889         return ERR_INVALID_VALUE;
890     }
891 
892     int32_t code = GetPendingWantCode(wantSender);
893     reply.WriteInt32(code);
894     return NO_ERROR;
895 }
896 
GetPendingWantTypeInner(MessageParcel & data,MessageParcel & reply)897 int AbilityManagerStub::GetPendingWantTypeInner(MessageParcel &data, MessageParcel &reply)
898 {
899     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
900     if (wantSender == nullptr) {
901         HILOG_ERROR("wantSender is nullptr");
902         return ERR_INVALID_VALUE;
903     }
904 
905     int32_t type = GetPendingWantType(wantSender);
906     reply.WriteInt32(type);
907     return NO_ERROR;
908 }
909 
RegisterCancelListenerInner(MessageParcel & data,MessageParcel & reply)910 int AbilityManagerStub::RegisterCancelListenerInner(MessageParcel &data, MessageParcel &reply)
911 {
912     sptr<IWantSender> sender = iface_cast<IWantSender>(data.ReadRemoteObject());
913     if (sender == nullptr) {
914         HILOG_ERROR("sender is nullptr");
915         return ERR_INVALID_VALUE;
916     }
917     sptr<IWantReceiver> receiver = iface_cast<IWantReceiver>(data.ReadRemoteObject());
918     if (receiver == nullptr) {
919         HILOG_ERROR("receiver is nullptr");
920         return ERR_INVALID_VALUE;
921     }
922     RegisterCancelListener(sender, receiver);
923     return NO_ERROR;
924 }
925 
UnregisterCancelListenerInner(MessageParcel & data,MessageParcel & reply)926 int AbilityManagerStub::UnregisterCancelListenerInner(MessageParcel &data, MessageParcel &reply)
927 {
928     sptr<IWantSender> sender = iface_cast<IWantSender>(data.ReadRemoteObject());
929     if (sender == nullptr) {
930         HILOG_ERROR("sender is nullptr");
931         return ERR_INVALID_VALUE;
932     }
933     sptr<IWantReceiver> receiver = iface_cast<IWantReceiver>(data.ReadRemoteObject());
934     if (receiver == nullptr) {
935         HILOG_ERROR("receiver is nullptr");
936         return ERR_INVALID_VALUE;
937     }
938     UnregisterCancelListener(sender, receiver);
939     return NO_ERROR;
940 }
941 
GetPendingRequestWantInner(MessageParcel & data,MessageParcel & reply)942 int AbilityManagerStub::GetPendingRequestWantInner(MessageParcel &data, MessageParcel &reply)
943 {
944     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
945     if (wantSender == nullptr) {
946         HILOG_ERROR("wantSender is nullptr");
947         return ERR_INVALID_VALUE;
948     }
949 
950     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
951     int32_t result = GetPendingRequestWant(wantSender, want);
952     if (result != NO_ERROR) {
953         HILOG_ERROR("GetPendingRequestWant is failed");
954         return ERR_INVALID_VALUE;
955     }
956     reply.WriteParcelable(want.get());
957     return NO_ERROR;
958 }
959 
GetWantSenderInfoInner(MessageParcel & data,MessageParcel & reply)960 int AbilityManagerStub::GetWantSenderInfoInner(MessageParcel &data, MessageParcel &reply)
961 {
962     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
963     if (wantSender == nullptr) {
964         HILOG_ERROR("wantSender is nullptr");
965         return ERR_INVALID_VALUE;
966     }
967 
968     std::shared_ptr<WantSenderInfo> info(data.ReadParcelable<WantSenderInfo>());
969     int32_t result = GetWantSenderInfo(wantSender, info);
970     if (result != NO_ERROR) {
971         HILOG_ERROR("GetWantSenderInfo is failed");
972         return ERR_INVALID_VALUE;
973     }
974     reply.WriteParcelable(info.get());
975     return NO_ERROR;
976 }
977 
SetShowOnLockScreenInner(MessageParcel & data,MessageParcel & reply)978 int AbilityManagerStub::SetShowOnLockScreenInner(MessageParcel &data, MessageParcel &reply)
979 {
980     auto isAllow = data.ReadBool();
981     int result = SetShowOnLockScreen(isAllow);
982     if (!reply.WriteInt32(result)) {
983         HILOG_ERROR("SetShowOnLockScreen error");
984         return ERR_INVALID_VALUE;
985     }
986     return NO_ERROR;
987 }
988 
GetSystemMemoryAttrInner(MessageParcel & data,MessageParcel & reply)989 int AbilityManagerStub::GetSystemMemoryAttrInner(MessageParcel &data, MessageParcel &reply)
990 {
991     AppExecFwk::SystemMemoryAttr memoryInfo;
992     GetSystemMemoryAttr(memoryInfo);
993     reply.WriteParcelable(&memoryInfo);
994     return NO_ERROR;
995 }
996 
GetAppMemorySizeInner(MessageParcel & data,MessageParcel & reply)997 int AbilityManagerStub::GetAppMemorySizeInner(MessageParcel &data, MessageParcel &reply)
998 {
999     int32_t result = GetAppMemorySize();
1000     HILOG_INFO("GetAppMemorySizeInner result %{public}d", result);
1001     if (!reply.WriteInt32(result)) {
1002         HILOG_ERROR("GetAppMemorySize error");
1003         return ERR_INVALID_VALUE;
1004     }
1005     return NO_ERROR;
1006 }
1007 
IsRamConstrainedDeviceInner(MessageParcel & data,MessageParcel & reply)1008 int AbilityManagerStub::IsRamConstrainedDeviceInner(MessageParcel &data, MessageParcel &reply)
1009 {
1010     auto result = IsRamConstrainedDevice();
1011     if (!reply.WriteBool(result)) {
1012         HILOG_ERROR("reply write failed.");
1013         return ERR_INVALID_VALUE;
1014     }
1015     return NO_ERROR;
1016 }
1017 
ContinueMissionInner(MessageParcel & data,MessageParcel & reply)1018 int AbilityManagerStub::ContinueMissionInner(MessageParcel &data, MessageParcel &reply)
1019 {
1020     std::string srcDeviceId = data.ReadString();
1021     std::string dstDeviceId = data.ReadString();
1022     int32_t missionId = data.ReadInt32();
1023     sptr<IRemoteObject> callback = data.ReadRemoteObject();
1024     if (callback == nullptr) {
1025         HILOG_ERROR("ContinueMissionInner callback readParcelable failed!");
1026         return ERR_NULL_OBJECT;
1027     }
1028     std::unique_ptr<WantParams> wantParams(data.ReadParcelable<WantParams>());
1029     if (wantParams == nullptr) {
1030         HILOG_ERROR("ContinueMissionInner wantParams readParcelable failed!");
1031         return ERR_NULL_OBJECT;
1032     }
1033     int32_t result = ContinueMission(srcDeviceId, dstDeviceId, missionId, callback, *wantParams);
1034     HILOG_INFO("ContinueMissionInner result = %{public}d", result);
1035     return result;
1036 }
1037 
ContinueAbilityInner(MessageParcel & data,MessageParcel & reply)1038 int AbilityManagerStub::ContinueAbilityInner(MessageParcel &data, MessageParcel &reply)
1039 {
1040     std::string deviceId = data.ReadString();
1041     int32_t missionId = data.ReadInt32();
1042     int32_t result = ContinueAbility(deviceId, missionId);
1043     HILOG_INFO("ContinueAbilityInner result = %{public}d", result);
1044     return result;
1045 }
1046 
StartContinuationInner(MessageParcel & data,MessageParcel & reply)1047 int AbilityManagerStub::StartContinuationInner(MessageParcel &data, MessageParcel &reply)
1048 {
1049     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1050     if (want == nullptr) {
1051         HILOG_ERROR("StartContinuationInner want readParcelable failed!");
1052         return ERR_NULL_OBJECT;
1053     }
1054 
1055     sptr<IRemoteObject> abilityToken = data.ReadRemoteObject();
1056     if (abilityToken == nullptr) {
1057         HILOG_ERROR("Get abilityToken failed!");
1058         return ERR_NULL_OBJECT;
1059     }
1060     int32_t status = data.ReadInt32();
1061     int32_t result = StartContinuation(*want, abilityToken, status);
1062     HILOG_INFO("StartContinuationInner result = %{public}d", result);
1063 
1064     return result;
1065 }
1066 
NotifyCompleteContinuationInner(MessageParcel & data,MessageParcel & reply)1067 int AbilityManagerStub::NotifyCompleteContinuationInner(MessageParcel &data, MessageParcel &reply)
1068 {
1069     std::string devId = data.ReadString();
1070     int32_t sessionId = data.ReadInt32();
1071     bool isSuccess = data.ReadBool();
1072 
1073     NotifyCompleteContinuation(devId, sessionId, isSuccess);
1074     HILOG_INFO("NotifyCompleteContinuationInner end");
1075     return NO_ERROR;
1076 }
1077 
NotifyContinuationResultInner(MessageParcel & data,MessageParcel & reply)1078 int AbilityManagerStub::NotifyContinuationResultInner(MessageParcel &data, MessageParcel &reply)
1079 {
1080     int32_t missionId = data.ReadInt32();
1081     int32_t continuationResult = data.ReadInt32();
1082 
1083     int32_t result = NotifyContinuationResult(missionId, continuationResult);
1084     HILOG_INFO("StartContinuationInner result = %{public}d", result);
1085     return result;
1086 }
1087 
LockMissionForCleanupInner(MessageParcel & data,MessageParcel & reply)1088 int AbilityManagerStub::LockMissionForCleanupInner(MessageParcel &data, MessageParcel &reply)
1089 {
1090     int32_t id = data.ReadInt32();
1091     int result = LockMissionForCleanup(id);
1092     if (!reply.WriteInt32(result)) {
1093         HILOG_ERROR("AbilityManagerStub: lock mission failed.");
1094         return ERR_INVALID_VALUE;
1095     }
1096     return NO_ERROR;
1097 }
1098 
UnlockMissionForCleanupInner(MessageParcel & data,MessageParcel & reply)1099 int AbilityManagerStub::UnlockMissionForCleanupInner(MessageParcel &data, MessageParcel &reply)
1100 {
1101     int32_t id = data.ReadInt32();
1102     int result = UnlockMissionForCleanup(id);
1103     if (!reply.WriteInt32(result)) {
1104         HILOG_ERROR("AbilityManagerStub: unlock mission failed.");
1105         return ERR_INVALID_VALUE;
1106     }
1107     return NO_ERROR;
1108 }
1109 
RegisterMissionListenerInner(MessageParcel & data,MessageParcel & reply)1110 int AbilityManagerStub::RegisterMissionListenerInner(MessageParcel &data, MessageParcel &reply)
1111 {
1112     sptr<IMissionListener> listener = iface_cast<IMissionListener>(data.ReadRemoteObject());
1113     if (listener == nullptr) {
1114         HILOG_ERROR("stub register mission listener, listener is nullptr.");
1115         return ERR_INVALID_VALUE;
1116     }
1117 
1118     int32_t result = RegisterMissionListener(listener);
1119     reply.WriteInt32(result);
1120     return NO_ERROR;
1121 }
1122 
UnRegisterMissionListenerInner(MessageParcel & data,MessageParcel & reply)1123 int AbilityManagerStub::UnRegisterMissionListenerInner(MessageParcel &data, MessageParcel &reply)
1124 {
1125     sptr<IMissionListener> listener = iface_cast<IMissionListener>(data.ReadRemoteObject());
1126     if (listener == nullptr) {
1127         HILOG_ERROR("stub unregister mission listener, listener is nullptr.");
1128         return ERR_INVALID_VALUE;
1129     }
1130 
1131     int32_t result = UnRegisterMissionListener(listener);
1132     reply.WriteInt32(result);
1133     return NO_ERROR;
1134 }
1135 
GetMissionInfosInner(MessageParcel & data,MessageParcel & reply)1136 int AbilityManagerStub::GetMissionInfosInner(MessageParcel &data, MessageParcel &reply)
1137 {
1138     std::string deviceId = Str16ToStr8(data.ReadString16());
1139     int numMax = data.ReadInt32();
1140     std::vector<MissionInfo> missionInfos;
1141     int32_t result = GetMissionInfos(deviceId, numMax, missionInfos);
1142     reply.WriteInt32(missionInfos.size());
1143     for (auto &it : missionInfos) {
1144         if (!reply.WriteParcelable(&it)) {
1145             return ERR_INVALID_VALUE;
1146         }
1147     }
1148     if (!reply.WriteInt32(result)) {
1149         return ERR_INVALID_VALUE;
1150     }
1151     return result;
1152 }
1153 
GetMissionInfoInner(MessageParcel & data,MessageParcel & reply)1154 int AbilityManagerStub::GetMissionInfoInner(MessageParcel &data, MessageParcel &reply)
1155 {
1156     MissionInfo info;
1157     std::string deviceId = Str16ToStr8(data.ReadString16());
1158     int32_t missionId = data.ReadInt32();
1159     int result = GetMissionInfo(deviceId, missionId, info);
1160     if (!reply.WriteParcelable(&info)) {
1161         HILOG_ERROR("GetMissionInfo error");
1162         return ERR_INVALID_VALUE;
1163     }
1164 
1165     if (!reply.WriteInt32(result)) {
1166         HILOG_ERROR("GetMissionInfo result error");
1167         return ERR_INVALID_VALUE;
1168     }
1169     return NO_ERROR;
1170 }
1171 
CleanMissionInner(MessageParcel & data,MessageParcel & reply)1172 int AbilityManagerStub::CleanMissionInner(MessageParcel &data, MessageParcel &reply)
1173 {
1174     int32_t missionId = data.ReadInt32();
1175     int result = CleanMission(missionId);
1176     if (!reply.WriteInt32(result)) {
1177         HILOG_ERROR("CleanMission failed.");
1178         return ERR_INVALID_VALUE;
1179     }
1180     return NO_ERROR;
1181 }
1182 
CleanAllMissionsInner(MessageParcel & data,MessageParcel & reply)1183 int AbilityManagerStub::CleanAllMissionsInner(MessageParcel &data, MessageParcel &reply)
1184 {
1185     int result = CleanAllMissions();
1186     if (!reply.WriteInt32(result)) {
1187         HILOG_ERROR("CleanAllMissions failed.");
1188         return ERR_INVALID_VALUE;
1189     }
1190     return NO_ERROR;
1191 }
1192 
MoveMissionToFrontInner(MessageParcel & data,MessageParcel & reply)1193 int AbilityManagerStub::MoveMissionToFrontInner(MessageParcel &data, MessageParcel &reply)
1194 {
1195     int32_t missionId = data.ReadInt32();
1196     int result = MoveMissionToFront(missionId);
1197     if (!reply.WriteInt32(result)) {
1198         HILOG_ERROR("MoveMissionToFront failed.");
1199         return ERR_INVALID_VALUE;
1200     }
1201     return NO_ERROR;
1202 }
1203 
GetMissionIdByTokenInner(MessageParcel & data,MessageParcel & reply)1204 int AbilityManagerStub::GetMissionIdByTokenInner(MessageParcel &data, MessageParcel &reply)
1205 {
1206     sptr<IRemoteObject> token = data.ReadRemoteObject();
1207     int32_t missionId = GetMissionIdByToken(token);
1208     if (!reply.WriteInt32(missionId)) {
1209         HILOG_ERROR("GetMissionIdByToken write missionId failed.");
1210         return ERR_INVALID_VALUE;
1211     }
1212     return NO_ERROR;
1213 }
1214 
MoveMissionToFrontByOptionsInner(MessageParcel & data,MessageParcel & reply)1215 int AbilityManagerStub::MoveMissionToFrontByOptionsInner(MessageParcel &data, MessageParcel &reply)
1216 {
1217     int32_t missionId = data.ReadInt32();
1218     std::unique_ptr<StartOptions> startOptions(data.ReadParcelable<StartOptions>());
1219     if (startOptions == nullptr) {
1220         HILOG_ERROR("startOptions is nullptr");
1221         return ERR_INVALID_VALUE;
1222     }
1223     int result = MoveMissionToFront(missionId, *startOptions);
1224     if (!reply.WriteInt32(result)) {
1225         HILOG_ERROR("MoveMissionToFront failed.");
1226         return ERR_INVALID_VALUE;
1227     }
1228     return NO_ERROR;
1229 }
1230 
StartAbilityByCallInner(MessageParcel & data,MessageParcel & reply)1231 int AbilityManagerStub::StartAbilityByCallInner(MessageParcel &data, MessageParcel &reply)
1232 {
1233 
1234     HILOG_DEBUG("AbilityManagerStub::StartAbilityByCallInner begin.");
1235     Want *want = data.ReadParcelable<Want>();
1236     if (want == nullptr) {
1237         HILOG_ERROR("want is nullptr");
1238         return ERR_INVALID_VALUE;
1239     }
1240 
1241     auto callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
1242     sptr<IRemoteObject> callerToken = nullptr;
1243     if (data.ReadBool()) {
1244         callerToken = data.ReadRemoteObject();
1245     }
1246     int32_t result = StartAbilityByCall(*want, callback, callerToken);
1247 
1248     HILOG_DEBUG("resolve call ability ret = %d", result);
1249 
1250     reply.WriteInt32(result);
1251     delete want;
1252 
1253     HILOG_DEBUG("AbilityManagerStub::StartAbilityByCallInner end.");
1254 
1255     return NO_ERROR;
1256 }
1257 
ReleaseInner(MessageParcel & data,MessageParcel & reply)1258 int AbilityManagerStub::ReleaseInner(MessageParcel &data, MessageParcel &reply)
1259 {
1260     auto callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
1261     if (callback == nullptr) {
1262         HILOG_ERROR("callback is nullptr");
1263         return ERR_INVALID_VALUE;
1264     }
1265 
1266     std::unique_ptr<AppExecFwk::ElementName> element(data.ReadParcelable<AppExecFwk::ElementName>());
1267     if (element == nullptr) {
1268         HILOG_ERROR("callback stub receive element is nullptr");
1269         return ERR_INVALID_VALUE;
1270     }
1271     int32_t result = ReleaseAbility(callback, *element);
1272 
1273     HILOG_DEBUG("release call ability ret = %d", result);
1274 
1275     reply.WriteInt32(result);
1276 
1277     return NO_ERROR;
1278 }
1279 
StartUserInner(MessageParcel & data,MessageParcel & reply)1280 int AbilityManagerStub::StartUserInner(MessageParcel &data, MessageParcel &reply)
1281 {
1282     int32_t userId = data.ReadInt32();
1283     int result = StartUser(userId);
1284     if (!reply.WriteInt32(result)) {
1285         HILOG_ERROR("StartUser failed.");
1286         return ERR_INVALID_VALUE;
1287     }
1288     return NO_ERROR;
1289 }
1290 
StopUserInner(MessageParcel & data,MessageParcel & reply)1291 int AbilityManagerStub::StopUserInner(MessageParcel &data, MessageParcel &reply)
1292 {
1293     int32_t userId = data.ReadInt32();
1294     sptr<IStopUserCallback> callback = nullptr;
1295     if (data.ReadBool()) {
1296         callback = iface_cast<IStopUserCallback>(data.ReadRemoteObject());
1297     }
1298     int result = StopUser(userId, callback);
1299     if (!reply.WriteInt32(result)) {
1300         HILOG_ERROR("StopUser failed.");
1301         return ERR_INVALID_VALUE;
1302     }
1303     return NO_ERROR;
1304 }
1305 
SetMissionLabelInner(MessageParcel & data,MessageParcel & reply)1306 int AbilityManagerStub::SetMissionLabelInner(MessageParcel &data, MessageParcel &reply)
1307 {
1308     sptr<IRemoteObject> token = data.ReadRemoteObject();
1309     if (!token) {
1310         HILOG_ERROR("SetMissionLabelInner read ability token failed.");
1311         return ERR_NULL_OBJECT;
1312     }
1313 
1314     std::string label = Str16ToStr8(data.ReadString16());
1315     int result = SetMissionLabel(token, label);
1316     if (!reply.WriteInt32(result)) {
1317         HILOG_ERROR("SetMissionLabel failed.");
1318         return ERR_INVALID_VALUE;
1319     }
1320     return NO_ERROR;
1321 }
1322 
SetMissionIconInner(MessageParcel & data,MessageParcel & reply)1323 int AbilityManagerStub::SetMissionIconInner(MessageParcel &data, MessageParcel &reply)
1324 {
1325 #ifdef SUPPORT_GRAPHICS
1326     sptr<IRemoteObject> token = data.ReadRemoteObject();
1327     if (!token) {
1328         HILOG_ERROR("SetMissionIconInner read ability token failed.");
1329         return ERR_NULL_OBJECT;
1330     }
1331 
1332     std::shared_ptr<Media::PixelMap> icon(data.ReadParcelable<Media::PixelMap>());
1333     if (!icon) {
1334         HILOG_ERROR("SetMissionIconInner read icon failed.");
1335         return ERR_NULL_OBJECT;
1336     }
1337 
1338     int result = SetMissionIcon(token, icon);
1339     if (!reply.WriteInt32(result)) {
1340         HILOG_ERROR("SetMissionIcon failed.");
1341         return ERR_INVALID_VALUE;
1342     }
1343     return NO_ERROR;
1344 #else
1345     HILOG_ERROR("do not support SetMissionIcon.");
1346     return ERR_INVALID_VALUE;
1347 #endif
1348 }
1349 
GetAbilityRunningInfosInner(MessageParcel & data,MessageParcel & reply)1350 int AbilityManagerStub::GetAbilityRunningInfosInner(MessageParcel &data, MessageParcel &reply)
1351 {
1352     std::vector<AbilityRunningInfo> abilityRunningInfos;
1353     auto result = GetAbilityRunningInfos(abilityRunningInfos);
1354     reply.WriteInt32(abilityRunningInfos.size());
1355     for (auto &it : abilityRunningInfos) {
1356         if (!reply.WriteParcelable(&it)) {
1357             return ERR_INVALID_VALUE;
1358         }
1359     }
1360     if (!reply.WriteInt32(result)) {
1361         return ERR_INVALID_VALUE;
1362     }
1363     return result;
1364 }
1365 
GetExtensionRunningInfosInner(MessageParcel & data,MessageParcel & reply)1366 int AbilityManagerStub::GetExtensionRunningInfosInner(MessageParcel &data, MessageParcel &reply)
1367 {
1368     auto upperLimit = data.ReadInt32();
1369     std::vector<ExtensionRunningInfo> infos;
1370     auto result = GetExtensionRunningInfos(upperLimit, infos);
1371     reply.WriteInt32(infos.size());
1372     for (auto &it : infos) {
1373         if (!reply.WriteParcelable(&it)) {
1374             return ERR_INVALID_VALUE;
1375         }
1376     }
1377     if (!reply.WriteInt32(result)) {
1378         return ERR_INVALID_VALUE;
1379     }
1380     return result;
1381 }
1382 
GetProcessRunningInfosInner(MessageParcel & data,MessageParcel & reply)1383 int AbilityManagerStub::GetProcessRunningInfosInner(MessageParcel &data, MessageParcel &reply)
1384 {
1385     std::vector<AppExecFwk::RunningProcessInfo> infos;
1386     auto result = GetProcessRunningInfos(infos);
1387     reply.WriteInt32(infos.size());
1388     for (auto &it : infos) {
1389         if (!reply.WriteParcelable(&it)) {
1390             return ERR_INVALID_VALUE;
1391         }
1392     }
1393     if (!reply.WriteInt32(result)) {
1394         return ERR_INVALID_VALUE;
1395     }
1396     return NO_ERROR;
1397 }
1398 
StartSyncRemoteMissionsInner(MessageParcel & data,MessageParcel & reply)1399 int AbilityManagerStub::StartSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply)
1400 {
1401     std::string deviceId = data.ReadString();
1402     bool fixConflict = data.ReadBool();
1403     int64_t tag = data.ReadInt64();
1404     int result = StartSyncRemoteMissions(deviceId, fixConflict, tag);
1405     if (!reply.WriteInt32(result)) {
1406         HILOG_ERROR("StartSyncRemoteMissionsInner failed.");
1407         return ERR_INVALID_VALUE;
1408     }
1409     return NO_ERROR;
1410 }
1411 
StopSyncRemoteMissionsInner(MessageParcel & data,MessageParcel & reply)1412 int AbilityManagerStub::StopSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply)
1413 {
1414     int result = StopSyncRemoteMissions(data.ReadString());
1415     if (!reply.WriteInt32(result)) {
1416         HILOG_ERROR("StopSyncRemoteMissionsInner failed.");
1417         return ERR_INVALID_VALUE;
1418     }
1419     return NO_ERROR;
1420 }
1421 
RegisterRemoteMissionListenerInner(MessageParcel & data,MessageParcel & reply)1422 int AbilityManagerStub::RegisterRemoteMissionListenerInner(MessageParcel &data, MessageParcel &reply)
1423 {
1424     std::string deviceId = data.ReadString();
1425     if (deviceId.empty()) {
1426         HILOG_ERROR("AbilityManagerStub: RegisterRemoteMissionListenerInner deviceId empty!");
1427         return ERR_NULL_OBJECT;
1428     }
1429     sptr<IRemoteMissionListener> listener = iface_cast<IRemoteMissionListener>(data.ReadRemoteObject());
1430     if (listener == nullptr) {
1431         HILOG_ERROR("AbilityManagerStub: RegisterRemoteMissionListenerInner listener readParcelable failed!");
1432         return ERR_NULL_OBJECT;
1433     }
1434     int32_t result = RegisterMissionListener(deviceId, listener);
1435     HILOG_INFO("AbilityManagerStub: RegisterRemoteMissionListenerInner result = %{public}d", result);
1436     return result;
1437 }
1438 
UnRegisterRemoteMissionListenerInner(MessageParcel & data,MessageParcel & reply)1439 int AbilityManagerStub::UnRegisterRemoteMissionListenerInner(MessageParcel &data, MessageParcel &reply)
1440 {
1441     std::string deviceId = data.ReadString();
1442     if (deviceId.empty()) {
1443         HILOG_ERROR("AbilityManagerStub: UnRegisterRemoteMissionListenerInner deviceId empty!");
1444         return ERR_NULL_OBJECT;
1445     }
1446     sptr<IRemoteMissionListener> listener = iface_cast<IRemoteMissionListener>(data.ReadRemoteObject());
1447     if (listener == nullptr) {
1448         HILOG_ERROR("AbilityManagerStub: UnRegisterRemoteMissionListenerInner listener readParcelable failed!");
1449         return ERR_NULL_OBJECT;
1450     }
1451     int32_t result = UnRegisterMissionListener(deviceId, listener);
1452     HILOG_INFO("AbilityManagerStub: UnRegisterRemoteMissionListenerInner result = %{public}d", result);
1453     return result;
1454 }
1455 
RegisterSnapshotHandlerInner(MessageParcel & data,MessageParcel & reply)1456 int AbilityManagerStub::RegisterSnapshotHandlerInner(MessageParcel &data, MessageParcel &reply)
1457 {
1458     sptr<ISnapshotHandler> handler = iface_cast<ISnapshotHandler>(data.ReadRemoteObject());
1459     if (handler == nullptr) {
1460         HILOG_ERROR("snapshot: AbilityManagerStub read snapshot handler failed!");
1461         return ERR_NULL_OBJECT;
1462     }
1463     int32_t result = RegisterSnapshotHandler(handler);
1464     HILOG_INFO("snapshot: AbilityManagerStub register snapshot handler result = %{public}d", result);
1465     return result;
1466 }
1467 
GetMissionSnapshotInfoInner(MessageParcel & data,MessageParcel & reply)1468 int AbilityManagerStub::GetMissionSnapshotInfoInner(MessageParcel &data, MessageParcel &reply)
1469 {
1470     std::string deviceId = data.ReadString();
1471     int32_t missionId = data.ReadInt32();
1472     MissionSnapshot missionSnapshot;
1473     int32_t result = GetMissionSnapshot(deviceId, missionId, missionSnapshot);
1474     HILOG_INFO("snapshot: AbilityManagerStub get snapshot result = %{public}d", result);
1475     if (!reply.WriteParcelable(&missionSnapshot)) {
1476         HILOG_ERROR("GetMissionSnapshot error");
1477         return ERR_INVALID_VALUE;
1478     }
1479     if (!reply.WriteInt32(result)) {
1480         HILOG_ERROR("GetMissionSnapshot result error");
1481         return ERR_INVALID_VALUE;
1482     }
1483     return NO_ERROR;
1484 }
1485 
SetAbilityControllerInner(MessageParcel & data,MessageParcel & reply)1486 int AbilityManagerStub::SetAbilityControllerInner(MessageParcel &data, MessageParcel &reply)
1487 {
1488     sptr<AppExecFwk::IAbilityController> controller =
1489         iface_cast<AppExecFwk::IAbilityController>(data.ReadRemoteObject());
1490     if (controller == nullptr) {
1491         HILOG_ERROR("AbilityManagerStub: setAbilityControllerInner controller readParcelable failed!");
1492         return ERR_NULL_OBJECT;
1493     }
1494     bool imAStabilityTest = data.ReadBool();
1495     int32_t result = SetAbilityController(controller, imAStabilityTest);
1496     HILOG_INFO("AbilityManagerStub: setAbilityControllerInner result = %{public}d", result);
1497     if (!reply.WriteInt32(result)) {
1498         HILOG_ERROR("setAbilityControllerInner failed.");
1499         return ERR_INVALID_VALUE;
1500     }
1501     return NO_ERROR;
1502 }
1503 
IsRunningInStabilityTestInner(MessageParcel & data,MessageParcel & reply)1504 int AbilityManagerStub::IsRunningInStabilityTestInner(MessageParcel &data, MessageParcel &reply)
1505 {
1506     bool result = IsRunningInStabilityTest();
1507     HILOG_INFO("AbilityManagerStub: IsRunningInStabilityTest result = %{public}d", result);
1508     if (!reply.WriteBool(result)) {
1509         HILOG_ERROR("IsRunningInStabilityTest failed.");
1510         return ERR_INVALID_VALUE;
1511     }
1512     return NO_ERROR;
1513 }
1514 
StartUserTestInner(MessageParcel & data,MessageParcel & reply)1515 int AbilityManagerStub::StartUserTestInner(MessageParcel &data, MessageParcel &reply)
1516 {
1517     Want *want = data.ReadParcelable<Want>();
1518     if (want == nullptr) {
1519         HILOG_ERROR("want is nullptr");
1520         return ERR_INVALID_VALUE;
1521     }
1522     auto observer = data.ReadRemoteObject();
1523     int32_t result = StartUserTest(*want, observer);
1524     reply.WriteInt32(result);
1525     delete want;
1526     return result;
1527 }
1528 
FinishUserTestInner(MessageParcel & data,MessageParcel & reply)1529 int AbilityManagerStub::FinishUserTestInner(MessageParcel &data, MessageParcel &reply)
1530 {
1531     std::string msg = data.ReadString();
1532     int resultCode = data.ReadInt32();
1533     std::string bundleName = data.ReadString();
1534     int32_t result = FinishUserTest(msg, resultCode, bundleName);
1535     reply.WriteInt32(result);
1536     return result;
1537 }
1538 
GetCurrentTopAbilityInner(MessageParcel & data,MessageParcel & reply)1539 int AbilityManagerStub::GetCurrentTopAbilityInner(MessageParcel &data, MessageParcel &reply)
1540 {
1541     sptr<IRemoteObject> token;
1542     auto result = GetCurrentTopAbility(token);
1543     if (!reply.WriteRemoteObject(token)) {
1544         HILOG_ERROR("data write failed.");
1545         return ERR_INVALID_VALUE;
1546     }
1547     reply.WriteInt32(result);
1548 
1549     return NO_ERROR;
1550 }
1551 
DelegatorDoAbilityForegroundInner(MessageParcel & data,MessageParcel & reply)1552 int AbilityManagerStub::DelegatorDoAbilityForegroundInner(MessageParcel &data, MessageParcel &reply)
1553 {
1554     sptr<IRemoteObject> token = data.ReadRemoteObject();
1555     auto result = DelegatorDoAbilityForeground(token);
1556     reply.WriteInt32(result);
1557 
1558     return NO_ERROR;
1559 }
1560 
DelegatorDoAbilityBackgroundInner(MessageParcel & data,MessageParcel & reply)1561 int AbilityManagerStub::DelegatorDoAbilityBackgroundInner(MessageParcel &data, MessageParcel &reply)
1562 {
1563     sptr<IRemoteObject> token = data.ReadRemoteObject();
1564     auto result = DelegatorDoAbilityBackground(token);
1565     reply.WriteInt32(result);
1566     return NO_ERROR;
1567 }
1568 
DoAbilityForeground(const sptr<IRemoteObject> & token,uint32_t flag)1569 int AbilityManagerStub::DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag)
1570 {
1571     return 0;
1572 }
1573 
DoAbilityBackground(const sptr<IRemoteObject> & token,uint32_t flag)1574 int AbilityManagerStub::DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag)
1575 {
1576     return 0;
1577 }
1578 
DoAbilityForegroundInner(MessageParcel & data,MessageParcel & reply)1579 int AbilityManagerStub::DoAbilityForegroundInner(MessageParcel &data, MessageParcel &reply)
1580 {
1581     sptr<IRemoteObject> token = data.ReadRemoteObject();
1582     uint32_t flag = data.ReadUint32();
1583     auto result = DoAbilityForeground(token, flag);
1584     reply.WriteInt32(result);
1585 
1586     return NO_ERROR;
1587 }
1588 
DoAbilityBackgroundInner(MessageParcel & data,MessageParcel & reply)1589 int AbilityManagerStub::DoAbilityBackgroundInner(MessageParcel &data, MessageParcel &reply)
1590 {
1591     sptr<IRemoteObject> token = data.ReadRemoteObject();
1592     uint32_t flag = data.ReadUint32();
1593     auto result = DoAbilityBackground(token, flag);
1594     reply.WriteInt32(result);
1595     return NO_ERROR;
1596 }
1597 
SendANRProcessIDInner(MessageParcel & data,MessageParcel & reply)1598 int AbilityManagerStub::SendANRProcessIDInner(MessageParcel &data, MessageParcel &reply)
1599 {
1600     int32_t pid = data.ReadInt32();
1601     int32_t result = SendANRProcessID(pid);
1602     if (!reply.WriteInt32(result)) {
1603         HILOG_ERROR("reply write failed.");
1604         return ERR_INVALID_VALUE;
1605     }
1606     return NO_ERROR;
1607 }
1608 
ForceTimeoutForTestInner(MessageParcel & data,MessageParcel & reply)1609 int AbilityManagerStub::ForceTimeoutForTestInner(MessageParcel &data, MessageParcel &reply)
1610 {
1611     std::string abilityName = Str16ToStr8(data.ReadString16());
1612     std::string state = Str16ToStr8(data.ReadString16());
1613     int result = ForceTimeoutForTest(abilityName, state);
1614     if (!reply.WriteInt32(result)) {
1615         HILOG_ERROR("force ability timeout error");
1616         return ERR_INVALID_VALUE;
1617     }
1618     return NO_ERROR;
1619 }
1620 
DumpAbilityInfoDoneInner(MessageParcel & data,MessageParcel & reply)1621 int AbilityManagerStub::DumpAbilityInfoDoneInner(MessageParcel &data, MessageParcel &reply)
1622 {
1623     std::vector<std::string> infos;
1624     data.ReadStringVector(&infos);
1625     sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1626     int32_t result = DumpAbilityInfoDone(infos, callerToken);
1627     if (!reply.WriteInt32(result)) {
1628         HILOG_ERROR("reply write failed.");
1629         return ERR_INVALID_VALUE;
1630     }
1631     return NO_ERROR;
1632 }
1633 }  // namespace AAFwk
1634 }  // namespace OHOS
1635