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 case static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESSES_IN_BATCH):
219 return HandleKillProcessesInBatch(data, reply);
220 case static_cast<uint32_t>(IAmsMgr::Message::SEND_APP_SPAWN_UNINSTALL_DEBUG_HAP_MSG):
221 return HandleSendAppSpawnUninstallDebugHapMsg(data);
222 }
223 return AAFwk::ERR_CODE_NOT_EXIST;
224 }
225
HandleLoadAbility(MessageParcel & data,MessageParcel & reply)226 ErrCode AmsMgrStub::HandleLoadAbility(MessageParcel &data, MessageParcel &reply)
227 {
228 HITRACE_METER(HITRACE_TAG_APP);
229 std::shared_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
230 if (!abilityInfo) {
231 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<AbilityInfo> failed");
232 return ERR_APPEXECFWK_PARCEL_ERROR;
233 }
234
235 std::shared_ptr<ApplicationInfo> appInfo(data.ReadParcelable<ApplicationInfo>());
236 if (!appInfo) {
237 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<ApplicationInfo> failed");
238 return ERR_APPEXECFWK_PARCEL_ERROR;
239 }
240
241 std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
242 if (!want) {
243 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable want failed");
244 return ERR_APPEXECFWK_PARCEL_ERROR;
245 }
246 std::shared_ptr<AbilityRuntime::LoadParam> loadParam(data.ReadParcelable<AbilityRuntime::LoadParam>());
247 if (!loadParam) {
248 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable loadParam failed");
249 return ERR_APPEXECFWK_PARCEL_ERROR;
250 }
251
252 LoadAbility(abilityInfo, appInfo, want, loadParam);
253 return NO_ERROR;
254 }
255
HandleTerminateAbility(MessageParcel & data,MessageParcel & reply)256 ErrCode AmsMgrStub::HandleTerminateAbility(MessageParcel &data, MessageParcel &reply)
257 {
258 HITRACE_METER(HITRACE_TAG_APP);
259 sptr<IRemoteObject> token = data.ReadRemoteObject();
260 bool clearMissionFlag = data.ReadBool();
261 TerminateAbility(token, clearMissionFlag);
262 return NO_ERROR;
263 }
264
HandleUpdateAbilityState(MessageParcel & data,MessageParcel & reply)265 ErrCode AmsMgrStub::HandleUpdateAbilityState(MessageParcel &data, MessageParcel &reply)
266 {
267 HITRACE_METER(HITRACE_TAG_APP);
268 sptr<IRemoteObject> token = data.ReadRemoteObject();
269 int32_t state = data.ReadInt32();
270 UpdateAbilityState(token, static_cast<AbilityState>(state));
271 return NO_ERROR;
272 }
273
HandleUpdateExtensionState(MessageParcel & data,MessageParcel & reply)274 ErrCode AmsMgrStub::HandleUpdateExtensionState(MessageParcel &data, MessageParcel &reply)
275 {
276 sptr<IRemoteObject> token = data.ReadRemoteObject();
277 int32_t state = data.ReadInt32();
278 UpdateExtensionState(token, static_cast<ExtensionState>(state));
279 return NO_ERROR;
280 }
281
HandleRegisterAppStateCallback(MessageParcel & data,MessageParcel & reply)282 ErrCode AmsMgrStub::HandleRegisterAppStateCallback(MessageParcel &data, MessageParcel &reply)
283 {
284 HITRACE_METER(HITRACE_TAG_APP);
285 sptr<IAppStateCallback> callback = nullptr;
286 if (data.ReadBool()) {
287 sptr<IRemoteObject> obj = data.ReadRemoteObject();
288 callback = iface_cast<IAppStateCallback>(obj);
289 }
290 RegisterAppStateCallback(callback);
291 return NO_ERROR;
292 }
293
HandleAbilityBehaviorAnalysis(MessageParcel & data,MessageParcel & reply)294 ErrCode AmsMgrStub::HandleAbilityBehaviorAnalysis(MessageParcel &data, MessageParcel &reply)
295 {
296 HITRACE_METER(HITRACE_TAG_APP);
297 sptr<IRemoteObject> token = data.ReadRemoteObject();
298 sptr<IRemoteObject> preToke = nullptr;
299 if (data.ReadBool()) {
300 preToke = data.ReadRemoteObject();
301 }
302 int32_t visibility = data.ReadInt32();
303 int32_t perceptibility = data.ReadInt32();
304 int32_t connectionState = data.ReadInt32();
305
306 AbilityBehaviorAnalysis(token, preToke, visibility, perceptibility, connectionState);
307 return NO_ERROR;
308 }
309
HandleKillProcessByAbilityToken(MessageParcel & data,MessageParcel & reply)310 ErrCode AmsMgrStub::HandleKillProcessByAbilityToken(MessageParcel &data, MessageParcel &reply)
311 {
312 HITRACE_METER(HITRACE_TAG_APP);
313 sptr<IRemoteObject> token = data.ReadRemoteObject();
314
315 KillProcessByAbilityToken(token);
316 return NO_ERROR;
317 }
318
HandleKillProcessesByUserId(MessageParcel & data,MessageParcel & reply)319 ErrCode AmsMgrStub::HandleKillProcessesByUserId(MessageParcel &data, MessageParcel &reply)
320 {
321 HITRACE_METER(HITRACE_TAG_APP);
322 int32_t userId = data.ReadInt32();
323
324 KillProcessesByUserId(userId);
325 return NO_ERROR;
326 }
327
HandleKillProcessesByPids(MessageParcel & data,MessageParcel & reply)328 ErrCode AmsMgrStub::HandleKillProcessesByPids(MessageParcel &data, MessageParcel &reply)
329 {
330 HITRACE_METER(HITRACE_TAG_APP);
331 auto size = data.ReadUint32();
332 if (size == 0 || size > MAX_KILL_PROCESS_PID_COUNT) {
333 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size");
334 return ERR_INVALID_VALUE;
335 }
336 std::vector<int32_t> pids;
337 for (uint32_t i = 0; i < size; i++) {
338 pids.emplace_back(data.ReadInt32());
339 }
340
341 KillProcessesByPids(pids);
342 return NO_ERROR;
343 }
344
HandleAttachPidToParent(MessageParcel & data,MessageParcel & reply)345 ErrCode AmsMgrStub::HandleAttachPidToParent(MessageParcel &data, MessageParcel &reply)
346 {
347 HITRACE_METER(HITRACE_TAG_APP);
348 sptr<IRemoteObject> token = data.ReadRemoteObject();
349 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
350 AttachPidToParent(token, callerToken);
351 return NO_ERROR;
352 }
353
HandleKillProcessWithAccount(MessageParcel & data,MessageParcel & reply)354 ErrCode AmsMgrStub::HandleKillProcessWithAccount(MessageParcel &data, MessageParcel &reply)
355 {
356 TAG_LOGI(AAFwkTag::APPMGR, "enter");
357
358 HITRACE_METER(HITRACE_TAG_APP);
359
360 std::string bundleName = data.ReadString();
361 int accountId = data.ReadInt32();
362 bool clearPageStack = data.ReadBool();
363
364 TAG_LOGI(AAFwkTag::APPMGR,
365 "bundleName = %{public}s, accountId = %{public}d, clearPageStack = %{public}d",
366 bundleName.c_str(), accountId, clearPageStack);
367
368 int32_t result = KillProcessWithAccount(bundleName, accountId, clearPageStack);
369 reply.WriteInt32(result);
370
371 TAG_LOGI(AAFwkTag::APPMGR, "end");
372
373 return NO_ERROR;
374 }
375
HandleKillProcessesInBatch(MessageParcel & data,MessageParcel & reply)376 ErrCode AmsMgrStub::HandleKillProcessesInBatch(MessageParcel &data, MessageParcel &reply)
377 {
378 TAG_LOGI(AAFwkTag::APPMGR, "enter");
379
380 HITRACE_METER(HITRACE_TAG_APP);
381
382 auto size = data.ReadUint32();
383 TAG_LOGI(AAFwkTag::APPMGR, "pids.size=%{public}d", size);
384 if (size == 0 || size > MAX_KILL_PROCESS_PID_COUNT) {
385 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size");
386 return ERR_INVALID_VALUE;
387 }
388 std::vector<int32_t> pids;
389 for (uint32_t i = 0; i < size; i++) {
390 pids.emplace_back(data.ReadInt32());
391 }
392
393 int32_t result = KillProcessesInBatch(pids);
394 reply.WriteInt32(result);
395
396 TAG_LOGI(AAFwkTag::APPMGR, "end");
397
398 return NO_ERROR;
399 }
400
HandleKillApplication(MessageParcel & data,MessageParcel & reply)401 ErrCode AmsMgrStub::HandleKillApplication(MessageParcel &data, MessageParcel &reply)
402 {
403 HITRACE_METER(HITRACE_TAG_APP);
404 std::string bundleName = data.ReadString();
405 bool clearPageStack = data.ReadBool();
406
407 TAG_LOGI(AAFwkTag::APPMGR, "bundleName = %{public}s, clearPageStack = %{public}d",
408 bundleName.c_str(), clearPageStack);
409
410 int32_t result = KillApplication(bundleName, clearPageStack);
411 reply.WriteInt32(result);
412 return NO_ERROR;
413 }
414
HandleForceKillApplication(MessageParcel & data,MessageParcel & reply)415 ErrCode AmsMgrStub::HandleForceKillApplication(MessageParcel &data, MessageParcel &reply)
416 {
417 HITRACE_METER(HITRACE_TAG_APP);
418 std::string bundleName = data.ReadString();
419 int userId = data.ReadInt32();
420 int appIndex = data.ReadInt32();
421
422 TAG_LOGI(AAFwkTag::APPMGR, "bundleName = %{public}s,userId=%{public}d,appIndex=%{public}d",
423 bundleName.c_str(), userId, appIndex);
424
425 int32_t result = ForceKillApplication(bundleName, userId, appIndex);
426 reply.WriteInt32(result);
427 return NO_ERROR;
428 }
429
HandleKillProcessesByAccessTokenId(MessageParcel & data,MessageParcel & reply)430 ErrCode AmsMgrStub::HandleKillProcessesByAccessTokenId(MessageParcel &data, MessageParcel &reply)
431 {
432 HITRACE_METER(HITRACE_TAG_APP);
433 int accessTokenId = data.ReadInt32();
434
435 TAG_LOGI(AAFwkTag::APPMGR, "accessTokenId=%{public}d", accessTokenId);
436
437 int32_t result = KillProcessesByAccessTokenId(accessTokenId);
438 reply.WriteInt32(result);
439 return NO_ERROR;
440 }
441
HandleKillApplicationByUid(MessageParcel & data,MessageParcel & reply)442 ErrCode AmsMgrStub::HandleKillApplicationByUid(MessageParcel &data, MessageParcel &reply)
443 {
444 HITRACE_METER(HITRACE_TAG_APP);
445 std::string bundleName = data.ReadString();
446 int uid = data.ReadInt32();
447 std::string reason = data.ReadString();
448 TAG_LOGW(AAFwkTag::APPMGR, "KillApplicationByUid,callingPid=%{public}d", IPCSkeleton::GetCallingPid());
449 int32_t result = KillApplicationByUid(bundleName, uid, reason);
450 reply.WriteInt32(result);
451 return NO_ERROR;
452 }
453
HandleKillApplicationSelf(MessageParcel & data,MessageParcel & reply)454 ErrCode AmsMgrStub::HandleKillApplicationSelf(MessageParcel &data, MessageParcel &reply)
455 {
456 HITRACE_METER(HITRACE_TAG_APP);
457 TAG_LOGW(AAFwkTag::APPMGR, "KillApplicationSelf,callingPid=%{public}d", IPCSkeleton::GetCallingPid());
458 bool clearPageStack = data.ReadBool();
459 std::string reason = data.ReadString();
460 int32_t result = KillApplicationSelf(clearPageStack, reason);
461 if (!reply.WriteInt32(result)) {
462 TAG_LOGE(AAFwkTag::APPMGR, "result write failed.");
463 return ERR_INVALID_VALUE;
464 }
465 return NO_ERROR;
466 }
467
HandleAbilityAttachTimeOut(MessageParcel & data,MessageParcel & reply)468 int32_t AmsMgrStub::HandleAbilityAttachTimeOut(MessageParcel &data, MessageParcel &reply)
469 {
470 HITRACE_METER(HITRACE_TAG_APP);
471 sptr<IRemoteObject> token = data.ReadRemoteObject();
472 AbilityAttachTimeOut(token);
473 return NO_ERROR;
474 }
475
HandlePrepareTerminate(MessageParcel & data,MessageParcel & reply)476 int32_t AmsMgrStub::HandlePrepareTerminate(MessageParcel &data, MessageParcel &reply)
477 {
478 sptr<IRemoteObject> token = data.ReadRemoteObject();
479 bool clearMissionFlag = data.ReadBool();
480 PrepareTerminate(token, clearMissionFlag);
481 return NO_ERROR;
482 }
483
UpdateExtensionState(const sptr<IRemoteObject> & token,const ExtensionState state)484 void AmsMgrStub::UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state)
485 {}
486
HandleGetRunningProcessInfoByToken(MessageParcel & data,MessageParcel & reply)487 int32_t AmsMgrStub::HandleGetRunningProcessInfoByToken(MessageParcel &data, MessageParcel &reply)
488 {
489 RunningProcessInfo processInfo;
490 auto token = data.ReadRemoteObject();
491 GetRunningProcessInfoByToken(token, processInfo);
492 if (reply.WriteParcelable(&processInfo)) {
493 TAG_LOGE(AAFwkTag::APPMGR, "process info write failed.");
494 return ERR_INVALID_VALUE;
495 }
496 return NO_ERROR;
497 }
498
HandleSetAbilityForegroundingFlagToAppRecord(MessageParcel & data,MessageParcel & reply)499 int32_t AmsMgrStub::HandleSetAbilityForegroundingFlagToAppRecord(MessageParcel &data, MessageParcel &reply)
500 {
501 RunningProcessInfo processInfo;
502 auto pid = static_cast<pid_t>(data.ReadInt32());
503 SetAbilityForegroundingFlagToAppRecord(pid);
504 return NO_ERROR;
505 }
506
HandleStartSpecifiedAbility(MessageParcel & data,MessageParcel & reply)507 int32_t AmsMgrStub::HandleStartSpecifiedAbility(MessageParcel &data, MessageParcel &reply)
508 {
509 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
510 if (want == nullptr) {
511 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
512 return ERR_INVALID_VALUE;
513 }
514
515 AbilityInfo *abilityInfo = data.ReadParcelable<AbilityInfo>();
516 if (abilityInfo == nullptr) {
517 TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo is nullptr.");
518 delete want;
519 return ERR_INVALID_VALUE;
520 }
521 StartSpecifiedAbility(*want, *abilityInfo, data.ReadInt32());
522 delete want;
523 delete abilityInfo;
524 return NO_ERROR;
525 }
526
HandleRegisterStartSpecifiedAbilityResponse(MessageParcel & data,MessageParcel & reply)527 int32_t AmsMgrStub::HandleRegisterStartSpecifiedAbilityResponse(MessageParcel &data, MessageParcel &reply)
528 {
529 sptr<IRemoteObject> obj = data.ReadRemoteObject();
530 sptr<IStartSpecifiedAbilityResponse> response = iface_cast<IStartSpecifiedAbilityResponse>(obj);
531 RegisterStartSpecifiedAbilityResponse(response);
532 return NO_ERROR;
533 }
534
HandleGetApplicationInfoByProcessID(MessageParcel & data,MessageParcel & reply)535 int32_t AmsMgrStub::HandleGetApplicationInfoByProcessID(MessageParcel &data, MessageParcel &reply)
536 {
537 HITRACE_METER(HITRACE_TAG_APP);
538 int32_t pid = data.ReadInt32();
539 AppExecFwk::ApplicationInfo application;
540 bool debug;
541 int32_t result = GetApplicationInfoByProcessID(pid, application, debug);
542 if (!reply.WriteInt32(result)) {
543 TAG_LOGE(AAFwkTag::APPMGR, "write result error.");
544 return ERR_INVALID_VALUE;
545 }
546 if (!reply.WriteParcelable(&application)) {
547 TAG_LOGE(AAFwkTag::APPMGR, "write application info failed");
548 return ERR_INVALID_VALUE;
549 }
550 if (!reply.WriteBool(debug)) {
551 TAG_LOGE(AAFwkTag::APPMGR, "write debug info failed");
552 return ERR_INVALID_VALUE;
553 }
554 return NO_ERROR;
555 }
556
HandleNotifyAppMgrRecordExitReason(MessageParcel & data,MessageParcel & reply)557 int32_t AmsMgrStub::HandleNotifyAppMgrRecordExitReason(MessageParcel &data, MessageParcel &reply)
558 {
559 TAG_LOGD(AAFwkTag::APPMGR, "called");
560 int32_t pid = data.ReadInt32();
561 int32_t reason = data.ReadInt32();
562 std::string exitMsg = Str16ToStr8(data.ReadString16());
563 int32_t result = NotifyAppMgrRecordExitReason(pid, reason, exitMsg);
564 if (!reply.WriteInt32(result)) {
565 TAG_LOGE(AAFwkTag::APPMGR, "Write result failed.");
566 return IPC_PROXY_ERR;
567 }
568 return NO_ERROR;
569 }
570
HandleUpdateApplicationInfoInstalled(MessageParcel & data,MessageParcel & reply)571 int32_t AmsMgrStub::HandleUpdateApplicationInfoInstalled(MessageParcel &data, MessageParcel &reply)
572 {
573 HITRACE_METER(HITRACE_TAG_APP);
574 std::string bundleName = data.ReadString();
575 int uid = data.ReadInt32();
576 int32_t result = UpdateApplicationInfoInstalled(bundleName, uid);
577 reply.WriteInt32(result);
578 return NO_ERROR;
579 }
580
HandleSetCurrentUserId(MessageParcel & data,MessageParcel & reply)581 int32_t AmsMgrStub::HandleSetCurrentUserId(MessageParcel &data, MessageParcel &reply)
582 {
583 int32_t userId = data.ReadInt32();
584 SetCurrentUserId(userId);
585 return NO_ERROR;
586 }
587
HandleSetEnableStartProcessFlagByUserId(MessageParcel & data,MessageParcel & reply)588 int32_t AmsMgrStub::HandleSetEnableStartProcessFlagByUserId(MessageParcel &data, MessageParcel &reply)
589 {
590 int32_t userId = data.ReadInt32();
591 bool enableStartProcess = data.ReadBool();
592 SetEnableStartProcessFlagByUserId(userId, enableStartProcess);
593 return NO_ERROR;
594 }
595
HandleGetBundleNameByPid(MessageParcel & data,MessageParcel & reply)596 int32_t AmsMgrStub::HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply)
597 {
598 int32_t pid = data.ReadInt32();
599 std::string bundleName;
600 int32_t uid;
601 GetBundleNameByPid(pid, bundleName, uid);
602
603 reply.WriteString(bundleName);
604 reply.WriteInt32(uid);
605 return NO_ERROR;
606 }
607
HandleRegisterAppDebugListener(MessageParcel & data,MessageParcel & reply)608 int32_t AmsMgrStub::HandleRegisterAppDebugListener(MessageParcel &data, MessageParcel &reply)
609 {
610 TAG_LOGD(AAFwkTag::APPMGR, "called");
611 auto appDebugLister = iface_cast<IAppDebugListener>(data.ReadRemoteObject());
612 if (appDebugLister == nullptr) {
613 TAG_LOGE(AAFwkTag::APPMGR, "App debug lister is null.");
614 return ERR_INVALID_VALUE;
615 }
616
617 auto result = RegisterAppDebugListener(appDebugLister);
618 if (!reply.WriteInt32(result)) {
619 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
620 return ERR_INVALID_VALUE;
621 }
622 return NO_ERROR;
623 }
624
HandleUnregisterAppDebugListener(MessageParcel & data,MessageParcel & reply)625 int32_t AmsMgrStub::HandleUnregisterAppDebugListener(MessageParcel &data, MessageParcel &reply)
626 {
627 TAG_LOGD(AAFwkTag::APPMGR, "called");
628 auto appDebugLister = iface_cast<IAppDebugListener>(data.ReadRemoteObject());
629 if (appDebugLister == nullptr) {
630 TAG_LOGE(AAFwkTag::APPMGR, "App debug lister is nullptr.");
631 return ERR_INVALID_VALUE;
632 }
633
634 auto result = UnregisterAppDebugListener(appDebugLister);
635 if (!reply.WriteInt32(result)) {
636 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
637 return ERR_INVALID_VALUE;
638 }
639 return NO_ERROR;
640 }
641
HandleAttachAppDebug(MessageParcel & data,MessageParcel & reply)642 int32_t AmsMgrStub::HandleAttachAppDebug(MessageParcel &data, MessageParcel &reply)
643 {
644 TAG_LOGD(AAFwkTag::APPMGR, "called");
645 auto bundleName = data.ReadString();
646 if (bundleName.empty()) {
647 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
648 return ERR_INVALID_VALUE;
649 }
650
651 auto result = AttachAppDebug(bundleName);
652 if (!reply.WriteInt32(result)) {
653 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
654 return ERR_INVALID_VALUE;
655 }
656 return NO_ERROR;
657 }
658
HandleDetachAppDebug(MessageParcel & data,MessageParcel & reply)659 int32_t AmsMgrStub::HandleDetachAppDebug(MessageParcel &data, MessageParcel &reply)
660 {
661 TAG_LOGD(AAFwkTag::APPMGR, "called");
662 auto bundleName = data.ReadString();
663 if (bundleName.empty()) {
664 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
665 return ERR_INVALID_VALUE;
666 }
667
668 auto result = DetachAppDebug(bundleName);
669 if (!reply.WriteInt32(result)) {
670 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
671 return ERR_INVALID_VALUE;
672 }
673 return NO_ERROR;
674 }
675
HandleSetAppWaitingDebug(MessageParcel & data,MessageParcel & reply)676 int32_t AmsMgrStub::HandleSetAppWaitingDebug(MessageParcel &data, MessageParcel &reply)
677 {
678 TAG_LOGD(AAFwkTag::APPMGR, "called");
679 auto bundleName = data.ReadString();
680 if (bundleName.empty()) {
681 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
682 return ERR_INVALID_VALUE;
683 }
684 auto isPersist = data.ReadBool();
685 auto result = SetAppWaitingDebug(bundleName, isPersist);
686 if (!reply.WriteInt32(result)) {
687 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
688 return ERR_INVALID_VALUE;
689 }
690 return NO_ERROR;
691 }
692
HandleCancelAppWaitingDebug(MessageParcel & data,MessageParcel & reply)693 int32_t AmsMgrStub::HandleCancelAppWaitingDebug(MessageParcel &data, MessageParcel &reply)
694 {
695 TAG_LOGD(AAFwkTag::APPMGR, "called");
696 auto result = CancelAppWaitingDebug();
697 if (!reply.WriteInt32(result)) {
698 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
699 return ERR_INVALID_VALUE;
700 }
701 return NO_ERROR;
702 }
703
HandleGetWaitingDebugApp(MessageParcel & data,MessageParcel & reply)704 int32_t AmsMgrStub::HandleGetWaitingDebugApp(MessageParcel &data, MessageParcel &reply)
705 {
706 TAG_LOGD(AAFwkTag::APPMGR, "called");
707 std::vector<std::string> debugInfoList;
708 auto result = GetWaitingDebugApp(debugInfoList);
709 if (!reply.WriteInt32(result)) {
710 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
711 return ERR_INVALID_VALUE;
712 }
713
714 int32_t listSize = static_cast<int32_t>(debugInfoList.size());
715 if (listSize > MAX_APP_DEBUG_COUNT) {
716 TAG_LOGE(AAFwkTag::APPMGR, "Max app debug count is %{public}d.", listSize);
717 return ERR_INVALID_VALUE;
718 }
719
720 if (!reply.WriteInt32(listSize)) {
721 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write list size.");
722 return ERR_INVALID_VALUE;
723 }
724
725 if (!reply.WriteStringVector(debugInfoList)) {
726 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write string vector debug info list.");
727 return ERR_INVALID_VALUE;
728 }
729 return NO_ERROR;
730 }
731
HandleIsWaitingDebugApp(MessageParcel & data,MessageParcel & reply)732 int32_t AmsMgrStub::HandleIsWaitingDebugApp(MessageParcel &data, MessageParcel &reply)
733 {
734 TAG_LOGD(AAFwkTag::APPMGR, "called");
735 auto bundleName = data.ReadString();
736 if (bundleName.empty()) {
737 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
738 return ERR_INVALID_VALUE;
739 }
740
741 auto result = IsWaitingDebugApp(bundleName);
742 if (!reply.WriteBool(result)) {
743 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
744 return ERR_INVALID_VALUE;
745 }
746 return NO_ERROR;
747 }
748
HandleSetKeepAliveEnableState(MessageParcel & data,MessageParcel & reply)749 int32_t AmsMgrStub::HandleSetKeepAliveEnableState(MessageParcel &data, MessageParcel &reply)
750 {
751 TAG_LOGD(AAFwkTag::APPMGR, "called");
752 auto bundleName = data.ReadString();
753 auto enable = data.ReadBool();
754 auto uid = data.ReadInt32();
755 SetKeepAliveEnableState(bundleName, enable, uid);
756 return NO_ERROR;
757 }
758
HandleClearNonPersistWaitingDebugFlag(MessageParcel & data,MessageParcel & reply)759 int32_t AmsMgrStub::HandleClearNonPersistWaitingDebugFlag(MessageParcel &data, MessageParcel &reply)
760 {
761 TAG_LOGD(AAFwkTag::APPMGR, "called");
762 ClearNonPersistWaitingDebugFlag();
763 return NO_ERROR;
764 }
765
HandleRegisterAbilityDebugResponse(MessageParcel & data,MessageParcel & reply)766 int32_t AmsMgrStub::HandleRegisterAbilityDebugResponse(MessageParcel &data, MessageParcel &reply)
767 {
768 TAG_LOGD(AAFwkTag::APPMGR, "called");
769 auto response = iface_cast<IAbilityDebugResponse>(data.ReadRemoteObject());
770 if (response == nullptr) {
771 TAG_LOGE(AAFwkTag::APPMGR, "Response is nullptr.");
772 return ERR_INVALID_VALUE;
773 }
774
775 auto result = RegisterAbilityDebugResponse(response);
776 if (!reply.WriteInt32(result)) {
777 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
778 return ERR_INVALID_VALUE;
779 }
780 return NO_ERROR;
781 }
782
HandleIsAttachDebug(MessageParcel & data,MessageParcel & reply)783 int32_t AmsMgrStub::HandleIsAttachDebug(MessageParcel &data, MessageParcel &reply)
784 {
785 TAG_LOGD(AAFwkTag::APPMGR, "called");
786 auto bundleName = data.ReadString();
787 if (bundleName.empty()) {
788 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
789 return ERR_INVALID_VALUE;
790 }
791
792 auto result = IsAttachDebug(bundleName);
793 if (!reply.WriteBool(result)) {
794 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
795 return ERR_INVALID_VALUE;
796 }
797 return NO_ERROR;
798 }
799
HandleClearProcessByToken(MessageParcel & data,MessageParcel & reply)800 int32_t AmsMgrStub::HandleClearProcessByToken(MessageParcel &data, MessageParcel &reply)
801 {
802 HITRACE_METER(HITRACE_TAG_APP);
803 sptr<IRemoteObject> token = data.ReadRemoteObject();
804 ClearProcessByToken(token);
805 return NO_ERROR;
806 }
807
HandleIsMemorySizeSufficent(MessageParcel & data,MessageParcel & reply)808 int32_t AmsMgrStub::HandleIsMemorySizeSufficent(MessageParcel &data, MessageParcel &reply)
809 {
810 auto result = IsMemorySizeSufficent();
811 if (!reply.WriteBool(result)) {
812 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
813 return ERR_INVALID_VALUE;
814 }
815 return NO_ERROR;
816 }
817
HandleAttachedToStatusBar(MessageParcel & data,MessageParcel & reply)818 ErrCode AmsMgrStub::HandleAttachedToStatusBar(MessageParcel &data, MessageParcel &reply)
819 {
820 HITRACE_METER(HITRACE_TAG_APP);
821 sptr<IRemoteObject> token = data.ReadRemoteObject();
822 AttachedToStatusBar(token);
823 return NO_ERROR;
824 }
825
HandleBlockProcessCacheByPids(MessageParcel & data,MessageParcel & reply)826 ErrCode AmsMgrStub::HandleBlockProcessCacheByPids(MessageParcel &data, MessageParcel &reply)
827 {
828 HITRACE_METER(HITRACE_TAG_APP);
829 auto size = data.ReadUint32();
830 if (size == 0 || size > MAX_KILL_PROCESS_PID_COUNT) {
831 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size.");
832 return ERR_INVALID_VALUE;
833 }
834 std::vector<int32_t> pids;
835 for (uint32_t i = 0; i < size; i++) {
836 pids.emplace_back(data.ReadInt32());
837 }
838
839 BlockProcessCacheByPids(pids);
840 return NO_ERROR;
841 }
842
HandleIsKilledForUpgradeWeb(MessageParcel & data,MessageParcel & reply)843 int32_t AmsMgrStub::HandleIsKilledForUpgradeWeb(MessageParcel &data, MessageParcel &reply)
844 {
845 TAG_LOGD(AAFwkTag::APPMGR, "Called.");
846 auto bundleName = data.ReadString();
847 if (bundleName.empty()) {
848 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
849 return ERR_INVALID_VALUE;
850 }
851
852 auto result = IsKilledForUpgradeWeb(bundleName);
853 if (!reply.WriteBool(result)) {
854 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
855 return ERR_INVALID_VALUE;
856 }
857 return NO_ERROR;
858 }
859
HandleCleanAbilityByUserRequest(MessageParcel & data,MessageParcel & reply)860 ErrCode AmsMgrStub::HandleCleanAbilityByUserRequest(MessageParcel &data, MessageParcel &reply)
861 {
862 HITRACE_METER(HITRACE_TAG_APP);
863 sptr<IRemoteObject> token = data.ReadRemoteObject();
864 auto result = CleanAbilityByUserRequest(token);
865 if (!reply.WriteBool(result)) {
866 TAG_LOGE(AAFwkTag::APPMGR, "fail to write the result.");
867 return ERR_INVALID_VALUE;
868 }
869 return NO_ERROR;
870 }
871
HandleIsProcessContainsOnlyUIAbility(MessageParcel & data,MessageParcel & reply)872 int32_t AmsMgrStub::HandleIsProcessContainsOnlyUIAbility(MessageParcel &data, MessageParcel &reply)
873 {
874 auto pid = data.ReadUint32();
875
876 auto result = IsProcessContainsOnlyUIAbility(pid);
877 if (!reply.WriteBool(result)) {
878 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result in HandleIsProcessContainsOnlyUIAbility.");
879 return ERR_INVALID_VALUE;
880 }
881 return NO_ERROR;
882 }
883
HandleIsProcessAttached(MessageParcel & data,MessageParcel & reply)884 int32_t AmsMgrStub::HandleIsProcessAttached(MessageParcel &data, MessageParcel &reply)
885 {
886 HITRACE_METER(HITRACE_TAG_APP);
887 sptr<IRemoteObject> token = data.ReadRemoteObject();
888 auto isAttached = IsProcessAttached(token);
889 if (!reply.WriteBool(isAttached)) {
890 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result");
891 return ERR_INVALID_VALUE;
892 }
893 return NO_ERROR;
894 }
895
HandleSendAppSpawnUninstallDebugHapMsg(MessageParcel & data)896 ErrCode AmsMgrStub::HandleSendAppSpawnUninstallDebugHapMsg(MessageParcel &data)
897 {
898 HITRACE_METER(HITRACE_TAG_APP);
899 auto userId = data.ReadInt32();
900 SendAppSpawnUninstallDebugHapMsg(userId);
901 return NO_ERROR;
902 }
903 } // namespace AppExecFwk
904 } // namespace OHOS
905