1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#ifndef OHOS_ROSEN_MOCK_SESSION_MANAGER_SERVICE_H 17e0dac50fSopenharmony_ci#define OHOS_ROSEN_MOCK_SESSION_MANAGER_SERVICE_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#include <shared_mutex> 20e0dac50fSopenharmony_ci#include <system_ability.h> 21e0dac50fSopenharmony_ci 22e0dac50fSopenharmony_ci#include "wm_single_instance.h" 23e0dac50fSopenharmony_ci#include "zidl/mock_session_manager_service_stub.h" 24e0dac50fSopenharmony_ci#include "zidl/session_manager_service_recover_interface.h" 25e0dac50fSopenharmony_ci 26e0dac50fSopenharmony_cinamespace OHOS { 27e0dac50fSopenharmony_cinamespace Rosen { 28e0dac50fSopenharmony_ciclass MockSessionManagerService : public SystemAbility, public MockSessionManagerServiceStub { 29e0dac50fSopenharmony_ciDECLARE_SYSTEM_ABILITY(MockSessionManagerService); 30e0dac50fSopenharmony_ciWM_DECLARE_SINGLE_INSTANCE_BASE(MockSessionManagerService); 31e0dac50fSopenharmony_cipublic: 32e0dac50fSopenharmony_ci bool SetSessionManagerService(const sptr<IRemoteObject>& sessionManagerService); 33e0dac50fSopenharmony_ci void NotifySceneBoardAvailable() override; 34e0dac50fSopenharmony_ci sptr<IRemoteObject> GetSessionManagerService() override; 35e0dac50fSopenharmony_ci sptr<IRemoteObject> GetScreenSessionManagerLite() override; 36e0dac50fSopenharmony_ci sptr<IRemoteObject> GetSceneSessionManager(); 37e0dac50fSopenharmony_ci void RegisterSMSRecoverListener(const sptr<IRemoteObject>& listener) override; 38e0dac50fSopenharmony_ci void UnregisterSMSRecoverListener() override; 39e0dac50fSopenharmony_ci void UnregisterSMSRecoverListener(int32_t userId, int32_t pid); 40e0dac50fSopenharmony_ci void RegisterSMSLiteRecoverListener(const sptr<IRemoteObject>& listener) override; 41e0dac50fSopenharmony_ci void UnregisterSMSLiteRecoverListener() override; 42e0dac50fSopenharmony_ci void UnregisterSMSLiteRecoverListener(int32_t userId, int32_t pid); 43e0dac50fSopenharmony_ci void OnStart() override; 44e0dac50fSopenharmony_ci int Dump(int fd, const std::vector<std::u16string>& args) override; 45e0dac50fSopenharmony_ci void NotifyWMSConnected(int32_t userId, int32_t screenId, bool isColdStart); 46e0dac50fSopenharmony_ci void NotifyNotKillService() {} 47e0dac50fSopenharmony_ci void GetProcessSurfaceNodeIdByPersistentId(const int32_t pid, 48e0dac50fSopenharmony_ci const std::vector<uint64_t>& windowIdList, std::vector<uint64_t>& surfaceNodeIds); 49e0dac50fSopenharmony_ci 50e0dac50fSopenharmony_ci /* 51e0dac50fSopenharmony_ci * Window Snapshot 52e0dac50fSopenharmony_ci */ 53e0dac50fSopenharmony_ci int32_t SetSnapshotSkipByUserIdAndBundleNames(int32_t userId, 54e0dac50fSopenharmony_ci const std::vector<std::string>& bundleNameList) override; 55e0dac50fSopenharmony_ci int32_t SetSnapshotSkipByIdNamesMap(const std::unordered_map<int32_t, 56e0dac50fSopenharmony_ci std::vector<std::string>>& userIdAndBunldeNames) override; 57e0dac50fSopenharmony_ci 58e0dac50fSopenharmony_ciprotected: 59e0dac50fSopenharmony_ci MockSessionManagerService(); 60e0dac50fSopenharmony_ci virtual ~MockSessionManagerService() = default; 61e0dac50fSopenharmony_ci 62e0dac50fSopenharmony_ciprivate: 63e0dac50fSopenharmony_ci class SMSDeathRecipient : public IRemoteObject::DeathRecipient { 64e0dac50fSopenharmony_ci public: 65e0dac50fSopenharmony_ci explicit SMSDeathRecipient(int32_t userId); 66e0dac50fSopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject>& object) override; 67e0dac50fSopenharmony_ci bool IsSceneBoardTestMode(); 68e0dac50fSopenharmony_ci void SetScreenId(int32_t screenId); 69e0dac50fSopenharmony_ci bool needKillService_ { true }; 70e0dac50fSopenharmony_ci 71e0dac50fSopenharmony_ci private: 72e0dac50fSopenharmony_ci int32_t userId_; 73e0dac50fSopenharmony_ci int32_t screenId_; 74e0dac50fSopenharmony_ci }; 75e0dac50fSopenharmony_ci sptr<SMSDeathRecipient> GetSMSDeathRecipientByUserId(int32_t userId); 76e0dac50fSopenharmony_ci void RemoveSMSDeathRecipientByUserId(int32_t userId); 77e0dac50fSopenharmony_ci sptr<IRemoteObject> GetSessionManagerServiceByUserId(int32_t userId); 78e0dac50fSopenharmony_ci void RemoveSessionManagerServiceByUserId(int32_t userId); 79e0dac50fSopenharmony_ci bool RegisterMockSessionManagerService(); 80e0dac50fSopenharmony_ci std::map<int32_t, sptr<ISessionManagerServiceRecoverListener>>* GetSMSRecoverListenerMap(int32_t userId); 81e0dac50fSopenharmony_ci std::map<int32_t, sptr<ISessionManagerServiceRecoverListener>>* GetSMSLiteRecoverListenerMap(int32_t userId); 82e0dac50fSopenharmony_ci void NotifySceneBoardAvailableToClient(int32_t userId); 83e0dac50fSopenharmony_ci void NotifySceneBoardAvailableToLiteClient(int32_t userId); 84e0dac50fSopenharmony_ci void NotifyWMSConnectionChanged(int32_t wmsUserId, int32_t screenId, bool isConnected); 85e0dac50fSopenharmony_ci void NotifyWMSConnectionChangedToClient(int32_t wmsUserId, int32_t screenId, bool isConnected); 86e0dac50fSopenharmony_ci void NotifyWMSConnectionChangedToLiteClient(int32_t wmsUserId, int32_t screenId, bool isConnected); 87e0dac50fSopenharmony_ci int DumpSessionInfo(const std::vector<std::string>& args, std::string& dumpInfo); 88e0dac50fSopenharmony_ci void ShowHelpInfo(std::string& dumpInfo); 89e0dac50fSopenharmony_ci void ShowAceDumpHelp(std::string& dumpInfo); 90e0dac50fSopenharmony_ci void ShowIllegalArgsInfo(std::string& dumpInfo); 91e0dac50fSopenharmony_ci 92e0dac50fSopenharmony_ci /* 93e0dac50fSopenharmony_ci * Window Snapshot 94e0dac50fSopenharmony_ci */ 95e0dac50fSopenharmony_ci sptr<IRemoteObject> GetSceneSessionManagerByUserId(int32_t userId); 96e0dac50fSopenharmony_ci int32_t RecoverSCBSnapshotSkipByUserId(int32_t userId); 97e0dac50fSopenharmony_ci int32_t NotifySCBSnapshotSkipByUserIdAndBundleNames(int32_t userId, 98e0dac50fSopenharmony_ci const std::vector<std::string>& bundleNameList, const sptr<IRemoteObject>& remoteObject); 99e0dac50fSopenharmony_ci 100e0dac50fSopenharmony_ci static void WriteStringToFile(int32_t pid, const char* str); 101e0dac50fSopenharmony_ci 102e0dac50fSopenharmony_ci sptr<IRemoteObject> screenSessionManager_; 103e0dac50fSopenharmony_ci sptr<IRemoteObject> sceneSessionManager_; 104e0dac50fSopenharmony_ci 105e0dac50fSopenharmony_ci std::shared_mutex smsDeathRecipientMapLock_; 106e0dac50fSopenharmony_ci std::map<int32_t, sptr<SMSDeathRecipient>> smsDeathRecipientMap_; 107e0dac50fSopenharmony_ci 108e0dac50fSopenharmony_ci std::shared_mutex sessionManagerServiceMapLock_; 109e0dac50fSopenharmony_ci std::map<int32_t, sptr<IRemoteObject>> sessionManagerServiceMap_; 110e0dac50fSopenharmony_ci 111e0dac50fSopenharmony_ci std::shared_mutex smsRecoverListenerLock_; 112e0dac50fSopenharmony_ci std::map<int32_t, std::map<int32_t, sptr<ISessionManagerServiceRecoverListener>>> smsRecoverListenerMap_; 113e0dac50fSopenharmony_ci 114e0dac50fSopenharmony_ci std::shared_mutex smsLiteRecoverListenerLock_; 115e0dac50fSopenharmony_ci std::map<int32_t, std::map<int32_t, sptr<ISessionManagerServiceRecoverListener>>> smsLiteRecoverListenerMap_; 116e0dac50fSopenharmony_ci 117e0dac50fSopenharmony_ci std::mutex wmsConnectionStatusLock_; 118e0dac50fSopenharmony_ci std::map<int32_t, bool> wmsConnectionStatusMap_; 119e0dac50fSopenharmony_ci 120e0dac50fSopenharmony_ci /* 121e0dac50fSopenharmony_ci * Window Snapshot 122e0dac50fSopenharmony_ci */ 123e0dac50fSopenharmony_ci std::mutex userIdBundleNamesMapLock_; 124e0dac50fSopenharmony_ci std::unordered_map<int32_t, std::vector<std::string>> userIdBundleNamesMap_; 125e0dac50fSopenharmony_ci 126e0dac50fSopenharmony_ci int32_t currentWMSUserId_; 127e0dac50fSopenharmony_ci int32_t currentScreenId_; 128e0dac50fSopenharmony_ci}; 129e0dac50fSopenharmony_ci} // namespace Rosen 130e0dac50fSopenharmony_ci} // namespace OHOS 131e0dac50fSopenharmony_ci 132e0dac50fSopenharmony_ci#endif // OHOS_ROSEN_MOCK_SESSION_MANAGER_SERVICE_H 133