• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "app_control_host.h"
17 
18 #include "app_control_constants.h"
19 #include "app_log_tag_wrapper.h"
20 #include "app_log_wrapper.h"
21 #include "appexecfwk_errors.h"
22 #include "bundle_framework_core_ipc_interface_code.h"
23 #include "bundle_memory_guard.h"
24 #include "disposed_rule.h"
25 #include "ipc_types.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
AppControlHost()29 AppControlHost::AppControlHost()
30 {
31     LOG_D(BMS_TAG_DEFAULT, "create AppControlHost");
32 }
33 
~AppControlHost()34 AppControlHost::~AppControlHost()
35 {
36     LOG_D(BMS_TAG_DEFAULT, "destroy AppControlHost");
37 }
38 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int AppControlHost::OnRemoteRequest(
40     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
41 {
42     BundleMemoryGuard memoryGuard;
43     LOG_I(BMS_TAG_DEFAULT, "AppControlHost OnRemoteRequest, message code : %{public}u", code);
44     std::u16string descriptor = AppControlHost::GetDescriptor();
45     std::u16string remoteDescriptor = data.ReadInterfaceToken();
46     if (descriptor != remoteDescriptor) {
47         LOG_E(BMS_TAG_DEFAULT, "descriptor invalid");
48         return OBJECT_NULL;
49     }
50 
51     switch (code) {
52         case static_cast<uint32_t>(AppControlManagerInterfaceCode::ADD_APP_INSTALL_CONTROL_RULE):
53             return HandleAddAppInstallControlRule(data, reply);
54         case static_cast<uint32_t>(AppControlManagerInterfaceCode::DELETE_APP_INSTALL_CONTROL_RULE):
55             return HandleDeleteAppInstallControlRule(data, reply);
56         case static_cast<uint32_t>(AppControlManagerInterfaceCode::CLEAN_APP_INSTALL_CONTROL_RULE):
57             return HandleCleanAppInstallControlRule(data, reply);
58         case static_cast<uint32_t>(AppControlManagerInterfaceCode::GET_APP_INSTALL_CONTROL_RULE):
59             return HandleGetAppInstallControlRule(data, reply);
60         case static_cast<uint32_t>(AppControlManagerInterfaceCode::ADD_APP_RUNNING_CONTROL_RULE):
61             return HandleAddAppRunningControlRule(data, reply);
62         case static_cast<uint32_t>(AppControlManagerInterfaceCode::DELETE_APP_RUNNING_CONTROL_RULE):
63             return HandleDeleteAppRunningControlRule(data, reply);
64         case static_cast<uint32_t>(AppControlManagerInterfaceCode::CLEAN_APP_RUNNING_CONTROL_RULE):
65             return HandleCleanAppRunningControlRule(data, reply);
66         case static_cast<uint32_t>(AppControlManagerInterfaceCode::GET_APP_RUNNING_CONTROL_RULE):
67             return HandleGetAppRunningControlRule(data, reply);
68         case static_cast<uint32_t>(AppControlManagerInterfaceCode::GET_APP_RUNNING_CONTROL_RULE_RESULT):
69             return HandleGetAppRunningControlRuleResult(data, reply);
70         case static_cast<uint32_t>(AppControlManagerInterfaceCode::CONFIRM_APP_JUMP_CONTROL_RULE):
71             return HandleConfirmAppJumpControlRule(data, reply);
72         case static_cast<uint32_t>(AppControlManagerInterfaceCode::ADD_APP_JUMP_CONTROL_RULE):
73             return HandleAddAppJumpControlRule(data, reply);
74         case static_cast<uint32_t>(AppControlManagerInterfaceCode::DELETE_APP_JUMP_CONTROL_RULE):
75             return HandleDeleteAppJumpControlRule(data, reply);
76         case static_cast<uint32_t>(AppControlManagerInterfaceCode::DELETE_APP_JUMP_CONTROL_RULE_BY_CALLER):
77             return HandleDeleteRuleByCallerBundleName(data, reply);
78         case static_cast<uint32_t>(AppControlManagerInterfaceCode::DELETE_APP_JUMP_CONTROL_RULE_BY_TARGET):
79             return HandleDeleteRuleByTargetBundleName(data, reply);
80         case static_cast<uint32_t>(AppControlManagerInterfaceCode::GET_APP_JUMP_CONTROL_RULE):
81             return HandleGetAppJumpControlRule(data, reply);
82         case static_cast<uint32_t>(AppControlManagerInterfaceCode::SET_DISPOSED_STATUS):
83             return HandleSetDisposedStatus(data, reply);
84         case static_cast<uint32_t>(AppControlManagerInterfaceCode::GET_DISPOSED_STATUS):
85             return HandleGetDisposedStatus(data, reply);
86         case static_cast<uint32_t>(AppControlManagerInterfaceCode::DELETE_DISPOSED_STATUS):
87             return HandleDeleteDisposedStatus(data, reply);
88         case static_cast<uint32_t>(AppControlManagerInterfaceCode::SET_DISPOSED_RULE):
89             return HandleSetDisposedRule(data, reply);
90         case static_cast<uint32_t>(AppControlManagerInterfaceCode::GET_DISPOSED_RULE):
91             return HandleGetDisposedRule(data, reply);
92         case static_cast<uint32_t>(AppControlManagerInterfaceCode::GET_ABILITY_RUNNING_CONTROL_RULE):
93             return HandleGetAbilityRunningControlRule(data, reply);
94         case static_cast<uint32_t>(AppControlManagerInterfaceCode::GET_DISPOSED_RULE_FOR_CLONE_APP):
95             return HandleGetDisposedRuleForCloneApp(data, reply);
96         case static_cast<uint32_t>(AppControlManagerInterfaceCode::SET_DISPOSED_RULE_FOR_CLONE_APP):
97             return HandleSetDisposedRuleForCloneApp(data, reply);
98         case static_cast<uint32_t>(AppControlManagerInterfaceCode::DELETE_DISPOSED_RULE_FOR_CLONE_APP):
99             return HandleDeleteDisposedRuleForCloneApp(data, reply);
100         case static_cast<uint32_t>(AppControlManagerInterfaceCode::SET_UNINSTALL_DISPOSED_RULE):
101             return HandleSetUninstallDisposedRule(data, reply);
102         case static_cast<uint32_t>(AppControlManagerInterfaceCode::GET_UNINSTALL_DISPOSED_RULE):
103             return HandleGetUninstallDisposedRule(data, reply);
104         case static_cast<uint32_t>(AppControlManagerInterfaceCode::DELETE_UNINSTALL_DISPOSED_RULE):
105             return HandleDeleteUninstallDisposedRule(data, reply);
106         default:
107             LOG_W(BMS_TAG_DEFAULT, "AppControlHost receive unknown code, code = %{public}d", code);
108             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
109     }
110 }
111 
HandleAddAppInstallControlRule(MessageParcel & data,MessageParcel & reply)112 ErrCode AppControlHost::HandleAddAppInstallControlRule(MessageParcel& data, MessageParcel& reply)
113 {
114     std::vector<std::string> appIds;
115     int32_t appIdSize = data.ReadInt32();
116     if (appIdSize > AppControlConstants::LIST_MAX_SIZE || appIdSize < 0) {
117         LOG_E(BMS_TAG_DEFAULT, "HandleAddAppInstallControlRule parameter is invalid");
118         return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
119     }
120     appIds.reserve(appIdSize);
121     for (int32_t i = 0; i < appIdSize; i++) {
122         appIds.emplace_back(data.ReadString());
123     }
124     AppInstallControlRuleType controlRuleType = static_cast<AppInstallControlRuleType>(data.ReadInt32());
125     int32_t userId = data.ReadInt32();
126     int32_t ret = AddAppInstallControlRule(appIds, controlRuleType, userId);
127     if (ret != ERR_OK) {
128         LOG_E(BMS_TAG_DEFAULT, "HandleAddAppInstallControlRule failed");
129     }
130     return ret;
131 }
132 
HandleDeleteAppInstallControlRule(MessageParcel & data,MessageParcel & reply)133 ErrCode AppControlHost::HandleDeleteAppInstallControlRule(MessageParcel& data, MessageParcel& reply)
134 {
135     AppInstallControlRuleType controlRuleType = static_cast<AppInstallControlRuleType>(data.ReadInt32());
136     std::vector<std::string> appIds;
137     int32_t appIdSize = data.ReadInt32();
138     if (appIdSize > AppControlConstants::LIST_MAX_SIZE || appIdSize < 0) {
139         LOG_E(BMS_TAG_DEFAULT, "HandleDeleteAppInstallControlRule parameter is invalid");
140         return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
141     }
142     appIds.reserve(appIdSize);
143     for (int32_t i = 0; i < appIdSize; i++) {
144         appIds.emplace_back(data.ReadString());
145     }
146     int32_t userId = data.ReadInt32();
147     int32_t ret = DeleteAppInstallControlRule(controlRuleType, appIds, userId);
148     if (ret != ERR_OK) {
149         LOG_E(BMS_TAG_DEFAULT, "HandleDeleteAppInstallControlRule failed");
150     }
151     return ret;
152 }
153 
HandleCleanAppInstallControlRule(MessageParcel & data,MessageParcel & reply)154 ErrCode AppControlHost::HandleCleanAppInstallControlRule(MessageParcel& data, MessageParcel& reply)
155 {
156     AppInstallControlRuleType controlRuleType = static_cast<AppInstallControlRuleType>(data.ReadInt32());
157     int32_t userId = data.ReadInt32();
158     int32_t ret = DeleteAppInstallControlRule(controlRuleType, userId);
159     if (ret != ERR_OK) {
160         LOG_E(BMS_TAG_DEFAULT, "HandleCleanAppInstallControlRule failed");
161     }
162     return ret;
163 }
164 
HandleGetAppInstallControlRule(MessageParcel & data,MessageParcel & reply)165 ErrCode AppControlHost::HandleGetAppInstallControlRule(MessageParcel& data, MessageParcel& reply)
166 {
167     AppInstallControlRuleType controlRuleType = static_cast<AppInstallControlRuleType>(data.ReadInt32());
168     int32_t userId = data.ReadInt32();
169     std::vector<std::string> appIds;
170     int32_t ret = GetAppInstallControlRule(controlRuleType, userId, appIds);
171     if (ret != ERR_OK) {
172         LOG_E(BMS_TAG_DEFAULT, "HandleGetAppInstallControlRule failed");
173         return ret;
174     }
175     if (!WriteStringVector(appIds, reply)) {
176         LOG_E(BMS_TAG_DEFAULT, "write appIds failed");
177         return ERR_APPEXECFWK_PARCEL_ERROR;
178     }
179     return ERR_OK;
180 }
181 
HandleAddAppRunningControlRule(MessageParcel & data,MessageParcel & reply)182 ErrCode AppControlHost::HandleAddAppRunningControlRule(MessageParcel& data, MessageParcel& reply)
183 {
184     std::vector<AppRunningControlRule> controlRules;
185     auto ret = ReadParcelableVector(data, controlRules);
186     if (ret != ERR_OK) {
187         LOG_E(BMS_TAG_DEFAULT, "AddAppRunningControlRule read controlRuleParam failed");
188         return ret;
189     }
190     int32_t userId = data.ReadInt32();
191     return AddAppRunningControlRule(controlRules, userId);
192 }
193 
HandleDeleteAppRunningControlRule(MessageParcel & data,MessageParcel & reply)194 ErrCode AppControlHost::HandleDeleteAppRunningControlRule(MessageParcel& data, MessageParcel& reply)
195 {
196     std::vector<AppRunningControlRule> controlRules;
197     auto ret = ReadParcelableVector(data, controlRules);
198     if (ret != ERR_OK) {
199         LOG_E(BMS_TAG_DEFAULT, "DeleteAppRunningControlRule read controlRuleParam failed");
200         return ret;
201     }
202     int32_t userId = data.ReadInt32();
203     return DeleteAppRunningControlRule(controlRules, userId);
204 }
205 
HandleCleanAppRunningControlRule(MessageParcel & data,MessageParcel & reply)206 ErrCode AppControlHost::HandleCleanAppRunningControlRule(MessageParcel& data, MessageParcel& reply)
207 {
208     int32_t userId = data.ReadInt32();
209     int32_t ret = DeleteAppRunningControlRule(userId);
210     if (ret != ERR_OK) {
211         LOG_E(BMS_TAG_DEFAULT, "HandleCleanAppInstallControlRule failed");
212     }
213     return ret;
214 }
215 
HandleGetAppRunningControlRule(MessageParcel & data,MessageParcel & reply)216 ErrCode AppControlHost::HandleGetAppRunningControlRule(MessageParcel& data, MessageParcel& reply)
217 {
218     int32_t userId = data.ReadInt32();
219     std::vector<std::string> appIds;
220     int32_t ret = GetAppRunningControlRule(userId, appIds);
221     if (ret != ERR_OK) {
222         LOG_E(BMS_TAG_DEFAULT, "HandleGetAppRunningControlRule failed");
223         return ret;
224     }
225     if (!WriteStringVector(appIds, reply)) {
226         LOG_E(BMS_TAG_DEFAULT, "write appIds failed");
227         return ERR_APPEXECFWK_PARCEL_ERROR;
228     }
229     return ERR_OK;
230 }
231 
HandleGetAppRunningControlRuleResult(MessageParcel & data,MessageParcel & reply)232 ErrCode AppControlHost::HandleGetAppRunningControlRuleResult(MessageParcel& data, MessageParcel& reply)
233 {
234     std::string bundleName = data.ReadString();
235     int32_t userId = data.ReadInt32();
236     AppRunningControlRuleResult ruleResult;
237     int32_t ret = GetAppRunningControlRule(bundleName, userId, ruleResult);
238     if (ret != ERR_OK) {
239         LOG_E(BMS_TAG_DEFAULT, "HandleGetAppRunningControlRuleResult failed");
240     }
241     if (!reply.WriteInt32(ret)) {
242         LOG_E(BMS_TAG_DEFAULT, "write result failed");
243         return ERR_APPEXECFWK_PARCEL_ERROR;
244     }
245     if ((ret == ERR_OK) && !reply.WriteParcelable(&ruleResult)) {
246         LOG_E(BMS_TAG_DEFAULT, "write AppRunningControlRuleResult failed");
247         return ERR_APPEXECFWK_PARCEL_ERROR;
248     }
249     return ERR_OK;
250 }
251 
HandleConfirmAppJumpControlRule(MessageParcel & data,MessageParcel & reply)252 ErrCode AppControlHost::HandleConfirmAppJumpControlRule(MessageParcel& data, MessageParcel& reply)
253 {
254     std::string callerBundleName = data.ReadString();
255     std::string targetBundleName = data.ReadString();
256     int32_t userId = data.ReadInt32();
257     int32_t ret = ConfirmAppJumpControlRule(callerBundleName, targetBundleName, userId);
258     if (ret != ERR_OK) {
259         LOG_E(BMS_TAG_DEFAULT, "HandleConfirmAppJumpControlRule failed");
260     }
261     return ret;
262 }
263 
HandleAddAppJumpControlRule(MessageParcel & data,MessageParcel & reply)264 ErrCode AppControlHost::HandleAddAppJumpControlRule(MessageParcel& data, MessageParcel& reply)
265 {
266     std::vector<AppJumpControlRule> controlRules;
267     auto ret = ReadParcelableVector(data, controlRules);
268     if (ret != ERR_OK) {
269         LOG_E(BMS_TAG_DEFAULT, "HandleAddAppJumpControlRule read controlRuleParam failed");
270         return ret;
271     }
272     int32_t userId = data.ReadInt32();
273     return AddAppJumpControlRule(controlRules, userId);
274 }
275 
HandleDeleteAppJumpControlRule(MessageParcel & data,MessageParcel & reply)276 ErrCode AppControlHost::HandleDeleteAppJumpControlRule(MessageParcel& data, MessageParcel& reply)
277 {
278     std::vector<AppJumpControlRule> controlRules;
279     auto ret = ReadParcelableVector(data, controlRules);
280     if (ret != ERR_OK) {
281         LOG_E(BMS_TAG_DEFAULT, "HandleDeleteAppJumpControlRule read controlRuleParam failed");
282         return ret;
283     }
284     int32_t userId = data.ReadInt32();
285     return DeleteAppJumpControlRule(controlRules, userId);
286 }
287 
HandleDeleteRuleByCallerBundleName(MessageParcel & data,MessageParcel & reply)288 ErrCode AppControlHost::HandleDeleteRuleByCallerBundleName(MessageParcel& data, MessageParcel& reply)
289 {
290     std::string callerBundleName = data.ReadString();
291     int32_t userId = data.ReadInt32();
292     int32_t ret = DeleteRuleByCallerBundleName(callerBundleName, userId);
293     if (ret != ERR_OK) {
294         LOG_E(BMS_TAG_DEFAULT, "HandleDeleteRuleByCallerBundleName failed");
295     }
296     return ret;
297 }
298 
HandleDeleteRuleByTargetBundleName(MessageParcel & data,MessageParcel & reply)299 ErrCode AppControlHost::HandleDeleteRuleByTargetBundleName(MessageParcel& data, MessageParcel& reply)
300 {
301     std::string targetBundleName = data.ReadString();
302     int32_t userId = data.ReadInt32();
303     int32_t ret = DeleteRuleByTargetBundleName(targetBundleName, userId);
304     if (ret != ERR_OK) {
305         LOG_E(BMS_TAG_DEFAULT, "HandleDeleteRuleByTargetBundleName failed");
306     }
307     return ret;
308 }
309 
HandleGetAppJumpControlRule(MessageParcel & data,MessageParcel & reply)310 ErrCode AppControlHost::HandleGetAppJumpControlRule(MessageParcel& data, MessageParcel& reply)
311 {
312     std::string callerBundleName = data.ReadString();
313     std::string targetBundleName = data.ReadString();
314     int32_t userId = data.ReadInt32();
315     AppJumpControlRule rule;
316     int32_t ret = GetAppJumpControlRule(callerBundleName, targetBundleName, userId, rule);
317     if (ret != ERR_OK) {
318         LOG_E(BMS_TAG_DEFAULT, "HandleGetAppJumpControlRule failed");
319     }
320     if (!reply.WriteInt32(ret)) {
321         LOG_E(BMS_TAG_DEFAULT, "write result failed");
322         return ERR_APPEXECFWK_PARCEL_ERROR;
323     }
324     if ((ret == ERR_OK) && !reply.WriteParcelable(&rule)) {
325         LOG_E(BMS_TAG_DEFAULT, "write AppJumpControlRule failed");
326         return ERR_APPEXECFWK_PARCEL_ERROR;
327     }
328     return ERR_OK;
329 }
330 
HandleSetDisposedStatus(MessageParcel & data,MessageParcel & reply)331 ErrCode AppControlHost::HandleSetDisposedStatus(MessageParcel& data, MessageParcel& reply)
332 {
333     std::string appId = data.ReadString();
334     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
335     int32_t userId = data.ReadInt32();
336     if (want == nullptr) {
337         LOG_E(BMS_TAG_DEFAULT, "ReadParcelable<Want> failed");
338         return ERR_APPEXECFWK_PARCEL_ERROR;
339     }
340     ErrCode ret = SetDisposedStatus(appId, *want, userId);
341     if (!reply.WriteInt32(ret)) {
342         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
343         return ERR_APPEXECFWK_PARCEL_ERROR;
344     }
345     return ERR_OK;
346 }
347 
HandleDeleteDisposedStatus(MessageParcel & data,MessageParcel & reply)348 ErrCode AppControlHost::HandleDeleteDisposedStatus(MessageParcel& data, MessageParcel &reply)
349 {
350     std::string appId = data.ReadString();
351     int32_t userId = data.ReadInt32();
352     ErrCode ret = DeleteDisposedStatus(appId, userId);
353     if (!reply.WriteInt32(ret)) {
354         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
355         return ERR_APPEXECFWK_PARCEL_ERROR;
356     }
357     return ERR_OK;
358 }
359 
HandleGetDisposedStatus(MessageParcel & data,MessageParcel & reply)360 ErrCode AppControlHost::HandleGetDisposedStatus(MessageParcel& data, MessageParcel &reply)
361 {
362     std::string appId = data.ReadString();
363     int32_t userId = data.ReadInt32();
364     Want want;
365     ErrCode ret = GetDisposedStatus(appId, want, userId);
366     if (!reply.WriteInt32(ret)) {
367         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
368         return ERR_APPEXECFWK_PARCEL_ERROR;
369     }
370     if (ret == ERR_OK) {
371         if (!reply.WriteParcelable(&want)) {
372             LOG_E(BMS_TAG_DEFAULT, "write failed");
373             return ERR_APPEXECFWK_PARCEL_ERROR;
374         }
375     }
376     return ERR_OK;
377 }
378 
HandleGetDisposedRule(MessageParcel & data,MessageParcel & reply)379 ErrCode AppControlHost::HandleGetDisposedRule(MessageParcel& data, MessageParcel &reply)
380 {
381     std::string appId = data.ReadString();
382     int32_t userId = data.ReadInt32();
383     DisposedRule rule;
384     ErrCode ret = GetDisposedRule(appId, rule, userId);
385     if (!reply.WriteInt32(ret)) {
386         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
387         return ERR_APPEXECFWK_PARCEL_ERROR;
388     }
389     if (ret == ERR_OK) {
390         if (!reply.WriteParcelable(&rule)) {
391             LOG_E(BMS_TAG_DEFAULT, "write failed");
392             return ERR_APPEXECFWK_PARCEL_ERROR;
393         }
394     }
395     return ERR_OK;
396 }
397 
HandleSetDisposedRule(MessageParcel & data,MessageParcel & reply)398 ErrCode AppControlHost::HandleSetDisposedRule(MessageParcel& data, MessageParcel& reply)
399 {
400     std::string appId = data.ReadString();
401     std::unique_ptr<DisposedRule> disposedRule(data.ReadParcelable<DisposedRule>());
402     int32_t userId = data.ReadInt32();
403     if (disposedRule == nullptr) {
404         LOG_E(BMS_TAG_DEFAULT, "ReadParcelable<disposedRule> failed");
405         return ERR_APPEXECFWK_PARCEL_ERROR;
406     }
407     ErrCode ret = SetDisposedRule(appId, *disposedRule, userId);
408     if (!reply.WriteInt32(ret)) {
409         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
410         return ERR_APPEXECFWK_PARCEL_ERROR;
411     }
412     return ERR_OK;
413 }
414 
HandleGetAbilityRunningControlRule(MessageParcel & data,MessageParcel & reply)415 ErrCode AppControlHost::HandleGetAbilityRunningControlRule(MessageParcel& data, MessageParcel& reply)
416 {
417     std::string bundleName = data.ReadString();
418     int32_t userId = data.ReadInt32();
419     int32_t appIndex = data.ReadInt32();
420     std::vector<DisposedRule> rules;
421     ErrCode ret = GetAbilityRunningControlRule(bundleName, userId, rules, appIndex);
422     if (!reply.WriteInt32(ret)) {
423         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
424         return ERR_APPEXECFWK_PARCEL_ERROR;
425     }
426     if (ret == ERR_OK) {
427         if (!WriteParcelableVector(rules, reply)) {
428             LOG_E(BMS_TAG_DEFAULT, "write failed");
429             return ERR_APPEXECFWK_PARCEL_ERROR;
430         }
431     }
432     return ERR_OK;
433 }
434 
HandleGetDisposedRuleForCloneApp(MessageParcel & data,MessageParcel & reply)435 ErrCode AppControlHost::HandleGetDisposedRuleForCloneApp(MessageParcel& data, MessageParcel &reply)
436 {
437     std::string appId = data.ReadString();
438     int32_t userId = data.ReadInt32();
439     int32_t appIndex = data.ReadInt32();
440     DisposedRule rule;
441     ErrCode ret = GetDisposedRuleForCloneApp(appId, rule, appIndex, userId);
442     if (!reply.WriteInt32(ret)) {
443         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
444         return ERR_APPEXECFWK_PARCEL_ERROR;
445     }
446     if (ret == ERR_OK) {
447         if (!reply.WriteParcelable(&rule)) {
448             LOG_E(BMS_TAG_DEFAULT, "write failed");
449             return ERR_APPEXECFWK_PARCEL_ERROR;
450         }
451     }
452     return ERR_OK;
453 }
454 
HandleSetDisposedRuleForCloneApp(MessageParcel & data,MessageParcel & reply)455 ErrCode AppControlHost::HandleSetDisposedRuleForCloneApp(MessageParcel& data, MessageParcel& reply)
456 {
457     std::string appId = data.ReadString();
458     std::unique_ptr<DisposedRule> disposedRule(data.ReadParcelable<DisposedRule>());
459     int32_t userId = data.ReadInt32();
460     int32_t appIndex = data.ReadInt32();
461     if (disposedRule == nullptr) {
462         LOG_E(BMS_TAG_DEFAULT, "ReadParcelable<disposedRule> failed");
463         return ERR_APPEXECFWK_PARCEL_ERROR;
464     }
465     ErrCode ret = SetDisposedRuleForCloneApp(appId, *disposedRule, appIndex, userId);
466     if (!reply.WriteInt32(ret)) {
467         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
468         return ERR_APPEXECFWK_PARCEL_ERROR;
469     }
470     return ERR_OK;
471 }
472 
HandleDeleteDisposedRuleForCloneApp(MessageParcel & data,MessageParcel & reply)473 ErrCode AppControlHost::HandleDeleteDisposedRuleForCloneApp(MessageParcel& data, MessageParcel& reply)
474 {
475     std::string appId = data.ReadString();
476     int32_t userId = data.ReadInt32();
477     int32_t appIndex = data.ReadInt32();
478     ErrCode ret = DeleteDisposedRuleForCloneApp(appId, appIndex, userId);
479     if (!reply.WriteInt32(ret)) {
480         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
481         return ERR_APPEXECFWK_PARCEL_ERROR;
482     }
483     return ERR_OK;
484 }
485 
WriteStringVector(const std::vector<std::string> & stringVector,MessageParcel & reply)486 bool AppControlHost::WriteStringVector(const std::vector<std::string> &stringVector, MessageParcel &reply)
487 {
488     if (!reply.WriteInt32(stringVector.size())) {
489         LOG_E(BMS_TAG_DEFAULT, "write ParcelableVector failed");
490         return false;
491     }
492 
493     for (auto &string : stringVector) {
494         if (!reply.WriteString(string)) {
495             LOG_E(BMS_TAG_DEFAULT, "write string failed");
496             return false;
497         }
498     }
499     return true;
500 }
501 
502 template<typename T>
WriteParcelableVector(std::vector<T> & parcelableVector,MessageParcel & reply)503 bool AppControlHost::WriteParcelableVector(std::vector<T> &parcelableVector, MessageParcel &reply)
504 {
505     if (!reply.WriteInt32(parcelableVector.size())) {
506         LOG_E(BMS_TAG_DEFAULT, "write ParcelableVector failed");
507         return false;
508     }
509 
510     for (auto &parcelable : parcelableVector) {
511         if (!reply.WriteParcelable(&parcelable)) {
512             LOG_E(BMS_TAG_DEFAULT, "write ParcelableVector failed");
513             return false;
514         }
515     }
516     return true;
517 }
518 
519 template<typename T>
ReadParcelableVector(MessageParcel & data,std::vector<T> & parcelableInfos)520 ErrCode AppControlHost::ReadParcelableVector(MessageParcel &data, std::vector<T> &parcelableInfos)
521 {
522     int32_t infoSize = data.ReadInt32();
523     if (infoSize > AppControlConstants::LIST_MAX_SIZE) {
524         LOG_E(BMS_TAG_DEFAULT, "elements num exceeds the limit %{public}d", AppControlConstants::LIST_MAX_SIZE);
525         return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
526     }
527     for (int32_t i = 0; i < infoSize; i++) {
528         std::unique_ptr<T> info(data.ReadParcelable<T>());
529         if (info == nullptr) {
530             LOG_E(BMS_TAG_DEFAULT, "read parcelable infos failed");
531             return ERR_APPEXECFWK_PARCEL_ERROR;
532         }
533         parcelableInfos.emplace_back(*info);
534     }
535     LOG_D(BMS_TAG_DEFAULT, "read parcelable infos success");
536     return ERR_OK;
537 }
538 
HandleGetUninstallDisposedRule(MessageParcel & data,MessageParcel & reply)539 ErrCode AppControlHost::HandleGetUninstallDisposedRule(MessageParcel& data, MessageParcel& reply)
540 {
541     std::string appIdentifier = data.ReadString();
542     int32_t userId = data.ReadInt32();
543     int32_t appIndex = data.ReadInt32();
544     UninstallDisposedRule rule;
545     ErrCode ret = GetUninstallDisposedRule(appIdentifier, appIndex, userId, rule);
546     if (!reply.WriteInt32(ret)) {
547         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
548         return ERR_APPEXECFWK_PARCEL_ERROR;
549     }
550     if (ret == ERR_OK) {
551         if (!reply.WriteParcelable(&rule)) {
552             LOG_E(BMS_TAG_DEFAULT, "write failed");
553             return ERR_APPEXECFWK_PARCEL_ERROR;
554         }
555     }
556     return ERR_OK;
557 }
558 
HandleSetUninstallDisposedRule(MessageParcel & data,MessageParcel & reply)559 ErrCode AppControlHost::HandleSetUninstallDisposedRule(MessageParcel& data, MessageParcel& reply)
560 {
561     std::string appIdentifier = data.ReadString();
562     std::unique_ptr<UninstallDisposedRule> uninstallDisposedRule(data.ReadParcelable<UninstallDisposedRule>());
563     if (uninstallDisposedRule == nullptr) {
564         LOG_E(BMS_TAG_DEFAULT, "ReadParcelable<uninstalldisposedRule> failed");
565         return ERR_APPEXECFWK_PARCEL_ERROR;
566     }
567     int32_t userId = data.ReadInt32();
568     int32_t appIndex = data.ReadInt32();
569     ErrCode ret = SetUninstallDisposedRule(appIdentifier, *uninstallDisposedRule, appIndex, userId);
570     if (!reply.WriteInt32(ret)) {
571         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
572         return ERR_APPEXECFWK_PARCEL_ERROR;
573     }
574     return ERR_OK;
575 }
576 
HandleDeleteUninstallDisposedRule(MessageParcel & data,MessageParcel & reply)577 ErrCode AppControlHost::HandleDeleteUninstallDisposedRule(MessageParcel& data, MessageParcel& reply)
578 {
579     std::string appIdentifier = data.ReadString();
580     int32_t userId = data.ReadInt32();
581     int32_t appIndex = data.ReadInt32();
582     ErrCode ret = DeleteUninstallDisposedRule(appIdentifier, appIndex, userId);
583     if (!reply.WriteInt32(ret)) {
584         LOG_E(BMS_TAG_DEFAULT, "write ret failed");
585         return ERR_APPEXECFWK_PARCEL_ERROR;
586     }
587     return ERR_OK;
588 }
589 } // AppExecFwk
590 } // OHOS
591