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