• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #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_collaborator_proxy.h"
24 #include "ability_manager_errors.h"
25 #include "ability_scheduler_proxy.h"
26 #include "ability_scheduler_stub.h"
27 #include "session_info.h"
28 
29 namespace OHOS {
30 namespace AAFwk {
31 namespace {
32 const std::u16string extensionDescriptor = u"ohos.aafwk.ExtensionManager";
33 }
AbilityManagerStub()34 AbilityManagerStub::AbilityManagerStub()
35 {
36     FirstStepInit();
37     SecondStepInit();
38     ThirdStepInit();
39 }
40 
~AbilityManagerStub()41 AbilityManagerStub::~AbilityManagerStub()
42 {
43     requestFuncMap_.clear();
44 }
45 
FirstStepInit()46 void AbilityManagerStub::FirstStepInit()
47 {
48     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::TERMINATE_ABILITY)] =
49         &AbilityManagerStub::TerminateAbilityInner;
50     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::MINIMIZE_ABILITY)] =
51         &AbilityManagerStub::MinimizeAbilityInner;
52     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::ATTACH_ABILITY_THREAD)] =
53         &AbilityManagerStub::AttachAbilityThreadInner;
54     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::ABILITY_TRANSITION_DONE)] =
55         &AbilityManagerStub::AbilityTransitionDoneInner;
56     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CONNECT_ABILITY_DONE)] =
57         &AbilityManagerStub::ScheduleConnectAbilityDoneInner;
58     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::DISCONNECT_ABILITY_DONE)] =
59         &AbilityManagerStub::ScheduleDisconnectAbilityDoneInner;
60     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::COMMAND_ABILITY_DONE)] =
61         &AbilityManagerStub::ScheduleCommandAbilityDoneInner;
62     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::COMMAND_ABILITY_WINDOW_DONE)] =
63         &AbilityManagerStub::ScheduleCommandAbilityWindowDoneInner;
64     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::ACQUIRE_DATA_ABILITY)] =
65         &AbilityManagerStub::AcquireDataAbilityInner;
66     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::RELEASE_DATA_ABILITY)] =
67         &AbilityManagerStub::ReleaseDataAbilityInner;
68     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::KILL_PROCESS)] =
69         &AbilityManagerStub::KillProcessInner;
70     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::UNINSTALL_APP)] =
71         &AbilityManagerStub::UninstallAppInner;
72     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_ABILITY)] =
73         &AbilityManagerStub::StartAbilityInner;
74     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_ABILITY_ADD_CALLER)] =
75         &AbilityManagerStub::StartAbilityAddCallerInner;
76     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_BY_TOKEN)] =
77         &AbilityManagerStub::StartAbilityAsCallerByTokenInner;
78     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_FOR_OPTIONS)] =
79         &AbilityManagerStub::StartAbilityAsCallerForOptionInner;
80     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_ADD_CALLER)] =
81         &AbilityManagerStub::StartAbilityByUIContentSessionAddCallerInner;
82     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_FOR_OPTIONS)] =
83         &AbilityManagerStub::StartAbilityByUIContentSessionForOptionsInner;
84     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CONNECT_ABILITY)] =
85         &AbilityManagerStub::ConnectAbilityInner;
86     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::DISCONNECT_ABILITY)] =
87         &AbilityManagerStub::DisconnectAbilityInner;
88     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::STOP_SERVICE_ABILITY)] =
89         &AbilityManagerStub::StopServiceAbilityInner;
90     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::DUMP_STATE)] =
91         &AbilityManagerStub::DumpStateInner;
92     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::DUMPSYS_STATE)] =
93         &AbilityManagerStub::DumpSysStateInner;
94     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_ABILITY_FOR_SETTINGS)] =
95         &AbilityManagerStub::StartAbilityForSettingsInner;
96     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CONTINUE_MISSION)] =
97         &AbilityManagerStub::ContinueMissionInner;
98     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME)] =
99         &AbilityManagerStub::ContinueMissionOfBundleNameInner;
100     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CONTINUE_ABILITY)] =
101         &AbilityManagerStub::ContinueAbilityInner;
102     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_CONTINUATION)] =
103         &AbilityManagerStub::StartContinuationInner;
104     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::NOTIFY_COMPLETE_CONTINUATION)] =
105         &AbilityManagerStub::NotifyCompleteContinuationInner;
106     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::NOTIFY_CONTINUATION_RESULT)] =
107         &AbilityManagerStub::NotifyContinuationResultInner;
108     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::SEND_RESULT_TO_ABILITY)] =
109         &AbilityManagerStub::SendResultToAbilityInner;
110     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::REGISTER_REMOTE_MISSION_LISTENER)] =
111         &AbilityManagerStub::RegisterRemoteMissionListenerInner;
112     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::REGISTER_REMOTE_ON_LISTENER)] =
113         &AbilityManagerStub::RegisterRemoteOnListenerInner;
114     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::REGISTER_REMOTE_OFF_LISTENER)] =
115         &AbilityManagerStub::RegisterRemoteOffListenerInner;
116     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::UNREGISTER_REMOTE_MISSION_LISTENER)] =
117         &AbilityManagerStub::UnRegisterRemoteMissionListenerInner;
118     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_ABILITY_FOR_OPTIONS)] =
119         &AbilityManagerStub::StartAbilityForOptionsInner;
120     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_SYNC_MISSIONS)] =
121         &AbilityManagerStub::StartSyncRemoteMissionsInner;
122     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::STOP_SYNC_MISSIONS)] =
123         &AbilityManagerStub::StopSyncRemoteMissionsInner;
124 #ifdef ABILITY_COMMAND_FOR_TEST
125     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::FORCE_TIMEOUT)] =
126         &AbilityManagerStub::ForceTimeoutForTestInner;
127 #endif
128     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::FREE_INSTALL_ABILITY_FROM_REMOTE)] =
129         &AbilityManagerStub::FreeInstallAbilityFromRemoteInner;
130     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::ADD_FREE_INSTALL_OBSERVER)] =
131         &AbilityManagerStub::AddFreeInstallObserverInner;
132     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CONNECT_ABILITY_WITH_TYPE)] =
133         &AbilityManagerStub::ConnectAbilityWithTypeInner;
134     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::ABILITY_RECOVERY)] =
135         &AbilityManagerStub::ScheduleRecoverAbilityInner;
136     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::ABILITY_RECOVERY_ENABLE)] =
137         &AbilityManagerStub::EnableRecoverAbilityInner;
138     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::MINIMIZE_UI_ABILITY_BY_SCB)] =
139         &AbilityManagerStub::MinimizeUIAbilityBySCBInner;
140     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CLOSE_UI_ABILITY_BY_SCB)] =
141         &AbilityManagerStub::CloseUIAbilityBySCBInner;
142     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::REGISTER_COLLABORATOR)] =
143         &AbilityManagerStub::RegisterIAbilityManagerCollaboratorInner;
144     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::UNREGISTER_COLLABORATOR)] =
145         &AbilityManagerStub::UnregisterIAbilityManagerCollaboratorInner;
146     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::MOVE_MISSION_TO_BACKGROUND)] =
147         &AbilityManagerStub::MoveMissionToBackgroundInner;
148     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::TERMINATE_MISSION)] =
149         &AbilityManagerStub::TerminateMissionInner;
150 }
151 
SecondStepInit()152 void AbilityManagerStub::SecondStepInit()
153 {
154     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER)] =
155         &AbilityManagerStub::GetWantSenderInner;
156     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::SEND_PENDING_WANT_SENDER)] =
157         &AbilityManagerStub::SendWantSenderInner;
158     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CANCEL_PENDING_WANT_SENDER)] =
159         &AbilityManagerStub::CancelWantSenderInner;
160     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PENDING_WANT_UID)] =
161         &AbilityManagerStub::GetPendingWantUidInner;
162     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PENDING_WANT_USERID)] =
163         &AbilityManagerStub::GetPendingWantUserIdInner;
164     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PENDING_WANT_BUNDLENAME)] =
165         &AbilityManagerStub::GetPendingWantBundleNameInner;
166     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PENDING_WANT_CODE)] =
167         &AbilityManagerStub::GetPendingWantCodeInner;
168     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PENDING_WANT_TYPE)] =
169         &AbilityManagerStub::GetPendingWantTypeInner;
170     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::REGISTER_CANCEL_LISTENER)] =
171         &AbilityManagerStub::RegisterCancelListenerInner;
172     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::UNREGISTER_CANCEL_LISTENER)] =
173         &AbilityManagerStub::UnregisterCancelListenerInner;
174     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PENDING_REQUEST_WANT)] =
175         &AbilityManagerStub::GetPendingRequestWantInner;
176     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER_INFO)] =
177         &AbilityManagerStub::GetWantSenderInfoInner;
178     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_APP_MEMORY_SIZE)] =
179         &AbilityManagerStub::GetAppMemorySizeInner;
180     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::IS_RAM_CONSTRAINED_DEVICE)] =
181         &AbilityManagerStub::IsRamConstrainedDeviceInner;
182     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CLEAR_UP_APPLICATION_DATA)] =
183         &AbilityManagerStub::ClearUpApplicationDataInner;
184     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::LOCK_MISSION_FOR_CLEANUP)] =
185         &AbilityManagerStub::LockMissionForCleanupInner;
186     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::UNLOCK_MISSION_FOR_CLEANUP)] =
187         &AbilityManagerStub::UnlockMissionForCleanupInner;
188     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::REGISTER_MISSION_LISTENER)] =
189         &AbilityManagerStub::RegisterMissionListenerInner;
190     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::UNREGISTER_MISSION_LISTENER)] =
191         &AbilityManagerStub::UnRegisterMissionListenerInner;
192     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_MISSION_INFOS)] =
193         &AbilityManagerStub::GetMissionInfosInner;
194     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_MISSION_INFO_BY_ID)] =
195         &AbilityManagerStub::GetMissionInfoInner;
196     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CLEAN_MISSION)] =
197         &AbilityManagerStub::CleanMissionInner;
198     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CLEAN_ALL_MISSIONS)] =
199         &AbilityManagerStub::CleanAllMissionsInner;
200     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT)] =
201         &AbilityManagerStub::MoveMissionToFrontInner;
202     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT_BY_OPTIONS)] =
203         &AbilityManagerStub::MoveMissionToFrontByOptionsInner;
204     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_FOREGROUND)] =
205         &AbilityManagerStub::MoveMissionsToForegroundInner;
206     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_BACKGROUND)] =
207         &AbilityManagerStub::MoveMissionsToBackgroundInner;
208     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_CALL_ABILITY)] =
209         &AbilityManagerStub::StartAbilityByCallInner;
210     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CALL_REQUEST_DONE)] =
211         &AbilityManagerStub::CallRequestDoneInner;
212     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::RELEASE_CALL_ABILITY)] =
213         &AbilityManagerStub::ReleaseCallInner;
214     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_USER)] =
215         &AbilityManagerStub::StartUserInner;
216     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::STOP_USER)] =
217         &AbilityManagerStub::StopUserInner;
218     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_ABILITY_RUNNING_INFO)] =
219         &AbilityManagerStub::GetAbilityRunningInfosInner;
220     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_EXTENSION_RUNNING_INFO)] =
221         &AbilityManagerStub::GetExtensionRunningInfosInner;
222     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_PROCESS_RUNNING_INFO)] =
223         &AbilityManagerStub::GetProcessRunningInfosInner;
224     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::SET_ABILITY_CONTROLLER)] =
225         &AbilityManagerStub::SetAbilityControllerInner;
226     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_MISSION_SNAPSHOT_INFO)] =
227         &AbilityManagerStub::GetMissionSnapshotInfoInner;
228     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::IS_USER_A_STABILITY_TEST)] =
229         &AbilityManagerStub::IsRunningInStabilityTestInner;
230     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::SEND_APP_NOT_RESPONSE_PROCESS_ID)] =
231         &AbilityManagerStub::SendANRProcessIDInner;
232     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::ACQUIRE_SHARE_DATA)] =
233         &AbilityManagerStub::AcquireShareDataInner;
234     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::SHARE_DATA_DONE)] =
235         &AbilityManagerStub::ShareDataDoneInner;
236     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_ABILITY_TOKEN)] =
237         &AbilityManagerStub::GetAbilityTokenByCalleeObjInner;
238     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::FORCE_EXIT_APP)] =
239         &AbilityManagerStub::ForceExitAppInner;
240     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::RECORD_APP_EXIT_REASON)] =
241         &AbilityManagerStub::RecordAppExitReasonInner;
242     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::REGISTER_SESSION_HANDLER)] =
243         &AbilityManagerStub::RegisterSessionHandlerInner;
244 #ifdef ABILITY_COMMAND_FOR_TEST
245     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::BLOCK_ABILITY)] =
246         &AbilityManagerStub::BlockAbilityInner;
247     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::BLOCK_AMS_SERVICE)] =
248         &AbilityManagerStub::BlockAmsServiceInner;
249     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::BLOCK_APP_SERVICE)] =
250         &AbilityManagerStub::BlockAppServiceInner;
251 #endif
252 }
253 
ThirdStepInit()254 void AbilityManagerStub::ThirdStepInit()
255 {
256     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_USER_TEST)] =
257         &AbilityManagerStub::StartUserTestInner;
258     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::FINISH_USER_TEST)] =
259         &AbilityManagerStub::FinishUserTestInner;
260     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_TOP_ABILITY_TOKEN)] =
261         &AbilityManagerStub::GetTopAbilityTokenInner;
262     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CHECK_UI_EXTENSION_IS_FOCUSED)] =
263         &AbilityManagerStub::CheckUIExtensionIsFocusedInner;
264     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_FOREGROUND)] =
265         &AbilityManagerStub::DelegatorDoAbilityForegroundInner;
266     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_BACKGROUND)] =
267         &AbilityManagerStub::DelegatorDoAbilityBackgroundInner;
268     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::DO_ABILITY_FOREGROUND)] =
269         &AbilityManagerStub::DoAbilityForegroundInner;
270     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::DO_ABILITY_BACKGROUND)] =
271         &AbilityManagerStub::DoAbilityBackgroundInner;
272     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_MISSION_ID_BY_ABILITY_TOKEN)] =
273         &AbilityManagerStub::GetMissionIdByTokenInner;
274     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_TOP_ABILITY)] =
275         &AbilityManagerStub::GetTopAbilityInner;
276     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_ELEMENT_NAME_BY_TOKEN)] =
277         &AbilityManagerStub::GetElementNameByTokenInner;
278     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::DUMP_ABILITY_INFO_DONE)] =
279         &AbilityManagerStub::DumpAbilityInfoDoneInner;
280     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_EXTENSION_ABILITY)] =
281         &AbilityManagerStub::StartExtensionAbilityInner;
282     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::STOP_EXTENSION_ABILITY)] =
283         &AbilityManagerStub::StopExtensionAbilityInner;
284     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::UPDATE_MISSION_SNAPSHOT_FROM_WMS)] =
285         &AbilityManagerStub::UpdateMissionSnapShotFromWMSInner;
286     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::REGISTER_CONNECTION_OBSERVER)] =
287         &AbilityManagerStub::RegisterConnectionObserverInner;
288     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::UNREGISTER_CONNECTION_OBSERVER)] =
289         &AbilityManagerStub::UnregisterConnectionObserverInner;
290     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::GET_DLP_CONNECTION_INFOS)] =
291         &AbilityManagerStub::GetDlpConnectionInfosInner;
292     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::MOVE_ABILITY_TO_BACKGROUND)] =
293         &AbilityManagerStub::MoveAbilityToBackgroundInner;
294     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::SET_MISSION_CONTINUE_STATE)] =
295         &AbilityManagerStub::SetMissionContinueStateInner;
296     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY_BY_SCB)] =
297         &AbilityManagerStub::PrepareTerminateAbilityBySCBInner;
298 #ifdef SUPPORT_GRAPHICS
299     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::SET_MISSION_LABEL)] =
300         &AbilityManagerStub::SetMissionLabelInner;
301     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::SET_MISSION_ICON)] =
302         &AbilityManagerStub::SetMissionIconInner;
303     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::REGISTER_WMS_HANDLER)] =
304         &AbilityManagerStub::RegisterWindowManagerServiceHandlerInner;
305     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::COMPLETEFIRSTFRAMEDRAWING)] =
306         &AbilityManagerStub::CompleteFirstFrameDrawingInner;
307     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY)] =
308         &AbilityManagerStub::StartUIExtensionAbilityInner;
309     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::MINIMIZE_UI_EXTENSION_ABILITY)] =
310         &AbilityManagerStub::MinimizeUIExtensionAbilityInner;
311     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::TERMINATE_UI_EXTENSION_ABILITY)] =
312         &AbilityManagerStub::TerminateUIExtensionAbilityInner;
313     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::CONNECT_UI_EXTENSION_ABILITY)] =
314         &AbilityManagerStub::ConnectUIExtensionAbilityInner;
315     requestFuncMap_[static_cast<uint32_t>(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY)] =
316         &AbilityManagerStub::PrepareTerminateAbilityInner;
317 #endif
318     requestFuncMap_[REQUEST_DIALOG_SERVICE] = &AbilityManagerStub::HandleRequestDialogService;
319     requestFuncMap_[REPORT_DRAWN_COMPLETED] = &AbilityManagerStub::HandleReportDrawnCompleted;
320     requestFuncMap_[SET_COMPONENT_INTERCEPTION] = &AbilityManagerStub::SetComponentInterceptionInner;
321     requestFuncMap_[SEND_ABILITY_RESULT_BY_TOKEN] = &AbilityManagerStub::SendResultToAbilityByTokenInner;
322     requestFuncMap_[QUERY_MISSION_VAILD] = &AbilityManagerStub::IsValidMissionIdsInner;
323     requestFuncMap_[VERIFY_PERMISSION] = &AbilityManagerStub::VerifyPermissionInner;
324     requestFuncMap_[START_UI_ABILITY_BY_SCB] = &AbilityManagerStub::StartUIAbilityBySCBInner;
325     requestFuncMap_[SET_ROOT_SCENE_SESSION] = &AbilityManagerStub::SetRootSceneSessionInner;
326     requestFuncMap_[CALL_ABILITY_BY_SCB] = &AbilityManagerStub::CallUIAbilityBySCBInner;
327     requestFuncMap_[START_SPECIFIED_ABILITY_BY_SCB] = &AbilityManagerStub::StartSpecifiedAbilityBySCBInner;
328     requestFuncMap_[NOTIFY_SAVE_AS_RESULT] = &AbilityManagerStub::NotifySaveAsResultInner;
329     requestFuncMap_[SET_SESSIONMANAGERSERVICE] = &AbilityManagerStub::SetSessionManagerServiceInner;
330 }
331 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)332 int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
333 {
334     std::u16string abilityDescriptor = AbilityManagerStub::GetDescriptor();
335     std::u16string remoteDescriptor = data.ReadInterfaceToken();
336     if (abilityDescriptor != remoteDescriptor && extensionDescriptor != remoteDescriptor) {
337         HILOG_ERROR("local descriptor is not equal to remote");
338         return ERR_INVALID_STATE;
339     }
340 
341     auto itFunc = requestFuncMap_.find(code);
342     if (itFunc != requestFuncMap_.end()) {
343         auto requestFunc = itFunc->second;
344         if (requestFunc != nullptr) {
345             return (this->*requestFunc)(data, reply);
346         }
347     }
348     HILOG_WARN("default case, need check.");
349     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
350 }
351 
GetTopAbilityInner(MessageParcel & data,MessageParcel & reply)352 int AbilityManagerStub::GetTopAbilityInner(MessageParcel &data, MessageParcel &reply)
353 {
354     AppExecFwk::ElementName result = GetTopAbility();
355     if (result.GetDeviceID().empty()) {
356         HILOG_DEBUG("GetTopAbilityInner is nullptr");
357     }
358     reply.WriteParcelable(&result);
359     return NO_ERROR;
360 }
361 
GetElementNameByTokenInner(MessageParcel & data,MessageParcel & reply)362 int AbilityManagerStub::GetElementNameByTokenInner(MessageParcel &data, MessageParcel &reply)
363 {
364     sptr<IRemoteObject> token = data.ReadRemoteObject();;
365     AppExecFwk::ElementName result = GetElementNameByToken(token);
366     if (result.GetDeviceID().empty()) {
367         HILOG_DEBUG("GetElementNameByTokenInner is nullptr");
368     }
369     reply.WriteParcelable(&result);
370     return NO_ERROR;
371 }
372 
MoveAbilityToBackgroundInner(MessageParcel & data,MessageParcel & reply)373 int AbilityManagerStub::MoveAbilityToBackgroundInner(MessageParcel &data, MessageParcel &reply)
374 {
375     sptr<IRemoteObject> token = nullptr;
376     if (data.ReadBool()) {
377         token = data.ReadRemoteObject();
378     }
379     int32_t result = MoveAbilityToBackground(token);
380     if (!reply.WriteInt32(result)) {
381         HILOG_ERROR("write result failed");
382         return ERR_INVALID_VALUE;
383     }
384     return NO_ERROR;
385 }
386 
TerminateAbilityInner(MessageParcel & data,MessageParcel & reply)387 int AbilityManagerStub::TerminateAbilityInner(MessageParcel &data, MessageParcel &reply)
388 {
389     sptr<IRemoteObject> token = nullptr;
390     if (data.ReadBool()) {
391         token = data.ReadRemoteObject();
392     }
393     int resultCode = data.ReadInt32();
394     Want *resultWant = data.ReadParcelable<Want>();
395     bool flag = data.ReadBool();
396     int32_t result;
397     if (flag) {
398         result = TerminateAbility(token, resultCode, resultWant);
399     } else {
400         result = CloseAbility(token, resultCode, resultWant);
401     }
402     reply.WriteInt32(result);
403     if (resultWant != nullptr) {
404         delete resultWant;
405     }
406     return NO_ERROR;
407 }
408 
TerminateUIExtensionAbilityInner(MessageParcel & data,MessageParcel & reply)409 int AbilityManagerStub::TerminateUIExtensionAbilityInner(MessageParcel &data, MessageParcel &reply)
410 {
411     sptr<SessionInfo> extensionSessionInfo = nullptr;
412     if (data.ReadBool()) {
413         extensionSessionInfo = data.ReadParcelable<SessionInfo>();
414     }
415     int resultCode = data.ReadInt32();
416     Want *resultWant = data.ReadParcelable<Want>();
417     int32_t result = TerminateUIExtensionAbility(extensionSessionInfo, resultCode, resultWant);
418     reply.WriteInt32(result);
419     if (resultWant != nullptr) {
420         delete resultWant;
421     }
422     return NO_ERROR;
423 }
424 
SendResultToAbilityInner(MessageParcel & data,MessageParcel & reply)425 int AbilityManagerStub::SendResultToAbilityInner(MessageParcel &data, MessageParcel &reply)
426 {
427     int requestCode = data.ReadInt32();
428     int resultCode = data.ReadInt32();
429     Want *resultWant = data.ReadParcelable<Want>();
430     if (resultWant == nullptr) {
431         HILOG_ERROR("resultWant is nullptr");
432         return ERR_INVALID_VALUE;
433     }
434     int32_t result = SendResultToAbility(requestCode, resultCode, *resultWant);
435     reply.WriteInt32(result);
436     if (resultWant != nullptr) {
437         delete resultWant;
438     }
439     return NO_ERROR;
440 }
441 
MinimizeAbilityInner(MessageParcel & data,MessageParcel & reply)442 int AbilityManagerStub::MinimizeAbilityInner(MessageParcel &data, MessageParcel &reply)
443 {
444     auto token = data.ReadRemoteObject();
445     auto fromUser = data.ReadBool();
446     int32_t result = MinimizeAbility(token, fromUser);
447     reply.WriteInt32(result);
448     return NO_ERROR;
449 }
450 
MinimizeUIExtensionAbilityInner(MessageParcel & data,MessageParcel & reply)451 int AbilityManagerStub::MinimizeUIExtensionAbilityInner(MessageParcel &data, MessageParcel &reply)
452 {
453     sptr<SessionInfo> extensionSessionInfo = nullptr;
454     if (data.ReadBool()) {
455         extensionSessionInfo = data.ReadParcelable<SessionInfo>();
456     }
457     auto fromUser = data.ReadBool();
458     int32_t result = MinimizeUIExtensionAbility(extensionSessionInfo, fromUser);
459     reply.WriteInt32(result);
460     return NO_ERROR;
461 }
462 
MinimizeUIAbilityBySCBInner(MessageParcel & data,MessageParcel & reply)463 int AbilityManagerStub::MinimizeUIAbilityBySCBInner(MessageParcel &data, MessageParcel &reply)
464 {
465     sptr<SessionInfo> sessionInfo = nullptr;
466     if (data.ReadBool()) {
467         sessionInfo = data.ReadParcelable<SessionInfo>();
468     }
469     bool fromUser = data.ReadBool();
470     int32_t result = MinimizeUIAbilityBySCB(sessionInfo, fromUser);
471     reply.WriteInt32(result);
472     return NO_ERROR;
473 }
474 
AttachAbilityThreadInner(MessageParcel & data,MessageParcel & reply)475 int AbilityManagerStub::AttachAbilityThreadInner(MessageParcel &data, MessageParcel &reply)
476 {
477     auto scheduler = iface_cast<IAbilityScheduler>(data.ReadRemoteObject());
478     auto token = data.ReadRemoteObject();
479     int32_t result = AttachAbilityThread(scheduler, token);
480     reply.WriteInt32(result);
481     return NO_ERROR;
482 }
483 
AbilityTransitionDoneInner(MessageParcel & data,MessageParcel & reply)484 int AbilityManagerStub::AbilityTransitionDoneInner(MessageParcel &data, MessageParcel &reply)
485 {
486     auto token = data.ReadRemoteObject();
487     int targetState = data.ReadInt32();
488     std::unique_ptr<PacMap> saveData(data.ReadParcelable<PacMap>());
489     if (!saveData) {
490         HILOG_INFO("save data is nullptr");
491         return ERR_INVALID_VALUE;
492     }
493     int32_t result = AbilityTransitionDone(token, targetState, *saveData);
494     reply.WriteInt32(result);
495     return NO_ERROR;
496 }
497 
ScheduleConnectAbilityDoneInner(MessageParcel & data,MessageParcel & reply)498 int AbilityManagerStub::ScheduleConnectAbilityDoneInner(MessageParcel &data, MessageParcel &reply)
499 {
500     sptr<IRemoteObject> token = nullptr;
501     sptr<IRemoteObject> remoteObject = nullptr;
502     if (data.ReadBool()) {
503         token = data.ReadRemoteObject();
504     }
505     if (data.ReadBool()) {
506         remoteObject = data.ReadRemoteObject();
507     }
508     int32_t result = ScheduleConnectAbilityDone(token, remoteObject);
509     reply.WriteInt32(result);
510     return NO_ERROR;
511 }
512 
ScheduleDisconnectAbilityDoneInner(MessageParcel & data,MessageParcel & reply)513 int AbilityManagerStub::ScheduleDisconnectAbilityDoneInner(MessageParcel &data, MessageParcel &reply)
514 {
515     auto token = data.ReadRemoteObject();
516     int32_t result = ScheduleDisconnectAbilityDone(token);
517     reply.WriteInt32(result);
518     return NO_ERROR;
519 }
520 
ScheduleCommandAbilityDoneInner(MessageParcel & data,MessageParcel & reply)521 int AbilityManagerStub::ScheduleCommandAbilityDoneInner(MessageParcel &data, MessageParcel &reply)
522 {
523     auto token = data.ReadRemoteObject();
524     int32_t result = ScheduleCommandAbilityDone(token);
525     reply.WriteInt32(result);
526     return NO_ERROR;
527 }
528 
ScheduleCommandAbilityWindowDoneInner(MessageParcel & data,MessageParcel & reply)529 int AbilityManagerStub::ScheduleCommandAbilityWindowDoneInner(MessageParcel &data, MessageParcel &reply)
530 {
531     sptr<IRemoteObject> token = data.ReadRemoteObject();
532     sptr<SessionInfo> sessionInfo = data.ReadParcelable<SessionInfo>();
533     int32_t winCmd = data.ReadInt32();
534     int32_t abilityCmd = data.ReadInt32();
535     int32_t result = ScheduleCommandAbilityWindowDone(token, sessionInfo,
536         static_cast<WindowCommand>(winCmd), static_cast<AbilityCommand>(abilityCmd));
537     reply.WriteInt32(result);
538     return NO_ERROR;
539 }
540 
AcquireDataAbilityInner(MessageParcel & data,MessageParcel & reply)541 int AbilityManagerStub::AcquireDataAbilityInner(MessageParcel &data, MessageParcel &reply)
542 {
543     std::unique_ptr<Uri> uri(new Uri(data.ReadString()));
544     bool tryBind = data.ReadBool();
545     sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
546     sptr<IAbilityScheduler> result = AcquireDataAbility(*uri, tryBind, callerToken);
547     HILOG_DEBUG("acquire data ability %{public}s", result ? "ok" : "failed");
548     if (result) {
549         reply.WriteRemoteObject(result->AsObject());
550     } else {
551         reply.WriteParcelable(nullptr);
552     }
553     return NO_ERROR;
554 }
555 
ReleaseDataAbilityInner(MessageParcel & data,MessageParcel & reply)556 int AbilityManagerStub::ReleaseDataAbilityInner(MessageParcel &data, MessageParcel &reply)
557 {
558     auto scheduler = iface_cast<IAbilityScheduler>(data.ReadRemoteObject());
559     auto callerToken = data.ReadRemoteObject();
560     int32_t result = ReleaseDataAbility(scheduler, callerToken);
561     HILOG_DEBUG("release data ability ret = %d", result);
562     reply.WriteInt32(result);
563     return NO_ERROR;
564 }
565 
KillProcessInner(MessageParcel & data,MessageParcel & reply)566 int AbilityManagerStub::KillProcessInner(MessageParcel &data, MessageParcel &reply)
567 {
568     std::string bundleName = Str16ToStr8(data.ReadString16());
569     int result = KillProcess(bundleName);
570     if (!reply.WriteInt32(result)) {
571         HILOG_ERROR("remove stack error");
572         return ERR_INVALID_VALUE;
573     }
574     return NO_ERROR;
575 }
576 
ClearUpApplicationDataInner(MessageParcel & data,MessageParcel & reply)577 int AbilityManagerStub::ClearUpApplicationDataInner(MessageParcel &data, MessageParcel &reply)
578 {
579     std::string bundleName = Str16ToStr8(data.ReadString16());
580     int result = ClearUpApplicationData(bundleName);
581     if (!reply.WriteInt32(result)) {
582         HILOG_ERROR("ClearUpApplicationData error");
583         return ERR_INVALID_VALUE;
584     }
585     return NO_ERROR;
586 }
587 
UninstallAppInner(MessageParcel & data,MessageParcel & reply)588 int AbilityManagerStub::UninstallAppInner(MessageParcel &data, MessageParcel &reply)
589 {
590     std::string bundleName = Str16ToStr8(data.ReadString16());
591     int32_t uid = data.ReadInt32();
592     int result = UninstallApp(bundleName, uid);
593     if (!reply.WriteInt32(result)) {
594         HILOG_ERROR("remove stack error");
595         return ERR_INVALID_VALUE;
596     }
597     return NO_ERROR;
598 }
599 
StartAbilityInner(MessageParcel & data,MessageParcel & reply)600 int AbilityManagerStub::StartAbilityInner(MessageParcel &data, MessageParcel &reply)
601 {
602     Want *want = data.ReadParcelable<Want>();
603     if (want == nullptr) {
604         HILOG_ERROR("want is nullptr");
605         return ERR_INVALID_VALUE;
606     }
607     int32_t userId = data.ReadInt32();
608     int requestCode = data.ReadInt32();
609     int32_t result = StartAbility(*want, userId, requestCode);
610     reply.WriteInt32(result);
611     delete want;
612     return NO_ERROR;
613 }
614 
StartAbilityByUIContentSessionAddCallerInner(MessageParcel & data,MessageParcel & reply)615 int AbilityManagerStub::StartAbilityByUIContentSessionAddCallerInner(MessageParcel &data, MessageParcel &reply)
616 {
617     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
618     if (want == nullptr) {
619         HILOG_ERROR("want is nullptr");
620         return ERR_INVALID_VALUE;
621     }
622 
623     sptr<IRemoteObject> callerToken = nullptr;
624     if (data.ReadBool()) {
625         callerToken = data.ReadRemoteObject();
626     }
627 
628     sptr<SessionInfo> sessionInfo = nullptr;
629     if (data.ReadBool()) {
630         sessionInfo = data.ReadParcelable<SessionInfo>();
631     }
632 
633     int32_t userId = data.ReadInt32();
634     int requestCode = data.ReadInt32();
635     int32_t result = StartAbilityByUIContentSession(*want, callerToken, sessionInfo, userId, requestCode);
636     reply.WriteInt32(result);
637     return NO_ERROR;
638 }
639 
StartAbilityByUIContentSessionForOptionsInner(MessageParcel & data,MessageParcel & reply)640 int AbilityManagerStub::StartAbilityByUIContentSessionForOptionsInner(MessageParcel &data, MessageParcel &reply)
641 {
642     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
643     if (want == nullptr) {
644         HILOG_ERROR("want is nullptr");
645         return ERR_INVALID_VALUE;
646     }
647     std::unique_ptr<StartOptions> startOptions(data.ReadParcelable<StartOptions>());
648     if (startOptions == nullptr) {
649         HILOG_ERROR("startOptions is nullptr");
650         return ERR_INVALID_VALUE;
651     }
652     sptr<IRemoteObject> callerToken = nullptr;
653     if (data.ReadBool()) {
654         callerToken = data.ReadRemoteObject();
655     }
656     sptr<SessionInfo> sessionInfo = nullptr;
657     if (data.ReadBool()) {
658         sessionInfo = data.ReadParcelable<SessionInfo>();
659     }
660     int32_t userId = data.ReadInt32();
661     int requestCode = data.ReadInt32();
662     int32_t result = StartAbilityByUIContentSession(*want, *startOptions,
663         callerToken, sessionInfo, userId, requestCode);
664     reply.WriteInt32(result);
665     return NO_ERROR;
666 }
667 
StartExtensionAbilityInner(MessageParcel & data,MessageParcel & reply)668 int AbilityManagerStub::StartExtensionAbilityInner(MessageParcel &data, MessageParcel &reply)
669 {
670     Want *want = data.ReadParcelable<Want>();
671     if (want == nullptr) {
672         HILOG_ERROR("want is nullptr");
673         return ERR_INVALID_VALUE;
674     }
675     sptr<IRemoteObject> callerToken = nullptr;
676     if (data.ReadBool()) {
677         callerToken = data.ReadRemoteObject();
678     }
679     int32_t userId = data.ReadInt32();
680     int32_t extensionType = data.ReadInt32();
681     int32_t result = StartExtensionAbility(*want, callerToken, userId,
682         static_cast<AppExecFwk::ExtensionAbilityType>(extensionType));
683     reply.WriteInt32(result);
684     delete want;
685     return NO_ERROR;
686 }
687 
StartUIExtensionAbilityInner(MessageParcel & data,MessageParcel & reply)688 int AbilityManagerStub::StartUIExtensionAbilityInner(MessageParcel &data, MessageParcel &reply)
689 {
690     sptr<SessionInfo> extensionSessionInfo = nullptr;
691     if (data.ReadBool()) {
692         extensionSessionInfo = data.ReadParcelable<SessionInfo>();
693     }
694 
695     int32_t userId = data.ReadInt32();
696 
697     int32_t result = StartUIExtensionAbility(extensionSessionInfo, userId);
698     reply.WriteInt32(result);
699     return NO_ERROR;
700 }
701 
StopExtensionAbilityInner(MessageParcel & data,MessageParcel & reply)702 int AbilityManagerStub::StopExtensionAbilityInner(MessageParcel& data, MessageParcel& reply)
703 {
704     Want* want = data.ReadParcelable<Want>();
705     if (want == nullptr) {
706         HILOG_ERROR("want is nullptr");
707         return ERR_INVALID_VALUE;
708     }
709     sptr<IRemoteObject> callerToken = nullptr;
710     if (data.ReadBool()) {
711         callerToken = data.ReadRemoteObject();
712     }
713     int32_t userId = data.ReadInt32();
714     int32_t extensionType = data.ReadInt32();
715     int32_t result =
716         StopExtensionAbility(*want, callerToken, userId, static_cast<AppExecFwk::ExtensionAbilityType>(extensionType));
717     reply.WriteInt32(result);
718     delete want;
719     return NO_ERROR;
720 }
721 
StartAbilityAddCallerInner(MessageParcel & data,MessageParcel & reply)722 int AbilityManagerStub::StartAbilityAddCallerInner(MessageParcel &data, MessageParcel &reply)
723 {
724     Want *want = data.ReadParcelable<Want>();
725     if (want == nullptr) {
726         HILOG_ERROR("want is nullptr");
727         return ERR_INVALID_VALUE;
728     }
729 
730     sptr<IRemoteObject> callerToken = nullptr;
731     if (data.ReadBool()) {
732         callerToken = data.ReadRemoteObject();
733     }
734 
735     int32_t userId = data.ReadInt32();
736     int requestCode = data.ReadInt32();
737     int32_t result = StartAbility(*want, callerToken, userId, requestCode);
738     reply.WriteInt32(result);
739     delete want;
740     return NO_ERROR;
741 }
742 
StartAbilityAsCallerByTokenInner(MessageParcel & data,MessageParcel & reply)743 int AbilityManagerStub::StartAbilityAsCallerByTokenInner(MessageParcel &data, MessageParcel &reply)
744 {
745     Want *want = data.ReadParcelable<Want>();
746     if (want == nullptr) {
747         HILOG_ERROR("want is nullptr");
748         return ERR_INVALID_VALUE;
749     }
750 
751     sptr<IRemoteObject> callerToken = nullptr;
752     if (data.ReadBool()) {
753         callerToken = data.ReadRemoteObject();
754     }
755 
756     int32_t userId = data.ReadInt32();
757     int requestCode = data.ReadInt32();
758     int32_t result = StartAbilityAsCaller(*want, callerToken, userId, requestCode);
759     reply.WriteInt32(result);
760     delete want;
761     return NO_ERROR;
762 }
763 
StartAbilityAsCallerForOptionInner(MessageParcel & data,MessageParcel & reply)764 int AbilityManagerStub::StartAbilityAsCallerForOptionInner(MessageParcel &data, MessageParcel &reply)
765 {
766     Want *want = data.ReadParcelable<Want>();
767     if (want == nullptr) {
768         HILOG_ERROR("want is nullptr");
769         return ERR_INVALID_VALUE;
770     }
771     StartOptions *startOptions = data.ReadParcelable<StartOptions>();
772     if (startOptions == nullptr) {
773         HILOG_ERROR("startOptions is nullptr");
774         delete want;
775         return ERR_INVALID_VALUE;
776     }
777     sptr<IRemoteObject> callerToken = nullptr;
778     if (data.ReadBool()) {
779         callerToken = data.ReadRemoteObject();
780     }
781     int32_t userId = data.ReadInt32();
782     int requestCode = data.ReadInt32();
783     int32_t result = StartAbilityAsCaller(*want, *startOptions, callerToken, userId, requestCode);
784     reply.WriteInt32(result);
785     delete want;
786     delete startOptions;
787     return NO_ERROR;
788 }
789 
ConnectAbilityInner(MessageParcel & data,MessageParcel & reply)790 int AbilityManagerStub::ConnectAbilityInner(MessageParcel &data, MessageParcel &reply)
791 {
792     Want *want = data.ReadParcelable<Want>();
793     if (want == nullptr) {
794         HILOG_ERROR("want is nullptr");
795         return ERR_INVALID_VALUE;
796     }
797     sptr<IAbilityConnection> callback = nullptr;
798     sptr<IRemoteObject> token = nullptr;
799     if (data.ReadBool()) {
800         callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
801     }
802     if (data.ReadBool()) {
803         token = data.ReadRemoteObject();
804     }
805     int32_t userId = data.ReadInt32();
806     int32_t result = ConnectAbilityCommon(*want, callback, token, AppExecFwk::ExtensionAbilityType::SERVICE, userId);
807     reply.WriteInt32(result);
808     if (want != nullptr) {
809         delete want;
810     }
811     return NO_ERROR;
812 }
813 
ConnectAbilityWithTypeInner(MessageParcel & data,MessageParcel & reply)814 int AbilityManagerStub::ConnectAbilityWithTypeInner(MessageParcel &data, MessageParcel &reply)
815 {
816     Want *want = data.ReadParcelable<Want>();
817     if (want == nullptr) {
818         HILOG_ERROR("%{public}s, want is nullptr", __func__);
819         return ERR_INVALID_VALUE;
820     }
821     sptr<IAbilityConnection> callback = nullptr;
822     sptr<IRemoteObject> token = nullptr;
823     if (data.ReadBool()) {
824         callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
825     }
826     if (data.ReadBool()) {
827         token = data.ReadRemoteObject();
828     }
829     int32_t userId = data.ReadInt32();
830     AppExecFwk::ExtensionAbilityType extensionType = static_cast<AppExecFwk::ExtensionAbilityType>(data.ReadInt32());
831     int32_t result = ConnectAbilityCommon(*want, callback, token, extensionType, userId);
832     reply.WriteInt32(result);
833     if (want != nullptr) {
834         delete want;
835     }
836     return NO_ERROR;
837 }
838 
ConnectUIExtensionAbilityInner(MessageParcel & data,MessageParcel & reply)839 int AbilityManagerStub::ConnectUIExtensionAbilityInner(MessageParcel &data, MessageParcel &reply)
840 {
841     Want *want = data.ReadParcelable<Want>();
842     if (want == nullptr) {
843         HILOG_ERROR("%{public}s, want is nullptr", __func__);
844         return ERR_INVALID_VALUE;
845     }
846     sptr<IAbilityConnection> callback = nullptr;
847     if (data.ReadBool()) {
848         callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
849     }
850     sptr<SessionInfo> sessionInfo = nullptr;
851     if (data.ReadBool()) {
852         sessionInfo = data.ReadParcelable<SessionInfo>();
853     }
854     int32_t userId = data.ReadInt32();
855     int32_t result = ConnectUIExtensionAbility(*want, callback, sessionInfo, userId);
856     reply.WriteInt32(result);
857     if (want != nullptr) {
858         delete want;
859     }
860     return NO_ERROR;
861 }
862 
DisconnectAbilityInner(MessageParcel & data,MessageParcel & reply)863 int AbilityManagerStub::DisconnectAbilityInner(MessageParcel &data, MessageParcel &reply)
864 {
865     auto callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
866     int32_t result = DisconnectAbility(callback);
867     HILOG_DEBUG("disconnect ability ret = %d", result);
868     reply.WriteInt32(result);
869     return NO_ERROR;
870 }
871 
StopServiceAbilityInner(MessageParcel & data,MessageParcel & reply)872 int AbilityManagerStub::StopServiceAbilityInner(MessageParcel &data, MessageParcel &reply)
873 {
874     Want *want = data.ReadParcelable<Want>();
875     if (want == nullptr) {
876         HILOG_ERROR("want is nullptr");
877         return ERR_INVALID_VALUE;
878     }
879     int32_t userId = data.ReadInt32();
880     sptr<IRemoteObject> token = nullptr;
881     if (data.ReadBool()) {
882         token = data.ReadRemoteObject();
883     }
884     int32_t result = StopServiceAbility(*want, userId, token);
885     reply.WriteInt32(result);
886     delete want;
887     return NO_ERROR;
888 }
889 
DumpSysStateInner(MessageParcel & data,MessageParcel & reply)890 int AbilityManagerStub::DumpSysStateInner(MessageParcel &data, MessageParcel &reply)
891 {
892     std::vector<std::string> result;
893     std::string args = Str16ToStr8(data.ReadString16());
894     std::vector<std::string> argList;
895 
896     auto isClient = data.ReadBool();
897     auto isUserID = data.ReadBool();
898     auto UserID = data.ReadInt32();
899     SplitStr(args, " ", argList);
900     if (argList.empty()) {
901         return ERR_INVALID_VALUE;
902     }
903     DumpSysState(args, result, isClient, isUserID, UserID);
904     reply.WriteInt32(result.size());
905     for (auto stack : result) {
906         reply.WriteString16(Str8ToStr16(stack));
907     }
908     return NO_ERROR;
909 }
910 
DumpStateInner(MessageParcel & data,MessageParcel & reply)911 int AbilityManagerStub::DumpStateInner(MessageParcel &data, MessageParcel &reply)
912 {
913     std::vector<std::string> result;
914     std::string args = Str16ToStr8(data.ReadString16());
915     std::vector<std::string> argList;
916     SplitStr(args, " ", argList);
917     if (argList.empty()) {
918         return ERR_INVALID_VALUE;
919     }
920     DumpState(args, result);
921     reply.WriteInt32(result.size());
922     for (auto stack : result) {
923         reply.WriteString16(Str8ToStr16(stack));
924     }
925     return NO_ERROR;
926 }
927 
StartAbilityForSettingsInner(MessageParcel & data,MessageParcel & reply)928 int AbilityManagerStub::StartAbilityForSettingsInner(MessageParcel &data, MessageParcel &reply)
929 {
930     Want *want = data.ReadParcelable<Want>();
931     if (want == nullptr) {
932         HILOG_ERROR("want is nullptr");
933         return ERR_INVALID_VALUE;
934     }
935     AbilityStartSetting *abilityStartSetting = data.ReadParcelable<AbilityStartSetting>();
936     if (abilityStartSetting == nullptr) {
937         HILOG_ERROR("abilityStartSetting is nullptr");
938         delete want;
939         return ERR_INVALID_VALUE;
940     }
941     sptr<IRemoteObject> callerToken = nullptr;
942     if (data.ReadBool()) {
943         callerToken = data.ReadRemoteObject();
944     }
945     int32_t userId = data.ReadInt32();
946     int requestCode = data.ReadInt32();
947     int32_t result = StartAbility(*want, *abilityStartSetting, callerToken, userId, requestCode);
948     reply.WriteInt32(result);
949     delete want;
950     delete abilityStartSetting;
951     return NO_ERROR;
952 }
953 
StartAbilityForOptionsInner(MessageParcel & data,MessageParcel & reply)954 int AbilityManagerStub::StartAbilityForOptionsInner(MessageParcel &data, MessageParcel &reply)
955 {
956     Want *want = data.ReadParcelable<Want>();
957     if (want == nullptr) {
958         HILOG_ERROR("want is nullptr");
959         return ERR_INVALID_VALUE;
960     }
961     StartOptions *startOptions = data.ReadParcelable<StartOptions>();
962     if (startOptions == nullptr) {
963         HILOG_ERROR("startOptions is nullptr");
964         delete want;
965         return ERR_INVALID_VALUE;
966     }
967     sptr<IRemoteObject> callerToken = nullptr;
968     if (data.ReadBool()) {
969         callerToken = data.ReadRemoteObject();
970     }
971     int32_t userId = data.ReadInt32();
972     int requestCode = data.ReadInt32();
973     int32_t result = StartAbility(*want, *startOptions, callerToken, userId, requestCode);
974     reply.WriteInt32(result);
975     delete want;
976     delete startOptions;
977     return NO_ERROR;
978 }
979 
CloseUIAbilityBySCBInner(MessageParcel & data,MessageParcel & reply)980 int AbilityManagerStub::CloseUIAbilityBySCBInner(MessageParcel &data, MessageParcel &reply)
981 {
982     sptr<SessionInfo> sessionInfo = nullptr;
983     if (data.ReadBool()) {
984         sessionInfo = data.ReadParcelable<SessionInfo>();
985     }
986     int32_t result = CloseUIAbilityBySCB(sessionInfo);
987     reply.WriteInt32(result);
988     return NO_ERROR;
989 }
990 
GetWantSenderInner(MessageParcel & data,MessageParcel & reply)991 int AbilityManagerStub::GetWantSenderInner(MessageParcel &data, MessageParcel &reply)
992 {
993     std::unique_ptr<WantSenderInfo> wantSenderInfo(data.ReadParcelable<WantSenderInfo>());
994     if (wantSenderInfo == nullptr) {
995         HILOG_ERROR("wantSenderInfo is nullptr");
996         return ERR_INVALID_VALUE;
997     }
998     sptr<IRemoteObject> callerToken = nullptr;
999     if (data.ReadBool()) {
1000         callerToken = data.ReadRemoteObject();
1001     }
1002     sptr<IWantSender> wantSender = GetWantSender(*wantSenderInfo, callerToken);
1003     if (!reply.WriteRemoteObject(((wantSender == nullptr) ? nullptr : wantSender->AsObject()))) {
1004         HILOG_ERROR("failed to reply wantSender instance to client, for write parcel error");
1005         return ERR_INVALID_VALUE;
1006     }
1007     return NO_ERROR;
1008 }
1009 
SendWantSenderInner(MessageParcel & data,MessageParcel & reply)1010 int AbilityManagerStub::SendWantSenderInner(MessageParcel &data, MessageParcel &reply)
1011 {
1012     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
1013     if (wantSender == nullptr) {
1014         HILOG_ERROR("wantSender is nullptr");
1015         return ERR_INVALID_VALUE;
1016     }
1017     std::unique_ptr<SenderInfo> senderInfo(data.ReadParcelable<SenderInfo>());
1018     if (senderInfo == nullptr) {
1019         HILOG_ERROR("senderInfo is nullptr");
1020         return ERR_INVALID_VALUE;
1021     }
1022     int32_t result = SendWantSender(wantSender, *senderInfo);
1023     reply.WriteInt32(result);
1024     return NO_ERROR;
1025 }
1026 
CancelWantSenderInner(MessageParcel & data,MessageParcel & reply)1027 int AbilityManagerStub::CancelWantSenderInner(MessageParcel &data, MessageParcel &reply)
1028 {
1029     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
1030     if (wantSender == nullptr) {
1031         HILOG_ERROR("wantSender is nullptr");
1032         return ERR_INVALID_VALUE;
1033     }
1034     CancelWantSender(wantSender);
1035     return NO_ERROR;
1036 }
1037 
GetPendingWantUidInner(MessageParcel & data,MessageParcel & reply)1038 int AbilityManagerStub::GetPendingWantUidInner(MessageParcel &data, MessageParcel &reply)
1039 {
1040     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
1041     if (wantSender == nullptr) {
1042         HILOG_ERROR("wantSender is nullptr");
1043         return ERR_INVALID_VALUE;
1044     }
1045 
1046     int32_t uid = GetPendingWantUid(wantSender);
1047     reply.WriteInt32(uid);
1048     return NO_ERROR;
1049 }
1050 
GetPendingWantUserIdInner(MessageParcel & data,MessageParcel & reply)1051 int AbilityManagerStub::GetPendingWantUserIdInner(MessageParcel &data, MessageParcel &reply)
1052 {
1053     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
1054     if (wantSender == nullptr) {
1055         HILOG_ERROR("wantSender is nullptr");
1056         return ERR_INVALID_VALUE;
1057     }
1058 
1059     int32_t userId = GetPendingWantUserId(wantSender);
1060     reply.WriteInt32(userId);
1061     return NO_ERROR;
1062 }
1063 
GetPendingWantBundleNameInner(MessageParcel & data,MessageParcel & reply)1064 int AbilityManagerStub::GetPendingWantBundleNameInner(MessageParcel &data, MessageParcel &reply)
1065 {
1066     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
1067     if (wantSender == nullptr) {
1068         HILOG_ERROR("wantSender is nullptr");
1069         return ERR_INVALID_VALUE;
1070     }
1071 
1072     std::string bundleName = GetPendingWantBundleName(wantSender);
1073     reply.WriteString16(Str8ToStr16(bundleName));
1074     return NO_ERROR;
1075 }
1076 
GetPendingWantCodeInner(MessageParcel & data,MessageParcel & reply)1077 int AbilityManagerStub::GetPendingWantCodeInner(MessageParcel &data, MessageParcel &reply)
1078 {
1079     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
1080     if (wantSender == nullptr) {
1081         HILOG_ERROR("wantSender is nullptr");
1082         return ERR_INVALID_VALUE;
1083     }
1084 
1085     int32_t code = GetPendingWantCode(wantSender);
1086     reply.WriteInt32(code);
1087     return NO_ERROR;
1088 }
1089 
GetPendingWantTypeInner(MessageParcel & data,MessageParcel & reply)1090 int AbilityManagerStub::GetPendingWantTypeInner(MessageParcel &data, MessageParcel &reply)
1091 {
1092     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
1093     if (wantSender == nullptr) {
1094         HILOG_ERROR("wantSender is nullptr");
1095         return ERR_INVALID_VALUE;
1096     }
1097 
1098     int32_t type = GetPendingWantType(wantSender);
1099     reply.WriteInt32(type);
1100     return NO_ERROR;
1101 }
1102 
RegisterCancelListenerInner(MessageParcel & data,MessageParcel & reply)1103 int AbilityManagerStub::RegisterCancelListenerInner(MessageParcel &data, MessageParcel &reply)
1104 {
1105     sptr<IWantSender> sender = iface_cast<IWantSender>(data.ReadRemoteObject());
1106     if (sender == nullptr) {
1107         HILOG_ERROR("sender is nullptr");
1108         return ERR_INVALID_VALUE;
1109     }
1110     sptr<IWantReceiver> receiver = iface_cast<IWantReceiver>(data.ReadRemoteObject());
1111     if (receiver == nullptr) {
1112         HILOG_ERROR("receiver is nullptr");
1113         return ERR_INVALID_VALUE;
1114     }
1115     RegisterCancelListener(sender, receiver);
1116     return NO_ERROR;
1117 }
1118 
UnregisterCancelListenerInner(MessageParcel & data,MessageParcel & reply)1119 int AbilityManagerStub::UnregisterCancelListenerInner(MessageParcel &data, MessageParcel &reply)
1120 {
1121     sptr<IWantSender> sender = iface_cast<IWantSender>(data.ReadRemoteObject());
1122     if (sender == nullptr) {
1123         HILOG_ERROR("sender is nullptr");
1124         return ERR_INVALID_VALUE;
1125     }
1126     sptr<IWantReceiver> receiver = iface_cast<IWantReceiver>(data.ReadRemoteObject());
1127     if (receiver == nullptr) {
1128         HILOG_ERROR("receiver is nullptr");
1129         return ERR_INVALID_VALUE;
1130     }
1131     UnregisterCancelListener(sender, receiver);
1132     return NO_ERROR;
1133 }
1134 
GetPendingRequestWantInner(MessageParcel & data,MessageParcel & reply)1135 int AbilityManagerStub::GetPendingRequestWantInner(MessageParcel &data, MessageParcel &reply)
1136 {
1137     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
1138     if (wantSender == nullptr) {
1139         HILOG_ERROR("wantSender is nullptr");
1140         return ERR_INVALID_VALUE;
1141     }
1142 
1143     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
1144     int32_t result = GetPendingRequestWant(wantSender, want);
1145     if (result != NO_ERROR) {
1146         HILOG_ERROR("GetPendingRequestWant is failed");
1147         return ERR_INVALID_VALUE;
1148     }
1149     reply.WriteParcelable(want.get());
1150     return NO_ERROR;
1151 }
1152 
GetWantSenderInfoInner(MessageParcel & data,MessageParcel & reply)1153 int AbilityManagerStub::GetWantSenderInfoInner(MessageParcel &data, MessageParcel &reply)
1154 {
1155     sptr<IWantSender> wantSender = iface_cast<IWantSender>(data.ReadRemoteObject());
1156     if (wantSender == nullptr) {
1157         HILOG_ERROR("wantSender is nullptr");
1158         return ERR_INVALID_VALUE;
1159     }
1160 
1161     std::shared_ptr<WantSenderInfo> info(data.ReadParcelable<WantSenderInfo>());
1162     int32_t result = GetWantSenderInfo(wantSender, info);
1163     if (result != NO_ERROR) {
1164         HILOG_ERROR("GetWantSenderInfo is failed");
1165         return ERR_INVALID_VALUE;
1166     }
1167     reply.WriteParcelable(info.get());
1168     return NO_ERROR;
1169 }
1170 
GetAppMemorySizeInner(MessageParcel & data,MessageParcel & reply)1171 int AbilityManagerStub::GetAppMemorySizeInner(MessageParcel &data, MessageParcel &reply)
1172 {
1173     int32_t result = GetAppMemorySize();
1174     HILOG_INFO("GetAppMemorySizeInner result %{public}d", result);
1175     if (!reply.WriteInt32(result)) {
1176         HILOG_ERROR("GetAppMemorySize error");
1177         return ERR_INVALID_VALUE;
1178     }
1179     return NO_ERROR;
1180 }
1181 
IsRamConstrainedDeviceInner(MessageParcel & data,MessageParcel & reply)1182 int AbilityManagerStub::IsRamConstrainedDeviceInner(MessageParcel &data, MessageParcel &reply)
1183 {
1184     auto result = IsRamConstrainedDevice();
1185     if (!reply.WriteBool(result)) {
1186         HILOG_ERROR("reply write failed.");
1187         return ERR_INVALID_VALUE;
1188     }
1189     return NO_ERROR;
1190 }
1191 
ContinueMissionInner(MessageParcel & data,MessageParcel & reply)1192 int AbilityManagerStub::ContinueMissionInner(MessageParcel &data, MessageParcel &reply)
1193 {
1194     HILOG_INFO("amsStub %{public}s called.", __func__);
1195     std::string srcDeviceId = data.ReadString();
1196     std::string dstDeviceId = data.ReadString();
1197     int32_t missionId = data.ReadInt32();
1198     sptr<IRemoteObject> callback = data.ReadRemoteObject();
1199     if (callback == nullptr) {
1200         HILOG_ERROR("ContinueMissionInner callback readParcelable failed!");
1201         return ERR_NULL_OBJECT;
1202     }
1203     std::unique_ptr<WantParams> wantParams(data.ReadParcelable<WantParams>());
1204     if (wantParams == nullptr) {
1205         HILOG_ERROR("ContinueMissionInner wantParams readParcelable failed!");
1206         return ERR_NULL_OBJECT;
1207     }
1208     int32_t result = ContinueMission(srcDeviceId, dstDeviceId, missionId, callback, *wantParams);
1209     HILOG_INFO("ContinueMissionInner result = %{public}d", result);
1210     return result;
1211 }
1212 
ContinueMissionOfBundleNameInner(MessageParcel & data,MessageParcel & reply)1213 int AbilityManagerStub::ContinueMissionOfBundleNameInner(MessageParcel &data, MessageParcel &reply)
1214 {
1215     HILOG_INFO("amsStub %{public}s called.", __func__);
1216     std::string srcDeviceId = data.ReadString();
1217     std::string dstDeviceId = data.ReadString();
1218     std::string bundleName = data.ReadString();
1219     sptr<IRemoteObject> callback = data.ReadRemoteObject();
1220     if (callback == nullptr) {
1221         HILOG_ERROR("ContinueMissionInner callback readParcelable failed!");
1222         return ERR_NULL_OBJECT;
1223     }
1224     std::unique_ptr<WantParams> wantParams(data.ReadParcelable<WantParams>());
1225     if (wantParams == nullptr) {
1226         HILOG_ERROR("ContinueMissionInner wantParams readParcelable failed!");
1227         return ERR_NULL_OBJECT;
1228     }
1229     int32_t result = ContinueMission(srcDeviceId, dstDeviceId, bundleName, callback, *wantParams);
1230     HILOG_INFO("ContinueMissionInner result = %{public}d", result);
1231     return result;
1232 }
1233 
ContinueAbilityInner(MessageParcel & data,MessageParcel & reply)1234 int AbilityManagerStub::ContinueAbilityInner(MessageParcel &data, MessageParcel &reply)
1235 {
1236     std::string deviceId = data.ReadString();
1237     int32_t missionId = data.ReadInt32();
1238     uint32_t versionCode = data.ReadUint32();
1239     int32_t result = ContinueAbility(deviceId, missionId, versionCode);
1240     HILOG_INFO("ContinueAbilityInner result = %{public}d", result);
1241     return result;
1242 }
1243 
StartContinuationInner(MessageParcel & data,MessageParcel & reply)1244 int AbilityManagerStub::StartContinuationInner(MessageParcel &data, MessageParcel &reply)
1245 {
1246     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1247     if (want == nullptr) {
1248         HILOG_ERROR("StartContinuationInner want readParcelable failed!");
1249         return ERR_NULL_OBJECT;
1250     }
1251 
1252     sptr<IRemoteObject> abilityToken = data.ReadRemoteObject();
1253     if (abilityToken == nullptr) {
1254         HILOG_ERROR("Get abilityToken failed!");
1255         return ERR_NULL_OBJECT;
1256     }
1257     int32_t status = data.ReadInt32();
1258     int32_t result = StartContinuation(*want, abilityToken, status);
1259     HILOG_INFO("StartContinuationInner result = %{public}d", result);
1260 
1261     return result;
1262 }
1263 
NotifyCompleteContinuationInner(MessageParcel & data,MessageParcel & reply)1264 int AbilityManagerStub::NotifyCompleteContinuationInner(MessageParcel &data, MessageParcel &reply)
1265 {
1266     std::string devId = data.ReadString();
1267     int32_t sessionId = data.ReadInt32();
1268     bool isSuccess = data.ReadBool();
1269 
1270     NotifyCompleteContinuation(devId, sessionId, isSuccess);
1271     HILOG_INFO("NotifyCompleteContinuationInner end");
1272     return NO_ERROR;
1273 }
1274 
NotifyContinuationResultInner(MessageParcel & data,MessageParcel & reply)1275 int AbilityManagerStub::NotifyContinuationResultInner(MessageParcel &data, MessageParcel &reply)
1276 {
1277     int32_t missionId = data.ReadInt32();
1278     int32_t continuationResult = data.ReadInt32();
1279 
1280     int32_t result = NotifyContinuationResult(missionId, continuationResult);
1281     HILOG_INFO("StartContinuationInner result = %{public}d", result);
1282     return result;
1283 }
1284 
LockMissionForCleanupInner(MessageParcel & data,MessageParcel & reply)1285 int AbilityManagerStub::LockMissionForCleanupInner(MessageParcel &data, MessageParcel &reply)
1286 {
1287     int32_t id = data.ReadInt32();
1288     int result = LockMissionForCleanup(id);
1289     if (!reply.WriteInt32(result)) {
1290         HILOG_ERROR("AbilityManagerStub: lock mission failed.");
1291         return ERR_INVALID_VALUE;
1292     }
1293     return NO_ERROR;
1294 }
1295 
UnlockMissionForCleanupInner(MessageParcel & data,MessageParcel & reply)1296 int AbilityManagerStub::UnlockMissionForCleanupInner(MessageParcel &data, MessageParcel &reply)
1297 {
1298     int32_t id = data.ReadInt32();
1299     int result = UnlockMissionForCleanup(id);
1300     if (!reply.WriteInt32(result)) {
1301         HILOG_ERROR("AbilityManagerStub: unlock mission failed.");
1302         return ERR_INVALID_VALUE;
1303     }
1304     return NO_ERROR;
1305 }
1306 
RegisterMissionListenerInner(MessageParcel & data,MessageParcel & reply)1307 int AbilityManagerStub::RegisterMissionListenerInner(MessageParcel &data, MessageParcel &reply)
1308 {
1309     sptr<IMissionListener> listener = iface_cast<IMissionListener>(data.ReadRemoteObject());
1310     if (listener == nullptr) {
1311         HILOG_ERROR("stub register mission listener, listener is nullptr.");
1312         return ERR_INVALID_VALUE;
1313     }
1314 
1315     int32_t result = RegisterMissionListener(listener);
1316     reply.WriteInt32(result);
1317     return NO_ERROR;
1318 }
1319 
UnRegisterMissionListenerInner(MessageParcel & data,MessageParcel & reply)1320 int AbilityManagerStub::UnRegisterMissionListenerInner(MessageParcel &data, MessageParcel &reply)
1321 {
1322     sptr<IMissionListener> listener = iface_cast<IMissionListener>(data.ReadRemoteObject());
1323     if (listener == nullptr) {
1324         HILOG_ERROR("stub unregister mission listener, listener is nullptr.");
1325         return ERR_INVALID_VALUE;
1326     }
1327 
1328     int32_t result = UnRegisterMissionListener(listener);
1329     reply.WriteInt32(result);
1330     return NO_ERROR;
1331 }
1332 
GetMissionInfosInner(MessageParcel & data,MessageParcel & reply)1333 int AbilityManagerStub::GetMissionInfosInner(MessageParcel &data, MessageParcel &reply)
1334 {
1335     std::string deviceId = Str16ToStr8(data.ReadString16());
1336     int numMax = data.ReadInt32();
1337     std::vector<MissionInfo> missionInfos;
1338     int32_t result = GetMissionInfos(deviceId, numMax, missionInfos);
1339     reply.WriteInt32(missionInfos.size());
1340     for (auto &it : missionInfos) {
1341         if (!reply.WriteParcelable(&it)) {
1342             return ERR_INVALID_VALUE;
1343         }
1344     }
1345     if (!reply.WriteInt32(result)) {
1346         return ERR_INVALID_VALUE;
1347     }
1348     return result;
1349 }
1350 
GetMissionInfoInner(MessageParcel & data,MessageParcel & reply)1351 int AbilityManagerStub::GetMissionInfoInner(MessageParcel &data, MessageParcel &reply)
1352 {
1353     MissionInfo info;
1354     std::string deviceId = Str16ToStr8(data.ReadString16());
1355     int32_t missionId = data.ReadInt32();
1356     int result = GetMissionInfo(deviceId, missionId, info);
1357     if (!reply.WriteParcelable(&info)) {
1358         HILOG_ERROR("GetMissionInfo error");
1359         return ERR_INVALID_VALUE;
1360     }
1361 
1362     if (!reply.WriteInt32(result)) {
1363         HILOG_ERROR("GetMissionInfo result error");
1364         return ERR_INVALID_VALUE;
1365     }
1366     return NO_ERROR;
1367 }
1368 
CleanMissionInner(MessageParcel & data,MessageParcel & reply)1369 int AbilityManagerStub::CleanMissionInner(MessageParcel &data, MessageParcel &reply)
1370 {
1371     int32_t missionId = data.ReadInt32();
1372     int result = CleanMission(missionId);
1373     if (!reply.WriteInt32(result)) {
1374         HILOG_ERROR("CleanMission failed.");
1375         return ERR_INVALID_VALUE;
1376     }
1377     return NO_ERROR;
1378 }
1379 
CleanAllMissionsInner(MessageParcel & data,MessageParcel & reply)1380 int AbilityManagerStub::CleanAllMissionsInner(MessageParcel &data, MessageParcel &reply)
1381 {
1382     int result = CleanAllMissions();
1383     if (!reply.WriteInt32(result)) {
1384         HILOG_ERROR("CleanAllMissions failed.");
1385         return ERR_INVALID_VALUE;
1386     }
1387     return NO_ERROR;
1388 }
1389 
MoveMissionToFrontInner(MessageParcel & data,MessageParcel & reply)1390 int AbilityManagerStub::MoveMissionToFrontInner(MessageParcel &data, MessageParcel &reply)
1391 {
1392     int32_t missionId = data.ReadInt32();
1393     int result = MoveMissionToFront(missionId);
1394     if (!reply.WriteInt32(result)) {
1395         HILOG_ERROR("MoveMissionToFront failed.");
1396         return ERR_INVALID_VALUE;
1397     }
1398     return NO_ERROR;
1399 }
1400 
GetMissionIdByTokenInner(MessageParcel & data,MessageParcel & reply)1401 int AbilityManagerStub::GetMissionIdByTokenInner(MessageParcel &data, MessageParcel &reply)
1402 {
1403     sptr<IRemoteObject> token = data.ReadRemoteObject();
1404     int32_t missionId = GetMissionIdByToken(token);
1405     if (!reply.WriteInt32(missionId)) {
1406         HILOG_ERROR("GetMissionIdByToken write missionId failed.");
1407         return ERR_INVALID_VALUE;
1408     }
1409     return NO_ERROR;
1410 }
1411 
MoveMissionToFrontByOptionsInner(MessageParcel & data,MessageParcel & reply)1412 int AbilityManagerStub::MoveMissionToFrontByOptionsInner(MessageParcel &data, MessageParcel &reply)
1413 {
1414     int32_t missionId = data.ReadInt32();
1415     std::unique_ptr<StartOptions> startOptions(data.ReadParcelable<StartOptions>());
1416     if (startOptions == nullptr) {
1417         HILOG_ERROR("startOptions is nullptr");
1418         return ERR_INVALID_VALUE;
1419     }
1420     int result = MoveMissionToFront(missionId, *startOptions);
1421     if (!reply.WriteInt32(result)) {
1422         HILOG_ERROR("MoveMissionToFront failed.");
1423         return ERR_INVALID_VALUE;
1424     }
1425     return NO_ERROR;
1426 }
1427 
MoveMissionsToForegroundInner(MessageParcel & data,MessageParcel & reply)1428 int AbilityManagerStub::MoveMissionsToForegroundInner(MessageParcel &data, MessageParcel &reply)
1429 {
1430     HILOG_DEBUG("%{public}s is called.", __func__);
1431     std::vector<int32_t> missionIds;
1432     data.ReadInt32Vector(&missionIds);
1433     int32_t topMissionId = data.ReadInt32();
1434     int32_t errCode = MoveMissionsToForeground(missionIds, topMissionId);
1435     if (!reply.WriteInt32(errCode)) {
1436         return ERR_INVALID_VALUE;
1437     }
1438     return errCode;
1439 }
1440 
MoveMissionsToBackgroundInner(MessageParcel & data,MessageParcel & reply)1441 int AbilityManagerStub::MoveMissionsToBackgroundInner(MessageParcel &data, MessageParcel &reply)
1442 {
1443     HILOG_DEBUG("%{public}s is called.", __func__);
1444     std::vector<int32_t> missionIds;
1445     std::vector<int32_t> result;
1446 
1447     data.ReadInt32Vector(&missionIds);
1448     int32_t errCode = MoveMissionsToBackground(missionIds, result);
1449     HILOG_DEBUG("%{public}s is called. resultSize: %{public}zu", __func__, result.size());
1450     if (!reply.WriteInt32Vector(result)) {
1451         HILOG_ERROR("%{public}s is called. WriteInt32Vector Failed", __func__);
1452         return ERR_INVALID_VALUE;
1453     }
1454     if (!reply.WriteInt32(errCode)) {
1455         return ERR_INVALID_VALUE;
1456     }
1457     return NO_ERROR;
1458 }
1459 
StartAbilityByCallInner(MessageParcel & data,MessageParcel & reply)1460 int AbilityManagerStub::StartAbilityByCallInner(MessageParcel &data, MessageParcel &reply)
1461 {
1462     HILOG_DEBUG("AbilityManagerStub::StartAbilityByCallInner begin.");
1463     Want *want = data.ReadParcelable<Want>();
1464     if (want == nullptr) {
1465         HILOG_ERROR("want is nullptr");
1466         return ERR_INVALID_VALUE;
1467     }
1468 
1469     auto callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
1470     sptr<IRemoteObject> callerToken = nullptr;
1471     if (data.ReadBool()) {
1472         callerToken = data.ReadRemoteObject();
1473     }
1474 
1475     int32_t accountId = data.ReadInt32();
1476     int32_t result = StartAbilityByCall(*want, callback, callerToken, accountId);
1477 
1478     HILOG_DEBUG("resolve call ability ret = %d", result);
1479 
1480     reply.WriteInt32(result);
1481     delete want;
1482 
1483     HILOG_DEBUG("AbilityManagerStub::StartAbilityByCallInner end.");
1484 
1485     return NO_ERROR;
1486 }
1487 
StartUIAbilityBySCBInner(MessageParcel & data,MessageParcel & reply)1488 int AbilityManagerStub::StartUIAbilityBySCBInner(MessageParcel &data, MessageParcel &reply)
1489 {
1490     sptr<SessionInfo> sessionInfo = nullptr;
1491     if (data.ReadBool()) {
1492         sessionInfo = data.ReadParcelable<SessionInfo>();
1493     }
1494     int32_t result = StartUIAbilityBySCB(sessionInfo);
1495     reply.WriteInt32(result);
1496     return NO_ERROR;
1497 }
1498 
CallRequestDoneInner(MessageParcel & data,MessageParcel & reply)1499 int AbilityManagerStub::CallRequestDoneInner(MessageParcel &data, MessageParcel &reply)
1500 {
1501     sptr<IRemoteObject> token = data.ReadRemoteObject();
1502     sptr<IRemoteObject> callStub = data.ReadRemoteObject();
1503     CallRequestDone(token, callStub);
1504     return NO_ERROR;
1505 }
1506 
ReleaseCallInner(MessageParcel & data,MessageParcel & reply)1507 int AbilityManagerStub::ReleaseCallInner(MessageParcel &data, MessageParcel &reply)
1508 {
1509     auto callback = iface_cast<IAbilityConnection>(data.ReadRemoteObject());
1510     if (callback == nullptr) {
1511         HILOG_ERROR("callback is nullptr");
1512         return ERR_INVALID_VALUE;
1513     }
1514 
1515     std::unique_ptr<AppExecFwk::ElementName> element(data.ReadParcelable<AppExecFwk::ElementName>());
1516     if (element == nullptr) {
1517         HILOG_ERROR("callback stub receive element is nullptr");
1518         return ERR_INVALID_VALUE;
1519     }
1520     int32_t result = ReleaseCall(callback, *element);
1521 
1522     HILOG_DEBUG("release call ability ret = %d", result);
1523 
1524     reply.WriteInt32(result);
1525 
1526     return NO_ERROR;
1527 }
1528 
StartUserInner(MessageParcel & data,MessageParcel & reply)1529 int AbilityManagerStub::StartUserInner(MessageParcel &data, MessageParcel &reply)
1530 {
1531     int32_t userId = data.ReadInt32();
1532     int result = StartUser(userId);
1533     if (!reply.WriteInt32(result)) {
1534         HILOG_ERROR("StartUser failed.");
1535         return ERR_INVALID_VALUE;
1536     }
1537     return NO_ERROR;
1538 }
1539 
StopUserInner(MessageParcel & data,MessageParcel & reply)1540 int AbilityManagerStub::StopUserInner(MessageParcel &data, MessageParcel &reply)
1541 {
1542     int32_t userId = data.ReadInt32();
1543     sptr<IStopUserCallback> callback = nullptr;
1544     if (data.ReadBool()) {
1545         callback = iface_cast<IStopUserCallback>(data.ReadRemoteObject());
1546     }
1547     int result = StopUser(userId, callback);
1548     if (!reply.WriteInt32(result)) {
1549         HILOG_ERROR("StopUser failed.");
1550         return ERR_INVALID_VALUE;
1551     }
1552     return NO_ERROR;
1553 }
1554 
GetAbilityRunningInfosInner(MessageParcel & data,MessageParcel & reply)1555 int AbilityManagerStub::GetAbilityRunningInfosInner(MessageParcel &data, MessageParcel &reply)
1556 {
1557     std::vector<AbilityRunningInfo> abilityRunningInfos;
1558     auto result = GetAbilityRunningInfos(abilityRunningInfos);
1559     reply.WriteInt32(abilityRunningInfos.size());
1560     for (auto &it : abilityRunningInfos) {
1561         if (!reply.WriteParcelable(&it)) {
1562             return ERR_INVALID_VALUE;
1563         }
1564     }
1565     if (!reply.WriteInt32(result)) {
1566         return ERR_INVALID_VALUE;
1567     }
1568     return result;
1569 }
1570 
GetExtensionRunningInfosInner(MessageParcel & data,MessageParcel & reply)1571 int AbilityManagerStub::GetExtensionRunningInfosInner(MessageParcel &data, MessageParcel &reply)
1572 {
1573     auto upperLimit = data.ReadInt32();
1574     std::vector<ExtensionRunningInfo> infos;
1575     auto result = GetExtensionRunningInfos(upperLimit, infos);
1576     reply.WriteInt32(infos.size());
1577     for (auto &it : infos) {
1578         if (!reply.WriteParcelable(&it)) {
1579             return ERR_INVALID_VALUE;
1580         }
1581     }
1582     if (!reply.WriteInt32(result)) {
1583         return ERR_INVALID_VALUE;
1584     }
1585     return result;
1586 }
1587 
GetProcessRunningInfosInner(MessageParcel & data,MessageParcel & reply)1588 int AbilityManagerStub::GetProcessRunningInfosInner(MessageParcel &data, MessageParcel &reply)
1589 {
1590     std::vector<AppExecFwk::RunningProcessInfo> infos;
1591     auto result = GetProcessRunningInfos(infos);
1592     reply.WriteInt32(infos.size());
1593     for (auto &it : infos) {
1594         if (!reply.WriteParcelable(&it)) {
1595             return ERR_INVALID_VALUE;
1596         }
1597     }
1598     if (!reply.WriteInt32(result)) {
1599         return ERR_INVALID_VALUE;
1600     }
1601     return NO_ERROR;
1602 }
1603 
StartSyncRemoteMissionsInner(MessageParcel & data,MessageParcel & reply)1604 int AbilityManagerStub::StartSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply)
1605 {
1606     std::string deviceId = data.ReadString();
1607     bool fixConflict = data.ReadBool();
1608     int64_t tag = data.ReadInt64();
1609     int result = StartSyncRemoteMissions(deviceId, fixConflict, tag);
1610     if (!reply.WriteInt32(result)) {
1611         HILOG_ERROR("StartSyncRemoteMissionsInner failed.");
1612         return ERR_INVALID_VALUE;
1613     }
1614     return NO_ERROR;
1615 }
1616 
StopSyncRemoteMissionsInner(MessageParcel & data,MessageParcel & reply)1617 int AbilityManagerStub::StopSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply)
1618 {
1619     int result = StopSyncRemoteMissions(data.ReadString());
1620     if (!reply.WriteInt32(result)) {
1621         HILOG_ERROR("StopSyncRemoteMissionsInner failed.");
1622         return ERR_INVALID_VALUE;
1623     }
1624     return NO_ERROR;
1625 }
1626 
RegisterRemoteMissionListenerInner(MessageParcel & data,MessageParcel & reply)1627 int AbilityManagerStub::RegisterRemoteMissionListenerInner(MessageParcel &data, MessageParcel &reply)
1628 {
1629     std::string deviceId = data.ReadString();
1630     if (deviceId.empty()) {
1631         HILOG_ERROR("AbilityManagerStub: RegisterRemoteMissionListenerInner deviceId empty!");
1632         return ERR_NULL_OBJECT;
1633     }
1634     sptr<IRemoteMissionListener> listener = iface_cast<IRemoteMissionListener>(data.ReadRemoteObject());
1635     if (listener == nullptr) {
1636         HILOG_ERROR("AbilityManagerStub: RegisterRemoteMissionListenerInner listener readParcelable failed!");
1637         return ERR_NULL_OBJECT;
1638     }
1639     int32_t result = RegisterMissionListener(deviceId, listener);
1640     HILOG_INFO("AbilityManagerStub: RegisterRemoteMissionListenerInner result = %{public}d", result);
1641     return result;
1642 }
1643 
RegisterRemoteOnListenerInner(MessageParcel & data,MessageParcel & reply)1644 int AbilityManagerStub::RegisterRemoteOnListenerInner(MessageParcel &data, MessageParcel &reply)
1645 {
1646     std::string type = data.ReadString();
1647     if (type.empty()) {
1648         HILOG_ERROR("AbilityManagerStub: RegisterRemoteOnListenerInner type empty!");
1649         return ERR_NULL_OBJECT;
1650     }
1651     sptr<IRemoteOnListener> listener = iface_cast<IRemoteOnListener>(data.ReadRemoteObject());
1652     if (listener == nullptr) {
1653         HILOG_ERROR("AbilityManagerStub: RegisterRemoteOnListenerInner listener readParcelable failed!");
1654         return ERR_NULL_OBJECT;
1655     }
1656     int32_t result = RegisterOnListener(type, listener);
1657     HILOG_INFO("AbilityManagerStub: RegisterRemoteOnListenerInner result = %{public}d", result);
1658     return result;
1659 }
1660 
RegisterRemoteOffListenerInner(MessageParcel & data,MessageParcel & reply)1661 int AbilityManagerStub::RegisterRemoteOffListenerInner(MessageParcel &data, MessageParcel &reply)
1662 {
1663     std::string type = data.ReadString();
1664     if (type.empty()) {
1665         HILOG_ERROR("AbilityManagerStub: RegisterRemoteOffListenerInner type empty!");
1666         return ERR_NULL_OBJECT;
1667     }
1668     sptr<IRemoteOnListener> listener = iface_cast<IRemoteOnListener>(data.ReadRemoteObject());
1669     if (listener == nullptr) {
1670         HILOG_ERROR("AbilityManagerStub: RegisterRemoteOffListenerInner listener readParcelable failed!");
1671         return ERR_NULL_OBJECT;
1672     }
1673     int32_t result = RegisterOffListener(type, listener);
1674     HILOG_INFO("AbilityManagerStub: RegisterRemoteOffListenerInner result = %{public}d", result);
1675     return result;
1676 }
1677 
UnRegisterRemoteMissionListenerInner(MessageParcel & data,MessageParcel & reply)1678 int AbilityManagerStub::UnRegisterRemoteMissionListenerInner(MessageParcel &data, MessageParcel &reply)
1679 {
1680     std::string deviceId = data.ReadString();
1681     if (deviceId.empty()) {
1682         HILOG_ERROR("AbilityManagerStub: UnRegisterRemoteMissionListenerInner deviceId empty!");
1683         return ERR_NULL_OBJECT;
1684     }
1685     sptr<IRemoteMissionListener> listener = iface_cast<IRemoteMissionListener>(data.ReadRemoteObject());
1686     if (listener == nullptr) {
1687         HILOG_ERROR("AbilityManagerStub: UnRegisterRemoteMissionListenerInner listener readParcelable failed!");
1688         return ERR_NULL_OBJECT;
1689     }
1690     int32_t result = UnRegisterMissionListener(deviceId, listener);
1691     HILOG_INFO("AbilityManagerStub: UnRegisterRemoteMissionListenerInner result = %{public}d", result);
1692     return result;
1693 }
1694 
RegisterSnapshotHandlerInner(MessageParcel & data,MessageParcel & reply)1695 int AbilityManagerStub::RegisterSnapshotHandlerInner(MessageParcel &data, MessageParcel &reply)
1696 {
1697     sptr<ISnapshotHandler> handler = iface_cast<ISnapshotHandler>(data.ReadRemoteObject());
1698     if (handler == nullptr) {
1699         HILOG_ERROR("snapshot: AbilityManagerStub read snapshot handler failed!");
1700         return ERR_NULL_OBJECT;
1701     }
1702     int32_t result = RegisterSnapshotHandler(handler);
1703     HILOG_INFO("snapshot: AbilityManagerStub register snapshot handler result = %{public}d", result);
1704     return result;
1705 }
1706 
GetMissionSnapshotInfoInner(MessageParcel & data,MessageParcel & reply)1707 int AbilityManagerStub::GetMissionSnapshotInfoInner(MessageParcel &data, MessageParcel &reply)
1708 {
1709     std::string deviceId = data.ReadString();
1710     int32_t missionId = data.ReadInt32();
1711     bool isLowResolution = data.ReadBool();
1712     MissionSnapshot missionSnapshot;
1713     int32_t result = GetMissionSnapshot(deviceId, missionId, missionSnapshot, isLowResolution);
1714     HILOG_INFO("snapshot: AbilityManagerStub get snapshot result = %{public}d", result);
1715     if (!reply.WriteParcelable(&missionSnapshot)) {
1716         HILOG_ERROR("GetMissionSnapshot error");
1717         return ERR_INVALID_VALUE;
1718     }
1719     if (!reply.WriteInt32(result)) {
1720         HILOG_ERROR("GetMissionSnapshot result error");
1721         return ERR_INVALID_VALUE;
1722     }
1723     return NO_ERROR;
1724 }
1725 
SetAbilityControllerInner(MessageParcel & data,MessageParcel & reply)1726 int AbilityManagerStub::SetAbilityControllerInner(MessageParcel &data, MessageParcel &reply)
1727 {
1728     sptr<AppExecFwk::IAbilityController> controller =
1729         iface_cast<AppExecFwk::IAbilityController>(data.ReadRemoteObject());
1730     if (controller == nullptr) {
1731         HILOG_ERROR("AbilityManagerStub: setAbilityControllerInner controller readParcelable failed!");
1732         return ERR_NULL_OBJECT;
1733     }
1734     bool imAStabilityTest = data.ReadBool();
1735     int32_t result = SetAbilityController(controller, imAStabilityTest);
1736     HILOG_INFO("AbilityManagerStub: setAbilityControllerInner result = %{public}d", result);
1737     if (!reply.WriteInt32(result)) {
1738         HILOG_ERROR("setAbilityControllerInner failed.");
1739         return ERR_INVALID_VALUE;
1740     }
1741     return NO_ERROR;
1742 }
1743 
SetComponentInterceptionInner(MessageParcel & data,MessageParcel & reply)1744 int AbilityManagerStub::SetComponentInterceptionInner(MessageParcel &data, MessageParcel &reply)
1745 {
1746     sptr<AppExecFwk::IComponentInterception> componentInterception =
1747         iface_cast<AppExecFwk::IComponentInterception>(data.ReadRemoteObject());
1748     if (componentInterception == nullptr) {
1749         HILOG_ERROR("AbilityManagerStub: SetComponentInterceptionInner readParcelable failed!");
1750         return ERR_NULL_OBJECT;
1751     }
1752     int32_t result = SetComponentInterception(componentInterception);
1753     HILOG_INFO("AbilityManagerStub: SetComponentInterceptionInner result = %{public}d", result);
1754     if (!reply.WriteInt32(result)) {
1755         HILOG_ERROR("SetComponentInterceptionInner failed.");
1756         return ERR_INVALID_VALUE;
1757     }
1758     return NO_ERROR;
1759 }
1760 
SendResultToAbilityByTokenInner(MessageParcel & data,MessageParcel & reply)1761 int AbilityManagerStub::SendResultToAbilityByTokenInner(MessageParcel &data, MessageParcel &reply)
1762 {
1763     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1764     if (want == nullptr) {
1765         HILOG_ERROR("want is nullptr");
1766         return ERR_INVALID_VALUE;
1767     }
1768     sptr<IRemoteObject> abilityToken = data.ReadRemoteObject();
1769     int32_t requestCode = data.ReadInt32();
1770     int32_t resultCode = data.ReadInt32();
1771     int32_t userId = data.ReadInt32();
1772     int32_t result = SendResultToAbilityByToken(*want, abilityToken, requestCode, resultCode, userId);
1773     reply.WriteInt32(result);
1774     return NO_ERROR;
1775 }
1776 
IsRunningInStabilityTestInner(MessageParcel & data,MessageParcel & reply)1777 int AbilityManagerStub::IsRunningInStabilityTestInner(MessageParcel &data, MessageParcel &reply)
1778 {
1779     bool result = IsRunningInStabilityTest();
1780     HILOG_INFO("AbilityManagerStub: IsRunningInStabilityTest result = %{public}d", result);
1781     if (!reply.WriteBool(result)) {
1782         HILOG_ERROR("IsRunningInStabilityTest failed.");
1783         return ERR_INVALID_VALUE;
1784     }
1785     return NO_ERROR;
1786 }
1787 
StartUserTestInner(MessageParcel & data,MessageParcel & reply)1788 int AbilityManagerStub::StartUserTestInner(MessageParcel &data, MessageParcel &reply)
1789 {
1790     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1791     if (want == nullptr) {
1792         HILOG_ERROR("want is nullptr");
1793         return ERR_INVALID_VALUE;
1794     }
1795     auto observer = data.ReadRemoteObject();
1796     int32_t result = StartUserTest(*want, observer);
1797     reply.WriteInt32(result);
1798     return result;
1799 }
1800 
FinishUserTestInner(MessageParcel & data,MessageParcel & reply)1801 int AbilityManagerStub::FinishUserTestInner(MessageParcel &data, MessageParcel &reply)
1802 {
1803     std::string msg = data.ReadString();
1804     int64_t resultCode = data.ReadInt64();
1805     std::string bundleName = data.ReadString();
1806     int32_t result = FinishUserTest(msg, resultCode, bundleName);
1807     reply.WriteInt32(result);
1808     return result;
1809 }
1810 
GetTopAbilityTokenInner(MessageParcel & data,MessageParcel & reply)1811 int AbilityManagerStub::GetTopAbilityTokenInner(MessageParcel &data, MessageParcel &reply)
1812 {
1813     sptr<IRemoteObject> token;
1814     auto result = GetTopAbility(token);
1815     if (!reply.WriteRemoteObject(token)) {
1816         HILOG_ERROR("data write failed.");
1817         return ERR_INVALID_VALUE;
1818     }
1819     reply.WriteInt32(result);
1820 
1821     return NO_ERROR;
1822 }
1823 
CheckUIExtensionIsFocusedInner(MessageParcel & data,MessageParcel & reply)1824 int AbilityManagerStub::CheckUIExtensionIsFocusedInner(MessageParcel &data, MessageParcel &reply)
1825 {
1826     uint32_t uiExtensionTokenId = data.ReadUint32();
1827     bool isFocused = false;
1828     auto result = CheckUIExtensionIsFocused(uiExtensionTokenId, isFocused);
1829     if (result == ERR_OK) {
1830         if (!reply.WriteBool(isFocused)) {
1831             HILOG_ERROR("reply write failed.");
1832             return ERR_INVALID_VALUE;
1833         }
1834     }
1835     return result;
1836 }
1837 
DelegatorDoAbilityForegroundInner(MessageParcel & data,MessageParcel & reply)1838 int AbilityManagerStub::DelegatorDoAbilityForegroundInner(MessageParcel &data, MessageParcel &reply)
1839 {
1840     sptr<IRemoteObject> token = data.ReadRemoteObject();
1841     auto result = DelegatorDoAbilityForeground(token);
1842     reply.WriteInt32(result);
1843 
1844     return NO_ERROR;
1845 }
1846 
DelegatorDoAbilityBackgroundInner(MessageParcel & data,MessageParcel & reply)1847 int AbilityManagerStub::DelegatorDoAbilityBackgroundInner(MessageParcel &data, MessageParcel &reply)
1848 {
1849     sptr<IRemoteObject> token = data.ReadRemoteObject();
1850     auto result = DelegatorDoAbilityBackground(token);
1851     reply.WriteInt32(result);
1852     return NO_ERROR;
1853 }
1854 
DoAbilityForeground(const sptr<IRemoteObject> & token,uint32_t flag)1855 int AbilityManagerStub::DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag)
1856 {
1857     return 0;
1858 }
1859 
DoAbilityBackground(const sptr<IRemoteObject> & token,uint32_t flag)1860 int AbilityManagerStub::DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag)
1861 {
1862     return 0;
1863 }
1864 
DoAbilityForegroundInner(MessageParcel & data,MessageParcel & reply)1865 int AbilityManagerStub::DoAbilityForegroundInner(MessageParcel &data, MessageParcel &reply)
1866 {
1867     sptr<IRemoteObject> token = data.ReadRemoteObject();
1868     uint32_t flag = data.ReadUint32();
1869     auto result = DoAbilityForeground(token, flag);
1870     reply.WriteInt32(result);
1871 
1872     return NO_ERROR;
1873 }
1874 
DoAbilityBackgroundInner(MessageParcel & data,MessageParcel & reply)1875 int AbilityManagerStub::DoAbilityBackgroundInner(MessageParcel &data, MessageParcel &reply)
1876 {
1877     sptr<IRemoteObject> token = data.ReadRemoteObject();
1878     uint32_t flag = data.ReadUint32();
1879     auto result = DoAbilityBackground(token, flag);
1880     reply.WriteInt32(result);
1881     return NO_ERROR;
1882 }
1883 
SendANRProcessIDInner(MessageParcel & data,MessageParcel & reply)1884 int AbilityManagerStub::SendANRProcessIDInner(MessageParcel &data, MessageParcel &reply)
1885 {
1886     int32_t pid = data.ReadInt32();
1887     int32_t result = SendANRProcessID(pid);
1888     if (!reply.WriteInt32(result)) {
1889         HILOG_ERROR("reply write failed.");
1890         return ERR_INVALID_VALUE;
1891     }
1892     return NO_ERROR;
1893 }
1894 
RegisterObserver(const sptr<AbilityRuntime::IConnectionObserver> & observer)1895 int AbilityManagerStub::RegisterObserver(const sptr<AbilityRuntime::IConnectionObserver> &observer)
1896 {
1897     // should implement in child.
1898     return NO_ERROR;
1899 }
1900 
UnregisterObserver(const sptr<AbilityRuntime::IConnectionObserver> & observer)1901 int AbilityManagerStub::UnregisterObserver(const sptr<AbilityRuntime::IConnectionObserver> &observer)
1902 {
1903     // should implement in child
1904     return NO_ERROR;
1905 }
1906 
GetDlpConnectionInfos(std::vector<AbilityRuntime::DlpConnectionInfo> & infos)1907 int AbilityManagerStub::GetDlpConnectionInfos(std::vector<AbilityRuntime::DlpConnectionInfo> &infos)
1908 {
1909     // should implement in child
1910     return NO_ERROR;
1911 }
1912 
1913 #ifdef ABILITY_COMMAND_FOR_TEST
ForceTimeoutForTestInner(MessageParcel & data,MessageParcel & reply)1914 int AbilityManagerStub::ForceTimeoutForTestInner(MessageParcel &data, MessageParcel &reply)
1915 {
1916     std::string abilityName = Str16ToStr8(data.ReadString16());
1917     std::string state = Str16ToStr8(data.ReadString16());
1918     int result = ForceTimeoutForTest(abilityName, state);
1919     if (!reply.WriteInt32(result)) {
1920         HILOG_ERROR("force ability timeout error");
1921         return ERR_INVALID_VALUE;
1922     }
1923     return NO_ERROR;
1924 }
1925 
BlockAbilityInner(MessageParcel & data,MessageParcel & reply)1926 int AbilityManagerStub::BlockAbilityInner(MessageParcel &data, MessageParcel &reply)
1927 {
1928     int32_t abilityRecordId = data.ReadInt32();
1929     int32_t result = BlockAbility(abilityRecordId);
1930     if (!reply.WriteInt32(result)) {
1931         HILOG_ERROR("reply write failed.");
1932         return ERR_INVALID_VALUE;
1933     }
1934     return NO_ERROR;
1935 }
1936 
BlockAmsServiceInner(MessageParcel & data,MessageParcel & reply)1937 int AbilityManagerStub::BlockAmsServiceInner(MessageParcel &data, MessageParcel &reply)
1938 {
1939     int32_t result = BlockAmsService();
1940     if (!reply.WriteInt32(result)) {
1941         HILOG_ERROR("reply write failed.");
1942         return ERR_INVALID_VALUE;
1943     }
1944     return NO_ERROR;
1945 }
1946 
BlockAppServiceInner(MessageParcel & data,MessageParcel & reply)1947 int AbilityManagerStub::BlockAppServiceInner(MessageParcel &data, MessageParcel &reply)
1948 {
1949     int32_t result = BlockAppService();
1950     if (!reply.WriteInt32(result)) {
1951         HILOG_ERROR("reply write failed.");
1952         return ERR_INVALID_VALUE;
1953     }
1954     return NO_ERROR;
1955 }
1956 #endif
1957 
FreeInstallAbilityFromRemoteInner(MessageParcel & data,MessageParcel & reply)1958 int AbilityManagerStub::FreeInstallAbilityFromRemoteInner(MessageParcel &data, MessageParcel &reply)
1959 {
1960     std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
1961     if (want == nullptr) {
1962         HILOG_ERROR("want is nullptr");
1963         return ERR_INVALID_VALUE;
1964     }
1965     want->SetParam(FROM_REMOTE_KEY, true);
1966 
1967     auto callback = data.ReadRemoteObject();
1968     if (callback == nullptr) {
1969         HILOG_ERROR("callback is nullptr");
1970         return ERR_INVALID_VALUE;
1971     }
1972 
1973     int32_t userId = data.ReadInt32();
1974     int32_t requestCode = data.ReadInt32();
1975     int32_t result = FreeInstallAbilityFromRemote(*want, callback, userId, requestCode);
1976     if (!reply.WriteInt32(result)) {
1977         HILOG_ERROR("reply write failed.");
1978         return ERR_INVALID_VALUE;
1979     }
1980     return NO_ERROR;
1981 }
1982 
AddFreeInstallObserverInner(MessageParcel & data,MessageParcel & reply)1983 int AbilityManagerStub::AddFreeInstallObserverInner(MessageParcel &data, MessageParcel &reply)
1984 {
1985     sptr<AbilityRuntime::IFreeInstallObserver> observer =
1986         iface_cast<AbilityRuntime::IFreeInstallObserver>(data.ReadRemoteObject());
1987     int32_t result = AddFreeInstallObserver(observer);
1988     if (!reply.WriteInt32(result)) {
1989         HILOG_ERROR("reply write failed.");
1990         return ERR_INVALID_VALUE;
1991     }
1992     return NO_ERROR;
1993 }
1994 
DumpAbilityInfoDoneInner(MessageParcel & data,MessageParcel & reply)1995 int AbilityManagerStub::DumpAbilityInfoDoneInner(MessageParcel &data, MessageParcel &reply)
1996 {
1997     std::vector<std::string> infos;
1998     data.ReadStringVector(&infos);
1999     sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
2000     int32_t result = DumpAbilityInfoDone(infos, callerToken);
2001     if (!reply.WriteInt32(result)) {
2002         HILOG_ERROR("reply write failed.");
2003         return ERR_INVALID_VALUE;
2004     }
2005     return NO_ERROR;
2006 }
2007 
UpdateMissionSnapShotFromWMSInner(MessageParcel & data,MessageParcel & reply)2008 int AbilityManagerStub::UpdateMissionSnapShotFromWMSInner(MessageParcel &data, MessageParcel &reply)
2009 {
2010     sptr<IRemoteObject> token = data.ReadRemoteObject();
2011     if (token == nullptr) {
2012         HILOG_ERROR("read ability token failed.");
2013         return ERR_NULL_OBJECT;
2014     }
2015 
2016     std::shared_ptr<Media::PixelMap> pixelMap(data.ReadParcelable<Media::PixelMap>());
2017     if (pixelMap == nullptr) {
2018         HILOG_ERROR("read pixelMap failed.");
2019         return ERR_NULL_OBJECT;
2020     }
2021     UpdateMissionSnapShot(token, pixelMap);
2022     return NO_ERROR;
2023 }
2024 
EnableRecoverAbilityInner(MessageParcel & data,MessageParcel & reply)2025 int AbilityManagerStub::EnableRecoverAbilityInner(MessageParcel &data, MessageParcel &reply)
2026 {
2027     sptr<IRemoteObject> token = data.ReadRemoteObject();
2028     if (!token) {
2029         HILOG_ERROR("EnableRecoverAbilityInner read ability token failed.");
2030         return ERR_NULL_OBJECT;
2031     }
2032     EnableRecoverAbility(token);
2033     return NO_ERROR;
2034 }
2035 
HandleRequestDialogService(MessageParcel & data,MessageParcel & reply)2036 int AbilityManagerStub::HandleRequestDialogService(MessageParcel &data, MessageParcel &reply)
2037 {
2038     std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
2039     if (want == nullptr) {
2040         HILOG_ERROR("want is nullptr");
2041         return ERR_INVALID_VALUE;
2042     }
2043 
2044     sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
2045     if (!callerToken) {
2046         HILOG_ERROR("callerToken is invalid.");
2047         return ERR_INVALID_VALUE;
2048     }
2049 
2050     int32_t result = RequestDialogService(*want, callerToken);
2051     if (!reply.WriteInt32(result)) {
2052         HILOG_ERROR("reply write failed.");
2053         return ERR_INVALID_VALUE;
2054     }
2055     return NO_ERROR;
2056 }
2057 
HandleReportDrawnCompleted(MessageParcel & data,MessageParcel & reply)2058 int32_t AbilityManagerStub::HandleReportDrawnCompleted(MessageParcel &data, MessageParcel &reply)
2059 {
2060     HILOG_DEBUG("called.");
2061     sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
2062     if (callerToken == nullptr) {
2063         HILOG_ERROR("callerToken is invalid.");
2064         return ERR_INVALID_VALUE;
2065     }
2066 
2067     auto result = ReportDrawnCompleted(callerToken);
2068     if (!reply.WriteInt32(result)) {
2069         HILOG_ERROR("reply write failed.");
2070         return ERR_INVALID_VALUE;
2071     }
2072     return NO_ERROR;
2073 }
2074 
AcquireShareDataInner(MessageParcel & data,MessageParcel & reply)2075 int AbilityManagerStub::AcquireShareDataInner(MessageParcel &data, MessageParcel &reply)
2076 {
2077     int32_t missionId = data.ReadInt32();
2078     sptr<IAcquireShareDataCallback> shareData = iface_cast<IAcquireShareDataCallback>(data.ReadRemoteObject());
2079     if (!shareData) {
2080         HILOG_ERROR("shareData read failed.");
2081         return ERR_INVALID_VALUE;
2082     }
2083     int32_t result = AcquireShareData(missionId, shareData);
2084     if (!reply.WriteInt32(result)) {
2085         HILOG_ERROR("reply write failed.");
2086         return ERR_INVALID_VALUE;
2087     }
2088     return NO_ERROR;
2089 }
2090 
ShareDataDoneInner(MessageParcel & data,MessageParcel & reply)2091 int AbilityManagerStub::ShareDataDoneInner(MessageParcel &data, MessageParcel &reply)
2092 {
2093     sptr<IRemoteObject> token = data.ReadRemoteObject();
2094     if (!token) {
2095         HILOG_ERROR("ShareDataDone read ability token failed.");
2096         return ERR_NULL_OBJECT;
2097     }
2098     int32_t resultCode = data.ReadInt32();
2099     int32_t uniqueId = data.ReadInt32();
2100     std::shared_ptr<WantParams> wantParam(data.ReadParcelable<WantParams>());
2101     int32_t result = ShareDataDone(token, resultCode, uniqueId, *wantParam);
2102     if (!reply.WriteInt32(result)) {
2103         HILOG_ERROR("reply write failed.");
2104         return ERR_INVALID_VALUE;
2105     }
2106     return NO_ERROR;
2107 }
2108 
GetAbilityTokenByCalleeObjInner(MessageParcel & data,MessageParcel & reply)2109 int AbilityManagerStub::GetAbilityTokenByCalleeObjInner(MessageParcel &data, MessageParcel &reply)
2110 {
2111     sptr<IRemoteObject> callStub = data.ReadRemoteObject();
2112     if (!callStub) {
2113         HILOG_ERROR("GetAbilityToken read call stub failed.");
2114         return ERR_NULL_OBJECT;
2115     }
2116     sptr<IRemoteObject> result;
2117     GetAbilityTokenByCalleeObj(callStub, result);
2118     reply.WriteRemoteObject(result);
2119     return NO_ERROR;
2120 }
2121 
ScheduleRecoverAbilityInner(MessageParcel & data,MessageParcel & reply)2122 int AbilityManagerStub::ScheduleRecoverAbilityInner(MessageParcel &data, MessageParcel &reply)
2123 {
2124     sptr<IRemoteObject> token = data.ReadRemoteObject();
2125     if (!token) {
2126         HILOG_ERROR("ScheduleRecoverAbility read ability token failed.");
2127         return ERR_NULL_OBJECT;
2128     }
2129 
2130     int reason = data.ReadInt32();
2131     Want *want = data.ReadParcelable<Want>();
2132     ScheduleRecoverAbility(token, reason, want);
2133     if (want != nullptr) {
2134         delete want;
2135     }
2136     return NO_ERROR;
2137 }
2138 
RegisterConnectionObserverInner(MessageParcel & data,MessageParcel & reply)2139 int AbilityManagerStub::RegisterConnectionObserverInner(MessageParcel &data, MessageParcel &reply)
2140 {
2141     sptr<AbilityRuntime::IConnectionObserver> observer = iface_cast<AbilityRuntime::IConnectionObserver>(
2142         data.ReadRemoteObject());
2143     if (!observer) {
2144         HILOG_ERROR("RegisterConnectionObserverInner read observer failed.");
2145         return ERR_NULL_OBJECT;
2146     }
2147 
2148     return RegisterObserver(observer);
2149 }
2150 
UnregisterConnectionObserverInner(MessageParcel & data,MessageParcel & reply)2151 int AbilityManagerStub::UnregisterConnectionObserverInner(MessageParcel &data, MessageParcel &reply)
2152 {
2153     sptr<AbilityRuntime::IConnectionObserver> observer = iface_cast<AbilityRuntime::IConnectionObserver>(
2154         data.ReadRemoteObject());
2155     if (!observer) {
2156         HILOG_ERROR("UnregisterConnectionObserverInner read observer failed.");
2157         return ERR_NULL_OBJECT;
2158     }
2159 
2160     return UnregisterObserver(observer);
2161 }
2162 
GetDlpConnectionInfosInner(MessageParcel & data,MessageParcel & reply)2163 int AbilityManagerStub::GetDlpConnectionInfosInner(MessageParcel &data, MessageParcel &reply)
2164 {
2165     std::vector<AbilityRuntime::DlpConnectionInfo> infos;
2166     auto result = GetDlpConnectionInfos(infos);
2167     if (!reply.WriteInt32(result)) {
2168         HILOG_ERROR("write result failed");
2169         return ERR_INVALID_VALUE;
2170     }
2171 
2172     if (!reply.WriteInt32(infos.size())) {
2173         HILOG_ERROR("write infos size failed");
2174         return ERR_INVALID_VALUE;
2175     }
2176 
2177     for (auto &item : infos) {
2178         if (!reply.WriteParcelable(&item)) {
2179             HILOG_ERROR("write info item failed");
2180             return ERR_INVALID_VALUE;
2181         }
2182     }
2183 
2184     return ERR_OK;
2185 }
2186 
SetMissionContinueStateInner(MessageParcel & data,MessageParcel & reply)2187 int AbilityManagerStub::SetMissionContinueStateInner(MessageParcel &data, MessageParcel &reply)
2188 {
2189     sptr<IRemoteObject> token = data.ReadRemoteObject();
2190     if (!token) {
2191         HILOG_ERROR("SetMissionContinueStateInner read ability token failed.");
2192         return ERR_NULL_OBJECT;
2193     }
2194 
2195     int32_t state = data.ReadInt32();
2196     int result = SetMissionContinueState(token, static_cast<AAFwk::ContinueState>(state));
2197     if (!reply.WriteInt32(result)) {
2198         HILOG_ERROR("SetMissionContinueState failed.");
2199         return ERR_INVALID_VALUE;
2200     }
2201     return NO_ERROR;
2202 }
2203 
2204 #ifdef SUPPORT_GRAPHICS
SetMissionLabelInner(MessageParcel & data,MessageParcel & reply)2205 int AbilityManagerStub::SetMissionLabelInner(MessageParcel &data, MessageParcel &reply)
2206 {
2207     sptr<IRemoteObject> token = data.ReadRemoteObject();
2208     if (!token) {
2209         HILOG_ERROR("SetMissionLabelInner read ability token failed.");
2210         return ERR_NULL_OBJECT;
2211     }
2212 
2213     std::string label = Str16ToStr8(data.ReadString16());
2214     int result = SetMissionLabel(token, label);
2215     if (!reply.WriteInt32(result)) {
2216         HILOG_ERROR("SetMissionLabel failed.");
2217         return ERR_INVALID_VALUE;
2218     }
2219     return NO_ERROR;
2220 }
2221 
SetMissionIconInner(MessageParcel & data,MessageParcel & reply)2222 int AbilityManagerStub::SetMissionIconInner(MessageParcel &data, MessageParcel &reply)
2223 {
2224     sptr<IRemoteObject> token = data.ReadRemoteObject();
2225     if (!token) {
2226         HILOG_ERROR("SetMissionIconInner read ability token failed.");
2227         return ERR_NULL_OBJECT;
2228     }
2229 
2230     std::shared_ptr<Media::PixelMap> icon(data.ReadParcelable<Media::PixelMap>());
2231     if (!icon) {
2232         HILOG_ERROR("SetMissionIconInner read icon failed.");
2233         return ERR_NULL_OBJECT;
2234     }
2235 
2236     int result = SetMissionIcon(token, icon);
2237     if (!reply.WriteInt32(result)) {
2238         HILOG_ERROR("SetMissionIcon failed.");
2239         return ERR_INVALID_VALUE;
2240     }
2241     return NO_ERROR;
2242 }
2243 
RegisterWindowManagerServiceHandlerInner(MessageParcel & data,MessageParcel & reply)2244 int AbilityManagerStub::RegisterWindowManagerServiceHandlerInner(MessageParcel &data, MessageParcel &reply)
2245 {
2246     sptr<IWindowManagerServiceHandler> handler = iface_cast<IWindowManagerServiceHandler>(data.ReadRemoteObject());
2247     if (handler == nullptr) {
2248         HILOG_ERROR("%{public}s read WMS handler failed!", __func__);
2249         return ERR_NULL_OBJECT;
2250     }
2251     return RegisterWindowManagerServiceHandler(handler);
2252 }
2253 
CompleteFirstFrameDrawingInner(MessageParcel & data,MessageParcel & reply)2254 int AbilityManagerStub::CompleteFirstFrameDrawingInner(MessageParcel &data, MessageParcel &reply)
2255 {
2256     HILOG_DEBUG("%{public}s is called.", __func__);
2257     sptr<IRemoteObject> abilityToken = data.ReadRemoteObject();
2258     if (abilityToken == nullptr) {
2259         HILOG_ERROR("%{public}s read abilityToken failed!", __func__);
2260         return ERR_NULL_OBJECT;
2261     }
2262     CompleteFirstFrameDrawing(abilityToken);
2263     return 0;
2264 }
2265 
PrepareTerminateAbilityInner(MessageParcel & data,MessageParcel & reply)2266 int AbilityManagerStub::PrepareTerminateAbilityInner(MessageParcel &data, MessageParcel &reply)
2267 {
2268     HILOG_DEBUG("call");
2269     sptr<IRemoteObject> token = nullptr;
2270     if (data.ReadBool()) {
2271         token = data.ReadRemoteObject();
2272     }
2273     sptr<IPrepareTerminateCallback> callback = iface_cast<IPrepareTerminateCallback>(data.ReadRemoteObject());
2274     if (callback == nullptr) {
2275         HILOG_ERROR("callback is nullptr");
2276         return ERR_NULL_OBJECT;
2277     }
2278     int result = PrepareTerminateAbility(token, callback);
2279     if (!reply.WriteInt32(result)) {
2280         HILOG_ERROR("end faild. err: %{public}d", result);
2281         return ERR_INVALID_VALUE;
2282     }
2283     return NO_ERROR;
2284 }
2285 #endif
2286 
IsValidMissionIdsInner(MessageParcel & data,MessageParcel & reply)2287 int32_t AbilityManagerStub::IsValidMissionIdsInner(MessageParcel &data, MessageParcel &reply)
2288 {
2289     HILOG_DEBUG("%{public}s is called.", __func__);
2290     std::vector<int32_t> missionIds;
2291     std::vector<MissionVaildResult> results;
2292 
2293     data.ReadInt32Vector(&missionIds);
2294     auto err = IsValidMissionIds(missionIds, results);
2295     if (err != ERR_OK) {
2296         results.clear();
2297     }
2298 
2299     if (!reply.WriteInt32(err)) {
2300         return ERR_INVALID_VALUE;
2301     }
2302 
2303     reply.WriteInt32(static_cast<int32_t>(results.size()));
2304     for (auto &item : results) {
2305         if (!reply.WriteParcelable(&item)) {
2306             return ERR_INVALID_VALUE;
2307         }
2308     }
2309     return NO_ERROR;
2310 }
2311 
VerifyPermissionInner(MessageParcel & data,MessageParcel & reply)2312 int AbilityManagerStub::VerifyPermissionInner(MessageParcel &data, MessageParcel &reply)
2313 {
2314     HILOG_DEBUG("VerifyPermission call.");
2315     std::string permission = data.ReadString();
2316     int32_t pid = data.ReadInt32();
2317     int32_t uid = data.ReadInt32();
2318 
2319     auto result = VerifyPermission(permission, pid, uid);
2320     if (!reply.WriteInt32(result)) {
2321         HILOG_ERROR("VerifyPermission failed.");
2322         return ERR_INVALID_VALUE;
2323     }
2324     return NO_ERROR;
2325 }
2326 
ForceExitAppInner(MessageParcel & data,MessageParcel & reply)2327 int32_t AbilityManagerStub::ForceExitAppInner(MessageParcel &data, MessageParcel &reply)
2328 {
2329     int32_t pid = data.ReadInt32();
2330     Reason reason = static_cast<Reason>(data.ReadInt32());
2331     int32_t result = ForceExitApp(pid, reason);
2332     if (!reply.WriteInt32(result)) {
2333         HILOG_ERROR("write result failed.");
2334         return ERR_INVALID_VALUE;
2335     }
2336     return NO_ERROR;
2337 }
2338 
RecordAppExitReasonInner(MessageParcel & data,MessageParcel & reply)2339 int32_t AbilityManagerStub::RecordAppExitReasonInner(MessageParcel &data, MessageParcel &reply)
2340 {
2341     Reason reason = static_cast<Reason>(data.ReadInt32());
2342     int32_t result = RecordAppExitReason(reason);
2343     if (!reply.WriteInt32(result)) {
2344         HILOG_ERROR("write result failed.");
2345         return ERR_INVALID_VALUE;
2346     }
2347     return NO_ERROR;
2348 }
2349 
SetRootSceneSessionInner(MessageParcel & data,MessageParcel & reply)2350 int AbilityManagerStub::SetRootSceneSessionInner(MessageParcel &data, MessageParcel &reply)
2351 {
2352     HILOG_DEBUG("Call.");
2353     auto rootSceneSession = data.ReadRemoteObject();
2354     if (rootSceneSession == nullptr) {
2355         HILOG_ERROR("Read rootSceneSession failed.");
2356         return ERR_INVALID_VALUE;
2357     }
2358     SetRootSceneSession(rootSceneSession);
2359     return NO_ERROR;
2360 }
2361 
CallUIAbilityBySCBInner(MessageParcel & data,MessageParcel & reply)2362 int AbilityManagerStub::CallUIAbilityBySCBInner(MessageParcel &data, MessageParcel &reply)
2363 {
2364     HILOG_DEBUG("Call.");
2365     sptr<SessionInfo> sessionInfo = nullptr;
2366     if (data.ReadBool()) {
2367         sessionInfo = data.ReadParcelable<SessionInfo>();
2368     }
2369     CallUIAbilityBySCB(sessionInfo);
2370     return NO_ERROR;
2371 }
2372 
StartSpecifiedAbilityBySCBInner(MessageParcel & data,MessageParcel & reply)2373 int32_t AbilityManagerStub::StartSpecifiedAbilityBySCBInner(MessageParcel &data, MessageParcel &reply)
2374 {
2375     HILOG_DEBUG("Call.");
2376     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2377     if (want == nullptr) {
2378         HILOG_ERROR("want is nullptr");
2379         return ERR_INVALID_VALUE;
2380     }
2381     StartSpecifiedAbilityBySCB(*want);
2382     return NO_ERROR;
2383 }
2384 
NotifySaveAsResultInner(MessageParcel & data,MessageParcel & reply)2385 int AbilityManagerStub::NotifySaveAsResultInner(MessageParcel &data, MessageParcel &reply)
2386 {
2387     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2388     if (!want) {
2389         HILOG_ERROR("want is nullptr");
2390         return ERR_INVALID_VALUE;
2391     }
2392     int resultCode = data.ReadInt32();
2393     int requestCode = data.ReadInt32();
2394     int32_t result = NotifySaveAsResult(*want, resultCode, requestCode);
2395     reply.WriteInt32(result);
2396     return NO_ERROR;
2397 }
2398 
SetSessionManagerServiceInner(MessageParcel & data,MessageParcel & reply)2399 int AbilityManagerStub::SetSessionManagerServiceInner(MessageParcel &data, MessageParcel &reply)
2400 {
2401     sptr<IRemoteObject> sessionManagerService = data.ReadRemoteObject();
2402     if (!sessionManagerService) {
2403         HILOG_ERROR("SetSessionManagerServiceInner read ability token failed.");
2404         return ERR_NULL_OBJECT;
2405     }
2406     SetSessionManagerService(sessionManagerService);
2407     return NO_ERROR;
2408 }
2409 
RegisterIAbilityManagerCollaboratorInner(MessageParcel & data,MessageParcel & reply)2410 int32_t AbilityManagerStub::RegisterIAbilityManagerCollaboratorInner(MessageParcel &data, MessageParcel &reply)
2411 {
2412     int32_t type = data.ReadInt32();
2413     sptr<IAbilityManagerCollaborator> collaborator = iface_cast<IAbilityManagerCollaborator>(data.ReadRemoteObject());
2414     if (collaborator == nullptr) {
2415         HILOG_ERROR("read collaborator failed.");
2416         return ERR_NULL_OBJECT;
2417     }
2418     int32_t ret = RegisterIAbilityManagerCollaborator(type, collaborator);
2419     reply.WriteInt32(ret);
2420     return NO_ERROR;
2421 }
2422 
UnregisterIAbilityManagerCollaboratorInner(MessageParcel & data,MessageParcel & reply)2423 int32_t AbilityManagerStub::UnregisterIAbilityManagerCollaboratorInner(MessageParcel &data, MessageParcel &reply)
2424 {
2425     int32_t type = data.ReadInt32();
2426     int32_t ret = UnregisterIAbilityManagerCollaborator(type);
2427     reply.WriteInt32(ret);
2428     return NO_ERROR;
2429 }
2430 
MoveMissionToBackgroundInner(MessageParcel & data,MessageParcel & reply)2431 int32_t AbilityManagerStub::MoveMissionToBackgroundInner(MessageParcel &data, MessageParcel &reply)
2432 {
2433     int32_t missionId = data.ReadInt32();
2434     int32_t ret = MoveMissionToBackground(missionId);
2435     reply.WriteInt32(ret);
2436     return NO_ERROR;
2437 }
2438 
TerminateMissionInner(MessageParcel & data,MessageParcel & reply)2439 int32_t AbilityManagerStub::TerminateMissionInner(MessageParcel &data, MessageParcel &reply)
2440 {
2441     int32_t missionId = data.ReadInt32();
2442     int32_t ret = TerminateMission(missionId);
2443     reply.WriteInt32(ret);
2444     return NO_ERROR;
2445 }
2446 
PrepareTerminateAbilityBySCBInner(MessageParcel & data,MessageParcel & reply)2447 int AbilityManagerStub::PrepareTerminateAbilityBySCBInner(MessageParcel &data, MessageParcel &reply)
2448 {
2449     HILOG_DEBUG("Call.");
2450     sptr<SessionInfo> sessionInfo = nullptr;
2451     if (data.ReadBool()) {
2452         sessionInfo = data.ReadParcelable<SessionInfo>();
2453     }
2454     bool isPrepareTerminate = false;
2455     auto result = PrepareTerminateAbilityBySCB(sessionInfo, isPrepareTerminate);
2456     if (result == ERR_OK) {
2457         if (!reply.WriteBool(isPrepareTerminate)) {
2458             HILOG_ERROR("reply write failed.");
2459             return ERR_INVALID_VALUE;
2460         }
2461     }
2462     return result;
2463 }
2464 
RegisterSessionHandlerInner(MessageParcel & data,MessageParcel & reply)2465 int AbilityManagerStub::RegisterSessionHandlerInner(MessageParcel &data, MessageParcel &reply)
2466 {
2467     sptr<IRemoteObject> handler = data.ReadRemoteObject();
2468     if (handler == nullptr) {
2469         HILOG_ERROR("stub register session handler, handler is nullptr.");
2470         return ERR_INVALID_VALUE;
2471     }
2472     int32_t result = RegisterSessionHandler(handler);
2473     reply.WriteInt32(result);
2474     return NO_ERROR;
2475 }
2476 }  // namespace AAFwk
2477 }  // namespace OHOS
2478