• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "install_plugin_param.h"
17 
18 #include "app_log_wrapper.h"
19 #include "parcel_macro.h"
20 #include "string_ex.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 namespace {
25 constexpr const char* RENAME_INSTALL_KEY = "ohos.bms.param.renameInstall";
26 constexpr const char* PARAMETERS_VALUE_TRUE = "true";
27 }
28 
ReadFromParcel(Parcel & parcel)29 bool InstallPluginParam::ReadFromParcel(Parcel &parcel)
30 {
31     userId = parcel.ReadInt32();
32 
33     uint32_t parametersSize;
34     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, parametersSize);
35     CONTAINER_SECURITY_VERIFY(parcel, parametersSize, &parameters);
36     for (uint32_t i = 0; i < parametersSize; ++i) {
37         std::string key = parcel.ReadString();
38         std::string value = parcel.ReadString();
39         parameters.emplace(key, value);
40     }
41     return true;
42 }
43 
Unmarshalling(Parcel & parcel)44 InstallPluginParam *InstallPluginParam::Unmarshalling(Parcel &parcel)
45 {
46     InstallPluginParam *info = new (std::nothrow) InstallPluginParam();
47     if (info && !info->ReadFromParcel(parcel)) {
48         APP_LOGW("read from parcel failed");
49         delete info;
50         info = nullptr;
51     }
52     return info;
53 }
54 
Marshalling(Parcel & parcel) const55 bool InstallPluginParam::Marshalling(Parcel &parcel) const
56 {
57     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
58 
59     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, static_cast<uint32_t>(parameters.size()));
60     for (const auto &parameter : parameters) {
61         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, parameter.first);
62         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, parameter.second);
63     }
64     return true;
65 }
66 
IsRenameInstall() const67 bool InstallPluginParam::IsRenameInstall() const
68 {
69     for (const auto &item : parameters) {
70         if ((item.first == RENAME_INSTALL_KEY) && (item.second == PARAMETERS_VALUE_TRUE)) {
71             return true;
72         }
73     }
74     return false;
75 }
76 }  // namespace AppExecFwk
77 }  // namespace OHOS