mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-30 18:41:47 +00:00
commit
0bbf0ce227
@ -75,7 +75,6 @@ private:
|
||||
sptr<IRemoteObject> smsRecoverListener_ = nullptr;
|
||||
sptr<SSMDeathRecipient> ssmDeath_ = nullptr;
|
||||
sptr<FoundationDeathRecipient> foundationDeath_ = nullptr;
|
||||
bool destroyed_ = false;
|
||||
bool isFoundationListenerRegistered_ = false;
|
||||
// above guarded by mutex_
|
||||
|
||||
|
@ -85,7 +85,6 @@ private:
|
||||
sptr<IRemoteObject> smsRecoverListener_ = nullptr;
|
||||
sptr<FoundationDeathRecipientLite> foundationDeath_ = nullptr;
|
||||
bool recoverListenerRegistered_ = false;
|
||||
bool destroyed_ = false;
|
||||
bool isFoundationListenerRegistered_ = false;
|
||||
// above guarded by mutex_
|
||||
|
||||
|
@ -86,15 +86,7 @@ WM_IMPLEMENT_SINGLE_INSTANCE(SessionManager)
|
||||
|
||||
SessionManager::~SessionManager()
|
||||
{
|
||||
WLOGFI("SessionManager destroy!");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
destroyed_ = true;
|
||||
if (mockSessionManagerServiceProxy_ != nullptr) {
|
||||
std::string identity = IPCSkeleton::ResetCallingIdentity();
|
||||
mockSessionManagerServiceProxy_->UnregisterSMSRecoverListener();
|
||||
IPCSkeleton::SetCallingIdentity(identity);
|
||||
mockSessionManagerServiceProxy_ = nullptr;
|
||||
}
|
||||
WLOGFI("destroyed!");
|
||||
}
|
||||
|
||||
void SessionManager::OnWMSConnectionChangedCallback(
|
||||
@ -140,16 +132,11 @@ void SessionManager::OnWMSConnectionChanged(
|
||||
|
||||
void SessionManager::ClearSessionManagerProxy()
|
||||
{
|
||||
WLOGFI("ClearSessionManagerProxy enter!");
|
||||
WLOGFI("enter!");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (destroyed_) {
|
||||
WLOGFE("Already destroyed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sessionManagerServiceProxy_ != nullptr) {
|
||||
int refCount = sessionManagerServiceProxy_->GetSptrRefCount();
|
||||
WLOGFI("sessionManagerServiceProxy_ GetSptrRefCount : %{public}d", refCount);
|
||||
WLOGFI("sessionManagerServiceProxy GetSptrRefCount : %{public}d", refCount);
|
||||
sessionManagerServiceProxy_ = nullptr;
|
||||
}
|
||||
sceneSessionManagerProxy_ = nullptr;
|
||||
@ -177,7 +164,7 @@ void SessionManager::InitSessionManagerServiceProxy()
|
||||
|
||||
sessionManagerServiceProxy_ = SessionManagerLite::GetInstance().GetSessionManagerServiceProxy();
|
||||
if (!sessionManagerServiceProxy_) {
|
||||
WLOGFE("sessionManagerServiceProxy_ is nullptr");
|
||||
WLOGFE("sessionManagerServiceProxy is nullptr");
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,7 +192,7 @@ WMError SessionManager::InitMockSMSProxy()
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
if (!foundationDeath_) {
|
||||
foundationDeath_ = new (std::nothrow) FoundationDeathRecipient();
|
||||
foundationDeath_ = new FoundationDeathRecipient();
|
||||
if (!foundationDeath_) {
|
||||
WLOGFE("Failed to create death Recipient ptr FoundationDeathRecipient");
|
||||
return WMError::WM_ERROR_NO_MEM;
|
||||
@ -225,18 +212,18 @@ __attribute__((no_sanitize("cfi"))) void SessionManager::InitSceneSessionManager
|
||||
return;
|
||||
}
|
||||
if (!sessionManagerServiceProxy_) {
|
||||
WLOGFE("sessionManagerServiceProxy_ is nullptr");
|
||||
WLOGFE("sessionManagerServiceProxy is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject = sessionManagerServiceProxy_->GetSceneSessionManager();
|
||||
if (!remoteObject) {
|
||||
WLOGFW("Get scene session manager proxy failed, scene session manager service is null");
|
||||
WLOGFW("Get scene session manager proxy failed, null");
|
||||
return;
|
||||
}
|
||||
sceneSessionManagerProxy_ = iface_cast<ISceneSessionManager>(remoteObject);
|
||||
if (sceneSessionManagerProxy_) {
|
||||
ssmDeath_ = new (std::nothrow) SSMDeathRecipient();
|
||||
ssmDeath_ = new SSMDeathRecipient();
|
||||
if (!ssmDeath_) {
|
||||
WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient");
|
||||
return;
|
||||
@ -245,9 +232,8 @@ __attribute__((no_sanitize("cfi"))) void SessionManager::InitSceneSessionManager
|
||||
WLOGFE("Failed to add death recipient");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!sceneSessionManagerProxy_) {
|
||||
WLOGFW("Get scene session manager proxy failed, nullptr");
|
||||
} else {
|
||||
WLOGFW("Get scene session manager proxy failed, iface_cast null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,7 +241,7 @@ void SessionManager::RegisterSMSRecoverListener()
|
||||
{
|
||||
if (!isRecoverListenerRegistered_) {
|
||||
if (!mockSessionManagerServiceProxy_) {
|
||||
TLOGE(WmsLogTag::WMS_RECOVER, "mockSessionManagerServiceProxy_ is null");
|
||||
TLOGE(WmsLogTag::WMS_RECOVER, "mockSessionManagerServiceProxy is null");
|
||||
return;
|
||||
}
|
||||
isRecoverListenerRegistered_ = true;
|
||||
@ -300,12 +286,12 @@ void SessionManager::OnUserSwitch(const sptr<ISessionManagerService> &sessionMan
|
||||
sessionManagerServiceProxy_ = sessionManagerService;
|
||||
InitSceneSessionManagerProxy();
|
||||
if (!sceneSessionManagerProxy_) {
|
||||
TLOGE(WmsLogTag::WMS_MULTI_USER, "sceneSessionManagerProxy_ is null");
|
||||
TLOGE(WmsLogTag::WMS_MULTI_USER, "sceneSessionManagerProxy is null");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (userSwitchCallbackFunc_) {
|
||||
TLOGI(WmsLogTag::WMS_MULTI_USER, "User switch callback.");
|
||||
TLOGI(WmsLogTag::WMS_MULTI_USER, "User switch callback");
|
||||
userSwitchCallbackFunc_();
|
||||
}
|
||||
}
|
||||
@ -350,7 +336,7 @@ WMError SessionManager::RegisterWMSConnectionChangedListener(const WMSConnection
|
||||
|
||||
void SessionManager::RegisterUserSwitchListener(const UserSwitchCallbackFunc& callbackFunc)
|
||||
{
|
||||
TLOGI(WmsLogTag::WMS_MULTI_USER, "Register user switch listener enter");
|
||||
TLOGI(WmsLogTag::WMS_MULTI_USER, "enter");
|
||||
userSwitchCallbackFunc_ = callbackFunc;
|
||||
}
|
||||
|
||||
@ -368,32 +354,12 @@ void SessionManager::OnFoundationDied()
|
||||
|
||||
void FoundationDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
|
||||
{
|
||||
if (wptrDeath == nullptr) {
|
||||
WLOGFE("FoundationDeathRecipient wptrDeath is null");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> object = wptrDeath.promote();
|
||||
if (!object) {
|
||||
WLOGFE("FoundationDeathRecipient object is null");
|
||||
return;
|
||||
}
|
||||
TLOGI(WmsLogTag::WMS_RECOVER, "Foundation died");
|
||||
SessionManager::GetInstance().OnFoundationDied();
|
||||
}
|
||||
|
||||
void SSMDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
|
||||
{
|
||||
if (wptrDeath == nullptr) {
|
||||
WLOGFE("SSMDeathRecipient wptrDeath is null");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> object = wptrDeath.promote();
|
||||
if (!object) {
|
||||
WLOGFE("SSMDeathRecipient object is null");
|
||||
return;
|
||||
}
|
||||
WLOGI("ssm OnRemoteDied");
|
||||
SessionManager::GetInstance().Clear();
|
||||
SessionManager::GetInstance().ClearSessionManagerProxy();
|
||||
|
@ -112,21 +112,13 @@ WM_IMPLEMENT_SINGLE_INSTANCE(SessionManagerLite)
|
||||
|
||||
SessionManagerLite::~SessionManagerLite()
|
||||
{
|
||||
TLOGI(WmsLogTag::WMS_LIFE, "destroy");
|
||||
DeleteAllSessionListeners();
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
destroyed_ = true;
|
||||
TLOGI(WmsLogTag::WMS_LIFE, "destroyed");
|
||||
}
|
||||
|
||||
void SessionManagerLite::ClearSessionManagerProxy()
|
||||
{
|
||||
WLOGFD("ClearSessionManagerProxy enter");
|
||||
WLOGFI("enter");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (destroyed_) {
|
||||
WLOGFI("Already destroyed");
|
||||
return;
|
||||
}
|
||||
|
||||
sessionManagerServiceProxy_ = nullptr;
|
||||
sceneSessionManagerLiteProxy_ = nullptr;
|
||||
screenSessionManagerLiteProxy_ = nullptr;
|
||||
@ -205,11 +197,11 @@ void SessionManagerLite::RecoverSessionManagerService(const sptr<ISessionManager
|
||||
void SessionManagerLite::ReregisterSessionListener() const
|
||||
{
|
||||
if (sceneSessionManagerLiteProxy_ == nullptr) {
|
||||
TLOGE(WmsLogTag::WMS_RECOVER, "sceneSessionManagerLiteProxy_ is null");
|
||||
TLOGE(WmsLogTag::WMS_RECOVER, "sceneSessionManagerLiteProxy is null");
|
||||
return;
|
||||
}
|
||||
|
||||
TLOGI(WmsLogTag::WMS_RECOVER, "RecoverSessionListeners, listener count = %{public}" PRIu64,
|
||||
TLOGI(WmsLogTag::WMS_RECOVER, "listener count = %{public}" PRIu64,
|
||||
static_cast<int64_t>(sessionListeners_.size()));
|
||||
for (const auto& listener : sessionListeners_) {
|
||||
auto ret = sceneSessionManagerLiteProxy_->RegisterSessionListener(listener);
|
||||
@ -221,7 +213,7 @@ void SessionManagerLite::ReregisterSessionListener() const
|
||||
|
||||
void SessionManagerLite::RegisterUserSwitchListener(const UserSwitchCallbackFunc& callbackFunc)
|
||||
{
|
||||
TLOGI(WmsLogTag::WMS_MULTI_USER, "Register user switch listener enter");
|
||||
TLOGI(WmsLogTag::WMS_MULTI_USER, "enter");
|
||||
userSwitchCallbackFunc_ = callbackFunc;
|
||||
}
|
||||
|
||||
@ -263,7 +255,7 @@ void SessionManagerLite::OnUserSwitch(const sptr<ISessionManagerService> &sessio
|
||||
sceneSessionManagerLiteProxy_ = nullptr;
|
||||
InitSceneSessionManagerLiteProxy();
|
||||
if (!sceneSessionManagerLiteProxy_) {
|
||||
TLOGE(WmsLogTag::WMS_MULTI_USER, "sceneSessionManagerLiteProxy_ is null");
|
||||
TLOGE(WmsLogTag::WMS_MULTI_USER, "sceneSessionManagerLiteProxy is null");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -285,14 +277,14 @@ void SessionManagerLite::InitSessionManagerServiceProxy()
|
||||
return;
|
||||
}
|
||||
RegisterSMSRecoverListener();
|
||||
sptr<IRemoteObject> remoteObject2 = mockSessionManagerServiceProxy_->GetSessionManagerService();
|
||||
if (!remoteObject2) {
|
||||
WLOGFE("Remote object2 is nullptr");
|
||||
sptr<IRemoteObject> remoteObject = mockSessionManagerServiceProxy_->GetSessionManagerService();
|
||||
if (!remoteObject) {
|
||||
WLOGFE("Remote object is nullptr");
|
||||
return;
|
||||
}
|
||||
sessionManagerServiceProxy_ = iface_cast<ISessionManagerService>(remoteObject2);
|
||||
sessionManagerServiceProxy_ = iface_cast<ISessionManagerService>(remoteObject);
|
||||
if (!sessionManagerServiceProxy_) {
|
||||
WLOGFE("sessionManagerServiceProxy_ is nullptr");
|
||||
WLOGFE("sessionManagerServiceProxy is nullptr");
|
||||
}
|
||||
}
|
||||
|
||||
@ -302,18 +294,18 @@ void SessionManagerLite::InitScreenSessionManagerLiteProxy()
|
||||
return;
|
||||
}
|
||||
if (!mockSessionManagerServiceProxy_) {
|
||||
WLOGFE("mockSessionManagerServiceProxy_ is nullptr");
|
||||
WLOGFE("mockSessionManagerServiceProxy is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject = mockSessionManagerServiceProxy_->GetScreenSessionManagerLite();
|
||||
if (!remoteObject) {
|
||||
WLOGFW("Get screen session manager lite proxy failed, scene session manager service is null");
|
||||
WLOGFW("Get screen session manager lite proxy failed, null");
|
||||
return;
|
||||
}
|
||||
screenSessionManagerLiteProxy_ = iface_cast<IScreenSessionManagerLite>(remoteObject);
|
||||
if (!screenSessionManagerLiteProxy_) {
|
||||
WLOGFW("Get screen session manager lite proxy failed, nullptr");
|
||||
WLOGFW("Get screen session manager lite proxy failed, iface_cast null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,18 +315,18 @@ void SessionManagerLite::InitSceneSessionManagerLiteProxy()
|
||||
return;
|
||||
}
|
||||
if (!sessionManagerServiceProxy_) {
|
||||
WLOGFE("sessionManagerServiceProxy_ is nullptr");
|
||||
WLOGFE("sessionManagerServiceProxy is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject = sessionManagerServiceProxy_->GetSceneSessionManagerLite();
|
||||
if (!remoteObject) {
|
||||
WLOGFW("Get scene session manager proxy failed, scene session manager service is null");
|
||||
WLOGFW("Get scene session manager proxy failed, null");
|
||||
return;
|
||||
}
|
||||
sceneSessionManagerLiteProxy_ = iface_cast<ISceneSessionManagerLite>(remoteObject);
|
||||
if (sceneSessionManagerLiteProxy_) {
|
||||
ssmDeath_ = new (std::nothrow) SSMDeathRecipientLite();
|
||||
ssmDeath_ = new SSMDeathRecipientLite();
|
||||
if (!ssmDeath_) {
|
||||
WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient");
|
||||
return;
|
||||
@ -343,9 +335,8 @@ void SessionManagerLite::InitSceneSessionManagerLiteProxy()
|
||||
WLOGFE("Failed to add death recipient");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!sceneSessionManagerLiteProxy_) {
|
||||
WLOGFW("Get scene session manager proxy failed, nullptr");
|
||||
} else {
|
||||
WLOGFW("Get scene session manager proxy failed, iface_cast null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,16 +350,6 @@ void SessionManagerLite::Clear()
|
||||
|
||||
void SSMDeathRecipientLite::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
|
||||
{
|
||||
if (wptrDeath == nullptr) {
|
||||
WLOGFE("SSMDeathRecipientLite wptrDeath is null");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> object = wptrDeath.promote();
|
||||
if (!object) {
|
||||
WLOGFE("SSMDeathRecipientLite object is null");
|
||||
return;
|
||||
}
|
||||
WLOGI("ssm OnRemoteDied");
|
||||
SessionManagerLite::GetInstance().Clear();
|
||||
SessionManagerLite::GetInstance().ClearSessionManagerProxy();
|
||||
@ -412,7 +393,6 @@ WMError SessionManagerLite::InitMockSMSProxy()
|
||||
TLOGE(WmsLogTag::WMS_MULTI_USER, "Failed to get system ability mgr.");
|
||||
return WMError::WM_ERROR_NULLPTR;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID);
|
||||
if (!remoteObject) {
|
||||
TLOGE(WmsLogTag::WMS_MULTI_USER, "Remote object is nullptr");
|
||||
@ -430,7 +410,7 @@ WMError SessionManagerLite::InitMockSMSProxy()
|
||||
if (!foundationDeath_) {
|
||||
foundationDeath_ = sptr<FoundationDeathRecipientLite>::MakeSptr();
|
||||
if (!foundationDeath_) {
|
||||
TLOGE(WmsLogTag::WMS_MULTI_USER, "Failed to create death Recipient ptr FoundationDeathRecipientLite");
|
||||
TLOGE(WmsLogTag::WMS_MULTI_USER, "Failed to create death Recipient ptr");
|
||||
return WMError::WM_ERROR_NO_MEM;
|
||||
}
|
||||
}
|
||||
@ -446,7 +426,7 @@ void SessionManagerLite::RegisterSMSRecoverListener()
|
||||
{
|
||||
if (!recoverListenerRegistered_) {
|
||||
if (!mockSessionManagerServiceProxy_) {
|
||||
TLOGE(WmsLogTag::WMS_RECOVER, "mockSessionManagerServiceProxy_ is null");
|
||||
TLOGE(WmsLogTag::WMS_RECOVER, "mockSessionManagerServiceProxy is null");
|
||||
return;
|
||||
}
|
||||
recoverListenerRegistered_ = true;
|
||||
@ -473,23 +453,13 @@ void SessionManagerLite::OnWMSConnectionChangedCallback(
|
||||
|
||||
void FoundationDeathRecipientLite::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
|
||||
{
|
||||
if (wptrDeath == nullptr) {
|
||||
TLOGE(WmsLogTag::WMS_RECOVER, "FoundationDeathRecipient wptrDeath is null");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> object = wptrDeath.promote();
|
||||
if (!object) {
|
||||
TLOGE(WmsLogTag::WMS_RECOVER, "FoundationDeathRecipient object is null");
|
||||
return;
|
||||
}
|
||||
TLOGI(WmsLogTag::WMS_RECOVER, "Foundation died");
|
||||
SessionManagerLite::GetInstance().OnFoundationDied();
|
||||
}
|
||||
|
||||
void SessionManagerLite::OnFoundationDied()
|
||||
{
|
||||
TLOGI(WmsLogTag::WMS_RECOVER, "On foundation died enter");
|
||||
TLOGI(WmsLogTag::WMS_RECOVER, "enter");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
isFoundationListenerRegistered_ = false;
|
||||
recoverListenerRegistered_ = false;
|
||||
|
@ -245,7 +245,6 @@ HWTEST_F(SessionManagerLiteTest, OnWMSConnectionChangedCallback, Function | Smal
|
||||
sessionManagerLite.currentWMSUserId_ = SYSTEM_USERID;
|
||||
sessionManagerLite.OnWMSConnectionChanged(userId, screenId, isConnected, nullptr);
|
||||
|
||||
sessionManagerLite.destroyed_ = true;
|
||||
sessionManagerLite.ClearSessionManagerProxy();
|
||||
|
||||
sptr<ISessionManagerService> sessionManagerService;
|
||||
|
@ -102,7 +102,6 @@ HWTEST_F(SessionManagerTest, OnWMSConnectionChangedCallback, Function | SmallTes
|
||||
sessionManager.currentWMSUserId_ = SYSTEM_USERID;
|
||||
sessionManager.OnWMSConnectionChanged(userId, screenId, isConnected, nullptr);
|
||||
|
||||
sessionManager.destroyed_ = true;
|
||||
sessionManager.ClearSessionManagerProxy();
|
||||
|
||||
sptr<ISessionManagerService> sessionManagerService;
|
||||
@ -144,17 +143,14 @@ HWTEST_F(SessionManagerTest, OnWMSConnectionChanged, Function | SmallTest | Leve
|
||||
HWTEST_F(SessionManagerTest, ClearSessionManagerProxy, Function | SmallTest | Level2)
|
||||
{
|
||||
SessionManager sessionManager;
|
||||
|
||||
sessionManager.destroyed_ = true;
|
||||
|
||||
sessionManager.ClearSessionManagerProxy();
|
||||
ASSERT_EQ(sessionManager.sessionManagerServiceProxy_, nullptr);
|
||||
|
||||
sessionManager.destroyed_ = false;
|
||||
sessionManager.sessionManagerServiceProxy_ = nullptr;
|
||||
sessionManager.ClearSessionManagerProxy();
|
||||
ASSERT_EQ(sessionManager.sessionManagerServiceProxy_, nullptr);
|
||||
|
||||
sessionManager.destroyed_ = false;
|
||||
sptr<ISessionManagerService> sessionManagerServiceProxy;
|
||||
sessionManager.sessionManagerServiceProxy_ = sessionManagerServiceProxy;
|
||||
sessionManager.ClearSessionManagerProxy();
|
||||
|
Loading…
Reference in New Issue
Block a user