已合并
属性监听hook信息单独隔离 #18103
属性监听hook信息单独隔离 #18103
已合并
zhaoliang创建于 2月10日
3 个文件变更+113-14
@@ -190,7 +190,8 @@ public:
190 void NotifyDisplayDestroy(DisplayId displayId);190 void NotifyDisplayDestroy(DisplayId displayId);
191 void NotifyAndPublishEvent(sptr<DisplayInfo> displayInfo, ScreenId screenId, sptr<ScreenSession> screenSession);191 void NotifyAndPublishEvent(sptr<DisplayInfo> displayInfo, ScreenId screenId, sptr<ScreenSession> screenSession);
192 void NotifyDisplayChanged(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event);192 void NotifyDisplayChanged(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event);
193- void CheckAttributeChange(sptr<DisplayInfo> displayInfo, int32_t uid = INVALID_UID);193+ void CheckAttributeChange(sptr<DisplayInfo> displayInfo);
194+ void CheckAttributeChangeWithUid(sptr<DisplayInfo> displayInfo, int32_t uid);
194 void NotifyDisplayAttributeChanged(sptr<DisplayInfo> displayInfo, const std::vector<std::string>& attributes,195 void NotifyDisplayAttributeChanged(sptr<DisplayInfo> displayInfo, const std::vector<std::string>& attributes,
195 int32_t uid = INVALID_UID);196 int32_t uid = INVALID_UID);
196 void GetChangedListenableAttribute(sptr<DisplayInfo> displayInfo1, sptr<DisplayInfo> displayInfo2,197 void GetChangedListenableAttribute(sptr<DisplayInfo> displayInfo1, sptr<DisplayInfo> displayInfo2,
@@ -1035,6 +1036,8 @@ private:
1035 1036 
1036 std::mutex lastDisplayInfoMapMutex_;1037 std::mutex lastDisplayInfoMapMutex_;
1037 std::map<DisplayId, sptr<DisplayInfo>> lastDisplayInfoMap_;1038 std::map<DisplayId, sptr<DisplayInfo>> lastDisplayInfoMap_;
1039+ std::mutex lastDisplayInfoHookMapMutex_;
1040+ std::map<int32_t, std::map<DisplayId, sptr<DisplayInfo>>> lastDisplayInfoHookMap_;
1038 1041 
1039 std::atomic<PowerStateChangeReason> prePowerStateChangeReason_ =1042 std::atomic<PowerStateChangeReason> prePowerStateChangeReason_ =
1040 PowerStateChangeReason::STATE_CHANGE_REASON_UNKNOWN;1043 PowerStateChangeReason::STATE_CHANGE_REASON_UNKNOWN;
@@ -2377,7 +2377,8 @@ sptr<DisplayInfo> ScreenSessionManager::HookDisplayInfoByUid(sptr<DisplayInfo> d
2377 << " hO: " << info.displayOrientation_ << ", hEO: " << info.enableHookDisplayOrientation_2377 << " hO: " << info.displayOrientation_ << ", hEO: " << info.enableHookDisplayOrientation_
2378 << ", dW: " << displayInfo->GetHeight() << ", dH: " << displayInfo->GetHeight()2378 << ", dW: " << displayInfo->GetHeight() << ", dH: " << displayInfo->GetHeight()
2379 << ", dR: " << static_cast<uint32_t>(displayInfo->GetRotation())2379 << ", dR: " << static_cast<uint32_t>(displayInfo->GetRotation())
2380- << ", dO: " << static_cast<uint32_t>(displayInfo->GetDisplayOrientation());2380+ << ", dO: " << static_cast<uint32_t>(displayInfo->GetDisplayOrientation())
2381+ << ", uid: " << uid << ", pid: " << IPCSkeleton::GetCallingPid();
2381 TLOGNFI(WmsLogTag::DMS, "%{public}s", oss.str().c_str());2382 TLOGNFI(WmsLogTag::DMS, "%{public}s", oss.str().c_str());
2382 2383 
2383 displayInfo->SetWidth(info.width_);2384 displayInfo->SetWidth(info.width_);
@@ -3311,7 +3312,7 @@ void ScreenSessionManager::NotifyDisplayChangedByUidInner(sptr<DisplayInfo> disp
3311 ScreenSessionManagerAdapter::GetInstance().OnDisplayChange(displayInfo, event, uid);3312 ScreenSessionManagerAdapter::GetInstance().OnDisplayChange(displayInfo, event, uid);
3312 };3313 };
3313 taskScheduler_->PostAsyncTask(task, "NotifyDisplayChanged");3314 taskScheduler_->PostAsyncTask(task, "NotifyDisplayChanged");
3314- CheckAttributeChange(displayInfo, uid);3315+ CheckAttributeChangeWithUid(displayInfo, uid);
3315 TLOGNFI(WmsLogTag::DMS, "notify end");3316 TLOGNFI(WmsLogTag::DMS, "notify end");
3316}3317}
3317 3318 
@@ -6494,21 +6495,17 @@ void ScreenSessionManager::NotifyDisplayChanged(sptr<DisplayInfo> displayInfo, D
6494 taskScheduler_->PostAsyncTask(task, "NotifyDisplayChanged");6495 taskScheduler_->PostAsyncTask(task, "NotifyDisplayChanged");
6495}6496}
6496 6497 
6497-void ScreenSessionManager::CheckAttributeChange(sptr<DisplayInfo> displayInfo, int32_t uid)6498+void ScreenSessionManager::CheckAttributeChange(sptr<DisplayInfo> displayInfo)
6498{6499{
6499 if (displayInfo == nullptr) {6500 if (displayInfo == nullptr) {
6500 TLOGNFE(WmsLogTag::DMS, "DisplayInfo is nullptr");6501 TLOGNFE(WmsLogTag::DMS, "DisplayInfo is nullptr");
6501 return;6502 return;
6502 }6503 }
6503 DisplayId displayId = displayInfo->GetDisplayId();6504 DisplayId displayId = displayInfo->GetDisplayId();
6504- if (uid != INVALID_UID) {
6505- sptr<ScreenSession> screenSession = GetScreenSession(displayId);
6506- HookDisplayInfoByUid(displayInfo, screenSession, uid);
6507- }
6508 std::vector<std::string> attributes;6505 std::vector<std::string> attributes;
6509 std::lock_guard<std::mutex> lock(lastDisplayInfoMapMutex_);6506 std::lock_guard<std::mutex> lock(lastDisplayInfoMapMutex_);
6510 if (lastDisplayInfoMap_.find(displayId) == lastDisplayInfoMap_.end()) {6507 if (lastDisplayInfoMap_.find(displayId) == lastDisplayInfoMap_.end()) {
6511- lastDisplayInfoMap_.insert({displayId, std::move(new DisplayInfo())});6508+ lastDisplayInfoMap_.insert({displayId, sptr<DisplayInfo>::MakeSptr()});
6512 }6509 }
6513 auto lastDisplayInfo = lastDisplayInfoMap_[displayId];6510 auto lastDisplayInfo = lastDisplayInfoMap_[displayId];
6514 if (lastDisplayInfo == nullptr) {6511 if (lastDisplayInfo == nullptr) {
@@ -6529,13 +6526,48 @@ void ScreenSessionManager::CheckAttributeChange(sptr<DisplayInfo> displayInfo, i
6529 }6526 }
6530 TLOGD(WmsLogTag::DMS, "%{public}s]", oss.str().c_str());6527 TLOGD(WmsLogTag::DMS, "%{public}s]", oss.str().c_str());
6531 6528 
6532- if (uid != INVALID_UID) {6529+ NotifyDisplayAttributeChanged(displayInfo, attributes);
6533- NotifyDisplayAttributeChanged(displayInfo, attributes, uid);
6534- } else {
6535- NotifyDisplayAttributeChanged(displayInfo, attributes);
6536- }
6537 lastDisplayInfoMap_[displayId] = displayInfo;6530 lastDisplayInfoMap_[displayId] = displayInfo;
6538}6531}
6532+ 
6533+void ScreenSessionManager::CheckAttributeChangeWithUid(sptr<DisplayInfo> displayInfo, int32_t uid)
6534+{
6535+ if (displayInfo == nullptr) {
6536+ TLOGNFE(WmsLogTag::DMS, "DisplayInfo is nullptr");
6537+ return;
6538+ }
6539+ DisplayId displayId = displayInfo->GetDisplayId();
6540+ sptr<ScreenSession> screenSession = GetScreenSession(displayId);
6541+ HookDisplayInfoByUid(displayInfo, screenSession, uid);
6542+ 
6543+ std::lock_guard<std::mutex> lock(lastDisplayInfoHookMapMutex_);
6544+ if (lastDisplayInfoHookMap_.find(uid) == lastDisplayInfoHookMap_.end() ||
6545+ lastDisplayInfoHookMap_[uid].find(displayId) == lastDisplayInfoHookMap_[uid].end()) {
6546+ lastDisplayInfoHookMap_[uid][displayId] = sptr<DisplayInfo>::MakeSptr();
6547+ }
6548+ auto lastDisplayInfo = lastDisplayInfoHookMap_[uid][displayId];
6549+ if (lastDisplayInfo == nullptr) {
6550+ TLOGNFE(WmsLogTag::DMS, "LastDisplayInfo of displayId: %{public}" PRIu64 "is nullptr", displayId);
6551+ return;
6552+ }
6553+ std::vector<std::string> attributes;
6554+ GetChangedListenableAttribute(lastDisplayInfo, displayInfo, attributes);
6555+ if (attributes.empty()) {
6556+ TLOGNFW(WmsLogTag::DMS, "No attribute changed");
6557+ return;
6558+ }
6559+ 
6560+ std::ostringstream oss;
6561+ oss << "current changed attributes:[";
6562+ for (const auto& attribute : attributes) {
6563+ oss << attribute << ",";
6564+ }
6565+ std::string logStr = oss.str();
6566+ TLOGD(WmsLogTag::DMS, "uid is: %{public}d, %{public}s]", uid, logStr.c_str());
6567+ 
6568+ NotifyDisplayAttributeChanged(displayInfo, attributes, uid);
6569+ lastDisplayInfoHookMap_[uid][displayId] = displayInfo;
6570+}
6539 6571
6540void ScreenSessionManager::GetChangedListenableAttribute(sptr<DisplayInfo> displayInfo1, sptr<DisplayInfo> displayInfo2,6572void ScreenSessionManager::GetChangedListenableAttribute(sptr<DisplayInfo> displayInfo1, sptr<DisplayInfo> displayInfo2,
6541 std::vector<std::string>& attributes)6573 std::vector<std::string>& attributes)
@@ -3667,6 +3667,70 @@ HWTEST_F(ScreenSessionManagerTest, VirtualScreenWhiteList_UniqueScreen, TestSize
3667 ScreenSessionManager::GetInstance().DestroyVirtualScreen(virtualScreenId);3667 ScreenSessionManager::GetInstance().DestroyVirtualScreen(virtualScreenId);
3668}3668}
3669 3669 
3670+/**
3671+ * @tc.name: CheckAttributeChangeWithUid01
3672+ * @tc.desc: CheckAttributeChangeWithUid01 test
3673+ * @tc.type: FUNC
3674+ */
3675+HWTEST_F(ScreenSessionManagerTest, CheckAttributeChangeWithUid01, TestSize.Level1)
3676+{
3677+ g_errLog.clear();
3678+ LOG_SetCallback(MyLogCallback);
3679+ ASSERT_NE(ssm_, nullptr);
3680+ 
3681+ ssm_->CheckAttributeChangeWithUid(nullptr, 0);
3682+ EXPECT_TRUE(g_errLog.find("DisplayInfo is nullptr") != std::string::npos);
3683+ g_errLog.clear();
3684+}
3685+ 
3686+/**
3687+ * @tc.name: CheckAttributeChangeWithUid02
3688+ * @tc.desc: CheckAttributeChangeWithUid02 test
3689+ * @tc.type: FUNC
3690+ */
3691+HWTEST_F(ScreenSessionManagerTest, CheckAttributeChangeWithUid02, TestSize.Level1)
3692+{
3693+ g_errLog.clear();
3694+ LOG_SetCallback(MyLogCallback);
3695+ ASSERT_NE(ssm_, nullptr);
3696+
3697+ DisplayId displayId = 985;
3698+ int32_t uid = 123456;
3699+ ssm_->lastDisplayInfoHookMap_[uid][displayId] = new DisplayInfo();
3700+ sptr<DisplayInfo> displayInfo1 = ssm_->lastDisplayInfoHookMap_[uid][displayId];
3701+ displayInfo1->SetDisplayId(displayId);
3702+ ssm_->CheckAttributeChangeWithUid(displayInfo1, uid);
3703+ EXPECT_TRUE(g_errLog.find("No attribute changed") != std::string::npos);
3704+ ssm_->lastDisplayInfoHookMap_[uid].erase(displayId);
3705+ g_errLog.clear();
3706+}
3707+ 
3708+/**
3709+ * @tc.name: CheckAttributeChangeWithUid03
3710+ * @tc.desc: CheckAttributeChangeWithUid03 test
3711+ * @tc.type: FUNC
3712+ */
3713+HWTEST_F(ScreenSessionManagerTest, CheckAttributeChangeWithUid03, TestSize.Level1)
3714+{
3715+ g_errLog.clear();
3716+ LOG_SetCallback(MyLogCallback);
3717+ ASSERT_NE(ssm_, nullptr);
3718+
3719+ DisplayId displayId = 985;
3720+ int32_t uid = 123456;
3721+ ssm_->lastDisplayInfoHookMap_[uid][displayId] = new DisplayInfo();
3722+ sptr<DisplayInfo> displayInfo1 = ssm_->lastDisplayInfoHookMap_[uid][displayId];
3723+ displayInfo1->SetDisplayId(displayId);
3724+ displayInfo1->SetRotation(Rotation::ROTATION_180);
3725+ sptr<DisplayInfo> displayInfo2 = new DisplayInfo();
3726+ displayInfo2->SetRotation(Rotation::ROTATION_270);
3727+ displayInfo2->SetDisplayId(displayId);
3728+ ssm_->CheckAttributeChangeWithUid(displayInfo2, uid);
3729+ EXPECT_TRUE(g_errLog.find("No attribute changed") == std::string::npos);
3730+ ssm_->lastDisplayInfoHookMap_[uid].erase(displayId);
3731+ g_errLog.clear();
3732+}
3733+ 
3670/**3734/**
3671 * @tc.name: NotifyDisplayAttributeChanged3735 * @tc.name: NotifyDisplayAttributeChanged
3672 * @tc.desc: NotifyDisplayAttributeChanged test3736 * @tc.desc: NotifyDisplayAttributeChanged test