• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "common/include/window_session_property.h"
17 #include "window_manager_hilog.h"
18 #include "wm_common.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace {
23 constexpr uint32_t TOUCH_HOT_AREA_MAX_NUM = 10;
24 }
25 
WindowSessionProperty(const sptr<WindowSessionProperty> & property)26 WindowSessionProperty::WindowSessionProperty(const sptr<WindowSessionProperty>& property)
27 {
28     CopyFrom(property);
29 }
30 
SetWindowName(const std::string & name)31 void WindowSessionProperty::SetWindowName(const std::string& name)
32 {
33     windowName_ = name;
34 }
35 
SetSessionInfo(const SessionInfo & info)36 void WindowSessionProperty::SetSessionInfo(const SessionInfo& info)
37 {
38     sessionInfo_ = info;
39 }
40 
SetWindowRect(const struct Rect & rect)41 void WindowSessionProperty::SetWindowRect(const struct Rect& rect)
42 {
43     windowRect_ = rect;
44 }
45 
SetRequestRect(const Rect & requestRect)46 void WindowSessionProperty::SetRequestRect(const Rect& requestRect)
47 {
48     requestRect_ = requestRect;
49 }
50 
SetWindowType(WindowType type)51 void WindowSessionProperty::SetWindowType(WindowType type)
52 {
53     type_ = type;
54 }
55 
SetFocusable(bool isFocusable)56 void WindowSessionProperty::SetFocusable(bool isFocusable)
57 {
58     focusable_ = isFocusable;
59 }
60 
SetTouchable(bool isTouchable)61 void WindowSessionProperty::SetTouchable(bool isTouchable)
62 {
63     touchable_ = isTouchable;
64 }
65 
SetDragEnabled(bool dragEnabled)66 void WindowSessionProperty::SetDragEnabled(bool dragEnabled)
67 {
68     dragEnabled_ = dragEnabled;
69 }
70 
SetRaiseEnabled(bool raiseEnabled)71 void WindowSessionProperty::SetRaiseEnabled(bool raiseEnabled)
72 {
73     raiseEnabled_ = raiseEnabled;
74 }
75 
SetBrightness(float brightness)76 void WindowSessionProperty::SetBrightness(float brightness)
77 {
78     brightness_ = brightness;
79 }
80 
SetRequestedOrientation(Orientation orientation)81 void WindowSessionProperty::SetRequestedOrientation(Orientation orientation)
82 {
83     requestedOrientation_ = orientation;
84 }
85 
SetPrivacyMode(bool isPrivate)86 void WindowSessionProperty::SetPrivacyMode(bool isPrivate)
87 {
88     isPrivacyMode_ = isPrivate;
89 }
90 
SetSystemPrivacyMode(bool isSystemPrivate)91 void WindowSessionProperty::SetSystemPrivacyMode(bool isSystemPrivate)
92 {
93     isSystemPrivacyMode_ = isSystemPrivate;
94 }
95 
SetSystemCalling(bool isSystemCalling)96 void WindowSessionProperty::SetSystemCalling(bool isSystemCalling)
97 {
98     isSystemCalling_ = isSystemCalling;
99 }
100 
SetDisplayId(DisplayId displayId)101 void WindowSessionProperty::SetDisplayId(DisplayId displayId)
102 {
103     displayId_ = displayId;
104 }
105 
SetFloatingWindowAppType(bool isAppType)106 void WindowSessionProperty::SetFloatingWindowAppType(bool isAppType)
107 {
108     isFloatingWindowAppType_ = isAppType;
109 }
110 
GetWindowName() const111 const std::string& WindowSessionProperty::GetWindowName() const
112 {
113     return windowName_;
114 }
115 
GetSessionInfo() const116 const SessionInfo& WindowSessionProperty::GetSessionInfo() const
117 {
118     return sessionInfo_;
119 }
120 
GetWindowRect() const121 Rect WindowSessionProperty::GetWindowRect() const
122 {
123     return windowRect_;
124 }
125 
GetRequestRect() const126 Rect WindowSessionProperty::GetRequestRect() const
127 {
128     return requestRect_;
129 }
130 
GetWindowType() const131 WindowType WindowSessionProperty::GetWindowType() const
132 {
133     return type_;
134 }
135 
GetFocusable() const136 bool WindowSessionProperty::GetFocusable() const
137 {
138     return focusable_;
139 }
140 
GetTouchable() const141 bool WindowSessionProperty::GetTouchable() const
142 {
143     return touchable_;
144 }
145 
GetDragEnabled() const146 bool WindowSessionProperty::GetDragEnabled() const
147 {
148     return dragEnabled_;
149 }
150 
GetRaiseEnabled() const151 bool WindowSessionProperty::GetRaiseEnabled() const
152 {
153     return raiseEnabled_;
154 }
155 
GetBrightness() const156 float WindowSessionProperty::GetBrightness() const
157 {
158     return brightness_;
159 }
160 
GetRequestedOrientation() const161 Orientation WindowSessionProperty::GetRequestedOrientation() const
162 {
163     return requestedOrientation_;
164 }
165 
GetPrivacyMode() const166 bool WindowSessionProperty::GetPrivacyMode() const
167 {
168     return isPrivacyMode_;
169 }
170 
GetSystemPrivacyMode() const171 bool WindowSessionProperty::GetSystemPrivacyMode() const
172 {
173     return isSystemPrivacyMode_;
174 }
175 
GetSystemCalling() const176 bool WindowSessionProperty::GetSystemCalling() const
177 {
178     return isSystemCalling_;
179 }
180 
GetDisplayId() const181 DisplayId WindowSessionProperty::GetDisplayId() const
182 {
183     return displayId_;
184 }
185 
SetParentId(int32_t parentId)186 void WindowSessionProperty::SetParentId(int32_t parentId)
187 {
188     parentId_ = parentId;
189 }
190 
GetParentId() const191 int32_t WindowSessionProperty::GetParentId() const
192 {
193     return parentId_;
194 }
195 
SetWindowFlags(uint32_t flags)196 void WindowSessionProperty::SetWindowFlags(uint32_t flags)
197 {
198     flags_ = flags;
199 }
200 
AddWindowFlag(WindowFlag flag)201 void WindowSessionProperty::AddWindowFlag(WindowFlag flag)
202 {
203     flags_ |= static_cast<uint32_t>(flag);
204 }
205 
GetWindowFlags() const206 uint32_t WindowSessionProperty::GetWindowFlags() const
207 {
208     return flags_;
209 }
210 
SetPersistentId(int32_t persistentId)211 void WindowSessionProperty::SetPersistentId(int32_t persistentId)
212 {
213     persistentId_ = persistentId;
214 }
215 
GetPersistentId() const216 int32_t WindowSessionProperty::GetPersistentId() const
217 {
218     return persistentId_;
219 }
220 
SetParentPersistentId(int32_t persistentId)221 void WindowSessionProperty::SetParentPersistentId(int32_t persistentId)
222 {
223     parentPersistentId_ = persistentId;
224 }
225 
GetParentPersistentId() const226 int32_t WindowSessionProperty::GetParentPersistentId() const
227 {
228     return parentPersistentId_;
229 }
230 
SetTurnScreenOn(bool turnScreenOn)231 void WindowSessionProperty::SetTurnScreenOn(bool turnScreenOn)
232 {
233     turnScreenOn_ = turnScreenOn;
234 }
235 
IsTurnScreenOn() const236 bool WindowSessionProperty::IsTurnScreenOn() const
237 {
238     return turnScreenOn_;
239 }
240 
SetKeepScreenOn(bool keepScreenOn)241 void WindowSessionProperty::SetKeepScreenOn(bool keepScreenOn)
242 {
243     keepScreenOn_ = keepScreenOn;
244 }
245 
IsKeepScreenOn() const246 bool WindowSessionProperty::IsKeepScreenOn() const
247 {
248     return keepScreenOn_;
249 }
250 
SetAccessTokenId(uint32_t accessTokenId)251 void WindowSessionProperty::SetAccessTokenId(uint32_t accessTokenId)
252 {
253     accessTokenId_ = accessTokenId;
254 }
255 
GetAccessTokenId() const256 uint32_t WindowSessionProperty::GetAccessTokenId() const
257 {
258     return accessTokenId_;
259 }
260 
SetTokenState(bool hasToken)261 void WindowSessionProperty::SetTokenState(bool hasToken)
262 {
263     tokenState_ = hasToken;
264 }
265 
GetTokenState() const266 bool WindowSessionProperty::GetTokenState() const
267 {
268     return tokenState_;
269 }
270 
GetMaximizeMode() const271 MaximizeMode WindowSessionProperty::GetMaximizeMode() const
272 {
273     return maximizeMode_;
274 }
275 
SetMaximizeMode(MaximizeMode mode)276 void WindowSessionProperty::SetMaximizeMode(MaximizeMode mode)
277 {
278     maximizeMode_ = mode;
279 }
280 
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)281 void WindowSessionProperty::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
282 {
283     if (type == WindowType::WINDOW_TYPE_STATUS_BAR) {
284         sysBarPropMap_[type] = property;
285     }
286 }
287 
GetSystemBarProperty() const288 std::unordered_map<WindowType, SystemBarProperty> WindowSessionProperty::GetSystemBarProperty() const
289 {
290     return sysBarPropMap_;
291 }
292 
SetWindowLimits(const WindowLimits & windowLimits)293 void WindowSessionProperty::SetWindowLimits(const WindowLimits& windowLimits)
294 {
295     limits_ = windowLimits;
296 }
297 
GetWindowLimits() const298 WindowLimits WindowSessionProperty::GetWindowLimits() const
299 {
300     return limits_;
301 }
302 
SetWindowMode(WindowMode mode)303 void WindowSessionProperty::SetWindowMode(WindowMode mode)
304 {
305     windowMode_ = mode;
306 }
307 
GetWindowMode() const308 WindowMode WindowSessionProperty::GetWindowMode() const
309 {
310     return windowMode_;
311 }
312 
SetSessionGravity(SessionGravity gravity,uint32_t percent)313 void WindowSessionProperty::SetSessionGravity(SessionGravity gravity, uint32_t percent)
314 {
315     sessionGravity_ = gravity;
316     sessionGravitySizePercent_ = percent;
317 }
318 
GetSessionGravity(SessionGravity & gravity,uint32_t & percent)319 void WindowSessionProperty::GetSessionGravity(SessionGravity& gravity, uint32_t& percent)
320 {
321     gravity = sessionGravity_;
322     percent = sessionGravitySizePercent_;
323 }
324 
SetDecorEnable(bool isDecorEnable)325 void WindowSessionProperty::SetDecorEnable(bool isDecorEnable)
326 {
327     isDecorEnable_ = isDecorEnable;
328 }
329 
IsDecorEnable()330 bool WindowSessionProperty::IsDecorEnable()
331 {
332     return isDecorEnable_;
333 }
334 
SetModeSupportInfo(uint32_t modeSupportInfo)335 void WindowSessionProperty::SetModeSupportInfo(uint32_t modeSupportInfo)
336 {
337     modeSupportInfo_ = modeSupportInfo;
338 }
339 
GetModeSupportInfo() const340 uint32_t WindowSessionProperty::GetModeSupportInfo() const
341 {
342     return modeSupportInfo_;
343 }
344 
SetAnimationFlag(uint32_t animationFlag)345 void WindowSessionProperty::SetAnimationFlag(uint32_t animationFlag)
346 {
347     animationFlag_ = animationFlag;
348 }
349 
GetAnimationFlag() const350 uint32_t WindowSessionProperty::GetAnimationFlag() const
351 {
352     return animationFlag_;
353 }
354 
IsFloatingWindowAppType() const355 bool WindowSessionProperty::IsFloatingWindowAppType() const
356 {
357     return isFloatingWindowAppType_;
358 }
359 
SetTouchHotAreas(const std::vector<Rect> & rects)360 void WindowSessionProperty::SetTouchHotAreas(const std::vector<Rect>& rects)
361 {
362     touchHotAreas_ = rects;
363 }
364 
GetTouchHotAreas(std::vector<Rect> & rects) const365 void WindowSessionProperty::GetTouchHotAreas(std::vector<Rect>& rects) const
366 {
367     rects = touchHotAreas_;
368 }
369 
MarshallingWindowLimits(Parcel & parcel) const370 bool WindowSessionProperty::MarshallingWindowLimits(Parcel& parcel) const
371 {
372     if (parcel.WriteUint32(limits_.maxWidth_) &&
373         parcel.WriteUint32(limits_.maxHeight_) && parcel.WriteUint32(limits_.minWidth_) &&
374         parcel.WriteUint32(limits_.minHeight_) && parcel.WriteFloat(limits_.maxRatio_) &&
375         parcel.WriteFloat(limits_.minRatio_)) {
376         return true;
377     }
378     return false;
379 }
380 
UnmarshallingWindowLimits(Parcel & parcel,WindowSessionProperty * property)381 void WindowSessionProperty::UnmarshallingWindowLimits(Parcel& parcel, WindowSessionProperty* property)
382 {
383     WindowLimits windowLimits = { parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(),
384                                   parcel.ReadUint32(), parcel.ReadFloat(), parcel.ReadFloat() };
385     property->SetWindowLimits(windowLimits);
386 }
387 
MarshallingSystemBarMap(Parcel & parcel) const388 bool WindowSessionProperty::MarshallingSystemBarMap(Parcel& parcel) const
389 {
390     auto size = sysBarPropMap_.size();
391     if (!parcel.WriteUint32(static_cast<uint32_t>(size))) {
392         return false;
393     }
394     for (auto it : sysBarPropMap_) {
395         if (!parcel.WriteUint32(static_cast<uint32_t>(it.first))) {
396             return false;
397         }
398         if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) &&
399             parcel.WriteUint32(it.second.contentColor_))) {
400             return false;
401         }
402     }
403     return true;
404 }
405 
UnMarshallingSystemBarMap(Parcel & parcel,WindowSessionProperty * property)406 void WindowSessionProperty::UnMarshallingSystemBarMap(Parcel& parcel, WindowSessionProperty* property)
407 {
408     uint32_t size = parcel.ReadUint32();
409     for (uint32_t i = 0; i < size; i++) {
410         WindowType type = static_cast<WindowType>(parcel.ReadUint32());
411         SystemBarProperty prop = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32() };
412         property->SetSystemBarProperty(type, prop);
413     }
414 }
415 
MarshallingTouchHotAreas(Parcel & parcel) const416 bool WindowSessionProperty::MarshallingTouchHotAreas(Parcel& parcel) const
417 {
418     auto size = touchHotAreas_.size();
419     if (size > TOUCH_HOT_AREA_MAX_NUM) {
420         return false;
421     }
422     if (!parcel.WriteUint32(static_cast<uint32_t>(size))) {
423         return false;
424     }
425     for (const auto& rect : touchHotAreas_) {
426         if (!(parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
427             parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_))) {
428             return false;
429         }
430     }
431     return true;
432 }
433 
UnmarshallingTouchHotAreas(Parcel & parcel,WindowSessionProperty * property)434 void WindowSessionProperty::UnmarshallingTouchHotAreas(Parcel& parcel, WindowSessionProperty* property)
435 {
436     uint32_t size = parcel.ReadUint32();
437     if (size > TOUCH_HOT_AREA_MAX_NUM) {
438         return;
439     }
440     for (uint32_t i = 0; i < size; i++) {
441         property->touchHotAreas_.emplace_back(
442             Rect{ parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() });
443     }
444 }
445 
Marshalling(Parcel & parcel) const446 bool WindowSessionProperty::Marshalling(Parcel& parcel) const
447 {
448     return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) &&
449         parcel.WriteInt32(windowRect_.posY_) && parcel.WriteUint32(windowRect_.width_) &&
450         parcel.WriteUint32(windowRect_.height_) && parcel.WriteInt32(requestRect_.posX_) &&
451         parcel.WriteInt32(requestRect_.posY_) && parcel.WriteUint32(requestRect_.width_) &&
452         parcel.WriteUint32(requestRect_.height_) &&
453         parcel.WriteUint32(static_cast<uint32_t>(type_)) &&
454         parcel.WriteBool(focusable_) && parcel.WriteBool(touchable_) && parcel.WriteBool(tokenState_) &&
455         parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) &&
456         parcel.WriteBool(isPrivacyMode_) && parcel.WriteBool(isSystemPrivacyMode_) &&
457         parcel.WriteUint64(displayId_) && parcel.WriteInt32(persistentId_) &&
458         parcel.WriteString(sessionInfo_.bundleName_) && parcel.WriteString(sessionInfo_.moduleName_) &&
459         parcel.WriteString(sessionInfo_.abilityName_) &&
460         parcel.WriteInt32(parentPersistentId_) &&
461         parcel.WriteUint32(accessTokenId_) && parcel.WriteInt32(static_cast<uint32_t>(maximizeMode_)) &&
462         parcel.WriteFloat(brightness_) &&
463         parcel.WriteUint32(static_cast<uint32_t>(requestedOrientation_)) &&
464         parcel.WriteUint32(static_cast<uint32_t>(windowMode_)) &&
465         parcel.WriteUint32(flags_) && parcel.WriteBool(raiseEnabled_) &&
466         parcel.WriteBool(isDecorEnable_) && parcel.WriteBool(dragEnabled_) &&
467         MarshallingWindowLimits(parcel) &&
468         MarshallingSystemBarMap(parcel) && parcel.WriteUint32(animationFlag_) &&
469         parcel.WriteBool(isFloatingWindowAppType_) && MarshallingTouchHotAreas(parcel) &&
470         parcel.WriteBool(isSystemCalling_);
471 }
472 
Unmarshalling(Parcel & parcel)473 WindowSessionProperty* WindowSessionProperty::Unmarshalling(Parcel& parcel)
474 {
475     WindowSessionProperty* property = new(std::nothrow) WindowSessionProperty();
476     if (property == nullptr) {
477         return nullptr;
478     }
479     property->SetWindowName(parcel.ReadString());
480     Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() };
481     property->SetWindowRect(rect);
482     Rect reqRect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() };
483     property->SetRequestRect(reqRect);
484     property->SetWindowType(static_cast<WindowType>(parcel.ReadUint32()));
485     property->SetFocusable(parcel.ReadBool());
486     property->SetTouchable(parcel.ReadBool());
487     property->SetTokenState(parcel.ReadBool());
488     property->SetTurnScreenOn(parcel.ReadBool());
489     property->SetKeepScreenOn(parcel.ReadBool());
490     property->SetPrivacyMode(parcel.ReadBool());
491     property->SetSystemPrivacyMode(parcel.ReadBool());
492     property->SetDisplayId(parcel.ReadUint64());
493     property->SetPersistentId(parcel.ReadInt32());
494     SessionInfo info = { parcel.ReadString(), parcel.ReadString(), parcel.ReadString() };
495     property->SetSessionInfo(info);
496     property->SetParentPersistentId(parcel.ReadInt32());
497     property->SetAccessTokenId(parcel.ReadUint32());
498     property->SetMaximizeMode(static_cast<MaximizeMode>(parcel.ReadUint32()));
499     property->SetBrightness(parcel.ReadFloat());
500     property->SetRequestedOrientation(static_cast<Orientation>(parcel.ReadUint32()));
501     property->SetWindowMode(static_cast<WindowMode>(parcel.ReadUint32()));
502     property->SetWindowFlags(parcel.ReadUint32());
503     property->SetRaiseEnabled(parcel.ReadBool());
504     property->SetDecorEnable(parcel.ReadBool());
505     property->SetDragEnabled(parcel.ReadBool());
506     UnmarshallingWindowLimits(parcel, property);
507     UnMarshallingSystemBarMap(parcel, property);
508     property->SetAnimationFlag(parcel.ReadUint32());
509     property->SetFloatingWindowAppType(parcel.ReadBool());
510     UnmarshallingTouchHotAreas(parcel, property);
511     property->SetSystemCalling(parcel.ReadBool());
512     return property;
513 }
514 
CopyFrom(const sptr<WindowSessionProperty> & property)515 void WindowSessionProperty::CopyFrom(const sptr<WindowSessionProperty>& property)
516 {
517     windowName_ = property->windowName_;
518     sessionInfo_ = property->sessionInfo_;
519     requestRect_ = property->requestRect_;
520     windowRect_ = property->windowRect_;
521     type_ = property->type_;
522     focusable_= property->focusable_;
523     touchable_ = property->touchable_;
524     dragEnabled_ = property->dragEnabled_;
525     raiseEnabled_ = property->raiseEnabled_;
526     tokenState_ = property->tokenState_;
527     turnScreenOn_ = property->turnScreenOn_;
528     keepScreenOn_ = property->keepScreenOn_;
529     brightness_ = property->brightness_;
530     requestedOrientation_ = property->requestedOrientation_;
531     isPrivacyMode_ = property->isPrivacyMode_;
532     isSystemPrivacyMode_ = property->isSystemPrivacyMode_;
533     displayId_ = property->displayId_;
534     parentId_ = property->parentId_;
535     flags_ = property->flags_;
536     persistentId_ = property->persistentId_;
537     parentPersistentId_ = property->parentPersistentId_;
538     accessTokenId_ = property->accessTokenId_;
539     maximizeMode_ = property->maximizeMode_;
540     windowMode_ = property->windowMode_;
541     limits_ = property->limits_;
542     sysBarPropMap_ = property->sysBarPropMap_;
543     isDecorEnable_ = property->isDecorEnable_;
544     animationFlag_ = property->animationFlag_;
545     isFloatingWindowAppType_ = property->isFloatingWindowAppType_;
546     touchHotAreas_ = property->touchHotAreas_;
547     isSystemCalling_ = property->isSystemCalling_;
548 }
549 
SetTransform(const Transform & trans)550 void WindowSessionProperty::SetTransform(const Transform& trans)
551 {
552     trans_ = trans;
553 }
554 
GetTransform() const555 const Transform& WindowSessionProperty::GetTransform() const
556 {
557     return trans_;
558 }
559 } // namespace Rosen
560 } // namespace OHOS
561