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_MOCK_SESSION_MANAGER_SERVICE_H 17 #define OHOS_ROSEN_MOCK_SESSION_MANAGER_SERVICE_H 18 19 #include <shared_mutex> 20 #include <system_ability.h> 21 22 #include "mock_session_manager_interface_stub.h" 23 #include "wm_single_instance.h" 24 #include "zidl/session_manager_service_recover_interface.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 class MockSessionManagerService : public SystemAbility, public MockSessionManagerInterfaceStub { 29 DECLARE_SYSTEM_ABILITY(MockSessionManagerService); 30 WM_DECLARE_SINGLE_INSTANCE_BASE(MockSessionManagerService); 31 public: 32 ErrCode GetScreenSessionManagerLite(sptr<IRemoteObject>& screenSessionManagerLite) override; 33 sptr<IRemoteObject> GetSceneSessionManager(); 34 void OnStart() override; 35 int Dump(int fd, const std::vector<std::u16string>& args) override; 36 void GetProcessSurfaceNodeIdByPersistentId(const int32_t pid, 37 const std::vector<uint64_t>& windowIdList, std::vector<uint64_t>& surfaceNodeIds); 38 void AddSkipSelfWhenShowOnVirtualScreenList(const std::vector<int32_t>& persistentIds); 39 void RemoveSkipSelfWhenShowOnVirtualScreenList(const std::vector<int32_t>& persistentIds); 40 void SetScreenPrivacyWindowTagSwitch( 41 uint64_t screenId, const std::vector<std::string>& privacyWindowTags, bool enable); 42 43 /* 44 * Multi User 45 */ 46 bool SetSessionManagerService(const sptr<IRemoteObject>& sessionManagerService); 47 ErrCode GetSessionManagerService(sptr<IRemoteObject>& sessionManagerService) override; 48 void NotifyWMSConnected(int32_t userId, int32_t screenId, bool isColdStart); NotifyNotKillService()49 void NotifyNotKillService() {} 50 51 /* 52 * Window Recover 53 */ 54 ErrCode NotifySceneBoardAvailable() override; 55 ErrCode RegisterSMSRecoverListener(const sptr<IRemoteObject>& listener) override; 56 ErrCode UnregisterSMSRecoverListener() override; 57 void UnregisterSMSRecoverListener(int32_t userId, int32_t pid); 58 ErrCode RegisterSMSLiteRecoverListener(const sptr<IRemoteObject>& listener) override; 59 ErrCode UnregisterSMSLiteRecoverListener() override; 60 void UnregisterSMSLiteRecoverListener(int32_t userId, int32_t pid); 61 62 /* 63 * Window Snapshot 64 */ 65 ErrCode SetSnapshotSkipByUserIdAndBundleNames(int32_t userId, 66 const std::vector<std::string>& bundleNameList) override; 67 ErrCode SetSnapshotSkipByIdNamesMap(const std::unordered_map<int32_t, 68 std::vector<std::string>>& userIdAndBunldeNames) override; 69 70 protected: 71 MockSessionManagerService(); 72 virtual ~MockSessionManagerService() = default; 73 74 private: 75 /* 76 * Multi User 77 */ 78 class SMSDeathRecipient : public IRemoteObject::DeathRecipient { 79 public: 80 explicit SMSDeathRecipient(int32_t userId); 81 void OnRemoteDied(const wptr<IRemoteObject>& object) override; 82 bool IsSceneBoardTestMode(); 83 void SetScreenId(int32_t screenId); 84 bool needKillService_ { true }; 85 86 private: 87 int32_t userId_; 88 int32_t screenId_; 89 }; 90 sptr<SMSDeathRecipient> GetSMSDeathRecipientByUserId(int32_t userId); 91 void RemoveSMSDeathRecipientByUserId(int32_t userId); 92 sptr<IRemoteObject> GetSessionManagerServiceByUserId(int32_t userId); 93 void RemoveSessionManagerServiceByUserId(int32_t userId); 94 bool RegisterMockSessionManagerService(); 95 std::map<int32_t, sptr<ISessionManagerServiceRecoverListener>>* GetSMSRecoverListenerMap(int32_t userId); 96 std::map<int32_t, sptr<ISessionManagerServiceRecoverListener>>* GetSMSLiteRecoverListenerMap(int32_t userId); 97 void NotifySceneBoardAvailableToClient(int32_t userId); 98 void NotifySceneBoardAvailableToLiteClient(int32_t userId); 99 void NotifyWMSConnectionChanged(int32_t wmsUserId, int32_t screenId, bool isConnected); 100 void NotifyWMSConnectionChangedToClient(int32_t wmsUserId, int32_t screenId, bool isConnected); 101 void NotifyWMSConnectionChangedToLiteClient(int32_t wmsUserId, int32_t screenId, bool isConnected); 102 103 int DumpSessionInfo(const std::vector<std::string>& args, std::string& dumpInfo); 104 void ShowHelpInfo(std::string& dumpInfo); 105 void ShowAceDumpHelp(std::string& dumpInfo); 106 void ShowIllegalArgsInfo(std::string& dumpInfo); 107 108 /* 109 * Window Snapshot 110 */ 111 virtual sptr<IRemoteObject> GetSceneSessionManagerByUserId(int32_t userId); 112 ErrCode RecoverSCBSnapshotSkipByUserId(int32_t userId); 113 virtual ErrCode NotifySCBSnapshotSkipByUserIdAndBundleNames(int32_t userId, 114 const std::vector<std::string>& bundleNameList, const sptr<IRemoteObject>& remoteObject); 115 ErrCode SetSnapshotSkipByUserIdAndBundleNamesInner(int32_t userId, 116 const std::vector<std::string>& bundleNameList); 117 ErrCode SetSnapshotSkipByIdNamesMapInner(const std::unordered_map<int32_t, 118 std::vector<std::string>>& userIdAndBunldeNames); 119 120 sptr<IRemoteObject> screenSessionManager_; 121 sptr<IRemoteObject> sceneSessionManager_; 122 123 /* 124 * Multi User 125 */ 126 int32_t currentWMSUserId_; 127 int32_t currentScreenId_; 128 std::shared_mutex smsDeathRecipientMapLock_; 129 std::map<int32_t, sptr<SMSDeathRecipient>> smsDeathRecipientMap_; 130 std::shared_mutex sessionManagerServiceMapLock_; 131 std::map<int32_t, sptr<IRemoteObject>> sessionManagerServiceMap_; 132 std::mutex wmsConnectionStatusLock_; 133 std::map<int32_t, bool> wmsConnectionStatusMap_; 134 135 /* 136 * Window Recover 137 */ 138 std::shared_mutex smsRecoverListenerLock_; 139 std::map<int32_t, std::map<int32_t, sptr<ISessionManagerServiceRecoverListener>>> smsRecoverListenerMap_; 140 std::shared_mutex smsLiteRecoverListenerLock_; 141 std::map<int32_t, std::map<int32_t, sptr<ISessionManagerServiceRecoverListener>>> smsLiteRecoverListenerMap_; 142 143 /* 144 * Window Snapshot 145 */ 146 std::mutex userIdBundleNamesMapLock_; 147 std::unordered_map<int32_t, std::vector<std::string>> userIdBundleNamesMap_; 148 }; 149 } // namespace Rosen 150 } // namespace OHOS 151 152 #endif // OHOS_ROSEN_MOCK_SESSION_MANAGER_SERVICE_H 153