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 {
StartOptions(const StartOptions &other)24 StartOptions::StartOptions(const StartOptions &other)
25 {
26     windowMode_ = other.windowMode_;
27     displayId_ = other.displayId_;
28     withAnimation_ = other.withAnimation_;
29     windowLeft_ = other.windowLeft_;
30     windowTop_ = other.windowTop_;
31     windowWidth_ = other.windowWidth_;
32     windowHeight_ = other.windowHeight_;
33     windowLeftUsed_ = other.windowLeftUsed_;
34     windowTopUsed_ = other.windowTopUsed_;
35     windowWidthUsed_ = other.windowWidthUsed_;
36     windowHeightUsed_ = other.windowHeightUsed_;
37     processOptions = other.processOptions;
38     windowFocused_ = other.windowFocused_;
39     startWindowOption = other.startWindowOption;
40 }
41 
operator =(const StartOptions &other)42 StartOptions &StartOptions::operator=(const StartOptions &other)
43 {
44     if (this != &other) {
45         windowMode_ = other.windowMode_;
46         displayId_ = other.displayId_;
47         withAnimation_ = other.withAnimation_;
48         windowLeft_ = other.windowLeft_;
49         windowTop_ = other.windowTop_;
50         windowWidth_ = other.windowWidth_;
51         windowHeight_ = other.windowHeight_;
52         windowLeftUsed_ = other.windowLeftUsed_;
53         windowTopUsed_ = other.windowTopUsed_;
54         windowWidthUsed_ = other.windowWidthUsed_;
55         windowHeightUsed_ = other.windowHeightUsed_;
56         processOptions = other.processOptions;
57         windowFocused_ = other.windowFocused_;
58         startWindowOption = other.startWindowOption;
59     }
60     return *this;
61 }
62 
ReadFromParcel(Parcel &parcel)63 bool StartOptions::ReadFromParcel(Parcel &parcel)
64 {
65     SetWindowMode(parcel.ReadInt32());
66     SetDisplayID(parcel.ReadInt32());
67     SetWithAnimation(parcel.ReadBool());
68     SetWindowLeft(parcel.ReadInt32());
69     SetWindowTop(parcel.ReadInt32());
70     SetWindowWidth(parcel.ReadInt32());
71     SetWindowHeight(parcel.ReadInt32());
72     SetWindowFocused(parcel.ReadBool());
73     windowLeftUsed_ = parcel.ReadBool();
74     windowTopUsed_ = parcel.ReadBool();
75     windowWidthUsed_ = parcel.ReadBool();
76     windowHeightUsed_ = parcel.ReadBool();
77     processOptions.reset(parcel.ReadParcelable<ProcessOptions>());
78     startWindowOption.reset(parcel.ReadParcelable<StartWindowOption>());
79     return true;
80 }
81 
Unmarshalling(Parcel &parcel)82 StartOptions *StartOptions::Unmarshalling(Parcel &parcel)
83 {
84     StartOptions *option = new (std::nothrow) StartOptions();
85     if (option == nullptr) {
86         return nullptr;
87     }
88 
89     if (!option->ReadFromParcel(parcel)) {
90         delete option;
91         option = nullptr;
92     }
93 
94     return option;
95 }
96 
Marshalling(Parcel &parcel) const97 bool StartOptions::Marshalling(Parcel &parcel) const
98 {
99     parcel.WriteInt32(GetWindowMode());
100     parcel.WriteInt32(GetDisplayID());
101     parcel.WriteBool(GetWithAnimation());
102     parcel.WriteInt32(GetWindowLeft());
103     parcel.WriteInt32(GetWindowTop());
104     parcel.WriteInt32(GetWindowWidth());
105     parcel.WriteInt32(GetWindowHeight());
106     parcel.WriteBool(GetWindowFocused());
107     parcel.WriteBool(windowLeftUsed_);
108     parcel.WriteBool(windowTopUsed_);
109     parcel.WriteBool(windowWidthUsed_);
110     parcel.WriteBool(windowHeightUsed_);
111     if (!parcel.WriteParcelable(processOptions.get())) {
112         TAG_LOGE(AAFwkTag::ABILITYMGR, "write processOptions failed");
113         return false;
114     }
115     if (!parcel.WriteParcelable(startWindowOption.get())) {
116         TAG_LOGE(AAFwkTag::ABILITYMGR, "write startWindowOption failed");
117         return false;
118     }
119     return true;
120 }
121 
SetWindowMode(int32_t windowMode)122 void StartOptions::SetWindowMode(int32_t windowMode)
123 {
124     windowMode_ = windowMode;
125 }
126 
GetWindowMode() const127 int32_t StartOptions::GetWindowMode() const
128 {
129     return windowMode_;
130 }
131 
SetDisplayID(int32_t id)132 void StartOptions::SetDisplayID(int32_t id)
133 {
134     displayId_ = id;
135 }
136 
GetDisplayID() const137 int32_t StartOptions::GetDisplayID() const
138 {
139     return displayId_;
140 }
141 
SetWithAnimation(bool withAnimation)142 void StartOptions::SetWithAnimation(bool withAnimation)
143 {
144     withAnimation_ = withAnimation;
145 }
146 
GetWithAnimation() const147 bool StartOptions::GetWithAnimation() const
148 {
149     return withAnimation_;
150 }
151 
SetWindowLeft(int32_t windowLeft)152 void StartOptions::SetWindowLeft(int32_t windowLeft)
153 {
154     windowLeft_ = windowLeft;
155 }
156 
GetWindowLeft() const157 int32_t StartOptions::GetWindowLeft() const
158 {
159     return windowLeft_;
160 }
161 
SetWindowTop(int32_t windowTop)162 void StartOptions::SetWindowTop(int32_t windowTop)
163 {
164     windowTop_ = windowTop;
165 }
166 
GetWindowTop() const167 int32_t StartOptions::GetWindowTop() const
168 {
169     return windowTop_;
170 }
171 
SetWindowWidth(int32_t windowWidth)172 void StartOptions::SetWindowWidth(int32_t windowWidth)
173 {
174     windowWidth_ = windowWidth;
175 }
176 
GetWindowWidth() const177 int32_t StartOptions::GetWindowWidth() const
178 {
179     return windowWidth_;
180 }
181 
SetWindowHeight(int32_t windowHeight)182 void StartOptions::SetWindowHeight(int32_t windowHeight)
183 {
184     windowHeight_ = windowHeight;
185 }
186 
GetWindowHeight() const187 int32_t StartOptions::GetWindowHeight() const
188 {
189     return windowHeight_;
190 }
191 
SetWindowFocused(bool windowFocused)192 void StartOptions::SetWindowFocused(bool windowFocused)
193 {
194     windowFocused_ = windowFocused;
195 }
196 
GetWindowFocused() const197 int32_t StartOptions::GetWindowFocused() const
198 {
199     return windowFocused_;
200 }
201 }  // namespace AAFwk
202 }  // namespace OHOS
203