• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "edm_application_info.h"
17 
18 #include <cstring>
19 
20 #include "edm_log.h"
21 #include "string_ex.h"
22 #include "parcel_macro.h"
23 
24 namespace OHOS {
25 namespace EDM {
ReadFromParcel(Parcel & parcel)26 bool EdmResource::ReadFromParcel(Parcel &parcel)
27 {
28     bundleName = Str16ToStr8(parcel.ReadString16());
29     moduleName = Str16ToStr8(parcel.ReadString16());
30     id = parcel.ReadUint32();
31     return true;
32 }
33 
Marshalling(Parcel & parcel) const34 bool EdmResource::Marshalling(Parcel &parcel) const
35 {
36     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
37     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
38     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, id);
39     return true;
40 }
41 
Unmarshalling(Parcel & parcel)42 EdmResource *EdmResource::Unmarshalling(Parcel &parcel)
43 {
44     EdmResource *resource = new (std::nothrow) EdmResource;
45     if (resource && !resource->ReadFromParcel(parcel)) {
46         EDMLOGE("read from parcel failed");
47         delete resource;
48         resource = nullptr;
49     }
50     return resource;
51 }
52 
ReadFromParcel(Parcel & parcel)53 bool EdmApplicationInfo::ReadFromParcel(Parcel &parcel)
54 {
55     removable = parcel.ReadBool();
56     isSystemApp = parcel.ReadBool();
57     debug = parcel.ReadBool();
58     userDataClearable = parcel.ReadBool();
59     enabled = parcel.ReadBool();
60 
61     accessTokenId = parcel.ReadUint32();
62     iconId = parcel.ReadUint32();
63     labelId = parcel.ReadUint32();
64     descriptionId = parcel.ReadUint32();
65 
66     uid = parcel.ReadInt32();
67     appIndex = parcel.ReadInt32();
68 
69     name = Str16ToStr8(parcel.ReadString16());
70     description = Str16ToStr8(parcel.ReadString16());
71     label = Str16ToStr8(parcel.ReadString16());
72     icon = Str16ToStr8(parcel.ReadString16());
73     process = Str16ToStr8(parcel.ReadString16());
74     codePath = Str16ToStr8(parcel.ReadString16());
75     appDistributionType = Str16ToStr8(parcel.ReadString16());
76     appProvisionType = Str16ToStr8(parcel.ReadString16());
77     nativeLibraryPath = Str16ToStr8(parcel.ReadString16());
78     installSource = Str16ToStr8(parcel.ReadString16());
79     apiReleaseType = Str16ToStr8(parcel.ReadString16());
80 
81     std::unique_ptr<EdmResource> iconResourcePtr(parcel.ReadParcelable<EdmResource>());
82     if (!iconResourcePtr) {
83         EDMLOGE("icon ReadParcelable<EdmResource> failed");
84         return false;
85     }
86     iconResource = *iconResourcePtr;
87 
88     std::unique_ptr<EdmResource> labelResourcePtr(parcel.ReadParcelable<EdmResource>());
89     if (!labelResourcePtr) {
90         EDMLOGE("label ReadParcelable<EdmResource> failed");
91         return false;
92     }
93     labelResource = *labelResourcePtr;
94 
95     std::unique_ptr<EdmResource> descriptionResourcePtr(parcel.ReadParcelable<EdmResource>());
96     if (!descriptionResourcePtr) {
97         EDMLOGE("description ReadParcelable<EdmResource> failed");
98         return false;
99     }
100     descriptionResource = *descriptionResourcePtr;
101     return true;
102 }
103 
Marshalling(Parcel & parcel) const104 bool EdmApplicationInfo::Marshalling(Parcel &parcel) const
105 {
106     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, removable);
107     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isSystemApp);
108     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, debug);
109     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, userDataClearable);
110     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, enabled);
111 
112     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, accessTokenId);
113     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, iconId);
114     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, labelId);
115     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, descriptionId);
116 
117     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
118     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
119 
120     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
121     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description));
122     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label));
123     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(icon));
124     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(process));
125     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(codePath));
126     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appDistributionType));
127     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appProvisionType));
128     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(nativeLibraryPath));
129     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(installSource));
130     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(apiReleaseType));
131 
132     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &iconResource);
133     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &labelResource);
134     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &descriptionResource);
135     return true;
136 }
137 
Unmarshalling(Parcel & parcel)138 EdmApplicationInfo *EdmApplicationInfo::Unmarshalling(Parcel &parcel)
139 {
140     EdmApplicationInfo *info = new (std::nothrow) EdmApplicationInfo();
141     if (info && !info->ReadFromParcel(parcel)) {
142         EDMLOGE("read from parcel failed");
143         delete info;
144         info = nullptr;
145     }
146     return info;
147 }
148 } // namespace EDM
149 } // namespace OHOS