1 /*
2 * Copyright (c) 2021-2024 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 "ams_mgr_stub.h"
17 #include "ability_manager_errors.h"
18 #include "ability_info.h"
19 #include "app_debug_listener_interface.h"
20 #include "app_mgr_proxy.h"
21 #include "app_scheduler_interface.h"
22 #include "appexecfwk_errors.h"
23 #include "hilog_tag_wrapper.h"
24 #include "hitrace_meter.h"
25 #include "iapp_state_callback.h"
26 #include "ipc_skeleton.h"
27 #include "ipc_types.h"
28 #include "iremote_object.h"
29 #include "param.h"
30 #include "string_ex.h"
31
32 namespace OHOS {
33 namespace AppExecFwk {
34 namespace {
35 constexpr int32_t MAX_APP_DEBUG_COUNT = 100;
36 constexpr int32_t MAX_KILL_PROCESS_PID_COUNT = 100;
37 }
38
AmsMgrStub()39 AmsMgrStub::AmsMgrStub()
40 {
41 CreateMemberFuncMap();
42 }
43
~AmsMgrStub()44 AmsMgrStub::~AmsMgrStub() {}
45
CreateMemberFuncMap()46 void AmsMgrStub::CreateMemberFuncMap() {}
47
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)48 int AmsMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
49 {
50 if (code != static_cast<uint32_t>(IAmsMgr::Message::Get_BUNDLE_NAME_BY_PID)) {
51 TAG_LOGI(AAFwkTag::APPMGR, "OnReceived, code: %{public}u, flags: %{public}d", code,
52 option.GetFlags());
53 }
54 std::u16string descriptor = AmsMgrStub::GetDescriptor();
55 std::u16string remoteDescriptor = data.ReadInterfaceToken();
56 if (descriptor != remoteDescriptor) {
57 TAG_LOGE(AAFwkTag::APPMGR, "invalid descriptor");
58 return ERR_INVALID_STATE;
59 }
60 return OnRemoteRequestInner(code, data, reply, option);
61 }
62
OnRemoteRequestInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)63 int32_t AmsMgrStub::OnRemoteRequestInner(uint32_t code, MessageParcel &data,
64 MessageParcel &reply, MessageOption &option)
65 {
66 int retCode = ERR_OK;
67 retCode = OnRemoteRequestInnerFirst(code, data, reply, option);
68 if (retCode != AAFwk::ERR_CODE_NOT_EXIST) {
69 return retCode;
70 }
71 retCode = OnRemoteRequestInnerSecond(code, data, reply, option);
72 if (retCode != AAFwk::ERR_CODE_NOT_EXIST) {
73 return retCode;
74 }
75 retCode = OnRemoteRequestInnerThird(code, data, reply, option);
76 if (retCode != AAFwk::ERR_CODE_NOT_EXIST) {
77 return retCode;
78 }
79 retCode = OnRemoteRequestInnerFourth(code, data, reply, option);
80 if (retCode != AAFwk::ERR_CODE_NOT_EXIST) {
81 return retCode;
82 }
83 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
84 }
85
OnRemoteRequestInnerFirst(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)86 int32_t AmsMgrStub::OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data,
87 MessageParcel &reply, MessageOption &option)
88 {
89 switch (static_cast<uint32_t>(code)) {
90 case static_cast<uint32_t>(IAmsMgr::Message::LOAD_ABILITY):
91 return HandleLoadAbility(data, reply);
92 case static_cast<uint32_t>(IAmsMgr::Message::TERMINATE_ABILITY):
93 return HandleTerminateAbility(data, reply);
94 case static_cast<uint32_t>(IAmsMgr::Message::UPDATE_ABILITY_STATE):
95 return HandleUpdateAbilityState(data, reply);
96 case static_cast<uint32_t>(IAmsMgr::Message::UPDATE_EXTENSION_STATE):
97 return HandleUpdateExtensionState(data, reply);
98 case static_cast<uint32_t>(IAmsMgr::Message::REGISTER_APP_STATE_CALLBACK):
99 return HandleRegisterAppStateCallback(data, reply);
100 case static_cast<uint32_t>(IAmsMgr::Message::ABILITY_BEHAVIOR_ANALYSIS):
101 return HandleAbilityBehaviorAnalysis(data, reply);
102 case static_cast<uint32_t>(IAmsMgr::Message::KILL_PEOCESS_BY_ABILITY_TOKEN):
103 return HandleKillProcessByAbilityToken(data, reply);
104 case static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESSES_BY_USERID):
105 return HandleKillProcessesByUserId(data, reply);
106 case static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESS_WITH_ACCOUNT):
107 return HandleKillProcessWithAccount(data, reply);
108 case static_cast<uint32_t>(IAmsMgr::Message::KILL_APPLICATION):
109 return HandleKillApplication(data, reply);
110 case static_cast<uint32_t>(IAmsMgr::Message::ABILITY_ATTACH_TIMEOUT):
111 return HandleAbilityAttachTimeOut(data, reply);
112 case static_cast<uint32_t>(IAmsMgr::Message::PREPARE_TERMINATE_ABILITY):
113 return HandlePrepareTerminate(data, reply);
114 case static_cast<uint32_t>(IAmsMgr::Message::KILL_APPLICATION_BYUID):
115 return HandleKillApplicationByUid(data, reply);
116 case static_cast<uint32_t>(IAmsMgr::Message::KILL_APPLICATION_SELF):
117 return HandleKillApplicationSelf(data, reply);
118 case static_cast<uint32_t>(IAmsMgr::Message::GET_RUNNING_PROCESS_INFO_BY_TOKEN):
119 return HandleGetRunningProcessInfoByToken(data, reply);
120 }
121 return AAFwk::ERR_CODE_NOT_EXIST;
122 }
123
OnRemoteRequestInnerSecond(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)124 int32_t AmsMgrStub::OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data,
125 MessageParcel &reply, MessageOption &option)
126 {
127 switch (static_cast<uint32_t>(code)) {
128 case static_cast<uint32_t>(IAmsMgr::Message::SET_ABILITY_FOREGROUNDING_FLAG):
129 return HandleSetAbilityForegroundingFlagToAppRecord(data, reply);
130 case static_cast<uint32_t>(IAmsMgr::Message::START_SPECIFIED_ABILITY):
131 return HandleStartSpecifiedAbility(data, reply);
132 case static_cast<uint32_t>(IAmsMgr::Message::REGISTER_START_SPECIFIED_ABILITY_RESPONSE):
133 return HandleRegisterStartSpecifiedAbilityResponse(data, reply);
134 case static_cast<uint32_t>(IAmsMgr::Message::GET_APPLICATION_INFO_BY_PROCESS_ID):
135 return HandleGetApplicationInfoByProcessID(data, reply);
136 case static_cast<uint32_t>(IAmsMgr::Message::NOTIFY_APP_MGR_RECORD_EXIT_REASON):
137 return HandleNotifyAppMgrRecordExitReason(data, reply);
138 case static_cast<uint32_t>(IAmsMgr::Message::UPDATE_APPLICATION_INFO_INSTALLED):
139 return HandleUpdateApplicationInfoInstalled(data, reply);
140 case static_cast<uint32_t>(IAmsMgr::Message::SET_CURRENT_USER_ID):
141 return HandleSetCurrentUserId(data, reply);
142 case static_cast<uint32_t>(IAmsMgr::Message::ENABLE_START_PROCESS_FLAG_BY_USER_ID):
143 return HandleSetEnableStartProcessFlagByUserId(data, reply);
144 case static_cast<uint32_t>(IAmsMgr::Message::Get_BUNDLE_NAME_BY_PID):
145 return HandleGetBundleNameByPid(data, reply);
146 case static_cast<uint32_t>(IAmsMgr::Message::REGISTER_APP_DEBUG_LISTENER):
147 return HandleRegisterAppDebugListener(data, reply);
148 case static_cast<uint32_t>(IAmsMgr::Message::UNREGISTER_APP_DEBUG_LISTENER):
149 return HandleUnregisterAppDebugListener(data, reply);
150 case static_cast<uint32_t>(IAmsMgr::Message::ATTACH_APP_DEBUG):
151 return HandleAttachAppDebug(data, reply);
152 case static_cast<uint32_t>(IAmsMgr::Message::DETACH_APP_DEBUG):
153 return HandleDetachAppDebug(data, reply);
154 case static_cast<uint32_t>(IAmsMgr::Message::SET_APP_WAITING_DEBUG):
155 return HandleSetAppWaitingDebug(data, reply);
156 case static_cast<uint32_t>(IAmsMgr::Message::CANCEL_APP_WAITING_DEBUG):
157 return HandleCancelAppWaitingDebug(data, reply);
158 case static_cast<uint32_t>(IAmsMgr::Message::GET_WAITING_DEBUG_APP):
159 return HandleGetWaitingDebugApp(data, reply);
160 case static_cast<uint32_t>(IAmsMgr::Message::IS_WAITING_DEBUG_APP):
161 return HandleIsWaitingDebugApp(data, reply);
162 }
163 return AAFwk::ERR_CODE_NOT_EXIST;
164 }
165
OnRemoteRequestInnerThird(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)166 int32_t AmsMgrStub::OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data,
167 MessageParcel &reply, MessageOption &option)
168 {
169 switch (static_cast<uint32_t>(code)) {
170 case static_cast<uint32_t>(IAmsMgr::Message::CLEAR_NON_PERSIST_WAITING_DEBUG_FLAG):
171 return HandleClearNonPersistWaitingDebugFlag(data, reply);
172 case static_cast<uint32_t>(IAmsMgr::Message::REGISTER_ABILITY_DEBUG_RESPONSE):
173 return HandleRegisterAbilityDebugResponse(data, reply);
174 case static_cast<uint32_t>(IAmsMgr::Message::IS_ATTACH_DEBUG):
175 return HandleIsAttachDebug(data, reply);
176 case static_cast<uint32_t>(IAmsMgr::Message::CLEAR_PROCESS_BY_TOKEN):
177 return HandleClearProcessByToken(data, reply);
178 case static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESSES_BY_PIDS):
179 return HandleKillProcessesByPids(data, reply);
180 case static_cast<uint32_t>(IAmsMgr::Message::ATTACH_PID_TO_PARENT):
181 return HandleAttachPidToParent(data, reply);
182 case static_cast<uint32_t>(IAmsMgr::Message::IS_MEMORY_SIZE_SUFFICIENT):
183 return HandleIsMemorySizeSufficent(data, reply);
184 case static_cast<uint32_t>(IAmsMgr::Message::SET_KEEP_ALIVE_ENABLE_STATE):
185 return HandleSetKeepAliveEnableState(data, reply);
186 case static_cast<uint32_t>(IAmsMgr::Message::ATTACHED_TO_STATUS_BAR):
187 return HandleAttachedToStatusBar(data, reply);
188 case static_cast<uint32_t>(IAmsMgr::Message::UPDATE_CONFIGURATION):
189 return 0;
190 case static_cast<uint32_t>(IAmsMgr::Message::GET_CONFIGURATION):
191 return 0;
192 case static_cast<uint32_t>(IAmsMgr::Message::START_SPECIFIED_PROCESS):
193 return 0;
194 case static_cast<uint32_t>(IAmsMgr::Message::REGISTER_ABILITY_MS_DELEGATE):
195 return 0;
196 case static_cast<uint32_t>(IAmsMgr::Message::BLOCK_PROCESS_CACHE_BY_PIDS):
197 return HandleBlockProcessCacheByPids(data, reply);
198 case static_cast<uint32_t>(IAmsMgr::Message::IS_KILLED_FOR_UPGRADE_WEB):
199 return HandleIsKilledForUpgradeWeb(data, reply);
200 }
201 return AAFwk::ERR_CODE_NOT_EXIST;
202 }
203
OnRemoteRequestInnerFourth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)204 int32_t AmsMgrStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &data,
205 MessageParcel &reply, MessageOption &option)
206 {
207 switch (static_cast<uint32_t>(code)) {
208 case static_cast<uint32_t>(IAmsMgr::Message::IS_PROCESS_CONTAINS_ONLY_UI_EXTENSION):
209 return HandleIsProcessContainsOnlyUIAbility(data, reply);
210 case static_cast<uint32_t>(IAmsMgr::Message::FORCE_KILL_APPLICATION):
211 return HandleForceKillApplication(data, reply);
212 case static_cast<uint32_t>(IAmsMgr::Message::CLEAN_UIABILITY_BY_USER_REQUEST):
213 return HandleCleanAbilityByUserRequest(data, reply);
214 case static_cast<uint32_t>(IAmsMgr::Message::FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID):
215 return HandleKillProcessesByAccessTokenId(data, reply);
216 case static_cast<uint32_t>(IAmsMgr::Message::IS_PROCESS_ATTACHED):
217 return HandleIsProcessAttached(data, reply);
218 }
219 return AAFwk::ERR_CODE_NOT_EXIST;
220 }
221
HandleLoadAbility(MessageParcel & data,MessageParcel & reply)222 ErrCode AmsMgrStub::HandleLoadAbility(MessageParcel &data, MessageParcel &reply)
223 {
224 HITRACE_METER(HITRACE_TAG_APP);
225 std::shared_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
226 if (!abilityInfo) {
227 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<AbilityInfo> failed");
228 return ERR_APPEXECFWK_PARCEL_ERROR;
229 }
230
231 std::shared_ptr<ApplicationInfo> appInfo(data.ReadParcelable<ApplicationInfo>());
232 if (!appInfo) {
233 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<ApplicationInfo> failed");
234 return ERR_APPEXECFWK_PARCEL_ERROR;
235 }
236
237 std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
238 if (!want) {
239 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable want failed");
240 return ERR_APPEXECFWK_PARCEL_ERROR;
241 }
242 std::shared_ptr<AbilityRuntime::LoadParam> loadParam(data.ReadParcelable<AbilityRuntime::LoadParam>());
243 if (!loadParam) {
244 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable loadParam failed");
245 return ERR_APPEXECFWK_PARCEL_ERROR;
246 }
247
248 LoadAbility(abilityInfo, appInfo, want, loadParam);
249 return NO_ERROR;
250 }
251
HandleTerminateAbility(MessageParcel & data,MessageParcel & reply)252 ErrCode AmsMgrStub::HandleTerminateAbility(MessageParcel &data, MessageParcel &reply)
253 {
254 HITRACE_METER(HITRACE_TAG_APP);
255 sptr<IRemoteObject> token = data.ReadRemoteObject();
256 bool clearMissionFlag = data.ReadBool();
257 TerminateAbility(token, clearMissionFlag);
258 return NO_ERROR;
259 }
260
HandleUpdateAbilityState(MessageParcel & data,MessageParcel & reply)261 ErrCode AmsMgrStub::HandleUpdateAbilityState(MessageParcel &data, MessageParcel &reply)
262 {
263 HITRACE_METER(HITRACE_TAG_APP);
264 sptr<IRemoteObject> token = data.ReadRemoteObject();
265 int32_t state = data.ReadInt32();
266 UpdateAbilityState(token, static_cast<AbilityState>(state));
267 return NO_ERROR;
268 }
269
HandleUpdateExtensionState(MessageParcel & data,MessageParcel & reply)270 ErrCode AmsMgrStub::HandleUpdateExtensionState(MessageParcel &data, MessageParcel &reply)
271 {
272 sptr<IRemoteObject> token = data.ReadRemoteObject();
273 int32_t state = data.ReadInt32();
274 UpdateExtensionState(token, static_cast<ExtensionState>(state));
275 return NO_ERROR;
276 }
277
HandleRegisterAppStateCallback(MessageParcel & data,MessageParcel & reply)278 ErrCode AmsMgrStub::HandleRegisterAppStateCallback(MessageParcel &data, MessageParcel &reply)
279 {
280 HITRACE_METER(HITRACE_TAG_APP);
281 sptr<IAppStateCallback> callback = nullptr;
282 if (data.ReadBool()) {
283 sptr<IRemoteObject> obj = data.ReadRemoteObject();
284 callback = iface_cast<IAppStateCallback>(obj);
285 }
286 RegisterAppStateCallback(callback);
287 return NO_ERROR;
288 }
289
HandleAbilityBehaviorAnalysis(MessageParcel & data,MessageParcel & reply)290 ErrCode AmsMgrStub::HandleAbilityBehaviorAnalysis(MessageParcel &data, MessageParcel &reply)
291 {
292 HITRACE_METER(HITRACE_TAG_APP);
293 sptr<IRemoteObject> token = data.ReadRemoteObject();
294 sptr<IRemoteObject> preToke = nullptr;
295 if (data.ReadBool()) {
296 preToke = data.ReadRemoteObject();
297 }
298 int32_t visibility = data.ReadInt32();
299 int32_t perceptibility = data.ReadInt32();
300 int32_t connectionState = data.ReadInt32();
301
302 AbilityBehaviorAnalysis(token, preToke, visibility, perceptibility, connectionState);
303 return NO_ERROR;
304 }
305
HandleKillProcessByAbilityToken(MessageParcel & data,MessageParcel & reply)306 ErrCode AmsMgrStub::HandleKillProcessByAbilityToken(MessageParcel &data, MessageParcel &reply)
307 {
308 HITRACE_METER(HITRACE_TAG_APP);
309 sptr<IRemoteObject> token = data.ReadRemoteObject();
310
311 KillProcessByAbilityToken(token);
312 return NO_ERROR;
313 }
314
HandleKillProcessesByUserId(MessageParcel & data,MessageParcel & reply)315 ErrCode AmsMgrStub::HandleKillProcessesByUserId(MessageParcel &data, MessageParcel &reply)
316 {
317 HITRACE_METER(HITRACE_TAG_APP);
318 int32_t userId = data.ReadInt32();
319
320 KillProcessesByUserId(userId);
321 return NO_ERROR;
322 }
323
HandleKillProcessesByPids(MessageParcel & data,MessageParcel & reply)324 ErrCode AmsMgrStub::HandleKillProcessesByPids(MessageParcel &data, MessageParcel &reply)
325 {
326 HITRACE_METER(HITRACE_TAG_APP);
327 auto size = data.ReadUint32();
328 if (size == 0 || size > MAX_KILL_PROCESS_PID_COUNT) {
329 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size");
330 return ERR_INVALID_VALUE;
331 }
332 std::vector<int32_t> pids;
333 for (uint32_t i = 0; i < size; i++) {
334 pids.emplace_back(data.ReadInt32());
335 }
336
337 KillProcessesByPids(pids);
338 return NO_ERROR;
339 }
340
HandleAttachPidToParent(MessageParcel & data,MessageParcel & reply)341 ErrCode AmsMgrStub::HandleAttachPidToParent(MessageParcel &data, MessageParcel &reply)
342 {
343 HITRACE_METER(HITRACE_TAG_APP);
344 sptr<IRemoteObject> token = data.ReadRemoteObject();
345 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
346 AttachPidToParent(token, callerToken);
347 return NO_ERROR;
348 }
349
HandleKillProcessWithAccount(MessageParcel & data,MessageParcel & reply)350 ErrCode AmsMgrStub::HandleKillProcessWithAccount(MessageParcel &data, MessageParcel &reply)
351 {
352 TAG_LOGI(AAFwkTag::APPMGR, "enter");
353
354 HITRACE_METER(HITRACE_TAG_APP);
355
356 std::string bundleName = data.ReadString();
357 int accountId = data.ReadInt32();
358
359 TAG_LOGI(AAFwkTag::APPMGR, "bundleName = %{public}s, accountId = %{public}d", bundleName.c_str(), accountId);
360
361 int32_t result = KillProcessWithAccount(bundleName, accountId);
362 reply.WriteInt32(result);
363
364 TAG_LOGI(AAFwkTag::APPMGR, "end");
365
366 return NO_ERROR;
367 }
368
HandleKillApplication(MessageParcel & data,MessageParcel & reply)369 ErrCode AmsMgrStub::HandleKillApplication(MessageParcel &data, MessageParcel &reply)
370 {
371 HITRACE_METER(HITRACE_TAG_APP);
372 std::string bundleName = data.ReadString();
373
374 TAG_LOGW(AAFwkTag::APPMGR,
375 "KillApplication,callingPid=%{public}d,bundleName=%{public}s",
376 IPCSkeleton::GetCallingPid(), bundleName.c_str());
377
378 int32_t result = KillApplication(bundleName);
379 reply.WriteInt32(result);
380 return NO_ERROR;
381 }
382
HandleForceKillApplication(MessageParcel & data,MessageParcel & reply)383 ErrCode AmsMgrStub::HandleForceKillApplication(MessageParcel &data, MessageParcel &reply)
384 {
385 HITRACE_METER(HITRACE_TAG_APP);
386 std::string bundleName = data.ReadString();
387 int userId = data.ReadInt32();
388 int appIndex = data.ReadInt32();
389
390 TAG_LOGI(AAFwkTag::APPMGR, "bundleName = %{public}s,userId=%{public}d,appIndex=%{public}d",
391 bundleName.c_str(), userId, appIndex);
392
393 int32_t result = ForceKillApplication(bundleName, userId, appIndex);
394 reply.WriteInt32(result);
395 return NO_ERROR;
396 }
397
HandleKillProcessesByAccessTokenId(MessageParcel & data,MessageParcel & reply)398 ErrCode AmsMgrStub::HandleKillProcessesByAccessTokenId(MessageParcel &data, MessageParcel &reply)
399 {
400 HITRACE_METER(HITRACE_TAG_APP);
401 int accessTokenId = data.ReadInt32();
402
403 TAG_LOGI(AAFwkTag::APPMGR, "accessTokenId=%{public}d", accessTokenId);
404
405 int32_t result = KillProcessesByAccessTokenId(accessTokenId);
406 reply.WriteInt32(result);
407 return NO_ERROR;
408 }
409
HandleKillApplicationByUid(MessageParcel & data,MessageParcel & reply)410 ErrCode AmsMgrStub::HandleKillApplicationByUid(MessageParcel &data, MessageParcel &reply)
411 {
412 HITRACE_METER(HITRACE_TAG_APP);
413 std::string bundleName = data.ReadString();
414 int uid = data.ReadInt32();
415 std::string reason = data.ReadString();
416 TAG_LOGW(AAFwkTag::APPMGR, "KillApplicationByUid,callingPid=%{public}d", IPCSkeleton::GetCallingPid());
417 int32_t result = KillApplicationByUid(bundleName, uid, reason);
418 reply.WriteInt32(result);
419 return NO_ERROR;
420 }
421
HandleKillApplicationSelf(MessageParcel & data,MessageParcel & reply)422 ErrCode AmsMgrStub::HandleKillApplicationSelf(MessageParcel &data, MessageParcel &reply)
423 {
424 HITRACE_METER(HITRACE_TAG_APP);
425 TAG_LOGW(AAFwkTag::APPMGR, "KillApplicationSelf,callingPid=%{public}d", IPCSkeleton::GetCallingPid());
426 std::string reason = data.ReadString();
427 int32_t result = KillApplicationSelf(reason);
428 if (!reply.WriteInt32(result)) {
429 TAG_LOGE(AAFwkTag::APPMGR, "result write failed.");
430 return ERR_INVALID_VALUE;
431 }
432 return NO_ERROR;
433 }
434
HandleAbilityAttachTimeOut(MessageParcel & data,MessageParcel & reply)435 int32_t AmsMgrStub::HandleAbilityAttachTimeOut(MessageParcel &data, MessageParcel &reply)
436 {
437 HITRACE_METER(HITRACE_TAG_APP);
438 sptr<IRemoteObject> token = data.ReadRemoteObject();
439 AbilityAttachTimeOut(token);
440 return NO_ERROR;
441 }
442
HandlePrepareTerminate(MessageParcel & data,MessageParcel & reply)443 int32_t AmsMgrStub::HandlePrepareTerminate(MessageParcel &data, MessageParcel &reply)
444 {
445 sptr<IRemoteObject> token = data.ReadRemoteObject();
446 bool clearMissionFlag = data.ReadBool();
447 PrepareTerminate(token, clearMissionFlag);
448 return NO_ERROR;
449 }
450
UpdateExtensionState(const sptr<IRemoteObject> & token,const ExtensionState state)451 void AmsMgrStub::UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state)
452 {}
453
HandleGetRunningProcessInfoByToken(MessageParcel & data,MessageParcel & reply)454 int32_t AmsMgrStub::HandleGetRunningProcessInfoByToken(MessageParcel &data, MessageParcel &reply)
455 {
456 RunningProcessInfo processInfo;
457 auto token = data.ReadRemoteObject();
458 GetRunningProcessInfoByToken(token, processInfo);
459 if (reply.WriteParcelable(&processInfo)) {
460 TAG_LOGE(AAFwkTag::APPMGR, "process info write failed.");
461 return ERR_INVALID_VALUE;
462 }
463 return NO_ERROR;
464 }
465
HandleSetAbilityForegroundingFlagToAppRecord(MessageParcel & data,MessageParcel & reply)466 int32_t AmsMgrStub::HandleSetAbilityForegroundingFlagToAppRecord(MessageParcel &data, MessageParcel &reply)
467 {
468 RunningProcessInfo processInfo;
469 auto pid = static_cast<pid_t>(data.ReadInt32());
470 SetAbilityForegroundingFlagToAppRecord(pid);
471 return NO_ERROR;
472 }
473
HandleStartSpecifiedAbility(MessageParcel & data,MessageParcel & reply)474 int32_t AmsMgrStub::HandleStartSpecifiedAbility(MessageParcel &data, MessageParcel &reply)
475 {
476 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
477 if (want == nullptr) {
478 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
479 return ERR_INVALID_VALUE;
480 }
481
482 AbilityInfo *abilityInfo = data.ReadParcelable<AbilityInfo>();
483 if (abilityInfo == nullptr) {
484 TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo is nullptr.");
485 delete want;
486 return ERR_INVALID_VALUE;
487 }
488 StartSpecifiedAbility(*want, *abilityInfo, data.ReadInt32());
489 delete want;
490 delete abilityInfo;
491 return NO_ERROR;
492 }
493
HandleRegisterStartSpecifiedAbilityResponse(MessageParcel & data,MessageParcel & reply)494 int32_t AmsMgrStub::HandleRegisterStartSpecifiedAbilityResponse(MessageParcel &data, MessageParcel &reply)
495 {
496 sptr<IRemoteObject> obj = data.ReadRemoteObject();
497 sptr<IStartSpecifiedAbilityResponse> response = iface_cast<IStartSpecifiedAbilityResponse>(obj);
498 RegisterStartSpecifiedAbilityResponse(response);
499 return NO_ERROR;
500 }
501
HandleGetApplicationInfoByProcessID(MessageParcel & data,MessageParcel & reply)502 int32_t AmsMgrStub::HandleGetApplicationInfoByProcessID(MessageParcel &data, MessageParcel &reply)
503 {
504 HITRACE_METER(HITRACE_TAG_APP);
505 int32_t pid = data.ReadInt32();
506 AppExecFwk::ApplicationInfo application;
507 bool debug;
508 int32_t result = GetApplicationInfoByProcessID(pid, application, debug);
509 if (!reply.WriteInt32(result)) {
510 TAG_LOGE(AAFwkTag::APPMGR, "write result error.");
511 return ERR_INVALID_VALUE;
512 }
513 if (!reply.WriteParcelable(&application)) {
514 TAG_LOGE(AAFwkTag::APPMGR, "write application info failed");
515 return ERR_INVALID_VALUE;
516 }
517 if (!reply.WriteBool(debug)) {
518 TAG_LOGE(AAFwkTag::APPMGR, "write debug info failed");
519 return ERR_INVALID_VALUE;
520 }
521 return NO_ERROR;
522 }
523
HandleNotifyAppMgrRecordExitReason(MessageParcel & data,MessageParcel & reply)524 int32_t AmsMgrStub::HandleNotifyAppMgrRecordExitReason(MessageParcel &data, MessageParcel &reply)
525 {
526 TAG_LOGD(AAFwkTag::APPMGR, "called");
527 int32_t pid = data.ReadInt32();
528 int32_t reason = data.ReadInt32();
529 std::string exitMsg = Str16ToStr8(data.ReadString16());
530 int32_t result = NotifyAppMgrRecordExitReason(pid, reason, exitMsg);
531 if (!reply.WriteInt32(result)) {
532 TAG_LOGE(AAFwkTag::APPMGR, "Write result failed.");
533 return IPC_PROXY_ERR;
534 }
535 return NO_ERROR;
536 }
537
HandleUpdateApplicationInfoInstalled(MessageParcel & data,MessageParcel & reply)538 int32_t AmsMgrStub::HandleUpdateApplicationInfoInstalled(MessageParcel &data, MessageParcel &reply)
539 {
540 HITRACE_METER(HITRACE_TAG_APP);
541 std::string bundleName = data.ReadString();
542 int uid = data.ReadInt32();
543 int32_t result = UpdateApplicationInfoInstalled(bundleName, uid);
544 reply.WriteInt32(result);
545 return NO_ERROR;
546 }
547
HandleSetCurrentUserId(MessageParcel & data,MessageParcel & reply)548 int32_t AmsMgrStub::HandleSetCurrentUserId(MessageParcel &data, MessageParcel &reply)
549 {
550 int32_t userId = data.ReadInt32();
551 SetCurrentUserId(userId);
552 return NO_ERROR;
553 }
554
HandleSetEnableStartProcessFlagByUserId(MessageParcel & data,MessageParcel & reply)555 int32_t AmsMgrStub::HandleSetEnableStartProcessFlagByUserId(MessageParcel &data, MessageParcel &reply)
556 {
557 int32_t userId = data.ReadInt32();
558 bool enableStartProcess = data.ReadBool();
559 SetEnableStartProcessFlagByUserId(userId, enableStartProcess);
560 return NO_ERROR;
561 }
562
HandleGetBundleNameByPid(MessageParcel & data,MessageParcel & reply)563 int32_t AmsMgrStub::HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply)
564 {
565 int32_t pid = data.ReadInt32();
566 std::string bundleName;
567 int32_t uid;
568 GetBundleNameByPid(pid, bundleName, uid);
569
570 reply.WriteString(bundleName);
571 reply.WriteInt32(uid);
572 return NO_ERROR;
573 }
574
HandleRegisterAppDebugListener(MessageParcel & data,MessageParcel & reply)575 int32_t AmsMgrStub::HandleRegisterAppDebugListener(MessageParcel &data, MessageParcel &reply)
576 {
577 TAG_LOGD(AAFwkTag::APPMGR, "called");
578 auto appDebugLister = iface_cast<IAppDebugListener>(data.ReadRemoteObject());
579 if (appDebugLister == nullptr) {
580 TAG_LOGE(AAFwkTag::APPMGR, "App debug lister is null.");
581 return ERR_INVALID_VALUE;
582 }
583
584 auto result = RegisterAppDebugListener(appDebugLister);
585 if (!reply.WriteInt32(result)) {
586 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
587 return ERR_INVALID_VALUE;
588 }
589 return NO_ERROR;
590 }
591
HandleUnregisterAppDebugListener(MessageParcel & data,MessageParcel & reply)592 int32_t AmsMgrStub::HandleUnregisterAppDebugListener(MessageParcel &data, MessageParcel &reply)
593 {
594 TAG_LOGD(AAFwkTag::APPMGR, "called");
595 auto appDebugLister = iface_cast<IAppDebugListener>(data.ReadRemoteObject());
596 if (appDebugLister == nullptr) {
597 TAG_LOGE(AAFwkTag::APPMGR, "App debug lister is nullptr.");
598 return ERR_INVALID_VALUE;
599 }
600
601 auto result = UnregisterAppDebugListener(appDebugLister);
602 if (!reply.WriteInt32(result)) {
603 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
604 return ERR_INVALID_VALUE;
605 }
606 return NO_ERROR;
607 }
608
HandleAttachAppDebug(MessageParcel & data,MessageParcel & reply)609 int32_t AmsMgrStub::HandleAttachAppDebug(MessageParcel &data, MessageParcel &reply)
610 {
611 TAG_LOGD(AAFwkTag::APPMGR, "called");
612 auto bundleName = data.ReadString();
613 if (bundleName.empty()) {
614 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
615 return ERR_INVALID_VALUE;
616 }
617
618 auto result = AttachAppDebug(bundleName);
619 if (!reply.WriteInt32(result)) {
620 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
621 return ERR_INVALID_VALUE;
622 }
623 return NO_ERROR;
624 }
625
HandleDetachAppDebug(MessageParcel & data,MessageParcel & reply)626 int32_t AmsMgrStub::HandleDetachAppDebug(MessageParcel &data, MessageParcel &reply)
627 {
628 TAG_LOGD(AAFwkTag::APPMGR, "called");
629 auto bundleName = data.ReadString();
630 if (bundleName.empty()) {
631 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
632 return ERR_INVALID_VALUE;
633 }
634
635 auto result = DetachAppDebug(bundleName);
636 if (!reply.WriteInt32(result)) {
637 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
638 return ERR_INVALID_VALUE;
639 }
640 return NO_ERROR;
641 }
642
HandleSetAppWaitingDebug(MessageParcel & data,MessageParcel & reply)643 int32_t AmsMgrStub::HandleSetAppWaitingDebug(MessageParcel &data, MessageParcel &reply)
644 {
645 TAG_LOGD(AAFwkTag::APPMGR, "called");
646 auto bundleName = data.ReadString();
647 if (bundleName.empty()) {
648 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
649 return ERR_INVALID_VALUE;
650 }
651 auto isPersist = data.ReadBool();
652 auto result = SetAppWaitingDebug(bundleName, isPersist);
653 if (!reply.WriteInt32(result)) {
654 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
655 return ERR_INVALID_VALUE;
656 }
657 return NO_ERROR;
658 }
659
HandleCancelAppWaitingDebug(MessageParcel & data,MessageParcel & reply)660 int32_t AmsMgrStub::HandleCancelAppWaitingDebug(MessageParcel &data, MessageParcel &reply)
661 {
662 TAG_LOGD(AAFwkTag::APPMGR, "called");
663 auto result = CancelAppWaitingDebug();
664 if (!reply.WriteInt32(result)) {
665 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
666 return ERR_INVALID_VALUE;
667 }
668 return NO_ERROR;
669 }
670
HandleGetWaitingDebugApp(MessageParcel & data,MessageParcel & reply)671 int32_t AmsMgrStub::HandleGetWaitingDebugApp(MessageParcel &data, MessageParcel &reply)
672 {
673 TAG_LOGD(AAFwkTag::APPMGR, "called");
674 std::vector<std::string> debugInfoList;
675 auto result = GetWaitingDebugApp(debugInfoList);
676 if (!reply.WriteInt32(result)) {
677 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
678 return ERR_INVALID_VALUE;
679 }
680
681 int32_t listSize = static_cast<int32_t>(debugInfoList.size());
682 if (listSize > MAX_APP_DEBUG_COUNT) {
683 TAG_LOGE(AAFwkTag::APPMGR, "Max app debug count is %{public}d.", listSize);
684 return ERR_INVALID_VALUE;
685 }
686
687 if (!reply.WriteInt32(listSize)) {
688 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write list size.");
689 return ERR_INVALID_VALUE;
690 }
691
692 if (!reply.WriteStringVector(debugInfoList)) {
693 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write string vector debug info list.");
694 return ERR_INVALID_VALUE;
695 }
696 return NO_ERROR;
697 }
698
HandleIsWaitingDebugApp(MessageParcel & data,MessageParcel & reply)699 int32_t AmsMgrStub::HandleIsWaitingDebugApp(MessageParcel &data, MessageParcel &reply)
700 {
701 TAG_LOGD(AAFwkTag::APPMGR, "called");
702 auto bundleName = data.ReadString();
703 if (bundleName.empty()) {
704 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
705 return ERR_INVALID_VALUE;
706 }
707
708 auto result = IsWaitingDebugApp(bundleName);
709 if (!reply.WriteBool(result)) {
710 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
711 return ERR_INVALID_VALUE;
712 }
713 return NO_ERROR;
714 }
715
HandleSetKeepAliveEnableState(MessageParcel & data,MessageParcel & reply)716 int32_t AmsMgrStub::HandleSetKeepAliveEnableState(MessageParcel &data, MessageParcel &reply)
717 {
718 TAG_LOGD(AAFwkTag::APPMGR, "called");
719 auto bundleName = data.ReadString();
720 auto enable = data.ReadBool();
721 auto uid = data.ReadInt32();
722 SetKeepAliveEnableState(bundleName, enable, uid);
723 return NO_ERROR;
724 }
725
HandleClearNonPersistWaitingDebugFlag(MessageParcel & data,MessageParcel & reply)726 int32_t AmsMgrStub::HandleClearNonPersistWaitingDebugFlag(MessageParcel &data, MessageParcel &reply)
727 {
728 TAG_LOGD(AAFwkTag::APPMGR, "called");
729 ClearNonPersistWaitingDebugFlag();
730 return NO_ERROR;
731 }
732
HandleRegisterAbilityDebugResponse(MessageParcel & data,MessageParcel & reply)733 int32_t AmsMgrStub::HandleRegisterAbilityDebugResponse(MessageParcel &data, MessageParcel &reply)
734 {
735 TAG_LOGD(AAFwkTag::APPMGR, "called");
736 auto response = iface_cast<IAbilityDebugResponse>(data.ReadRemoteObject());
737 if (response == nullptr) {
738 TAG_LOGE(AAFwkTag::APPMGR, "Response is nullptr.");
739 return ERR_INVALID_VALUE;
740 }
741
742 auto result = RegisterAbilityDebugResponse(response);
743 if (!reply.WriteInt32(result)) {
744 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
745 return ERR_INVALID_VALUE;
746 }
747 return NO_ERROR;
748 }
749
HandleIsAttachDebug(MessageParcel & data,MessageParcel & reply)750 int32_t AmsMgrStub::HandleIsAttachDebug(MessageParcel &data, MessageParcel &reply)
751 {
752 TAG_LOGD(AAFwkTag::APPMGR, "called");
753 auto bundleName = data.ReadString();
754 if (bundleName.empty()) {
755 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
756 return ERR_INVALID_VALUE;
757 }
758
759 auto result = IsAttachDebug(bundleName);
760 if (!reply.WriteBool(result)) {
761 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
762 return ERR_INVALID_VALUE;
763 }
764 return NO_ERROR;
765 }
766
HandleClearProcessByToken(MessageParcel & data,MessageParcel & reply)767 int32_t AmsMgrStub::HandleClearProcessByToken(MessageParcel &data, MessageParcel &reply)
768 {
769 HITRACE_METER(HITRACE_TAG_APP);
770 sptr<IRemoteObject> token = data.ReadRemoteObject();
771 ClearProcessByToken(token);
772 return NO_ERROR;
773 }
774
HandleIsMemorySizeSufficent(MessageParcel & data,MessageParcel & reply)775 int32_t AmsMgrStub::HandleIsMemorySizeSufficent(MessageParcel &data, MessageParcel &reply)
776 {
777 auto result = IsMemorySizeSufficent();
778 if (!reply.WriteBool(result)) {
779 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
780 return ERR_INVALID_VALUE;
781 }
782 return NO_ERROR;
783 }
784
HandleAttachedToStatusBar(MessageParcel & data,MessageParcel & reply)785 ErrCode AmsMgrStub::HandleAttachedToStatusBar(MessageParcel &data, MessageParcel &reply)
786 {
787 HITRACE_METER(HITRACE_TAG_APP);
788 sptr<IRemoteObject> token = data.ReadRemoteObject();
789 AttachedToStatusBar(token);
790 return NO_ERROR;
791 }
792
HandleBlockProcessCacheByPids(MessageParcel & data,MessageParcel & reply)793 ErrCode AmsMgrStub::HandleBlockProcessCacheByPids(MessageParcel &data, MessageParcel &reply)
794 {
795 HITRACE_METER(HITRACE_TAG_APP);
796 auto size = data.ReadUint32();
797 if (size == 0 || size > MAX_KILL_PROCESS_PID_COUNT) {
798 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size.");
799 return ERR_INVALID_VALUE;
800 }
801 std::vector<int32_t> pids;
802 for (uint32_t i = 0; i < size; i++) {
803 pids.emplace_back(data.ReadInt32());
804 }
805
806 BlockProcessCacheByPids(pids);
807 return NO_ERROR;
808 }
809
HandleIsKilledForUpgradeWeb(MessageParcel & data,MessageParcel & reply)810 int32_t AmsMgrStub::HandleIsKilledForUpgradeWeb(MessageParcel &data, MessageParcel &reply)
811 {
812 TAG_LOGD(AAFwkTag::APPMGR, "Called.");
813 auto bundleName = data.ReadString();
814 if (bundleName.empty()) {
815 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
816 return ERR_INVALID_VALUE;
817 }
818
819 auto result = IsKilledForUpgradeWeb(bundleName);
820 if (!reply.WriteBool(result)) {
821 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
822 return ERR_INVALID_VALUE;
823 }
824 return NO_ERROR;
825 }
826
HandleCleanAbilityByUserRequest(MessageParcel & data,MessageParcel & reply)827 ErrCode AmsMgrStub::HandleCleanAbilityByUserRequest(MessageParcel &data, MessageParcel &reply)
828 {
829 HITRACE_METER(HITRACE_TAG_APP);
830 sptr<IRemoteObject> token = data.ReadRemoteObject();
831 auto result = CleanAbilityByUserRequest(token);
832 if (!reply.WriteBool(result)) {
833 TAG_LOGE(AAFwkTag::APPMGR, "fail to write the result.");
834 return ERR_INVALID_VALUE;
835 }
836 return NO_ERROR;
837 }
838
HandleIsProcessContainsOnlyUIAbility(MessageParcel & data,MessageParcel & reply)839 int32_t AmsMgrStub::HandleIsProcessContainsOnlyUIAbility(MessageParcel &data, MessageParcel &reply)
840 {
841 auto pid = data.ReadUint32();
842
843 auto result = IsProcessContainsOnlyUIAbility(pid);
844 if (!reply.WriteBool(result)) {
845 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result in HandleIsProcessContainsOnlyUIAbility.");
846 return ERR_INVALID_VALUE;
847 }
848 return NO_ERROR;
849 }
850
HandleIsProcessAttached(MessageParcel & data,MessageParcel & reply)851 int32_t AmsMgrStub::HandleIsProcessAttached(MessageParcel &data, MessageParcel &reply)
852 {
853 HITRACE_METER(HITRACE_TAG_APP);
854 sptr<IRemoteObject> token = data.ReadRemoteObject();
855 auto isAttached = IsProcessAttached(token);
856 if (!reply.WriteBool(isAttached)) {
857 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result");
858 return ERR_INVALID_VALUE;
859 }
860 return NO_ERROR;
861 }
862 } // namespace AppExecFwk
863 } // namespace OHOS
864