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 #ifndef OHOS_ROSEN_WINDOW_VISIBILITY_INFO_H
17 #define OHOS_ROSEN_WINDOW_VISIBILITY_INFO_H
18 
19 #include "wm_common.h"
20 
21 namespace OHOS::Rosen {
22 /**
23  * @enum WindowVisibilityState
24  *
25  * @brief Visibility state of a window
26  */
27 enum WindowVisibilityState : uint32_t {
28     WINDOW_VISIBILITY_STATE_NO_OCCLUSION = 0,
29     WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION,
30     WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION,
31     WINDOW_LAYER_STATE_MAX
32 };
33 
34 /**
35  * @enum WindowLayerState
36  *
37  * @brief Layer state of a window
38  */
39 enum WindowLayerState {
40     WINDOW_ALL_VISIBLE = 0,
41     WINDOW_SEMI_VISIBLE,
42     WINDOW_IN_VISIBLE,
43     WINDOW_LAYER_DRAWING,
44     WINDOW_LAYER_NO_DRAWING,
45     WINDOW_LAYER_UNKNOWN_STATE,
46 };
47 
48 /**
49  * @class WindowVisibilityInfo
50  *
51  * @brief Visibility info of window.
52  */
53 class WindowVisibilityInfo : public Parcelable {
54 public:
55     /**
56      * @brief Default construct of WindowVisibilityInfo.
57      */
58     WindowVisibilityInfo() = default;
59     /**
60      * @brief Construct of WindowVisibilityInfo.
61      *
62      * @param winId Window id.
63      * @param pid Process id.
64      * @param uid User id.
65      * @param visibility True means window is visible, false means the opposite.
66      * @param winType Type of window.
67      */
WindowVisibilityInfo(uint32_t winId,int32_t pid,int32_t uid,WindowVisibilityState visibilityState,WindowType winType)68     WindowVisibilityInfo(uint32_t winId, int32_t pid, int32_t uid, WindowVisibilityState visibilityState,
69         WindowType winType) : windowId_(winId), pid_(pid), uid_(uid), visibilityState_(visibilityState),
70         windowType_(winType) {};
71 
WindowVisibilityInfo(uint32_t winId,int32_t pid,int32_t uid,WindowVisibilityState visibilityState,WindowType winType,WindowStatus windowStatus,const Rect & rect,const std::string & bundleName,const std::string & abilityName,bool isFocused)72     WindowVisibilityInfo(uint32_t winId, int32_t pid, int32_t uid, WindowVisibilityState visibilityState,
73         WindowType winType, WindowStatus windowStatus, const Rect& rect, const std::string& bundleName,
74         const std::string& abilityName, bool isFocused) : windowId_(winId), pid_(pid), uid_(uid),
75         visibilityState_(visibilityState), windowType_(winType), windowStatus_(windowStatus), rect_(rect),
76         bundleName_(bundleName), abilityName_(abilityName), isFocused_(isFocused) {}
77 
78     /**
79      * @brief Deconstruct of WindowVisibilityInfo.
80      */
81     ~WindowVisibilityInfo() = default;
82 
83     /**
84      * @brief Marshalling WindowVisibilityInfo.
85      *
86      * @param parcel Package of WindowVisibilityInfo.
87      * @return True means marshall success, false means marshall failed.
88      */
89     virtual bool Marshalling(Parcel& parcel) const override;
90     /**
91      * @brief Unmarshalling WindowVisibilityInfo.
92      *
93      * @param parcel Package of WindowVisibilityInfo.
94      * @return WindowVisibilityInfo object.
95      */
96     static WindowVisibilityInfo* Unmarshalling(Parcel& parcel);
97 
GetWindowId()98     uint32_t GetWindowId() const { return windowId_; }
99 
GetRect()100     const Rect& GetRect() const { return rect_; }
101 
GetBundleName()102     const std::string& GetBundleName() const { return bundleName_; }
103 
GetAbilityName()104     const std::string& GetAbilityName() const { return abilityName_; }
105 
GetWindowStatus()106     WindowStatus GetWindowStatus() const { return windowStatus_; }
107 
GetWindowType()108     WindowType GetWindowType() const { return windowType_; }
109 
GetWindowVisibilityState()110     WindowVisibilityState GetWindowVisibilityState() const { return visibilityState_; }
111 
IsFocused()112     bool IsFocused() const { return isFocused_; }
113 
114     uint32_t windowId_ { INVALID_WINDOW_ID };
115     int32_t pid_ { 0 };
116     int32_t uid_ { 0 };
117     WindowVisibilityState visibilityState_ = WINDOW_LAYER_STATE_MAX;
118     WindowType windowType_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
119     WindowStatus windowStatus_ = WindowStatus::WINDOW_STATUS_UNDEFINED;
120     Rect rect_ = {0, 0, 0, 0};
121     std::string bundleName_;
122     std::string abilityName_;
123     bool isFocused_ = false;
124 };
125 } // namespace OHOS::Rosen
126 #endif // OHOS_ROSEN_WINDOW_VISIBILITY_INFO_H