• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_DM_SCREEN_MANAGER_H
17 #define FOUNDATION_DM_SCREEN_MANAGER_H
18 
19 #include <refbase.h>
20 #include "dm_common.h"
21 #include "wm_single_instance.h"
22 #include "screen_info.h"
23 
24 namespace OHOS::Rosen {
25 class ScreenManagerLite : public RefBase {
26 WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenManagerLite);
27 friend class DMSDeathRecipientLite;
28 public:
29     /*
30      * used by powermgr
31      */
32     class IScreenListener : public virtual RefBase {
33     public:
34         /**
35          * @brief Notify when a new screen is connected.
36          */
37         virtual void OnConnect(ScreenId) = 0;
38 
39         /**
40          * @brief Notify when a screen is disconnected.
41          */
42         virtual void OnDisconnect(ScreenId) = 0;
43 
44         /**
45          * @brief Notify when state of the screen is changed.
46          */
47         virtual void OnChange(ScreenId) = 0;
48     };
49 
50     class IScreenModeChangeListener : public virtual RefBase {
51     public:
52 
53         /**
54          * @brief Notify when state of the screenMode is changed.
55          */
56         virtual void NotifyScreenModeChange(const std::vector<sptr<ScreenInfo>>&) = 0;
57     };
58 
59     class IAbnormalScreenConnectChangeListener : public virtual RefBase {
60     public:
61         /**
62          * @brief Notify when a screen connection occurs due to an system exception.
63          */
64         virtual void NotifyAbnormalScreenConnectChange(ScreenId screenId) = 0;
65     };
66 
67     /**
68      * @brief Register screen connect change listener(Only for scenarios where system exceptions occur).
69      *
70      * @param listener IAbnormalScreenConnectChangeListener.
71      * @return DM_OK means register success, others means register failed.
72      */
73     DMError RegisterAbnormalScreenConnectChangeListener(sptr<IAbnormalScreenConnectChangeListener> listener);
74 
75     /**
76      * @brief Unregister screen connect change listener(Only for scenarios where system exceptions occur).
77      *
78      * @param listener IAbnormalScreenConnectChangeListener.
79      * @return DM_OK means unregister success, others means unregister failed.
80      */
81     DMError UnregisterAbnormalScreenConnectChangeListener(sptr<IAbnormalScreenConnectChangeListener> listener);
82 
83     /**
84      * @brief Register screen mode change listener.
85      *
86      * @param listener IScreenModeChangeListener.
87      * @return DM_OK means register success, others means register failed.
88      */
89     DMError RegisterScreenModeChangeListener(sptr<IScreenModeChangeListener> listener);
90 
91     /**
92      * @brief Unregister screen listener.
93      *
94      * @param listener IScreenModeChangeListener.
95      * @return DM_OK means unregister success, others means unregister failed.
96      */
97     DMError UnregisterScreenModeChangeListener(sptr<IScreenModeChangeListener> listener);
98 
99     /**
100      * @brief Register screen listener.
101      *
102      * @param listener IScreenListener.
103      * @return DM_OK means register success, others means register failed.
104      */
105     DMError RegisterScreenListener(sptr<IScreenListener> listener);
106 
107     /**
108      * @brief Unregister screen listener.
109      *
110      * @param listener IScreenListener.
111      * @return DM_OK means unregister success, others means unregister failed.
112      */
113     DMError UnregisterScreenListener(sptr<IScreenListener> listener);
114 
115     /**
116      * @brief Set the screen power state on the specified screen.
117      *
118      * @param screenId Screen id.
119      * @param state Screen power state.
120      * @param reason Reason for power state change.
121      * @return True means set success, false means set failed.
122      */
123     bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason);
124 
125     /**
126      * @brief Set the screen power states for all screens.
127      *
128      * @param state Screen power state.
129      * @param reason Reason for power state change.
130      * @return True means set success, false means set failed.
131      */
132     bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason);
133 
134     /**
135      * @brief Get screen power state.
136      *
137      * @param screenId Screen id.
138      * @return Power state of screen.
139      */
140     ScreenPowerState GetScreenPower(ScreenId screenId);
141 
142     /**
143      * @brief Get screen power state.
144      *
145      * @return Power state of screen.
146      */
147     ScreenPowerState GetScreenPower();
148 
149     /**
150      * @brief Get all physical screen ids.
151      *
152      * @param screenIds Store physical screen ids.
153      * @return DM_OK means getting ids success, others means getting ids failed.
154      */
155     DMError GetPhysicalScreenIds(std::vector<uint64_t>& screenIds);
156 
157     /**
158      * @brief Get all physical screeninfo.
159      *
160      * @param screenIds Store physical screeninfos.
161      * @return DM_OK means getting screeninfos success, others means getting screeninfos failed.
162      */
163     DMError GetPhysicalScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos);
164 private:
165     ScreenManagerLite();
166     ~ScreenManagerLite();
167     void OnRemoteDied();
168 
169     class Impl;
170     sptr<Impl> pImpl_;
171 };
172 } // namespace OHOS::Rosen
173 
174 #endif // FOUNDATION_DM_SCREEN_MANAGER_H