1 /*
2 * Copyright (c) 2021-2025 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::KILL_PEOCESS_BY_ABILITY_TOKEN):
101 return HandleKillProcessByAbilityToken(data, reply);
102 case static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESSES_BY_USERID):
103 return HandleKillProcessesByUserId(data, reply);
104 case static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESS_WITH_ACCOUNT):
105 return HandleKillProcessWithAccount(data, reply);
106 case static_cast<uint32_t>(IAmsMgr::Message::KILL_APPLICATION):
107 return HandleKillApplication(data, reply);
108 case static_cast<uint32_t>(IAmsMgr::Message::ABILITY_ATTACH_TIMEOUT):
109 return HandleAbilityAttachTimeOut(data, reply);
110 case static_cast<uint32_t>(IAmsMgr::Message::PREPARE_TERMINATE_ABILITY):
111 return HandlePrepareTerminate(data, reply);
112 case static_cast<uint32_t>(IAmsMgr::Message::KILL_APPLICATION_BYUID):
113 return HandleKillApplicationByUid(data, reply);
114 case static_cast<uint32_t>(IAmsMgr::Message::KILL_APPLICATION_SELF):
115 return HandleKillApplicationSelf(data, reply);
116 case static_cast<uint32_t>(IAmsMgr::Message::GET_RUNNING_PROCESS_INFO_BY_TOKEN):
117 return HandleGetRunningProcessInfoByToken(data, reply);
118 case static_cast<uint32_t>(IAmsMgr::Message::NOTIFY_UNINSTALL_OR_UPGRADE_APP):
119 return HandleNotifyUninstallOrUpgradeApp(data, reply);
120 case static_cast<uint32_t>(IAmsMgr::Message::NOTIFY_UNINSTALL_OR_UPGRADE_APP_END):
121 return HandleNotifyUninstallOrUpgradeAppEnd(data, reply);
122 }
123 return AAFwk::ERR_CODE_NOT_EXIST;
124 }
125
OnRemoteRequestInnerSecond(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)126 int32_t AmsMgrStub::OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data,
127 MessageParcel &reply, MessageOption &option)
128 {
129 switch (static_cast<uint32_t>(code)) {
130 case static_cast<uint32_t>(IAmsMgr::Message::SET_ABILITY_FOREGROUNDING_FLAG):
131 return HandleSetAbilityForegroundingFlagToAppRecord(data, reply);
132 case static_cast<uint32_t>(IAmsMgr::Message::START_SPECIFIED_ABILITY):
133 return HandleStartSpecifiedAbility(data, reply);
134 case static_cast<uint32_t>(IAmsMgr::Message::REGISTER_START_SPECIFIED_ABILITY_RESPONSE):
135 return HandleRegisterStartSpecifiedAbilityResponse(data, reply);
136 case static_cast<uint32_t>(IAmsMgr::Message::GET_APPLICATION_INFO_BY_PROCESS_ID):
137 return HandleGetApplicationInfoByProcessID(data, reply);
138 case static_cast<uint32_t>(IAmsMgr::Message::NOTIFY_APP_MGR_RECORD_EXIT_REASON):
139 return HandleNotifyAppMgrRecordExitReason(data, reply);
140 case static_cast<uint32_t>(IAmsMgr::Message::UPDATE_APPLICATION_INFO_INSTALLED):
141 return HandleUpdateApplicationInfoInstalled(data, reply);
142 case static_cast<uint32_t>(IAmsMgr::Message::SET_CURRENT_USER_ID):
143 return HandleSetCurrentUserId(data, reply);
144 case static_cast<uint32_t>(IAmsMgr::Message::ENABLE_START_PROCESS_FLAG_BY_USER_ID):
145 return HandleSetEnableStartProcessFlagByUserId(data, reply);
146 case static_cast<uint32_t>(IAmsMgr::Message::Get_BUNDLE_NAME_BY_PID):
147 return HandleGetBundleNameByPid(data, reply);
148 case static_cast<uint32_t>(IAmsMgr::Message::REGISTER_APP_DEBUG_LISTENER):
149 return HandleRegisterAppDebugListener(data, reply);
150 case static_cast<uint32_t>(IAmsMgr::Message::UNREGISTER_APP_DEBUG_LISTENER):
151 return HandleUnregisterAppDebugListener(data, reply);
152 case static_cast<uint32_t>(IAmsMgr::Message::ATTACH_APP_DEBUG):
153 return HandleAttachAppDebug(data, reply);
154 case static_cast<uint32_t>(IAmsMgr::Message::DETACH_APP_DEBUG):
155 return HandleDetachAppDebug(data, reply);
156 case static_cast<uint32_t>(IAmsMgr::Message::SET_APP_WAITING_DEBUG):
157 return HandleSetAppWaitingDebug(data, reply);
158 case static_cast<uint32_t>(IAmsMgr::Message::CANCEL_APP_WAITING_DEBUG):
159 return HandleCancelAppWaitingDebug(data, reply);
160 case static_cast<uint32_t>(IAmsMgr::Message::GET_WAITING_DEBUG_APP):
161 return HandleGetWaitingDebugApp(data, reply);
162 case static_cast<uint32_t>(IAmsMgr::Message::IS_WAITING_DEBUG_APP):
163 return HandleIsWaitingDebugApp(data, reply);
164 }
165 return AAFwk::ERR_CODE_NOT_EXIST;
166 }
167
OnRemoteRequestInnerThird(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)168 int32_t AmsMgrStub::OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data,
169 MessageParcel &reply, MessageOption &option)
170 {
171 switch (static_cast<uint32_t>(code)) {
172 case static_cast<uint32_t>(IAmsMgr::Message::CLEAR_NON_PERSIST_WAITING_DEBUG_FLAG):
173 return HandleClearNonPersistWaitingDebugFlag(data, reply);
174 case static_cast<uint32_t>(IAmsMgr::Message::REGISTER_ABILITY_DEBUG_RESPONSE):
175 return HandleRegisterAbilityDebugResponse(data, reply);
176 case static_cast<uint32_t>(IAmsMgr::Message::IS_ATTACH_DEBUG):
177 return HandleIsAttachDebug(data, reply);
178 case static_cast<uint32_t>(IAmsMgr::Message::CLEAR_PROCESS_BY_TOKEN):
179 return HandleClearProcessByToken(data, reply);
180 case static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESSES_BY_PIDS):
181 return HandleKillProcessesByPids(data, reply);
182 case static_cast<uint32_t>(IAmsMgr::Message::ATTACH_PID_TO_PARENT):
183 return HandleAttachPidToParent(data, reply);
184 case static_cast<uint32_t>(IAmsMgr::Message::IS_MEMORY_SIZE_SUFFICIENT):
185 return HandleIsMemorySizeSufficent(data, reply);
186 case static_cast<uint32_t>(IAmsMgr::Message::IS_NO_REQUIRE_BIG_MEMORY):
187 return HandleIsNoRequireBigMemory(data, reply);
188 case static_cast<uint32_t>(IAmsMgr::Message::SET_KEEP_ALIVE_ENABLE_STATE):
189 return HandleSetKeepAliveEnableState(data, reply);
190 case static_cast<uint32_t>(IAmsMgr::Message::ATTACHED_TO_STATUS_BAR):
191 return HandleAttachedToStatusBar(data, reply);
192 case static_cast<uint32_t>(IAmsMgr::Message::UPDATE_CONFIGURATION):
193 return 0;
194 case static_cast<uint32_t>(IAmsMgr::Message::GET_CONFIGURATION):
195 return 0;
196 case static_cast<uint32_t>(IAmsMgr::Message::START_SPECIFIED_PROCESS):
197 return 0;
198 case static_cast<uint32_t>(IAmsMgr::Message::REGISTER_ABILITY_MS_DELEGATE):
199 return 0;
200 case static_cast<uint32_t>(IAmsMgr::Message::BLOCK_PROCESS_CACHE_BY_PIDS):
201 return HandleBlockProcessCacheByPids(data, reply);
202 case static_cast<uint32_t>(IAmsMgr::Message::IS_KILLED_FOR_UPGRADE_WEB):
203 return HandleIsKilledForUpgradeWeb(data, reply);
204 case static_cast<uint32_t>(IAmsMgr::Message::PREPARE_TERMINATE_APP):
205 return HandlePrepareTerminateApp(data, reply);
206 }
207 return AAFwk::ERR_CODE_NOT_EXIST;
208 }
209
OnRemoteRequestInnerFourth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)210 int32_t AmsMgrStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &data,
211 MessageParcel &reply, MessageOption &option)
212 {
213 switch (static_cast<uint32_t>(code)) {
214 case static_cast<uint32_t>(IAmsMgr::Message::IS_PROCESS_CONTAINS_ONLY_UI_EXTENSION):
215 return HandleIsProcessContainsOnlyUIAbility(data, reply);
216 case static_cast<uint32_t>(IAmsMgr::Message::FORCE_KILL_APPLICATION):
217 return HandleForceKillApplication(data, reply);
218 case static_cast<uint32_t>(IAmsMgr::Message::CLEAN_UIABILITY_BY_USER_REQUEST):
219 return HandleCleanAbilityByUserRequest(data, reply);
220 case static_cast<uint32_t>(IAmsMgr::Message::FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID):
221 return HandleKillProcessesByAccessTokenId(data, reply);
222 case static_cast<uint32_t>(IAmsMgr::Message::IS_PROCESS_ATTACHED):
223 return HandleIsProcessAttached(data, reply);
224 case static_cast<uint32_t>(IAmsMgr::Message::IS_CALLER_KILLING):
225 return HandleIsCallerKilling(data, reply);
226 case static_cast<uint32_t>(IAmsMgr::Message::SET_KEEP_ALIVE_DKV):
227 return HandleSetKeepAliveDkv(data, reply);
228 case static_cast<uint32_t>(IAmsMgr::Message::SET_KEEP_ALIVE_APP_SERVICE):
229 return HandleSetKeepAliveAppService(data, reply);
230 case static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESSES_IN_BATCH):
231 return HandleKillProcessesInBatch(data, reply);
232 case static_cast<uint32_t>(IAmsMgr::Message::PRELOAD_APPLICATION_BY_PHASE):
233 return HandlePreloadApplicationByPhase(data, reply);
234 case static_cast<uint32_t>(IAmsMgr::Message::NOTIFY_PRELOAD_ABILITY_STATE_CHANGED):
235 return HandleNotifyPreloadAbilityStateChanged(data, reply);
236 case static_cast<uint32_t>(IAmsMgr::Message::CHECK_PRELOAD_APP_RECORD_EXIST):
237 return HandleCheckPreloadAppRecordExist(data, reply);
238 case static_cast<uint32_t>(IAmsMgr::Message::VERIFY_KILL_PROCESS_PERMISSION):
239 return HandleVerifyKillProcessPermission(data, reply);
240 }
241 return AAFwk::ERR_CODE_NOT_EXIST;
242 }
243
HandleLoadAbility(MessageParcel & data,MessageParcel & reply)244 ErrCode AmsMgrStub::HandleLoadAbility(MessageParcel &data, MessageParcel &reply)
245 {
246 HITRACE_METER(HITRACE_TAG_APP);
247 std::shared_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
248 if (!abilityInfo) {
249 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<AbilityInfo> failed");
250 return ERR_APPEXECFWK_PARCEL_ERROR;
251 }
252
253 std::shared_ptr<ApplicationInfo> appInfo(data.ReadParcelable<ApplicationInfo>());
254 if (!appInfo) {
255 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<ApplicationInfo> failed");
256 return ERR_APPEXECFWK_PARCEL_ERROR;
257 }
258
259 std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
260 if (!want) {
261 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable want failed");
262 return ERR_APPEXECFWK_PARCEL_ERROR;
263 }
264 std::shared_ptr<AbilityRuntime::LoadParam> loadParam(data.ReadParcelable<AbilityRuntime::LoadParam>());
265 if (!loadParam) {
266 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable loadParam failed");
267 return ERR_APPEXECFWK_PARCEL_ERROR;
268 }
269
270 LoadAbility(abilityInfo, appInfo, want, loadParam);
271 return NO_ERROR;
272 }
273
HandleTerminateAbility(MessageParcel & data,MessageParcel & reply)274 ErrCode AmsMgrStub::HandleTerminateAbility(MessageParcel &data, MessageParcel &reply)
275 {
276 HITRACE_METER(HITRACE_TAG_APP);
277 sptr<IRemoteObject> token = data.ReadRemoteObject();
278 bool clearMissionFlag = data.ReadBool();
279 TerminateAbility(token, clearMissionFlag);
280 return NO_ERROR;
281 }
282
HandleUpdateAbilityState(MessageParcel & data,MessageParcel & reply)283 ErrCode AmsMgrStub::HandleUpdateAbilityState(MessageParcel &data, MessageParcel &reply)
284 {
285 HITRACE_METER(HITRACE_TAG_APP);
286 sptr<IRemoteObject> token = data.ReadRemoteObject();
287 int32_t state = data.ReadInt32();
288 UpdateAbilityState(token, static_cast<AbilityState>(state));
289 return NO_ERROR;
290 }
291
HandleUpdateExtensionState(MessageParcel & data,MessageParcel & reply)292 ErrCode AmsMgrStub::HandleUpdateExtensionState(MessageParcel &data, MessageParcel &reply)
293 {
294 sptr<IRemoteObject> token = data.ReadRemoteObject();
295 int32_t state = data.ReadInt32();
296 UpdateExtensionState(token, static_cast<ExtensionState>(state));
297 return NO_ERROR;
298 }
299
HandleRegisterAppStateCallback(MessageParcel & data,MessageParcel & reply)300 ErrCode AmsMgrStub::HandleRegisterAppStateCallback(MessageParcel &data, MessageParcel &reply)
301 {
302 HITRACE_METER(HITRACE_TAG_APP);
303 sptr<IAppStateCallback> callback = nullptr;
304 if (data.ReadBool()) {
305 sptr<IRemoteObject> obj = data.ReadRemoteObject();
306 callback = iface_cast<IAppStateCallback>(obj);
307 }
308 RegisterAppStateCallback(callback);
309 return NO_ERROR;
310 }
311
HandleKillProcessByAbilityToken(MessageParcel & data,MessageParcel & reply)312 ErrCode AmsMgrStub::HandleKillProcessByAbilityToken(MessageParcel &data, MessageParcel &reply)
313 {
314 HITRACE_METER(HITRACE_TAG_APP);
315 sptr<IRemoteObject> token = data.ReadRemoteObject();
316
317 KillProcessByAbilityToken(token);
318 return NO_ERROR;
319 }
320
HandleKillProcessesByUserId(MessageParcel & data,MessageParcel & reply)321 ErrCode AmsMgrStub::HandleKillProcessesByUserId(MessageParcel &data, MessageParcel &reply)
322 {
323 HITRACE_METER(HITRACE_TAG_APP);
324 int32_t userId = data.ReadInt32();
325 sptr<AAFwk::IUserCallback> callback = nullptr;
326 bool isWithCallback = data.ReadBool();
327 if (isWithCallback) {
328 callback = iface_cast<AAFwk::IUserCallback>(data.ReadRemoteObject());
329 }
330
331 KillProcessesByUserId(userId, callback);
332 return NO_ERROR;
333 }
334
HandleKillProcessesByPids(MessageParcel & data,MessageParcel & reply)335 ErrCode AmsMgrStub::HandleKillProcessesByPids(MessageParcel &data, MessageParcel &reply)
336 {
337 HITRACE_METER(HITRACE_TAG_APP);
338 auto size = data.ReadUint32();
339 if (size == 0 || size > MAX_KILL_PROCESS_PID_COUNT) {
340 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size");
341 return ERR_INVALID_VALUE;
342 }
343 std::vector<int32_t> pids;
344 for (uint32_t i = 0; i < size; i++) {
345 pids.emplace_back(data.ReadInt32());
346 }
347 std::string reason = data.ReadString();
348 bool subProcess = data.ReadBool();
349 bool isKillPrecedeStart = data.ReadBool();
350 int32_t ret = KillProcessesByPids(pids, reason, subProcess, isKillPrecedeStart);
351 reply.WriteInt32(ret);
352 return NO_ERROR;
353 }
354
HandleAttachPidToParent(MessageParcel & data,MessageParcel & reply)355 ErrCode AmsMgrStub::HandleAttachPidToParent(MessageParcel &data, MessageParcel &reply)
356 {
357 HITRACE_METER(HITRACE_TAG_APP);
358 sptr<IRemoteObject> token = data.ReadRemoteObject();
359 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
360 AttachPidToParent(token, callerToken);
361 return NO_ERROR;
362 }
363
HandleKillProcessWithAccount(MessageParcel & data,MessageParcel & reply)364 ErrCode AmsMgrStub::HandleKillProcessWithAccount(MessageParcel &data, MessageParcel &reply)
365 {
366 TAG_LOGI(AAFwkTag::APPMGR, "enter");
367
368 HITRACE_METER(HITRACE_TAG_APP);
369
370 std::string bundleName = data.ReadString();
371 int accountId = data.ReadInt32();
372 bool clearPageStack = data.ReadBool();
373 auto appIndex = data.ReadInt32();
374
375 TAG_LOGI(AAFwkTag::APPMGR,
376 "bundleName = %{public}s, accountId = %{public}d, clearPageStack = %{public}d",
377 bundleName.c_str(), accountId, clearPageStack);
378
379 int32_t result = KillProcessWithAccount(bundleName, accountId, clearPageStack, appIndex);
380 reply.WriteInt32(result);
381
382 TAG_LOGI(AAFwkTag::APPMGR, "end");
383
384 return NO_ERROR;
385 }
386
HandleKillProcessesInBatch(MessageParcel & data,MessageParcel & reply)387 ErrCode AmsMgrStub::HandleKillProcessesInBatch(MessageParcel &data, MessageParcel &reply)
388 {
389 TAG_LOGI(AAFwkTag::APPMGR, "enter");
390
391 HITRACE_METER(HITRACE_TAG_APP);
392
393 auto size = data.ReadUint32();
394 TAG_LOGI(AAFwkTag::APPMGR, "pids.size=%{public}d", size);
395 if (size == 0 || size > MAX_KILL_PROCESS_PID_COUNT) {
396 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size");
397 return ERR_INVALID_VALUE;
398 }
399 std::vector<int32_t> pids;
400 for (uint32_t i = 0; i < size; i++) {
401 pids.emplace_back(data.ReadInt32());
402 }
403
404 int32_t result = KillProcessesInBatch(pids);
405 reply.WriteInt32(result);
406
407 TAG_LOGI(AAFwkTag::APPMGR, "end");
408
409 return NO_ERROR;
410 }
411
HandleKillApplication(MessageParcel & data,MessageParcel & reply)412 ErrCode AmsMgrStub::HandleKillApplication(MessageParcel &data, MessageParcel &reply)
413 {
414 HITRACE_METER(HITRACE_TAG_APP);
415 std::string bundleName = data.ReadString();
416 bool clearPageStack = data.ReadBool();
417 auto appIndex = data.ReadInt32();
418
419 TAG_LOGW(AAFwkTag::APPMGR,
420 "KillApplication,callingPid=%{public}d,bundleName=%{public}s,clearPageStack=%{public}d",
421 IPCSkeleton::GetCallingPid(), bundleName.c_str(), clearPageStack);
422
423 int32_t result = KillApplication(bundleName, clearPageStack, appIndex);
424 reply.WriteInt32(result);
425 return NO_ERROR;
426 }
427
HandleForceKillApplication(MessageParcel & data,MessageParcel & reply)428 ErrCode AmsMgrStub::HandleForceKillApplication(MessageParcel &data, MessageParcel &reply)
429 {
430 HITRACE_METER(HITRACE_TAG_APP);
431 std::string bundleName = data.ReadString();
432 int userId = data.ReadInt32();
433 int appIndex = data.ReadInt32();
434
435 TAG_LOGI(AAFwkTag::APPMGR, "bundleName = %{public}s,userId=%{public}d,appIndex=%{public}d",
436 bundleName.c_str(), userId, appIndex);
437
438 int32_t result = ForceKillApplication(bundleName, userId, appIndex);
439 reply.WriteInt32(result);
440 return NO_ERROR;
441 }
442
HandleKillProcessesByAccessTokenId(MessageParcel & data,MessageParcel & reply)443 ErrCode AmsMgrStub::HandleKillProcessesByAccessTokenId(MessageParcel &data, MessageParcel &reply)
444 {
445 HITRACE_METER(HITRACE_TAG_APP);
446 int accessTokenId = data.ReadInt32();
447
448 TAG_LOGI(AAFwkTag::APPMGR, "accessTokenId=%{public}d", accessTokenId);
449
450 int32_t result = KillProcessesByAccessTokenId(accessTokenId);
451 reply.WriteInt32(result);
452 return NO_ERROR;
453 }
454
HandleKillApplicationByUid(MessageParcel & data,MessageParcel & reply)455 ErrCode AmsMgrStub::HandleKillApplicationByUid(MessageParcel &data, MessageParcel &reply)
456 {
457 HITRACE_METER(HITRACE_TAG_APP);
458 std::string bundleName = data.ReadString();
459 int uid = data.ReadInt32();
460 std::string reason = data.ReadString();
461 TAG_LOGW(AAFwkTag::APPMGR, "KillApplicationByUid,callingPid=%{public}d", IPCSkeleton::GetCallingPid());
462 int32_t result = KillApplicationByUid(bundleName, uid, reason);
463 reply.WriteInt32(result);
464 return NO_ERROR;
465 }
466
HandleNotifyUninstallOrUpgradeApp(MessageParcel & data,MessageParcel & reply)467 ErrCode AmsMgrStub::HandleNotifyUninstallOrUpgradeApp(MessageParcel &data, MessageParcel &reply)
468 {
469 HITRACE_METER(HITRACE_TAG_APP);
470 std::string bundleName = data.ReadString();
471 int32_t uid = data.ReadInt32();
472 bool isUpgrade = data.ReadBool();
473 TAG_LOGW(AAFwkTag::APPMGR, "NotifyUninstallOrUpgradeApp, callingPid=%{public}d", IPCSkeleton::GetCallingPid());
474 int32_t result = NotifyUninstallOrUpgradeApp(bundleName, uid, isUpgrade);
475 if (!reply.WriteInt32(result)) {
476 TAG_LOGE(AAFwkTag::APPMGR, "result write failed.");
477 return ERR_INVALID_VALUE;
478 }
479 return NO_ERROR;
480 }
481
HandleNotifyUninstallOrUpgradeAppEnd(MessageParcel & data,MessageParcel & reply)482 ErrCode AmsMgrStub::HandleNotifyUninstallOrUpgradeAppEnd(MessageParcel &data, MessageParcel &reply)
483 {
484 HITRACE_METER(HITRACE_TAG_APP);
485 int32_t uid = data.ReadInt32();
486 TAG_LOGW(AAFwkTag::APPMGR, "NotifyUninstallOrUpgradeAppEnd, callingPid=%{public}d", IPCSkeleton::GetCallingPid());
487 NotifyUninstallOrUpgradeAppEnd(uid);
488 return NO_ERROR;
489 }
490
HandleKillApplicationSelf(MessageParcel & data,MessageParcel & reply)491 ErrCode AmsMgrStub::HandleKillApplicationSelf(MessageParcel &data, MessageParcel &reply)
492 {
493 HITRACE_METER(HITRACE_TAG_APP);
494 TAG_LOGW(AAFwkTag::APPMGR, "KillApplicationSelf,callingPid=%{public}d", IPCSkeleton::GetCallingPid());
495 bool clearPageStack = data.ReadBool();
496 std::string reason = data.ReadString();
497 int32_t result = KillApplicationSelf(clearPageStack, reason);
498 if (!reply.WriteInt32(result)) {
499 TAG_LOGE(AAFwkTag::APPMGR, "result write failed.");
500 return ERR_INVALID_VALUE;
501 }
502 return NO_ERROR;
503 }
504
HandleAbilityAttachTimeOut(MessageParcel & data,MessageParcel & reply)505 int32_t AmsMgrStub::HandleAbilityAttachTimeOut(MessageParcel &data, MessageParcel &reply)
506 {
507 HITRACE_METER(HITRACE_TAG_APP);
508 sptr<IRemoteObject> token = data.ReadRemoteObject();
509 AbilityAttachTimeOut(token);
510 return NO_ERROR;
511 }
512
HandlePrepareTerminate(MessageParcel & data,MessageParcel & reply)513 int32_t AmsMgrStub::HandlePrepareTerminate(MessageParcel &data, MessageParcel &reply)
514 {
515 sptr<IRemoteObject> token = data.ReadRemoteObject();
516 bool clearMissionFlag = data.ReadBool();
517 PrepareTerminate(token, clearMissionFlag);
518 return NO_ERROR;
519 }
520
UpdateExtensionState(const sptr<IRemoteObject> & token,const ExtensionState state)521 void AmsMgrStub::UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state)
522 {}
523
HandleGetRunningProcessInfoByToken(MessageParcel & data,MessageParcel & reply)524 int32_t AmsMgrStub::HandleGetRunningProcessInfoByToken(MessageParcel &data, MessageParcel &reply)
525 {
526 RunningProcessInfo processInfo;
527 auto token = data.ReadRemoteObject();
528 GetRunningProcessInfoByToken(token, processInfo);
529 if (reply.WriteParcelable(&processInfo)) {
530 TAG_LOGE(AAFwkTag::APPMGR, "process info write failed.");
531 return ERR_INVALID_VALUE;
532 }
533 return NO_ERROR;
534 }
535
HandleSetAbilityForegroundingFlagToAppRecord(MessageParcel & data,MessageParcel & reply)536 int32_t AmsMgrStub::HandleSetAbilityForegroundingFlagToAppRecord(MessageParcel &data, MessageParcel &reply)
537 {
538 RunningProcessInfo processInfo;
539 auto pid = static_cast<pid_t>(data.ReadInt32());
540 SetAbilityForegroundingFlagToAppRecord(pid);
541 return NO_ERROR;
542 }
543
HandlePrepareTerminateApp(MessageParcel & data,MessageParcel & reply)544 int32_t AmsMgrStub::HandlePrepareTerminateApp(MessageParcel &data, MessageParcel &reply)
545 {
546 TAG_LOGD(AAFwkTag::APPMGR, "called");
547 auto pid = static_cast<pid_t>(data.ReadInt32());
548 auto moduleName = data.ReadString();
549 PrepareTerminateApp(pid, moduleName);
550 return NO_ERROR;
551 }
552
HandleStartSpecifiedAbility(MessageParcel & data,MessageParcel & reply)553 int32_t AmsMgrStub::HandleStartSpecifiedAbility(MessageParcel &data, MessageParcel &reply)
554 {
555 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
556 if (want == nullptr) {
557 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
558 return ERR_INVALID_VALUE;
559 }
560
561 AbilityInfo *abilityInfo = data.ReadParcelable<AbilityInfo>();
562 if (abilityInfo == nullptr) {
563 TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo is nullptr.");
564 delete want;
565 return ERR_INVALID_VALUE;
566 }
567 StartSpecifiedAbility(*want, *abilityInfo, data.ReadInt32());
568 delete want;
569 delete abilityInfo;
570 return NO_ERROR;
571 }
572
HandleRegisterStartSpecifiedAbilityResponse(MessageParcel & data,MessageParcel & reply)573 int32_t AmsMgrStub::HandleRegisterStartSpecifiedAbilityResponse(MessageParcel &data, MessageParcel &reply)
574 {
575 sptr<IRemoteObject> obj = data.ReadRemoteObject();
576 sptr<IStartSpecifiedAbilityResponse> response = iface_cast<IStartSpecifiedAbilityResponse>(obj);
577 RegisterStartSpecifiedAbilityResponse(response);
578 return NO_ERROR;
579 }
580
HandleGetApplicationInfoByProcessID(MessageParcel & data,MessageParcel & reply)581 int32_t AmsMgrStub::HandleGetApplicationInfoByProcessID(MessageParcel &data, MessageParcel &reply)
582 {
583 HITRACE_METER(HITRACE_TAG_APP);
584 int32_t pid = data.ReadInt32();
585 AppExecFwk::ApplicationInfo application;
586 bool debug;
587 int32_t result = GetApplicationInfoByProcessID(pid, application, debug);
588 if (!reply.WriteInt32(result)) {
589 TAG_LOGE(AAFwkTag::APPMGR, "write result error.");
590 return ERR_INVALID_VALUE;
591 }
592 if (!reply.WriteParcelable(&application)) {
593 TAG_LOGE(AAFwkTag::APPMGR, "write application info failed");
594 return ERR_INVALID_VALUE;
595 }
596 if (!reply.WriteBool(debug)) {
597 TAG_LOGE(AAFwkTag::APPMGR, "write debug info failed");
598 return ERR_INVALID_VALUE;
599 }
600 return NO_ERROR;
601 }
602
HandleNotifyAppMgrRecordExitReason(MessageParcel & data,MessageParcel & reply)603 int32_t AmsMgrStub::HandleNotifyAppMgrRecordExitReason(MessageParcel &data, MessageParcel &reply)
604 {
605 TAG_LOGD(AAFwkTag::APPMGR, "called");
606 int32_t pid = data.ReadInt32();
607 int32_t reason = data.ReadInt32();
608 std::string exitMsg = Str16ToStr8(data.ReadString16());
609 int32_t result = NotifyAppMgrRecordExitReason(pid, reason, exitMsg);
610 if (!reply.WriteInt32(result)) {
611 TAG_LOGE(AAFwkTag::APPMGR, "Write result failed.");
612 return IPC_PROXY_ERR;
613 }
614 return NO_ERROR;
615 }
616
HandleUpdateApplicationInfoInstalled(MessageParcel & data,MessageParcel & reply)617 int32_t AmsMgrStub::HandleUpdateApplicationInfoInstalled(MessageParcel &data, MessageParcel &reply)
618 {
619 HITRACE_METER(HITRACE_TAG_APP);
620 std::string bundleName = data.ReadString();
621 int uid = data.ReadInt32();
622 std::string moduleName = data.ReadString();
623 int32_t result = UpdateApplicationInfoInstalled(bundleName, uid, moduleName, data.ReadBool());
624 reply.WriteInt32(result);
625 return NO_ERROR;
626 }
627
HandleSetCurrentUserId(MessageParcel & data,MessageParcel & reply)628 int32_t AmsMgrStub::HandleSetCurrentUserId(MessageParcel &data, MessageParcel &reply)
629 {
630 int32_t userId = data.ReadInt32();
631 SetCurrentUserId(userId);
632 return NO_ERROR;
633 }
634
HandleSetEnableStartProcessFlagByUserId(MessageParcel & data,MessageParcel & reply)635 int32_t AmsMgrStub::HandleSetEnableStartProcessFlagByUserId(MessageParcel &data, MessageParcel &reply)
636 {
637 int32_t userId = data.ReadInt32();
638 bool enableStartProcess = data.ReadBool();
639 SetEnableStartProcessFlagByUserId(userId, enableStartProcess);
640 return NO_ERROR;
641 }
642
HandleGetBundleNameByPid(MessageParcel & data,MessageParcel & reply)643 int32_t AmsMgrStub::HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply)
644 {
645 int32_t pid = data.ReadInt32();
646 std::string bundleName;
647 int32_t uid;
648 GetBundleNameByPid(pid, bundleName, uid);
649
650 reply.WriteString(bundleName);
651 reply.WriteInt32(uid);
652 return NO_ERROR;
653 }
654
HandleRegisterAppDebugListener(MessageParcel & data,MessageParcel & reply)655 int32_t AmsMgrStub::HandleRegisterAppDebugListener(MessageParcel &data, MessageParcel &reply)
656 {
657 TAG_LOGD(AAFwkTag::APPMGR, "called");
658 auto appDebugLister = iface_cast<IAppDebugListener>(data.ReadRemoteObject());
659 if (appDebugLister == nullptr) {
660 TAG_LOGE(AAFwkTag::APPMGR, "App debug lister is null.");
661 return ERR_INVALID_VALUE;
662 }
663
664 auto result = RegisterAppDebugListener(appDebugLister);
665 if (!reply.WriteInt32(result)) {
666 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
667 return ERR_INVALID_VALUE;
668 }
669 return NO_ERROR;
670 }
671
HandleUnregisterAppDebugListener(MessageParcel & data,MessageParcel & reply)672 int32_t AmsMgrStub::HandleUnregisterAppDebugListener(MessageParcel &data, MessageParcel &reply)
673 {
674 TAG_LOGD(AAFwkTag::APPMGR, "called");
675 auto appDebugLister = iface_cast<IAppDebugListener>(data.ReadRemoteObject());
676 if (appDebugLister == nullptr) {
677 TAG_LOGE(AAFwkTag::APPMGR, "App debug lister is nullptr.");
678 return ERR_INVALID_VALUE;
679 }
680
681 auto result = UnregisterAppDebugListener(appDebugLister);
682 if (!reply.WriteInt32(result)) {
683 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
684 return ERR_INVALID_VALUE;
685 }
686 return NO_ERROR;
687 }
688
HandleAttachAppDebug(MessageParcel & data,MessageParcel & reply)689 int32_t AmsMgrStub::HandleAttachAppDebug(MessageParcel &data, MessageParcel &reply)
690 {
691 TAG_LOGD(AAFwkTag::APPMGR, "called");
692 auto bundleName = data.ReadString();
693 if (bundleName.empty()) {
694 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
695 return ERR_INVALID_VALUE;
696 }
697 auto isDebugFromLocal = data.ReadBool();
698
699 auto result = AttachAppDebug(bundleName, isDebugFromLocal);
700 if (!reply.WriteInt32(result)) {
701 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
702 return ERR_INVALID_VALUE;
703 }
704 return NO_ERROR;
705 }
706
HandleDetachAppDebug(MessageParcel & data,MessageParcel & reply)707 int32_t AmsMgrStub::HandleDetachAppDebug(MessageParcel &data, MessageParcel &reply)
708 {
709 TAG_LOGD(AAFwkTag::APPMGR, "called");
710 auto bundleName = data.ReadString();
711 if (bundleName.empty()) {
712 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
713 return ERR_INVALID_VALUE;
714 }
715
716 auto result = DetachAppDebug(bundleName);
717 if (!reply.WriteInt32(result)) {
718 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
719 return ERR_INVALID_VALUE;
720 }
721 return NO_ERROR;
722 }
723
HandleSetAppWaitingDebug(MessageParcel & data,MessageParcel & reply)724 int32_t AmsMgrStub::HandleSetAppWaitingDebug(MessageParcel &data, MessageParcel &reply)
725 {
726 TAG_LOGD(AAFwkTag::APPMGR, "called");
727 auto bundleName = data.ReadString();
728 if (bundleName.empty()) {
729 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
730 return ERR_INVALID_VALUE;
731 }
732 auto isPersist = data.ReadBool();
733 auto result = SetAppWaitingDebug(bundleName, isPersist);
734 if (!reply.WriteInt32(result)) {
735 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
736 return ERR_INVALID_VALUE;
737 }
738 return NO_ERROR;
739 }
740
HandleCancelAppWaitingDebug(MessageParcel & data,MessageParcel & reply)741 int32_t AmsMgrStub::HandleCancelAppWaitingDebug(MessageParcel &data, MessageParcel &reply)
742 {
743 TAG_LOGD(AAFwkTag::APPMGR, "called");
744 auto result = CancelAppWaitingDebug();
745 if (!reply.WriteInt32(result)) {
746 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
747 return ERR_INVALID_VALUE;
748 }
749 return NO_ERROR;
750 }
751
HandleGetWaitingDebugApp(MessageParcel & data,MessageParcel & reply)752 int32_t AmsMgrStub::HandleGetWaitingDebugApp(MessageParcel &data, MessageParcel &reply)
753 {
754 TAG_LOGD(AAFwkTag::APPMGR, "called");
755 std::vector<std::string> debugInfoList;
756 auto result = GetWaitingDebugApp(debugInfoList);
757 if (!reply.WriteInt32(result)) {
758 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
759 return ERR_INVALID_VALUE;
760 }
761
762 int32_t listSize = static_cast<int32_t>(debugInfoList.size());
763 if (listSize > MAX_APP_DEBUG_COUNT) {
764 TAG_LOGE(AAFwkTag::APPMGR, "Max app debug count is %{public}d.", listSize);
765 return ERR_INVALID_VALUE;
766 }
767
768 if (!reply.WriteInt32(listSize)) {
769 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write list size.");
770 return ERR_INVALID_VALUE;
771 }
772
773 if (!reply.WriteStringVector(debugInfoList)) {
774 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write string vector debug info list.");
775 return ERR_INVALID_VALUE;
776 }
777 return NO_ERROR;
778 }
779
HandleIsWaitingDebugApp(MessageParcel & data,MessageParcel & reply)780 int32_t AmsMgrStub::HandleIsWaitingDebugApp(MessageParcel &data, MessageParcel &reply)
781 {
782 TAG_LOGD(AAFwkTag::APPMGR, "called");
783 auto bundleName = data.ReadString();
784 if (bundleName.empty()) {
785 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
786 return ERR_INVALID_VALUE;
787 }
788
789 auto result = IsWaitingDebugApp(bundleName);
790 if (!reply.WriteBool(result)) {
791 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
792 return ERR_INVALID_VALUE;
793 }
794 return NO_ERROR;
795 }
796
HandleSetKeepAliveEnableState(MessageParcel & data,MessageParcel & reply)797 int32_t AmsMgrStub::HandleSetKeepAliveEnableState(MessageParcel &data, MessageParcel &reply)
798 {
799 TAG_LOGD(AAFwkTag::APPMGR, "called");
800 auto bundleName = data.ReadString();
801 auto enable = data.ReadBool();
802 auto uid = data.ReadInt32();
803 SetKeepAliveEnableState(bundleName, enable, uid);
804 return NO_ERROR;
805 }
806
HandleSetKeepAliveDkv(MessageParcel & data,MessageParcel & reply)807 int32_t AmsMgrStub::HandleSetKeepAliveDkv(MessageParcel &data, MessageParcel &reply)
808 {
809 TAG_LOGD(AAFwkTag::APPMGR, "called");
810 auto bundleName = data.ReadString();
811 auto enable = data.ReadBool();
812 auto uid = data.ReadInt32();
813 SetKeepAliveDkv(bundleName, enable, uid);
814 return NO_ERROR;
815 }
816
HandleSetKeepAliveAppService(MessageParcel & data,MessageParcel & reply)817 int32_t AmsMgrStub::HandleSetKeepAliveAppService(MessageParcel &data, MessageParcel &reply)
818 {
819 TAG_LOGD(AAFwkTag::APPMGR, "HandleSetKeepAliveAppService called");
820 auto bundleName = data.ReadString();
821 auto enable = data.ReadBool();
822 auto uid = data.ReadInt32();
823 SetKeepAliveAppService(bundleName, enable, uid);
824 return NO_ERROR;
825 }
826
HandleClearNonPersistWaitingDebugFlag(MessageParcel & data,MessageParcel & reply)827 int32_t AmsMgrStub::HandleClearNonPersistWaitingDebugFlag(MessageParcel &data, MessageParcel &reply)
828 {
829 TAG_LOGD(AAFwkTag::APPMGR, "called");
830 ClearNonPersistWaitingDebugFlag();
831 return NO_ERROR;
832 }
833
HandleRegisterAbilityDebugResponse(MessageParcel & data,MessageParcel & reply)834 int32_t AmsMgrStub::HandleRegisterAbilityDebugResponse(MessageParcel &data, MessageParcel &reply)
835 {
836 TAG_LOGD(AAFwkTag::APPMGR, "called");
837 auto response = iface_cast<IAbilityDebugResponse>(data.ReadRemoteObject());
838 if (response == nullptr) {
839 TAG_LOGE(AAFwkTag::APPMGR, "Response is nullptr.");
840 return ERR_INVALID_VALUE;
841 }
842
843 auto result = RegisterAbilityDebugResponse(response);
844 if (!reply.WriteInt32(result)) {
845 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
846 return ERR_INVALID_VALUE;
847 }
848 return NO_ERROR;
849 }
850
HandleIsAttachDebug(MessageParcel & data,MessageParcel & reply)851 int32_t AmsMgrStub::HandleIsAttachDebug(MessageParcel &data, MessageParcel &reply)
852 {
853 TAG_LOGD(AAFwkTag::APPMGR, "called");
854 auto bundleName = data.ReadString();
855 if (bundleName.empty()) {
856 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
857 return ERR_INVALID_VALUE;
858 }
859
860 auto result = IsAttachDebug(bundleName);
861 if (!reply.WriteBool(result)) {
862 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
863 return ERR_INVALID_VALUE;
864 }
865 return NO_ERROR;
866 }
867
HandleClearProcessByToken(MessageParcel & data,MessageParcel & reply)868 int32_t AmsMgrStub::HandleClearProcessByToken(MessageParcel &data, MessageParcel &reply)
869 {
870 HITRACE_METER(HITRACE_TAG_APP);
871 sptr<IRemoteObject> token = data.ReadRemoteObject();
872 ClearProcessByToken(token);
873 return NO_ERROR;
874 }
875
HandleIsMemorySizeSufficent(MessageParcel & data,MessageParcel & reply)876 int32_t AmsMgrStub::HandleIsMemorySizeSufficent(MessageParcel &data, MessageParcel &reply)
877 {
878 auto result = IsMemorySizeSufficent();
879 if (!reply.WriteBool(result)) {
880 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
881 return ERR_INVALID_VALUE;
882 }
883 return NO_ERROR;
884 }
885
HandleIsNoRequireBigMemory(MessageParcel & data,MessageParcel & reply)886 int32_t AmsMgrStub::HandleIsNoRequireBigMemory(MessageParcel &data, MessageParcel &reply)
887 {
888 auto result = IsNoRequireBigMemory();
889 if (!reply.WriteBool(result)) {
890 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
891 return ERR_INVALID_VALUE;
892 }
893 return NO_ERROR;
894 }
895
HandleAttachedToStatusBar(MessageParcel & data,MessageParcel & reply)896 ErrCode AmsMgrStub::HandleAttachedToStatusBar(MessageParcel &data, MessageParcel &reply)
897 {
898 HITRACE_METER(HITRACE_TAG_APP);
899 sptr<IRemoteObject> token = data.ReadRemoteObject();
900 AttachedToStatusBar(token);
901 return NO_ERROR;
902 }
903
HandleBlockProcessCacheByPids(MessageParcel & data,MessageParcel & reply)904 ErrCode AmsMgrStub::HandleBlockProcessCacheByPids(MessageParcel &data, MessageParcel &reply)
905 {
906 HITRACE_METER(HITRACE_TAG_APP);
907 auto size = data.ReadUint32();
908 if (size == 0 || size > MAX_KILL_PROCESS_PID_COUNT) {
909 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size.");
910 return ERR_INVALID_VALUE;
911 }
912 std::vector<int32_t> pids;
913 for (uint32_t i = 0; i < size; i++) {
914 pids.emplace_back(data.ReadInt32());
915 }
916
917 BlockProcessCacheByPids(pids);
918 return NO_ERROR;
919 }
920
HandleIsKilledForUpgradeWeb(MessageParcel & data,MessageParcel & reply)921 int32_t AmsMgrStub::HandleIsKilledForUpgradeWeb(MessageParcel &data, MessageParcel &reply)
922 {
923 TAG_LOGD(AAFwkTag::APPMGR, "called");
924 auto bundleName = data.ReadString();
925 if (bundleName.empty()) {
926 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
927 return ERR_INVALID_VALUE;
928 }
929
930 auto result = IsKilledForUpgradeWeb(bundleName);
931 if (!reply.WriteBool(result)) {
932 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
933 return ERR_INVALID_VALUE;
934 }
935 return NO_ERROR;
936 }
937
HandleCleanAbilityByUserRequest(MessageParcel & data,MessageParcel & reply)938 ErrCode AmsMgrStub::HandleCleanAbilityByUserRequest(MessageParcel &data, MessageParcel &reply)
939 {
940 HITRACE_METER(HITRACE_TAG_APP);
941 sptr<IRemoteObject> token = data.ReadRemoteObject();
942 auto result = CleanAbilityByUserRequest(token);
943 if (!reply.WriteBool(result)) {
944 TAG_LOGE(AAFwkTag::APPMGR, "fail to write the result.");
945 return ERR_INVALID_VALUE;
946 }
947 return NO_ERROR;
948 }
949
HandleIsProcessContainsOnlyUIAbility(MessageParcel & data,MessageParcel & reply)950 int32_t AmsMgrStub::HandleIsProcessContainsOnlyUIAbility(MessageParcel &data, MessageParcel &reply)
951 {
952 auto pid = data.ReadUint32();
953
954 auto result = IsProcessContainsOnlyUIAbility(pid);
955 if (!reply.WriteBool(result)) {
956 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result in HandleIsProcessContainsOnlyUIAbility.");
957 return ERR_INVALID_VALUE;
958 }
959 return NO_ERROR;
960 }
961
HandleIsProcessAttached(MessageParcel & data,MessageParcel & reply)962 int32_t AmsMgrStub::HandleIsProcessAttached(MessageParcel &data, MessageParcel &reply)
963 {
964 HITRACE_METER(HITRACE_TAG_APP);
965 sptr<IRemoteObject> token = data.ReadRemoteObject();
966 auto isAttached = IsProcessAttached(token);
967 if (!reply.WriteBool(isAttached)) {
968 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result");
969 return ERR_INVALID_VALUE;
970 }
971 return NO_ERROR;
972 }
973
HandleIsCallerKilling(MessageParcel & data,MessageParcel & reply)974 int32_t AmsMgrStub::HandleIsCallerKilling(MessageParcel &data, MessageParcel &reply)
975 {
976 HITRACE_METER(HITRACE_TAG_APP);
977 auto callerKey = data.ReadString();
978 auto isCallerKilling = IsCallerKilling(callerKey);
979 if (!reply.WriteBool(isCallerKilling)) {
980 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result");
981 return ERR_INVALID_VALUE;
982 }
983 return NO_ERROR;
984 }
985
HandlePreloadApplicationByPhase(MessageParcel & data,MessageParcel & reply)986 int32_t AmsMgrStub::HandlePreloadApplicationByPhase(MessageParcel &data, MessageParcel &reply)
987 {
988 HITRACE_METER(HITRACE_TAG_APP);
989 auto bundleName = data.ReadString();
990 auto userId = data.ReadInt32();
991 auto appIndex = data.ReadInt32();
992 auto preloadPhase = data.ReadInt32();
993 auto ret = PreloadApplicationByPhase(bundleName, userId, appIndex,
994 static_cast<AppExecFwk::PreloadPhase>(preloadPhase));
995 if (!reply.WriteInt32(ret)) {
996 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write ret");
997 return AAFwk::ERR_WRITE_RESULT_CODE_FAILED;
998 }
999 return NO_ERROR;
1000 }
1001
HandleNotifyPreloadAbilityStateChanged(MessageParcel & data,MessageParcel & reply)1002 int32_t AmsMgrStub::HandleNotifyPreloadAbilityStateChanged(MessageParcel &data, MessageParcel &reply)
1003 {
1004 HITRACE_METER(HITRACE_TAG_APP);
1005 sptr<IRemoteObject> token = data.ReadRemoteObject();
1006 bool isPreForeground = data.ReadBool();
1007 if (token == nullptr) {
1008 TAG_LOGE(AAFwkTag::APPMGR, "null token");
1009 return AAFwk::INVALID_CALLER_TOKEN;
1010 }
1011 auto ret = NotifyPreloadAbilityStateChanged(token, isPreForeground);
1012 if (!reply.WriteInt32(ret)) {
1013 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write ret");
1014 return AAFwk::ERR_WRITE_RESULT_CODE_FAILED;
1015 }
1016 return NO_ERROR;
1017 }
1018
HandleCheckPreloadAppRecordExist(MessageParcel & data,MessageParcel & reply)1019 int32_t AmsMgrStub::HandleCheckPreloadAppRecordExist(MessageParcel &data, MessageParcel &reply)
1020 {
1021 HITRACE_METER(HITRACE_TAG_APP);
1022 auto bundleName = data.ReadString();
1023 auto userId = data.ReadInt32();
1024 auto appIndex = data.ReadInt32();
1025 bool isExist = false;
1026 auto ret = CheckPreloadAppRecordExist(bundleName, userId, appIndex, isExist);
1027 if (!reply.WriteInt32(ret)) {
1028 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write ret");
1029 return AAFwk::ERR_WRITE_RESULT_CODE_FAILED;
1030 }
1031 if (ret == NO_ERROR && !reply.WriteBool(isExist)) {
1032 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write isExist");
1033 return AAFwk::ERR_WRITE_BOOL_FAILED;
1034 }
1035 return NO_ERROR;
1036 }
1037
HandleVerifyKillProcessPermission(MessageParcel & data,MessageParcel & reply)1038 int32_t AmsMgrStub::HandleVerifyKillProcessPermission(MessageParcel &data, MessageParcel &reply)
1039 {
1040 TAG_LOGD(AAFwkTag::APPMGR, "called");
1041 auto bundleName = data.ReadString();
1042 if (bundleName.empty()) {
1043 TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
1044 return ERR_INVALID_VALUE;
1045 }
1046
1047 auto result = VerifyKillProcessPermission(bundleName);
1048 if (!reply.WriteInt32(result)) {
1049 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1050 return AAFwk::ERR_WRITE_RESULT_CODE_FAILED;
1051 }
1052 return NO_ERROR;
1053 }
1054 } // namespace AppExecFwk
1055 } // namespace OHOS
1056