1 /*
2 * Copyright (c) 2023-2024 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 "form_instance.h"
17 #include "fms_log_wrapper.h"
18 #include "message_parcel.h"
19 #include "string_ex.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)23 bool FormInstance::ReadFromParcel(Parcel &parcel)
24 {
25 formId = parcel.ReadInt64();
26 formHostName = Str16ToStr8(parcel.ReadString16());
27 formVisiblity = static_cast<FormVisibilityType>(parcel.ReadInt32());
28 specification = parcel.ReadInt32();
29 bundleName = Str16ToStr8(parcel.ReadString16());
30 moduleName = Str16ToStr8(parcel.ReadString16());
31 abilityName = Str16ToStr8(parcel.ReadString16());
32 formName = Str16ToStr8(parcel.ReadString16());
33 formUsageState = static_cast<FormUsageState>(parcel.ReadInt32());
34 description = Str16ToStr8(parcel.ReadString16());
35 appIndex = parcel.ReadInt32();
36 userId = parcel.ReadInt32();
37 return true;
38 }
39
Marshalling(Parcel & parcel) const40 bool FormInstance::Marshalling(Parcel &parcel) const
41 {
42 // write formId
43 if (!parcel.WriteInt64(formId)) {
44 return false;
45 }
46
47 // write formHostName
48 if (!parcel.WriteString16(Str8ToStr16(formHostName))) {
49 return false;
50 }
51
52 // write formVisiblity
53 if (!parcel.WriteInt32(static_cast<int32_t>(formVisiblity))) {
54 return false;
55 }
56
57 // write specification
58 if (!parcel.WriteInt32(specification)) {
59 return false;
60 }
61
62 // write bundleName
63 if (!parcel.WriteString16(Str8ToStr16(bundleName))) {
64 return false;
65 }
66
67 // write moduleName
68 if (!parcel.WriteString16(Str8ToStr16(moduleName))) {
69 return false;
70 }
71
72 // write abilityName
73 if (!parcel.WriteString16(Str8ToStr16(abilityName))) {
74 return false;
75 }
76
77 // write formName
78 if (!parcel.WriteString16(Str8ToStr16(formName))) {
79 return false;
80 }
81
82 // write formUsageState
83 if (!parcel.WriteInt32(static_cast<int32_t>(formUsageState))) {
84 return false;
85 }
86
87 // write description
88 if (!parcel.WriteString16(Str8ToStr16(description))) {
89 return false;
90 }
91
92 // write appIndex
93 if (!parcel.WriteInt32(appIndex)) {
94 return false;
95 }
96
97 // write userId
98 if (!parcel.WriteInt32(userId)) {
99 return false;
100 }
101 return true;
102 }
103
Unmarshalling(Parcel & parcel)104 FormInstance* FormInstance::Unmarshalling(Parcel &parcel)
105 {
106 std::unique_ptr<FormInstance> object = std::make_unique<FormInstance>();
107 if (object && !object->ReadFromParcel(parcel)) {
108 object = nullptr;
109 return nullptr;
110 }
111 return object.release();
112 }
113
ReadFromParcel(Parcel & parcel)114 bool Rect::ReadFromParcel(Parcel &parcel)
115 {
116 left = parcel.ReadDouble();
117 top = parcel.ReadDouble();
118 width = parcel.ReadDouble();
119 height = parcel.ReadDouble();
120 HILOG_INFO("call rect: %{public}f, %{public}f, %{public}f, %{public}f", left, top, width, height);
121 return true;
122 }
123
Marshalling(Parcel & parcel) const124 bool Rect::Marshalling(Parcel &parcel) const
125 {
126 if (!parcel.WriteDouble(left)) {
127 return false;
128 }
129 if (!parcel.WriteDouble(top)) {
130 return false;
131 }
132 if (!parcel.WriteDouble(width)) {
133 return false;
134 }
135 if (!parcel.WriteDouble(height)) {
136 return false;
137 }
138 return true;
139 }
140
Unmarshalling(Parcel & parcel)141 Rect* Rect::Unmarshalling(Parcel &parcel)
142 {
143 std::unique_ptr<Rect> object = std::make_unique<Rect>();
144 if (object && !object->ReadFromParcel(parcel)) {
145 object = nullptr;
146 return nullptr;
147 }
148 return object.release();
149 }
150
ReadFromParcel(Parcel & parcel)151 bool OverflowInfo::ReadFromParcel(Parcel &parcel)
152 {
153 if (!area.ReadFromParcel(parcel)) {
154 return false;
155 }
156 duration = parcel.ReadInt32();
157 useDefaultAnimation = parcel.ReadBool();
158 HILOG_INFO("OverflowInfo, rect: %{public}f, %{public}f, %{public}f, %{public}f, duration: %{public}d,"
159 " useDefaultAnimate: %{public}d", area.left, area.top, area.width, area.height, duration, useDefaultAnimation);
160 return true;
161 }
162
Marshalling(Parcel & parcel) const163 bool OverflowInfo::Marshalling(Parcel &parcel) const
164 {
165 if (!area.Marshalling(parcel)) {
166 HILOG_ERROR("Write area failed");
167 return false;
168 }
169 if (!parcel.WriteInt32(duration)) {
170 HILOG_ERROR("Write duraion failed");
171 return false;
172 }
173 if (!parcel.WriteBool(useDefaultAnimation)) {
174 HILOG_ERROR("Write useDefaultAnimate failed");
175 return false;
176 }
177 return true;
178 }
179
Unmarshalling(Parcel & parcel)180 OverflowInfo* OverflowInfo::Unmarshalling(Parcel &parcel)
181 {
182 std::unique_ptr<OverflowInfo> object = std::make_unique<OverflowInfo>();
183 if (object && !object->ReadFromParcel(parcel)) {
184 object = nullptr;
185 return nullptr;
186 }
187 return object.release();
188 }
189 } // namespace AppExecFwk
190 } // namespace OHOS
191