1 /* 2 * Copyright (c) 2023 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 OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_MANAGER_H 17 #define OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_MANAGER_H 18 19 #include "common/include/task_scheduler.h" 20 #include "interfaces/include/ws_common.h" 21 #include "wm_single_instance.h" 22 23 namespace OHOS::AAFwk { 24 class SessionInfo; 25 } // namespace OHOS::AAFwk 26 27 namespace OHOS::Rosen { 28 class ExtensionSession; 29 class ExtensionSessionManager { 30 WM_DECLARE_SINGLE_INSTANCE_BASE(ExtensionSessionManager) 31 public: 32 /** 33 * @brief create extension session 34 * 35 * @param sessionInfo sessionInfo, identify extension session instance 36 * @return sptr<ExtensionSession> return session if create extension session success;Otherwise, return nullptr 37 */ 38 sptr<ExtensionSession> RequestExtensionSession(const SessionInfo& sessionInfo); 39 40 /** 41 * @brief active extension session 42 * 43 * @param extensionSession the extension session need to be activated 44 * @return WSError 45 */ 46 WSError RequestExtensionSessionActivation(const sptr<ExtensionSession>& extensionSession, uint32_t hostWindowId, 47 std::function<void(WSError)>&& resultCallback); 48 49 /** 50 * @brief background extension session 51 * 52 * @param extensionSession the extension session need to be go background 53 * @return WSError 54 */ 55 WSError RequestExtensionSessionBackground( 56 const sptr<ExtensionSession>& extensionSession, std::function<void(WSError)>&& resultCallback); 57 58 /** 59 * @brief destroy extension session 60 * 61 * @param extensionSession the extension session need to be destroyed 62 * @return WSError 63 */ 64 WSError RequestExtensionSessionDestruction( 65 const sptr<ExtensionSession>& extensionSession, std::function<void(WSError)>&& resultCallback); 66 67 /** 68 * @brief destroy extension session done 69 * 70 * @param extensionSession the extension session need to be destroyed 71 * @return WSError 72 */ 73 WSError RequestExtensionSessionDestructionDone(const sptr<ExtensionSession>& extensionSession); 74 75 private: 76 ExtensionSessionManager(); 77 ~ExtensionSessionManager() = default; 78 79 sptr<AAFwk::SessionInfo> SetAbilitySessionInfo(const sptr<ExtensionSession>& extensionSession); 80 float GetSystemDensity(uint64_t displayId); 81 82 std::shared_ptr<TaskScheduler> taskScheduler_; 83 }; 84 } // namespace OHOS::Rosen 85 86 #endif // OHOS_ROSEN_WINDOW_SCENE_EXTENSION_SESSION_MANAGER_H 87