• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_param.h"
17 
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20 
21 #include "app_log_wrapper.h"
22 #include "parcel_macro.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)26 bool InstallParam::ReadFromParcel(Parcel &parcel)
27 {
28     int32_t flagData;
29     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, flagData);
30     installFlag = static_cast<InstallFlag>(flagData);
31 
32     int32_t locationData;
33     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, locationData);
34     installLocation = static_cast<InstallLocation>(locationData);
35 
36     userId = parcel.ReadInt32();
37     isKeepData = parcel.ReadBool();
38 
39     int32_t hashParamSize;
40     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hashParamSize);
41     CONTAINER_SECURITY_VERIFY(parcel, hashParamSize, &hashParams);
42     for (int32_t i = 0; i < hashParamSize; ++i) {
43         std::string moduleName = Str16ToStr8(parcel.ReadString16());
44         std::string hashValue = Str16ToStr8(parcel.ReadString16());
45         hashParams.emplace(moduleName, hashValue);
46     }
47     crowdtestDeadline = parcel.ReadInt64();
48 
49     int32_t sharedBundleDirPathsSize;
50     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, sharedBundleDirPathsSize);
51     CONTAINER_SECURITY_VERIFY(parcel, sharedBundleDirPathsSize, &sharedBundleDirPaths);
52     for (int32_t i = 0; i < sharedBundleDirPathsSize; ++i) {
53         std::string sharedBundleDirPath = Str16ToStr8(parcel.ReadString16());
54         sharedBundleDirPaths.emplace_back(sharedBundleDirPath);
55     }
56     specifiedDistributionType = Str16ToStr8(parcel.ReadString16());
57     additionalInfo = Str16ToStr8(parcel.ReadString16());
58 
59     int32_t verifyCodeParamSize;
60     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, verifyCodeParamSize);
61     CONTAINER_SECURITY_VERIFY(parcel, verifyCodeParamSize, &verifyCodeParams);
62     for (int32_t i = 0; i < verifyCodeParamSize; ++i) {
63         std::string moduleName = Str16ToStr8(parcel.ReadString16());
64         std::string signatureFilePath = Str16ToStr8(parcel.ReadString16());
65         verifyCodeParams.emplace(moduleName, signatureFilePath);
66     }
67     isSelfUpdate = parcel.ReadBool();
68     return true;
69 }
70 
Unmarshalling(Parcel & parcel)71 InstallParam *InstallParam::Unmarshalling(Parcel &parcel)
72 {
73     InstallParam *info = new (std::nothrow) InstallParam();
74     if (info && !info->ReadFromParcel(parcel)) {
75         APP_LOGW("read from parcel failed");
76         delete info;
77         info = nullptr;
78     }
79     return info;
80 }
81 
Marshalling(Parcel & parcel) const82 bool InstallParam::Marshalling(Parcel &parcel) const
83 {
84     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(installFlag));
85     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(installLocation));
86     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
87     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isKeepData);
88 
89     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(hashParams.size()));
90     for (const auto &hashParam : hashParams) {
91         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hashParam.first));
92         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hashParam.second));
93     }
94     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, crowdtestDeadline);
95 
96     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(sharedBundleDirPaths.size()));
97     for (const auto& sharedBundleDirPath : sharedBundleDirPaths) {
98         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(sharedBundleDirPath));
99     }
100 
101     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(specifiedDistributionType));
102     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(additionalInfo));
103     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(verifyCodeParams.size()));
104     for (const auto &verifyCodeParam : verifyCodeParams) {
105         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(verifyCodeParam.first));
106         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(verifyCodeParam.second));
107     }
108     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isSelfUpdate);
109     return true;
110 }
111 
ReadFromParcel(Parcel & parcel)112 bool UninstallParam::ReadFromParcel(Parcel &parcel)
113 {
114     bundleName = Str16ToStr8(parcel.ReadString16());
115     moduleName = Str16ToStr8(parcel.ReadString16());
116     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, versionCode);
117     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
118     return true;
119 }
120 
Unmarshalling(Parcel & parcel)121 UninstallParam* UninstallParam::Unmarshalling(Parcel &parcel)
122 {
123     UninstallParam *info = new (std::nothrow) UninstallParam();
124     if (info && !info->ReadFromParcel(parcel)) {
125         APP_LOGW("read from parcel failed");
126         delete info;
127         info = nullptr;
128     }
129     return info;
130 }
131 
Marshalling(Parcel & parcel) const132 bool UninstallParam::Marshalling(Parcel &parcel) const
133 {
134     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
135     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
136     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, versionCode);
137     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
138     return true;
139 }
140 }  // namespace AppExecFwk
141 }  // namespace OHOS
142