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