1 /*
2  * Copyright (c) 2021-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 "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     windowLeftUsed_ = other.windowLeftUsed_;
36     windowTopUsed_ = other.windowTopUsed_;
37     windowWidthUsed_ = other.windowWidthUsed_;
38     windowHeightUsed_ = other.windowHeightUsed_;
39     processOptions = other.processOptions;
40     windowFocused_ = other.windowFocused_;
41     startWindowOption = other.startWindowOption;
42     supportWindowModes_ = other.supportWindowModes_;
43 }
44 
operator =(const StartOptions & other)45 StartOptions &StartOptions::operator=(const StartOptions &other)
46 {
47     if (this != &other) {
48         windowMode_ = other.windowMode_;
49         displayId_ = other.displayId_;
50         withAnimation_ = other.withAnimation_;
51         windowLeft_ = other.windowLeft_;
52         windowTop_ = other.windowTop_;
53         windowWidth_ = other.windowWidth_;
54         windowHeight_ = other.windowHeight_;
55         windowLeftUsed_ = other.windowLeftUsed_;
56         windowTopUsed_ = other.windowTopUsed_;
57         windowWidthUsed_ = other.windowWidthUsed_;
58         windowHeightUsed_ = other.windowHeightUsed_;
59         processOptions = other.processOptions;
60         windowFocused_ = other.windowFocused_;
61         startWindowOption = other.startWindowOption;
62         supportWindowModes_ = other.supportWindowModes_;
63     }
64     return *this;
65 }
66 
ReadFromParcel(Parcel & parcel)67 bool StartOptions::ReadFromParcel(Parcel &parcel)
68 {
69     SetWindowMode(parcel.ReadInt32());
70     SetDisplayID(parcel.ReadInt32());
71     SetWithAnimation(parcel.ReadBool());
72     SetWindowLeft(parcel.ReadInt32());
73     SetWindowTop(parcel.ReadInt32());
74     SetWindowWidth(parcel.ReadInt32());
75     SetWindowHeight(parcel.ReadInt32());
76     SetWindowFocused(parcel.ReadBool());
77     windowLeftUsed_ = parcel.ReadBool();
78     windowTopUsed_ = parcel.ReadBool();
79     windowWidthUsed_ = parcel.ReadBool();
80     windowHeightUsed_ = parcel.ReadBool();
81     processOptions.reset(parcel.ReadParcelable<ProcessOptions>());
82     startWindowOption.reset(parcel.ReadParcelable<StartWindowOption>());
83     auto size = parcel.ReadInt32();
84     if (size > MAX_SUPPOPRT_WINDOW_MODES_SIZE) {
85         TAG_LOGE(AAFwkTag::ABILITYMGR, "supportWindowModes size exceeds max");
86         return false;
87     }
88     for (int i = 0; i < size; i++) {
89         supportWindowModes_.emplace_back(AppExecFwk::SupportWindowMode(parcel.ReadInt32()));
90     }
91     return true;
92 }
93 
Unmarshalling(Parcel & parcel)94 StartOptions *StartOptions::Unmarshalling(Parcel &parcel)
95 {
96     StartOptions *option = new (std::nothrow) StartOptions();
97     if (option == nullptr) {
98         return nullptr;
99     }
100 
101     if (!option->ReadFromParcel(parcel)) {
102         delete option;
103         option = nullptr;
104     }
105 
106     return option;
107 }
108 
Marshalling(Parcel & parcel) const109 bool StartOptions::Marshalling(Parcel &parcel) const
110 {
111     parcel.WriteInt32(GetWindowMode());
112     parcel.WriteInt32(GetDisplayID());
113     parcel.WriteBool(GetWithAnimation());
114     parcel.WriteInt32(GetWindowLeft());
115     parcel.WriteInt32(GetWindowTop());
116     parcel.WriteInt32(GetWindowWidth());
117     parcel.WriteInt32(GetWindowHeight());
118     parcel.WriteBool(GetWindowFocused());
119     parcel.WriteBool(windowLeftUsed_);
120     parcel.WriteBool(windowTopUsed_);
121     parcel.WriteBool(windowWidthUsed_);
122     parcel.WriteBool(windowHeightUsed_);
123     if (!parcel.WriteParcelable(processOptions.get())) {
124         TAG_LOGE(AAFwkTag::ABILITYMGR, "Write processOptions failed.");
125         return false;
126     }
127     if (!parcel.WriteParcelable(startWindowOption.get())) {
128         TAG_LOGE(AAFwkTag::ABILITYMGR, "write startWindowOption failed");
129         return false;
130     }
131     if (!parcel.WriteInt32(supportWindowModes_.size())) {
132         TAG_LOGE(AAFwkTag::ABILITYMGR, "write supportWindowModes_ failed");
133         return false;
134     }
135     for (auto windowMode : supportWindowModes_) {
136         if (!parcel.WriteInt32(static_cast<int32_t>(windowMode))) {
137             TAG_LOGE(AAFwkTag::ABILITYMGR, "write windowMode failed");
138             return false;
139         }
140     }
141     return true;
142 }
143 
SetWindowMode(int32_t windowMode)144 void StartOptions::SetWindowMode(int32_t windowMode)
145 {
146     windowMode_ = windowMode;
147 }
148 
GetWindowMode() const149 int32_t StartOptions::GetWindowMode() const
150 {
151     return windowMode_;
152 }
153 
SetDisplayID(int32_t id)154 void StartOptions::SetDisplayID(int32_t id)
155 {
156     displayId_ = id;
157 }
158 
GetDisplayID() const159 int32_t StartOptions::GetDisplayID() const
160 {
161     return displayId_;
162 }
163 
SetWithAnimation(bool withAnimation)164 void StartOptions::SetWithAnimation(bool withAnimation)
165 {
166     withAnimation_ = withAnimation;
167 }
168 
GetWithAnimation() const169 bool StartOptions::GetWithAnimation() const
170 {
171     return withAnimation_;
172 }
173 
SetWindowLeft(int32_t windowLeft)174 void StartOptions::SetWindowLeft(int32_t windowLeft)
175 {
176     windowLeft_ = windowLeft;
177 }
178 
GetWindowLeft() const179 int32_t StartOptions::GetWindowLeft() const
180 {
181     return windowLeft_;
182 }
183 
SetWindowTop(int32_t windowTop)184 void StartOptions::SetWindowTop(int32_t windowTop)
185 {
186     windowTop_ = windowTop;
187 }
188 
GetWindowTop() const189 int32_t StartOptions::GetWindowTop() const
190 {
191     return windowTop_;
192 }
193 
SetWindowWidth(int32_t windowWidth)194 void StartOptions::SetWindowWidth(int32_t windowWidth)
195 {
196     windowWidth_ = windowWidth;
197 }
198 
GetWindowWidth() const199 int32_t StartOptions::GetWindowWidth() const
200 {
201     return windowWidth_;
202 }
203 
SetWindowHeight(int32_t windowHeight)204 void StartOptions::SetWindowHeight(int32_t windowHeight)
205 {
206     windowHeight_ = windowHeight;
207 }
208 
GetWindowHeight() const209 int32_t StartOptions::GetWindowHeight() const
210 {
211     return windowHeight_;
212 }
213 
SetWindowFocused(bool windowFocused)214 void StartOptions::SetWindowFocused(bool windowFocused)
215 {
216     windowFocused_ = windowFocused;
217 }
218 
GetWindowFocused() const219 int32_t StartOptions::GetWindowFocused() const
220 {
221     return windowFocused_;
222 }
223 }  // namespace AAFwk
224 }  // namespace OHOS
225