1 /*
2  * Copyright (c) 2022-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 CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_WINDOW_STATE_OBSERVER_H_
17 #define CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_WINDOW_STATE_OBSERVER_H_
18 
19 #include <sys/types.h>
20 #include "iremote_object.h"
21 #include "window_manager_lite.h"
22 #include "wm_common.h"
23 #include "nlohmann/json.hpp"
24 #include <cstdint>
25 
26 namespace OHOS {
27 namespace ResourceSchedule {
28 namespace RSSWindowMode {
29     enum:uint8_t {
30         // The frist bit represents the floating bit,0 to enter, 1 to exit
31         // The second bit represents the split bit,0 to enter, 1 to exit
32         WINDOW_MODE_SPLIT_FLOATING = 0b00,
33         WINDOW_MODE_SPLIT = 0b01,
34         WINDOW_MODE_FLOATING = 0b10,
35         WINDOW_MODE_OTHER = 0b11,
36 
37         // The frist bit represents the floating bit,0 to changed, 1 to unchanged
38         // The second bit represents the split bit,0 to changed, 1 to unchanged
39         WINDOW_MODE_SPLIT_FLOATING_UNCHANGED = 0b00,
40         WINDOW_MODE_FLOATING_CHANGED = 0b01,
41         WINDOW_MODE_SPLIT_CHANGED = 0b10,
42         WINDOW_MODE_SPLIT_FLOATING_CHANGED = 0b11,
43     };
44 }
45 using OHOS::Rosen::IFocusChangedListener;
46 using OHOS::Rosen::IVisibilityChangedListener;
47 using OHOS::Rosen::IDrawingContentChangedListener;
48 using OHOS::Rosen::IWindowModeChangedListener;
49 using OHOS::Rosen::WindowType;
50 using OHOS::Rosen::FocusChangeInfo;
51 using OHOS::Rosen::WindowVisibilityInfo;
52 using OHOS::Rosen::WindowDrawingContentInfo;
53 using OHOS::Rosen::WindowModeType;
54 
55 class WindowStateObserver : public IFocusChangedListener {
56 public:
57     void OnFocused(const sptr<FocusChangeInfo>& focusChangeInfo) override;
58     void OnUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo) override;
59 };
60 
61 class WindowVisibilityObserver : public IVisibilityChangedListener {
62 public:
63     void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) override;
64 
65 private:
66     void MarshallingWindowVisibilityInfo(const sptr<WindowVisibilityInfo>& info, nlohmann::json& payload);
67 };
68 
69 class WindowDrawingContentObserver : public IDrawingContentChangedListener {
70 public:
71     void OnWindowDrawingContentChanged(const std::vector<sptr<WindowDrawingContentInfo>>& changeInfo) override;
72 
73 private:
74     void MarshallingWindowDrawingContentInfo(const sptr<WindowDrawingContentInfo>& info, nlohmann::json& payload);
75 };
76 class WindowModeObserver : public IWindowModeChangedListener {
77 public:
78     void OnWindowModeUpdate(const WindowModeType mode) override;
79 private:
80     uint8_t MarshallingWindowModeType(const WindowModeType mode);
81     uint8_t lastWindowMode_ = RSSWindowMode::WINDOW_MODE_OTHER;
82 };
83 } // namespace ResourceSchedule
84 } // namespace OHOS
85 #endif // CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_WINDOW_STATE_OBSERVER_H_
86