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