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