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 handle new want. 120 * 121 * @param want ability want. 122 * @return the error code of window 123 */ 124 WMError OnNewWant(const AAFwk::Want& want); 125 126 /** 127 * Request to get the focus. 128 * 129 * @return the error code of window 130 */ 131 WMError RequestFocus() const; 132 133 /** 134 * Update ability configuration. 135 * 136 * @param configuration the configuration of ability 137 */ 138 void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration); 139 140 /** 141 * Set main window system bar property 142 * 143 * @param type the type of window 144 * @param property the property of system bar 145 * @return the error code of window 146 */ 147 WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const; 148 149 /** 150 * Get content info of main window. 151 * 152 * @return content info of main window 153 */ 154 std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) const; 155 156 /** 157 * @brief Handle and notify memory. 158 * 159 * @param level memory level 160 * @return the error code of window 161 */ 162 WMError NotifyMemoryLevel(int32_t level); 163 164 public: 165 static const DisplayId DEFAULT_DISPLAY_ID = 0; 166 167 private: 168 void OnLastStrongRef(const void *) override; 169 170 private: 171 mutable std::mutex mainWindowMutex_; 172 sptr<Window> mainWindow_ = nullptr; 173 // Above guarded by mainWindowMutex_ 174 175 uint32_t mainWindowId_ = 0; 176 }; 177 178 } // namespace Rosen 179 } // namespace OHOS 180 #endif // INTERFACES_INNERKITS_WINDOW_SCENE_H 181