• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "wm_animation_common.h"
22 
23 namespace OHOS {
24 namespace AAFwk {
25 constexpr int MAX_SUPPOPRT_WINDOW_MODES_SIZE = 10;
26 
StartOptions(const StartOptions & other)27 StartOptions::StartOptions(const StartOptions &other)
28 {
29     windowMode_ = other.windowMode_;
30     displayId_ = other.displayId_;
31     withAnimation_ = other.withAnimation_;
32     windowLeft_ = other.windowLeft_;
33     windowTop_ = other.windowTop_;
34     windowWidth_ = other.windowWidth_;
35     windowHeight_ = other.windowHeight_;
36     minWindowWidth_ = other.minWindowWidth_;
37     minWindowHeight_ = other.minWindowHeight_;
38     maxWindowWidth_ = other.maxWindowWidth_;
39     maxWindowHeight_ = other.maxWindowHeight_;
40     windowLeftUsed_ = other.windowLeftUsed_;
41     windowTopUsed_ = other.windowTopUsed_;
42     windowWidthUsed_ = other.windowWidthUsed_;
43     windowHeightUsed_ = other.windowHeightUsed_;
44     minWindowWidthUsed_ = other.minWindowWidthUsed_;
45     minWindowHeightUsed_ = other.minWindowHeightUsed_;
46     maxWindowWidthUsed_ = other.maxWindowWidthUsed_;
47     maxWindowHeightUsed_ = other.maxWindowHeightUsed_;
48     processOptions = other.processOptions;
49     windowFocused_ = other.windowFocused_;
50     hideStartWindow_ = other.hideStartWindow_;
51     startWindowOption = other.startWindowOption;
52     supportWindowModes_ = other.supportWindowModes_;
53     requestId_ = other.requestId_;
54     windowCreateParams_ = other.windowCreateParams_;
55 }
56 
operator =(const StartOptions & other)57 StartOptions &StartOptions::operator=(const StartOptions &other)
58 {
59     if (this != &other) {
60         windowMode_ = other.windowMode_;
61         displayId_ = other.displayId_;
62         withAnimation_ = other.withAnimation_;
63         windowLeft_ = other.windowLeft_;
64         windowTop_ = other.windowTop_;
65         windowWidth_ = other.windowWidth_;
66         windowHeight_ = other.windowHeight_;
67         minWindowWidth_ = other.minWindowWidth_;
68         minWindowHeight_ = other.minWindowHeight_;
69         maxWindowWidth_ = other.maxWindowWidth_;
70         maxWindowHeight_ = other.maxWindowHeight_;
71         windowLeftUsed_ = other.windowLeftUsed_;
72         windowTopUsed_ = other.windowTopUsed_;
73         windowWidthUsed_ = other.windowWidthUsed_;
74         windowHeightUsed_ = other.windowHeightUsed_;
75         minWindowWidthUsed_ = other.minWindowWidthUsed_;
76         minWindowHeightUsed_ = other.minWindowHeightUsed_;
77         maxWindowWidthUsed_ = other.maxWindowWidthUsed_;
78         maxWindowHeightUsed_ = other.maxWindowHeightUsed_;
79         processOptions = other.processOptions;
80         windowFocused_ = other.windowFocused_;
81         hideStartWindow_ = other.hideStartWindow_;
82         startWindowOption = other.startWindowOption;
83         supportWindowModes_ = other.supportWindowModes_;
84         requestId_ = other.requestId_;
85         windowCreateParams_ = other.windowCreateParams_;
86     }
87     return *this;
88 }
89 
ReadFromParcel(Parcel & parcel)90 bool StartOptions::ReadFromParcel(Parcel &parcel)
91 {
92     SetWindowMode(parcel.ReadInt32());
93     SetDisplayID(parcel.ReadInt32());
94     SetWithAnimation(parcel.ReadBool());
95     SetWindowLeft(parcel.ReadInt32());
96     SetWindowTop(parcel.ReadInt32());
97     SetWindowWidth(parcel.ReadInt32());
98     SetWindowHeight(parcel.ReadInt32());
99     SetMinWindowWidth(parcel.ReadInt32());
100     SetMinWindowHeight(parcel.ReadInt32());
101     SetMaxWindowWidth(parcel.ReadInt32());
102     SetMaxWindowHeight(parcel.ReadInt32());
103     SetWindowFocused(parcel.ReadBool());
104     SetHideStartWindow(parcel.ReadBool());
105     windowLeftUsed_ = parcel.ReadBool();
106     windowTopUsed_ = parcel.ReadBool();
107     windowWidthUsed_ = parcel.ReadBool();
108     windowHeightUsed_ = parcel.ReadBool();
109     minWindowWidthUsed_ = parcel.ReadBool();
110     minWindowHeightUsed_ = parcel.ReadBool();
111     maxWindowWidthUsed_ = parcel.ReadBool();
112     maxWindowHeightUsed_ = parcel.ReadBool();
113     processOptions.reset(parcel.ReadParcelable<ProcessOptions>());
114     startWindowOption.reset(parcel.ReadParcelable<StartWindowOption>());
115     auto size = parcel.ReadInt32();
116     if (size > MAX_SUPPOPRT_WINDOW_MODES_SIZE) {
117         TAG_LOGE(AAFwkTag::ABILITYMGR, "supportWindowModes size exceeds max");
118         return false;
119     }
120     for (int i = 0; i < size; i++) {
121         supportWindowModes_.emplace_back(AppExecFwk::SupportWindowMode(parcel.ReadInt32()));
122     }
123     requestId_ = parcel.ReadString();
124     windowCreateParams_.reset(parcel.ReadParcelable<Rosen::WindowCreateParams>());
125     return true;
126 }
127 
Unmarshalling(Parcel & parcel)128 StartOptions *StartOptions::Unmarshalling(Parcel &parcel)
129 {
130     StartOptions *option = new (std::nothrow) StartOptions();
131     if (option == nullptr) {
132         return nullptr;
133     }
134 
135     if (!option->ReadFromParcel(parcel)) {
136         delete option;
137         option = nullptr;
138     }
139 
140     return option;
141 }
142 
Marshalling(Parcel & parcel) const143 bool StartOptions::Marshalling(Parcel &parcel) const
144 {
145     parcel.WriteInt32(GetWindowMode());
146     parcel.WriteInt32(GetDisplayID());
147     parcel.WriteBool(GetWithAnimation());
148     parcel.WriteInt32(GetWindowLeft());
149     parcel.WriteInt32(GetWindowTop());
150     parcel.WriteInt32(GetWindowWidth());
151     parcel.WriteInt32(GetWindowHeight());
152     parcel.WriteInt32(GetMinWindowWidth());
153     parcel.WriteInt32(GetMinWindowHeight());
154     parcel.WriteInt32(GetMaxWindowWidth());
155     parcel.WriteInt32(GetMaxWindowHeight());
156     parcel.WriteBool(GetWindowFocused());
157     parcel.WriteBool(GetHideStartWindow());
158     parcel.WriteBool(windowLeftUsed_);
159     parcel.WriteBool(windowTopUsed_);
160     parcel.WriteBool(windowWidthUsed_);
161     parcel.WriteBool(windowHeightUsed_);
162     parcel.WriteBool(minWindowWidthUsed_);
163     parcel.WriteBool(minWindowHeightUsed_);
164     parcel.WriteBool(maxWindowWidthUsed_);
165     parcel.WriteBool(maxWindowHeightUsed_);
166     if (!parcel.WriteParcelable(processOptions.get())) {
167         TAG_LOGE(AAFwkTag::ABILITYMGR, "write processOptions failed");
168         return false;
169     }
170     if (!parcel.WriteParcelable(startWindowOption.get())) {
171         TAG_LOGE(AAFwkTag::ABILITYMGR, "write startWindowOption failed");
172         return false;
173     }
174     if (!parcel.WriteInt32(supportWindowModes_.size())) {
175         TAG_LOGE(AAFwkTag::ABILITYMGR, "write supportWindowModes_ failed");
176         return false;
177     }
178     for (auto windowMode : supportWindowModes_) {
179         if (!parcel.WriteInt32(static_cast<int32_t>(windowMode))) {
180             TAG_LOGE(AAFwkTag::ABILITYMGR, "write windowMode failed");
181             return false;
182         }
183     }
184     parcel.WriteString(requestId_);
185     return MarshallingTwo(parcel);
186 }
187 
MarshallingTwo(Parcel & parcel) const188 bool StartOptions::MarshallingTwo(Parcel &parcel) const
189 {
190     if (!parcel.WriteParcelable(windowCreateParams_.get())) {
191         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write windowCreateParams_ failed");
192         return false;
193     }
194     return true;
195 }
196 
SetWindowMode(int32_t windowMode)197 void StartOptions::SetWindowMode(int32_t windowMode)
198 {
199     windowMode_ = windowMode;
200 }
201 
GetWindowMode() const202 int32_t StartOptions::GetWindowMode() const
203 {
204     return windowMode_;
205 }
206 
SetDisplayID(int32_t id)207 void StartOptions::SetDisplayID(int32_t id)
208 {
209     displayId_ = id;
210 }
211 
GetDisplayID() const212 int32_t StartOptions::GetDisplayID() const
213 {
214     return displayId_;
215 }
216 
SetWithAnimation(bool withAnimation)217 void StartOptions::SetWithAnimation(bool withAnimation)
218 {
219     withAnimation_ = withAnimation;
220 }
221 
GetWithAnimation() const222 bool StartOptions::GetWithAnimation() const
223 {
224     return withAnimation_;
225 }
226 
SetWindowLeft(int32_t windowLeft)227 void StartOptions::SetWindowLeft(int32_t windowLeft)
228 {
229     windowLeft_ = windowLeft;
230 }
231 
GetWindowLeft() const232 int32_t StartOptions::GetWindowLeft() const
233 {
234     return windowLeft_;
235 }
236 
SetWindowTop(int32_t windowTop)237 void StartOptions::SetWindowTop(int32_t windowTop)
238 {
239     windowTop_ = windowTop;
240 }
241 
GetWindowTop() const242 int32_t StartOptions::GetWindowTop() const
243 {
244     return windowTop_;
245 }
246 
SetWindowWidth(int32_t windowWidth)247 void StartOptions::SetWindowWidth(int32_t windowWidth)
248 {
249     windowWidth_ = windowWidth;
250 }
251 
GetWindowWidth() const252 int32_t StartOptions::GetWindowWidth() const
253 {
254     return windowWidth_;
255 }
256 
SetWindowHeight(int32_t windowHeight)257 void StartOptions::SetWindowHeight(int32_t windowHeight)
258 {
259     windowHeight_ = windowHeight;
260 }
261 
GetWindowHeight() const262 int32_t StartOptions::GetWindowHeight() const
263 {
264     return windowHeight_;
265 }
266 
SetMinWindowWidth(int32_t minWindowWidth)267 void StartOptions::SetMinWindowWidth(int32_t minWindowWidth)
268 {
269     minWindowWidth_ = minWindowWidth;
270 }
271 
GetMinWindowWidth() const272 int32_t StartOptions::GetMinWindowWidth() const
273 {
274     return minWindowWidth_;
275 }
276 
SetMinWindowHeight(int32_t minWindowHeight)277 void StartOptions::SetMinWindowHeight(int32_t minWindowHeight)
278 {
279     minWindowHeight_ = minWindowHeight;
280 }
281 
GetMinWindowHeight() const282 int32_t StartOptions::GetMinWindowHeight() const
283 {
284     return minWindowHeight_;
285 }
286 
SetMaxWindowWidth(int32_t maxWindowWidth)287 void StartOptions::SetMaxWindowWidth(int32_t maxWindowWidth)
288 {
289     maxWindowWidth_ = maxWindowWidth;
290 }
291 
GetMaxWindowWidth() const292 int32_t StartOptions::GetMaxWindowWidth() const
293 {
294     return maxWindowWidth_;
295 }
296 
SetMaxWindowHeight(int32_t maxWindowHeight)297 void StartOptions::SetMaxWindowHeight(int32_t maxWindowHeight)
298 {
299     maxWindowHeight_ = maxWindowHeight;
300 }
301 
GetMaxWindowHeight() const302 int32_t StartOptions::GetMaxWindowHeight() const
303 {
304     return maxWindowHeight_;
305 }
306 
SetWindowFocused(bool windowFocused)307 void StartOptions::SetWindowFocused(bool windowFocused)
308 {
309     windowFocused_ = windowFocused;
310 }
311 
GetWindowFocused() const312 int32_t StartOptions::GetWindowFocused() const
313 {
314     return windowFocused_;
315 }
316 
SetHideStartWindow(bool hideStartWindow)317 void StartOptions::SetHideStartWindow(bool hideStartWindow)
318 {
319     hideStartWindow_ = hideStartWindow;
320 }
321 
GetHideStartWindow() const322 bool StartOptions::GetHideStartWindow() const
323 {
324     return hideStartWindow_;
325 }
326 
327 }  // namespace AAFwk
328 }  // namespace OHOS
329