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 return true;
49 }
50
Unmarshalling(Parcel & parcel)51 InstallParam *InstallParam::Unmarshalling(Parcel &parcel)
52 {
53 InstallParam *info = new (std::nothrow) InstallParam();
54 if (info && !info->ReadFromParcel(parcel)) {
55 APP_LOGW("read from parcel failed");
56 delete info;
57 info = nullptr;
58 }
59 return info;
60 }
61
Marshalling(Parcel & parcel) const62 bool InstallParam::Marshalling(Parcel &parcel) const
63 {
64 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(installFlag));
65 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(installLocation));
66 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
67 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isKeepData);
68
69 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(hashParams.size()));
70 for (auto& hashParam : hashParams) {
71 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hashParam.first));
72 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hashParam.second));
73 }
74 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, crowdtestDeadline);
75
76 return true;
77 }
78 } // namespace AppExecFwk
79 } // namespace OHOS
80