• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef INTERFACES_INNERKITS_WINDOW_SCENE_H
17 #define INTERFACES_INNERKITS_WINDOW_SCENE_H
18 
19 #include <mutex>
20 
21 #include "window.h"
22 #include "window_option.h"
23 #include "wm_common.h"
24 
25 namespace OHOS::AppExecFwk {
26 class Configuration;
27 }
28 
29 namespace OHOS {
30 namespace Rosen {
31 class WindowScene : public RefBase {
32 public:
33     /**
34      * Default constructor used to create an empty WindowScene instance.
35      */
36     WindowScene() = default;
37 
38     /**
39      * Default deconstructor used to deconstruct.
40      *
41      */
42     ~WindowScene();
43 
44     /**
45      * Init a WindowScene instance based on the parameters displayId, context, listener and option.
46      *
47      * @param displayId the id of current display
48      * @param context current ability context
49      * @param listener the life cycle listener of the window
50      * @param option the settings for window, such as WindowType, width, height, etc
51      * @return the error code of window
52      */
53     WMError Init(DisplayId displayId, const std::shared_ptr<AbilityRuntime::Context>& context,
54         sptr<IWindowLifeCycle>& listener, sptr<WindowOption> option = nullptr);
55 
56     /**
57      * Init a WindowScene instance based on the parameters displayId, context, listener and option.
58      *
59      * @param displayId the id of current display
60      * @param context current ability context
61      * @param listener the life cycle listener of the window
62      * @param option the settings for window, such as WindowType, width, height, etc
63      * @param iSession session token of window session
64      * @param identityToken identity token of sceneSession
65      * @return the error code of window
66      */
67     WMError Init(DisplayId displayId, const std::shared_ptr<AbilityRuntime::Context>& context,
68         sptr<IWindowLifeCycle>& listener, sptr<WindowOption> option, const sptr<IRemoteObject>& iSession,
69         const std::string& identityToken = "");
70 
71     /**
72      * Create a window instance based on the parameters windowName and option.
73      *
74      * @param windowName the id of this window
75      * @param option the settings for window, such as WindowType, width, height, etc.
76      * @return the shared pointer of window
77      */
78     sptr<Window> CreateWindow(const std::string& windowName, sptr<WindowOption>& option) const;
79 
80     /**
81      * Get shared pointer of main window.
82      * Locks mainWindowMutex_
83      *
84      * @return the shared pointer of window
85      */
86     sptr<Window> GetMainWindow() const;
87 
88     /**
89      * Get a set of sub window.
90      *
91      * @return a set of sub window
92      */
93     std::vector<sptr<Window>> GetSubWindow();
94 
95     /**
96      * window go foreground.
97      *
98      * @param reason the reason of window to go to foreground, default 0.
99      * @return the error code of window
100      */
101     WMError GoForeground(uint32_t reason = 0);
102 
103     /**
104      * Window go background.
105      *
106      * @param reason the reason of window to go to background, default 0.
107      * @return the error code of window
108      */
109     WMError GoBackground(uint32_t reason = 0);
110 
111     /**
112      * Window go distroy.
113      *
114      * @return the error code of window
115      */
116     WMError GoDestroy();
117 
118     /**
119      * Window go resume.
120      *
121      * @return the error code of window
122      */
123     WMError GoResume();
124 
125     /**
126      * Window handle new want.
127      *
128      * @param want ability want.
129      * @return the error code of window
130      */
131     WMError OnNewWant(const AAFwk::Want& want);
132 
133     /**
134      * Request to get the focus.
135      *
136      * @return the error code of window
137      */
138     WMError RequestFocus() const;
139 
140     /**
141      * Update ability configuration.
142      *
143      * @param configuration the configuration of ability
144      */
145     void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
146 
147     /**
148      * @brief Update ability configuration for specified window.
149      *
150      * @param configuration the configuration of ability
151      * @param resourceManager the resource manager
152      */
153     void UpdateConfigurationForSpecified(const std::shared_ptr<AppExecFwk::Configuration>& configuration,
154         const std::shared_ptr<Global::Resource::ResourceManager>& resourceManager);
155 
156     /**
157      * Set main window system bar property
158      *
159      * @param type the type of window
160      * @param property the property of system bar
161      * @return the error code of window
162      */
163     WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const;
164 
165     /**
166      * Get content info of main window.
167      *
168      * @return content info of main window
169      */
170     std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) const;
171 
172     /**
173      * @brief Handle and notify memory.
174      *
175      * @param level memory level
176      * @return the error code of window
177      */
178     WMError NotifyMemoryLevel(int32_t level);
179 
180 public:
181     static const DisplayId DEFAULT_DISPLAY_ID = 0;
182 
183 private:
184     void OnLastStrongRef(const void *) override;
185 
186 private:
187     mutable std::mutex mainWindowMutex_;
188     sptr<Window> mainWindow_ = nullptr;
189     // Above guarded by mainWindowMutex_
190 
191     uint32_t mainWindowId_ = 0;
192 };
193 
194 } // namespace Rosen
195 } // namespace OHOS
196 #endif // INTERFACES_INNERKITS_WINDOW_SCENE_H
197