1 /*
2 * Copyright (c) 2021-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 "start_options.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "process_options.h"
20 #include "start_window_option.h"
21
22 namespace OHOS {
23 namespace AAFwk {
24 constexpr int MAX_SUPPOPRT_WINDOW_MODES_SIZE = 10;
25
StartOptions(const StartOptions & other)26 StartOptions::StartOptions(const StartOptions &other)
27 {
28 windowMode_ = other.windowMode_;
29 displayId_ = other.displayId_;
30 withAnimation_ = other.withAnimation_;
31 windowLeft_ = other.windowLeft_;
32 windowTop_ = other.windowTop_;
33 windowWidth_ = other.windowWidth_;
34 windowHeight_ = other.windowHeight_;
35 minWindowWidth_ = other.minWindowWidth_;
36 minWindowHeight_ = other.minWindowHeight_;
37 maxWindowWidth_ = other.maxWindowWidth_;
38 maxWindowHeight_ = other.maxWindowHeight_;
39 windowLeftUsed_ = other.windowLeftUsed_;
40 windowTopUsed_ = other.windowTopUsed_;
41 windowWidthUsed_ = other.windowWidthUsed_;
42 windowHeightUsed_ = other.windowHeightUsed_;
43 minWindowWidthUsed_ = other.minWindowWidthUsed_;
44 minWindowHeightUsed_ = other.minWindowHeightUsed_;
45 maxWindowWidthUsed_ = other.maxWindowWidthUsed_;
46 maxWindowHeightUsed_ = other.maxWindowHeightUsed_;
47 processOptions = other.processOptions;
48 windowFocused_ = other.windowFocused_;
49 startWindowOption = other.startWindowOption;
50 supportWindowModes_ = other.supportWindowModes_;
51 }
52
operator =(const StartOptions & other)53 StartOptions &StartOptions::operator=(const StartOptions &other)
54 {
55 if (this != &other) {
56 windowMode_ = other.windowMode_;
57 displayId_ = other.displayId_;
58 withAnimation_ = other.withAnimation_;
59 windowLeft_ = other.windowLeft_;
60 windowTop_ = other.windowTop_;
61 windowWidth_ = other.windowWidth_;
62 windowHeight_ = other.windowHeight_;
63 minWindowWidth_ = other.minWindowWidth_;
64 minWindowHeight_ = other.minWindowHeight_;
65 maxWindowWidth_ = other.maxWindowWidth_;
66 maxWindowHeight_ = other.maxWindowHeight_;
67 windowLeftUsed_ = other.windowLeftUsed_;
68 windowTopUsed_ = other.windowTopUsed_;
69 windowWidthUsed_ = other.windowWidthUsed_;
70 windowHeightUsed_ = other.windowHeightUsed_;
71 minWindowWidthUsed_ = other.minWindowWidthUsed_;
72 minWindowHeightUsed_ = other.minWindowHeightUsed_;
73 maxWindowWidthUsed_ = other.maxWindowWidthUsed_;
74 maxWindowHeightUsed_ = other.maxWindowHeightUsed_;
75 processOptions = other.processOptions;
76 windowFocused_ = other.windowFocused_;
77 startWindowOption = other.startWindowOption;
78 supportWindowModes_ = other.supportWindowModes_;
79 }
80 return *this;
81 }
82
ReadFromParcel(Parcel & parcel)83 bool StartOptions::ReadFromParcel(Parcel &parcel)
84 {
85 SetWindowMode(parcel.ReadInt32());
86 SetDisplayID(parcel.ReadInt32());
87 SetWithAnimation(parcel.ReadBool());
88 SetWindowLeft(parcel.ReadInt32());
89 SetWindowTop(parcel.ReadInt32());
90 SetWindowWidth(parcel.ReadInt32());
91 SetWindowHeight(parcel.ReadInt32());
92 SetMinWindowWidth(parcel.ReadInt32());
93 SetMinWindowHeight(parcel.ReadInt32());
94 SetMaxWindowWidth(parcel.ReadInt32());
95 SetMaxWindowHeight(parcel.ReadInt32());
96 SetWindowFocused(parcel.ReadBool());
97 windowLeftUsed_ = parcel.ReadBool();
98 windowTopUsed_ = parcel.ReadBool();
99 windowWidthUsed_ = parcel.ReadBool();
100 windowHeightUsed_ = parcel.ReadBool();
101 minWindowWidthUsed_ = parcel.ReadBool();
102 minWindowHeightUsed_ = parcel.ReadBool();
103 maxWindowWidthUsed_ = parcel.ReadBool();
104 maxWindowHeightUsed_ = parcel.ReadBool();
105 processOptions.reset(parcel.ReadParcelable<ProcessOptions>());
106 startWindowOption.reset(parcel.ReadParcelable<StartWindowOption>());
107 auto size = parcel.ReadInt32();
108 if (size > MAX_SUPPOPRT_WINDOW_MODES_SIZE) {
109 TAG_LOGE(AAFwkTag::ABILITYMGR, "supportWindowModes size exceeds max");
110 return false;
111 }
112 for (int i = 0; i < size; i++) {
113 supportWindowModes_.emplace_back(AppExecFwk::SupportWindowMode(parcel.ReadInt32()));
114 }
115 return true;
116 }
117
Unmarshalling(Parcel & parcel)118 StartOptions *StartOptions::Unmarshalling(Parcel &parcel)
119 {
120 StartOptions *option = new (std::nothrow) StartOptions();
121 if (option == nullptr) {
122 return nullptr;
123 }
124
125 if (!option->ReadFromParcel(parcel)) {
126 delete option;
127 option = nullptr;
128 }
129
130 return option;
131 }
132
Marshalling(Parcel & parcel) const133 bool StartOptions::Marshalling(Parcel &parcel) const
134 {
135 parcel.WriteInt32(GetWindowMode());
136 parcel.WriteInt32(GetDisplayID());
137 parcel.WriteBool(GetWithAnimation());
138 parcel.WriteInt32(GetWindowLeft());
139 parcel.WriteInt32(GetWindowTop());
140 parcel.WriteInt32(GetWindowWidth());
141 parcel.WriteInt32(GetWindowHeight());
142 parcel.WriteInt32(GetMinWindowWidth());
143 parcel.WriteInt32(GetMinWindowHeight());
144 parcel.WriteInt32(GetMaxWindowWidth());
145 parcel.WriteInt32(GetMaxWindowHeight());
146 parcel.WriteBool(GetWindowFocused());
147 parcel.WriteBool(windowLeftUsed_);
148 parcel.WriteBool(windowTopUsed_);
149 parcel.WriteBool(windowWidthUsed_);
150 parcel.WriteBool(windowHeightUsed_);
151 parcel.WriteBool(minWindowWidthUsed_);
152 parcel.WriteBool(minWindowHeightUsed_);
153 parcel.WriteBool(maxWindowWidthUsed_);
154 parcel.WriteBool(maxWindowHeightUsed_);
155 if (!parcel.WriteParcelable(processOptions.get())) {
156 TAG_LOGE(AAFwkTag::ABILITYMGR, "write processOptions failed");
157 return false;
158 }
159 if (!parcel.WriteParcelable(startWindowOption.get())) {
160 TAG_LOGE(AAFwkTag::ABILITYMGR, "write startWindowOption failed");
161 return false;
162 }
163 if (!parcel.WriteInt32(supportWindowModes_.size())) {
164 TAG_LOGE(AAFwkTag::ABILITYMGR, "write supportWindowModes_ failed");
165 return false;
166 }
167 for (auto windowMode : supportWindowModes_) {
168 if (!parcel.WriteInt32(static_cast<int32_t>(windowMode))) {
169 TAG_LOGE(AAFwkTag::ABILITYMGR, "write windowMode failed");
170 return false;
171 }
172 }
173 return true;
174 }
175
SetWindowMode(int32_t windowMode)176 void StartOptions::SetWindowMode(int32_t windowMode)
177 {
178 windowMode_ = windowMode;
179 }
180
GetWindowMode() const181 int32_t StartOptions::GetWindowMode() const
182 {
183 return windowMode_;
184 }
185
SetDisplayID(int32_t id)186 void StartOptions::SetDisplayID(int32_t id)
187 {
188 displayId_ = id;
189 }
190
GetDisplayID() const191 int32_t StartOptions::GetDisplayID() const
192 {
193 return displayId_;
194 }
195
SetWithAnimation(bool withAnimation)196 void StartOptions::SetWithAnimation(bool withAnimation)
197 {
198 withAnimation_ = withAnimation;
199 }
200
GetWithAnimation() const201 bool StartOptions::GetWithAnimation() const
202 {
203 return withAnimation_;
204 }
205
SetWindowLeft(int32_t windowLeft)206 void StartOptions::SetWindowLeft(int32_t windowLeft)
207 {
208 windowLeft_ = windowLeft;
209 }
210
GetWindowLeft() const211 int32_t StartOptions::GetWindowLeft() const
212 {
213 return windowLeft_;
214 }
215
SetWindowTop(int32_t windowTop)216 void StartOptions::SetWindowTop(int32_t windowTop)
217 {
218 windowTop_ = windowTop;
219 }
220
GetWindowTop() const221 int32_t StartOptions::GetWindowTop() const
222 {
223 return windowTop_;
224 }
225
SetWindowWidth(int32_t windowWidth)226 void StartOptions::SetWindowWidth(int32_t windowWidth)
227 {
228 windowWidth_ = windowWidth;
229 }
230
GetWindowWidth() const231 int32_t StartOptions::GetWindowWidth() const
232 {
233 return windowWidth_;
234 }
235
SetWindowHeight(int32_t windowHeight)236 void StartOptions::SetWindowHeight(int32_t windowHeight)
237 {
238 windowHeight_ = windowHeight;
239 }
240
GetWindowHeight() const241 int32_t StartOptions::GetWindowHeight() const
242 {
243 return windowHeight_;
244 }
245
SetMinWindowWidth(int32_t minWindowWidth)246 void StartOptions::SetMinWindowWidth(int32_t minWindowWidth)
247 {
248 minWindowWidth_ = minWindowWidth;
249 }
250
GetMinWindowWidth() const251 int32_t StartOptions::GetMinWindowWidth() const
252 {
253 return minWindowWidth_;
254 }
255
SetMinWindowHeight(int32_t minWindowHeight)256 void StartOptions::SetMinWindowHeight(int32_t minWindowHeight)
257 {
258 minWindowHeight_ = minWindowHeight;
259 }
260
GetMinWindowHeight() const261 int32_t StartOptions::GetMinWindowHeight() const
262 {
263 return minWindowHeight_;
264 }
265
SetMaxWindowWidth(int32_t maxWindowWidth)266 void StartOptions::SetMaxWindowWidth(int32_t maxWindowWidth)
267 {
268 maxWindowWidth_ = maxWindowWidth;
269 }
270
GetMaxWindowWidth() const271 int32_t StartOptions::GetMaxWindowWidth() const
272 {
273 return maxWindowWidth_;
274 }
275
SetMaxWindowHeight(int32_t maxWindowHeight)276 void StartOptions::SetMaxWindowHeight(int32_t maxWindowHeight)
277 {
278 maxWindowHeight_ = maxWindowHeight;
279 }
280
GetMaxWindowHeight() const281 int32_t StartOptions::GetMaxWindowHeight() const
282 {
283 return maxWindowHeight_;
284 }
285
SetWindowFocused(bool windowFocused)286 void StartOptions::SetWindowFocused(bool windowFocused)
287 {
288 windowFocused_ = windowFocused;
289 }
290
GetWindowFocused() const291 int32_t StartOptions::GetWindowFocused() const
292 {
293 return windowFocused_;
294 }
295 } // namespace AAFwk
296 } // namespace OHOS
297