• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, label);
40     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, icon);
41 
42     int32_t foregroundSize;
43     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, foregroundSize);
44     CONTAINER_SECURITY_VERIFY(parcel, foregroundSize, &foreground);
45     uint8_t foregroundVal = 0;
46     for (auto i = 0; i < foregroundSize; i++) {
47         READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8Unaligned, parcel, foregroundVal);
48         foreground.emplace_back(foregroundVal);
49     }
50 
51     int32_t backgroundSize;
52     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, backgroundSize);
53     CONTAINER_SECURITY_VERIFY(parcel, backgroundSize, &background);
54     uint8_t backgroundVal = 0;
55     for (auto i = 0; i < backgroundSize; i++) {
56         READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8Unaligned, parcel, backgroundVal);
57         background.emplace_back(backgroundVal);
58     }
59 
60     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
61     return true;
62 }
63 
Marshalling(Parcel & parcel) const64 bool LauncherAbilityResourceInfo::Marshalling(Parcel &parcel) const
65 {
66     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
67     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
68     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(abilityName));
69     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, label);
70     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, icon);
71     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, foreground.size());
72     for (const auto &data : foreground) {
73         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8Unaligned, parcel, data);
74     }
75     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, background.size());
76     for (const auto &data : background) {
77         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint8Unaligned, parcel, data);
78     }
79     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
80     return true;
81 }
82 
Unmarshalling(Parcel & parcel)83 LauncherAbilityResourceInfo *LauncherAbilityResourceInfo::Unmarshalling(Parcel &parcel)
84 {
85     LauncherAbilityResourceInfo *info = new (std::nothrow) LauncherAbilityResourceInfo();
86     if ((info != nullptr) && !info->ReadFromParcel(parcel)) {
87         APP_LOGW("read from parcel failed");
88         delete info;
89         info = nullptr;
90     }
91     return info;
92 }
93 } // AppExecFwk
94 } // OHOS
95