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