1 /*
2 * Copyright (c) 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 "launcher_ability_resource_info.h"
17
18 #include "app_log_wrapper.h"
19 #include "nlohmann/json.hpp"
20 #include "parcel_macro.h"
21 #include "string_ex.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)25 bool LauncherAbilityResourceInfo::ReadFromParcel(Parcel &parcel)
26 {
27 std::u16string bundleNameVal;
28 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, bundleNameVal);
29 bundleName = Str16ToStr8(bundleNameVal);
30
31 std::u16string moduleNameVal;
32 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, moduleNameVal);
33 moduleName = Str16ToStr8(moduleNameVal);
34
35 std::u16string abilityNameVal;
36 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, abilityNameVal);
37 abilityName = Str16ToStr8(abilityNameVal);
38
39 std::u16string labelVal;
40 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, labelVal);
41 label = Str16ToStr8(labelVal);
42
43 std::u16string iconVal;
44 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, iconVal);
45 icon = Str16ToStr8(iconVal);
46
47 int32_t foregroundSize;
48 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, foregroundSize);
49 CONTAINER_SECURITY_VERIFY(parcel, foregroundSize, &foreground);
50 for (auto i = 0; i < foregroundSize; i++) {
51 foreground.emplace_back(parcel.ReadUint8());
52 }
53
54 int32_t backgroundSize;
55 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, backgroundSize);
56 CONTAINER_SECURITY_VERIFY(parcel, backgroundSize, &background);
57 for (auto i = 0; i < backgroundSize; i++) {
58 background.emplace_back(parcel.ReadUint8());
59 }
60
61 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
62 return true;
63 }
64
Marshalling(Parcel & parcel) const65 bool LauncherAbilityResourceInfo::Marshalling(Parcel &parcel) const
66 {
67 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
68 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
69 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(abilityName));
70 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label));
71 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(icon));
72 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, foreground.size());
73 for (const auto &data : foreground) {
74 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8, parcel, data);
75 }
76 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, background.size());
77 for (const auto &data : background) {
78 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8, parcel, data);
79 }
80 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
81 return true;
82 }
83
Unmarshalling(Parcel & parcel)84 LauncherAbilityResourceInfo *LauncherAbilityResourceInfo::Unmarshalling(Parcel &parcel)
85 {
86 LauncherAbilityResourceInfo *info = new (std::nothrow) LauncherAbilityResourceInfo();
87 if ((info != nullptr) && !info->ReadFromParcel(parcel)) {
88 APP_LOGW("read from parcel failed");
89 delete info;
90 info = nullptr;
91 }
92 return info;
93 }
94 } // AppExecFwk
95 } // OHOS
96