隐私空间退出删除场景bugfix

Signed-off-by: chenyunjiu <chenyunjiu1@huawei.com>
This commit is contained in:
cloud_nine 2024-07-16 10:56:04 +08:00
parent fe90e85669
commit 90e66a1d5d
4 changed files with 97 additions and 59 deletions

View File

@ -39,6 +39,7 @@ public:
void ExcuteDumpCmd(); void ExcuteDumpCmd();
void DumpEventTracker(EventTracker& tracker); void DumpEventTracker(EventTracker& tracker);
void DumpFreezedPidList(std::set<int32_t> pidList); void DumpFreezedPidList(std::set<int32_t> pidList);
void DumpMultiUserInfo(std::vector<int32_t> oldScbPids, int32_t userId, int32_t ScbPid);
private: private:
void ShowHelpInfo(); void ShowHelpInfo();

View File

@ -294,7 +294,8 @@ private:
void AddVirtualScreenDeathRecipient(const sptr<IRemoteObject>& displayManagerAgent, ScreenId smsScreenId); void AddVirtualScreenDeathRecipient(const sptr<IRemoteObject>& displayManagerAgent, ScreenId smsScreenId);
void PublishCastEvent(const bool &isPlugIn); void PublishCastEvent(const bool &isPlugIn);
void HandleScreenEvent(sptr<ScreenSession> screenSession, ScreenId screenId, ScreenEvent screenEvent); void HandleScreenEvent(sptr<ScreenSession> screenSession, ScreenId screenId, ScreenEvent screenEvent);
void ScbStatusRecoveryWhenSwitchUser(int32_t newScbPid); void ScbStatusRecoveryWhenSwitchUser(std::vector<int32_t> oldScbPids, int32_t newScbPid);
void SwitchScbNodeHandle(int32_t userId, int32_t newScbPid, bool coldBoot);
void SetClientInner(); void SetClientInner();
void GetCurrentScreenPhyBounds(float& phyWidth, float& phyHeight, bool& isReset, const ScreenId& screenid); void GetCurrentScreenPhyBounds(float& phyWidth, float& phyHeight, bool& isReset, const ScreenId& screenid);
@ -353,11 +354,11 @@ private:
std::shared_ptr<TaskScheduler> taskScheduler_; std::shared_ptr<TaskScheduler> taskScheduler_;
std::shared_ptr<TaskScheduler> screenPowerTaskScheduler_; std::shared_ptr<TaskScheduler> screenPowerTaskScheduler_;
std::mutex oldScbPidsMutex_;
std::condition_variable scbSwitchCV_;
int32_t currentUserId_ { 0 }; int32_t currentUserId_ { 0 };
int32_t currentScbPId_ { -1 }; int32_t currentScbPId_ { -1 };
std::mutex oldScbPidsMutex_;
std::vector<int32_t> oldScbPids_ {}; std::vector<int32_t> oldScbPids_ {};
mutable std::mutex currentUserIdMutex_;
std::map<int32_t, sptr<IScreenSessionManagerClient>> clientProxyMap_; std::map<int32_t, sptr<IScreenSessionManagerClient>> clientProxyMap_;
sptr<IScreenSessionManagerClient> clientProxy_; sptr<IScreenSessionManagerClient> clientProxy_;

View File

@ -114,6 +114,20 @@ void ScreenSessionDumper::DumpEventTracker(EventTracker& tracker)
dumpInfo_.append(oss.str()); dumpInfo_.append(oss.str());
} }
void ScreenSessionDumper::DumpMultiUserInfo(std::vector<int32_t> oldScbPids, int32_t userId, int32_t ScbPid)
{
std::ostringstream oss;
oss << "-------------- DMS Multi User Info --------------" << std::endl;
oss << std::left << "[oldScbPid:] ";
for (auto oldScbPid : oldScbPids) {
oss << oldScbPid << " ";
}
oss << std::endl;
oss << std::left << "[userId:] " << userId << std::endl;
oss << std::left << "[ScbPid:] " << ScbPid << std::endl;
dumpInfo_.append(oss.str());
}
void ScreenSessionDumper::DumpFreezedPidList(std::set<int32_t> pidList) void ScreenSessionDumper::DumpFreezedPidList(std::set<int32_t> pidList)
{ {
std::ostringstream oss; std::ostringstream oss;

View File

@ -67,6 +67,7 @@ const int32_t SLEEP_10_MS = 10 * 1000; // 10ms
const int32_t CV_WAIT_SCREENON_MS = 300; const int32_t CV_WAIT_SCREENON_MS = 300;
const int32_t CV_WAIT_SCREENOFF_MS = 1500; const int32_t CV_WAIT_SCREENOFF_MS = 1500;
const int32_t CV_WAIT_SCREENOFF_MS_MAX = 3000; const int32_t CV_WAIT_SCREENOFF_MS_MAX = 3000;
const int32_t CV_WAIT_SCBSWITCH_MS = 3000;
const std::u16string DEFAULT_USTRING = u"error"; const std::u16string DEFAULT_USTRING = u"error";
const std::string DEFAULT_STRING = "error"; const std::string DEFAULT_STRING = "error";
const std::string ARG_DUMP_HELP = "-h"; const std::string ARG_DUMP_HELP = "-h";
@ -88,6 +89,7 @@ const ScreenId SCREEN_ID_PC_MAIN = 9;
const std::vector<std::string> displayModeCommands = {"-f", "-m", "-sub", "-coor"}; const std::vector<std::string> displayModeCommands = {"-f", "-m", "-sub", "-coor"};
constexpr int32_t INVALID_UID = -1; constexpr int32_t INVALID_UID = -1;
constexpr int32_t INVALID_USER_ID = -1; constexpr int32_t INVALID_USER_ID = -1;
constexpr int32_t INVALID_SCB_PID = -1;
constexpr int32_t BASE_USER_RANGE = 200000; constexpr int32_t BASE_USER_RANGE = 200000;
static bool g_foldScreenFlag = system::GetParameter("const.window.foldscreen.type", "") != ""; static bool g_foldScreenFlag = system::GetParameter("const.window.foldscreen.type", "") != "";
static const int32_t g_screenRotationOffSet = system::GetIntParameter<int32_t>("const.fold.screen_rotation.offset", 0); static const int32_t g_screenRotationOffSet = system::GetIntParameter<int32_t>("const.fold.screen_rotation.offset", 0);
@ -4254,11 +4256,20 @@ void ScreenSessionManager::NotifyClientProxyUpdateFoldDisplayMode(FoldDisplayMod
void ScreenSessionManager::ScbClientDeathCallback(int32_t deathScbPid) void ScreenSessionManager::ScbClientDeathCallback(int32_t deathScbPid)
{ {
std::lock_guard<std::mutex> lock(oldScbPidsMutex_); std::unique_lock<std::mutex> lock(oldScbPidsMutex_);
if (oldScbPids_.empty()) { if (deathScbPid == currentScbPId_ || currentScbPId_ == INVALID_SCB_PID) {
return; clientProxy_ = nullptr;
TLOGE(WmsLogTag::DMS, "death callback, clientProxy is set null");
} }
TLOGI(WmsLogTag::DMS, "old scb: %{public}d death", deathScbPid); if (scbSwitchCV_.wait_for(lock, std::chrono::milliseconds(CV_WAIT_SCBSWITCH_MS))
== std::cv_status::timeout) {
TLOGE(WmsLogTag::DMS, "set client task deathScbPid:%{public}d, timeout: %{public}d",
deathScbPid, CV_WAIT_SCBSWITCH_MS);
}
std::ostringstream oss;
oss << "Scb client death: " << deathScbPid;
TLOGI(WmsLogTag::DMS, "%{public}s", oss.str().c_str());
screenEventTracker_.RecordEvent(oss.str());
oldScbPids_.erase(std::remove(oldScbPids_.begin(), oldScbPids_.end(), deathScbPid), oldScbPids_.end()); oldScbPids_.erase(std::remove(oldScbPids_.begin(), oldScbPids_.end(), deathScbPid), oldScbPids_.end());
} }
@ -4287,35 +4298,11 @@ void ScreenSessionManager::SwitchUser()
} }
auto userId = GetUserIdByCallingUid(); auto userId = GetUserIdByCallingUid();
auto newScbPid = IPCSkeleton::GetCallingPid(); auto newScbPid = IPCSkeleton::GetCallingPid();
TLOGI(WmsLogTag::DMS, "switch userId:%{public}d, currentId:%{public}d", userId, currentUserId_); SwitchScbNodeHandle(userId, newScbPid, false);
{ MockSessionManagerService::GetInstance().NotifyWMSConnected(newScbPid, GetDefaultScreenId(), false);
std::lock_guard<std::mutex> lock(currentUserIdMutex_);
if (userId == currentUserId_) {
TLOGI(WmsLogTag::DMS, "switch user not change");
return;
}
std::lock_guard<std::mutex> lockScb(oldScbPidsMutex_);
if (clientProxy_) {
auto pidIter = std::find(oldScbPids_.begin(), oldScbPids_.end(), currentScbPId_);
if (pidIter == oldScbPids_.end() && currentScbPId_ > 0) {
oldScbPids_.emplace_back(currentScbPId_);
}
oldScbPids_.erase(std::remove(oldScbPids_.begin(), oldScbPids_.end(), newScbPid), oldScbPids_.end());
}
currentUserId_ = userId;
currentScbPId_ = newScbPid;
auto it = clientProxyMap_.find(currentUserId_);
if (it != clientProxyMap_.end()) {
clientProxy_ = it->second;
}
if (clientProxy_) {
ScbStatusRecoveryWhenSwitchUser(newScbPid);
}
}
MockSessionManagerService::GetInstance().NotifyWMSConnected(currentUserId_, GetDefaultScreenId(), false);
} }
void ScreenSessionManager::ScbStatusRecoveryWhenSwitchUser(int32_t newScbPid) void ScreenSessionManager::ScbStatusRecoveryWhenSwitchUser(std::vector<int32_t> oldScbPids, int32_t newScbPid)
{ {
NotifyFoldStatusChanged(GetFoldStatus()); NotifyFoldStatusChanged(GetFoldStatus());
NotifyDisplayModeChanged(GetFoldDisplayMode()); NotifyDisplayModeChanged(GetFoldDisplayMode());
@ -4341,12 +4328,7 @@ void ScreenSessionManager::ScbStatusRecoveryWhenSwitchUser(int32_t newScbPid)
} else { } else {
screenSession->UpdateRotationAfterBoot(true); screenSession->UpdateRotationAfterBoot(true);
} }
if (oldScbPids_.size() == 0) { auto delayTask = [this, oldScbPids, newScbPid] {
screenEventTracker_.RecordEvent("swicth user failed, oldScbPids is null");
TLOGE(WmsLogTag::DMS, "swicth user failed, oldScbPids is null");
return;
}
auto delayTask = [this, oldScbPids = oldScbPids_, newScbPid] {
if (!clientProxy_) { if (!clientProxy_) {
TLOGE(WmsLogTag::DMS, "clientProxy is null"); TLOGE(WmsLogTag::DMS, "clientProxy is null");
return; return;
@ -4360,8 +4342,7 @@ void ScreenSessionManager::ScbStatusRecoveryWhenSwitchUser(int32_t newScbPid)
void ScreenSessionManager::SetClient(const sptr<IScreenSessionManagerClient>& client) void ScreenSessionManager::SetClient(const sptr<IScreenSessionManagerClient>& client)
{ {
if (!SessionPermission::IsSystemCalling()) { if (!SessionPermission::IsSystemCalling()) {
TLOGE(WmsLogTag::DMS, "permission denied"); TLOGE(WmsLogTag::DMS, "permission denied, calling clientName: %{public}s, calling pid: %{public}d",
TLOGE(WmsLogTag::DMS, "calling clientName: %{public}s, calling pid: %{public}d",
SysCapUtil::GetClientName().c_str(), IPCSkeleton::GetCallingPid()); SysCapUtil::GetClientName().c_str(), IPCSkeleton::GetCallingPid());
return; return;
} }
@ -4369,33 +4350,69 @@ void ScreenSessionManager::SetClient(const sptr<IScreenSessionManagerClient>& cl
TLOGE(WmsLogTag::DMS, "SetClient client is null"); TLOGE(WmsLogTag::DMS, "SetClient client is null");
return; return;
} }
clientProxy_ = client;
auto userId = GetUserIdByCallingUid(); auto userId = GetUserIdByCallingUid();
auto newScbPid = IPCSkeleton::GetCallingPid(); auto newScbPid = IPCSkeleton::GetCallingPid();
MockSessionManagerService::GetInstance().NotifyWMSConnected(userId, GetDefaultScreenId(), true);
NotifyClientProxyUpdateFoldDisplayMode(GetFoldDisplayMode());
SetClientInner();
SwitchScbNodeHandle(userId, newScbPid, true);
AddScbClientDeathRecipient(client, newScbPid);
std::ostringstream oss; std::ostringstream oss;
oss << "set client userId: " << userId oss << "set client userId: " << userId
<< " clientName: " << SysCapUtil::GetClientName(); << " clientName: " << SysCapUtil::GetClientName();
TLOGI(WmsLogTag::DMS, "%{public}s", oss.str().c_str()); TLOGI(WmsLogTag::DMS, "%{public}s", oss.str().c_str());
screenEventTracker_.RecordEvent(oss.str()); screenEventTracker_.RecordEvent(oss.str());
{ }
std::lock_guard<std::mutex> lock(currentUserIdMutex_);
if (clientProxy_ != nullptr && userId != currentUserId_ && currentUserId_ > 0) { void ScreenSessionManager::SwitchScbNodeHandle(int32_t newUserId, int32_t newScbPid, bool coldBoot)
auto pidIter = std::find(oldScbPids_.begin(), oldScbPids_.end(), currentScbPId_); {
if (pidIter == oldScbPids_.end() && currentScbPId_ > 0) { std::ostringstream oss;
oldScbPids_.emplace_back(currentScbPId_); oss << "currentUserId: " << currentUserId_
} << " currentScbPId" << currentScbPId_
oldScbPids_.erase(std::remove(oldScbPids_.begin(), oldScbPids_.end(), newScbPid), oldScbPids_.end()); << " newUserId: " << newUserId
clientProxy_->SwitchUserCallback(oldScbPids_, newScbPid); << " newScbPid: " << newScbPid
<< " coldBoot: " << static_cast<int32_t>(coldBoot);
TLOGI(WmsLogTag::DMS, "%{public}s", oss.str().c_str());
screenEventTracker_.RecordEvent(oss.str());
std::unique_lock<std::mutex> lock(oldScbPidsMutex_);
if (currentScbPId_ != INVALID_SCB_PID) {
auto pidIter = std::find(oldScbPids_.begin(), oldScbPids_.end(), currentScbPId_);
if (pidIter == oldScbPids_.end() && currentScbPId_ > 0) {
oldScbPids_.emplace_back(currentScbPId_);
}
oldScbPids_.erase(std::remove(oldScbPids_.begin(), oldScbPids_.end(), newScbPid), oldScbPids_.end());
if (oldScbPids_.size() == 0) {
TLOGE(WmsLogTag::DMS, "swicth user failed, oldScbPids is null");
screenEventTracker_.RecordEvent("swicth user failed, oldScbPids is null");
} }
currentUserId_ = userId;
currentScbPId_ = newScbPid;
clientProxy_ = client;
clientProxyMap_[currentUserId_] = client;
} }
MockSessionManagerService::GetInstance().NotifyWMSConnected(userId, GetDefaultScreenId(), true); if (!clientProxy_) {
NotifyClientProxyUpdateFoldDisplayMode(GetFoldDisplayMode()); TLOGE(WmsLogTag::DMS, "clientProxy is null");
SetClientInner(); return;
AddScbClientDeathRecipient(client, newScbPid); }
if (coldBoot) {
clientProxy_->SwitchUserCallback(oldScbPids_, newScbPid);
clientProxyMap_[newUserId] = clientProxy_;
} else {
// hot switch
if (clientProxyMap_.count(newUserId) == 0) {
TLOGE(WmsLogTag::DMS, "not found client proxy. userId:%{public}d.", newUserId);
return;
}
if (newUserId == currentUserId_) {
TLOGI(WmsLogTag::DMS, "switch user not change");
return;
}
clientProxy_ = clientProxyMap_[newUserId];
ScbStatusRecoveryWhenSwitchUser(oldScbPids_, newScbPid);
}
currentUserId_ = newUserId;
currentScbPId_ = newScbPid;
scbSwitchCV_.notify_all();
} }
void ScreenSessionManager::SetClientInner() void ScreenSessionManager::SetClientInner()
@ -4419,6 +4436,10 @@ void ScreenSessionManager::SetClientInner()
SetRotation(iter.first, Rotation::ROTATION_0, false); SetRotation(iter.first, Rotation::ROTATION_0, false);
iter.second->SetDisplayBoundary(RectF(0, 0, phyWidth, phyHeight), 0); iter.second->SetDisplayBoundary(RectF(0, 0, phyWidth, phyHeight), 0);
} }
if (!clientProxy_) {
TLOGE(WmsLogTag::DMS, "clientProxy is null");
return;
}
clientProxy_->OnScreenConnectionChanged(iter.first, ScreenEvent::CONNECTED, clientProxy_->OnScreenConnectionChanged(iter.first, ScreenEvent::CONNECTED,
iter.second->GetRSScreenId(), iter.second->GetName()); iter.second->GetRSScreenId(), iter.second->GetName());
} }
@ -4566,6 +4587,7 @@ int ScreenSessionManager::Dump(int fd, const std::vector<std::u16string>& args)
} }
dumper->DumpFreezedPidList(freezedPidList_); dumper->DumpFreezedPidList(freezedPidList_);
dumper->DumpEventTracker(screenEventTracker_); dumper->DumpEventTracker(screenEventTracker_);
dumper->DumpMultiUserInfo(oldScbPids_, currentUserId_, currentScbPId_);
dumper->ExcuteDumpCmd(); dumper->ExcuteDumpCmd();
std::vector<std::string> params; std::vector<std::string> params;