已合并
修复解注册角度传感器状态不更新问题 #17294
wulong158创建于 2025年12月20日
修复解注册角度传感器状态不更新问题 #17294
已合并
共 6 个文件变更+188-0
Mwindow_scene/screen_session_manager/include/fold_screen_controller/fold_screen_sensor_manager.h+4-0
| @@ -39,6 +39,10 @@ public: | |||
| 39 | 39 | ||
| 40 | void RegisterApplicationStateObserver(); | 40 | void RegisterApplicationStateObserver(); |
| 41 | 41 | ||
| 42 | + void UnRegisterPostureCallback(); | ||
| 43 | + | ||
| 44 | + void UnRegisterHallCallback(); | ||
| 45 | + | ||
| 42 | void RegisterHallCallback(); | 46 | void RegisterHallCallback(); |
| 43 | 47 | ||
| 44 | void SetFoldScreenPolicy(sptr<FoldScreenPolicy> foldScreenPolicy); | 48 | void SetFoldScreenPolicy(sptr<FoldScreenPolicy> foldScreenPolicy); |
Mwindow_scene/screen_session_manager/include/fold_screen_controller/secondary_fold_sensor_manager.h+2-0
| @@ -39,6 +39,8 @@ public: | |||
| 39 | void SetSensorFoldStateManager(sptr<SensorFoldStateManager> sensorFoldStateManager); | 39 | void SetSensorFoldStateManager(sptr<SensorFoldStateManager> sensorFoldStateManager); |
| 40 | void RegisterPostureCallback(); | 40 | void RegisterPostureCallback(); |
| 41 | void RegisterHallCallback(); | 41 | void RegisterHallCallback(); |
| 42 | + void UnRegisterPostureCallback(); | ||
| 43 | + void UnRegisterHallCallback(); | ||
| 42 | void HandlePostureData(const SensorEvent * const event); | 44 | void HandlePostureData(const SensorEvent * const event); |
| 43 | void HandleHallDataExt(const SensorEvent * const event); | 45 | void HandleHallDataExt(const SensorEvent * const event); |
| 44 | void PowerKeySetScreenActiveRect(); | 46 | void PowerKeySetScreenActiveRect(); |
| @@ -105,6 +105,15 @@ void ScreenSensorMgr::RegisterHallCallback() | |||
| 105 | 105 | ||
| 106 | void ScreenSensorMgr::UnRegisterHallCallback() | 106 | void ScreenSensorMgr::UnRegisterHallCallback() |
| 107 | { | 107 | { |
| 108 | + if (!ProductConfig::GetInstance().IsSingleDisplaySuperFoldDevice()) { | ||
| 109 | + if (ProductConfig::GetInstance().IsSecondaryDisplayFoldDevice()) { | ||
| 110 | + SecondaryFoldSensorManager::GetInstance().UnRegisterHallCallback(); | ||
| 111 | + } else { | ||
| 112 | + FoldScreenSensorManager::GetInstance().UnRegisterHallCallback(); | ||
| 113 | + } | ||
| 114 | + return; | ||
| 115 | + } | ||
| 116 | + | ||
| 108 | int ret = UnSubscribeSensorCallback(SENSOR_TYPE_ID_HALL_EXT); | 117 | int ret = UnSubscribeSensorCallback(SENSOR_TYPE_ID_HALL_EXT); |
| 109 | if (ret == SENSOR_SUCCESS) { | 118 | if (ret == SENSOR_SUCCESS) { |
| 110 | registerHall_ = false; | 119 | registerHall_ = false; |
| @@ -116,6 +125,15 @@ void ScreenSensorMgr::UnRegisterHallCallback() | |||
| 116 | 125 | ||
| 117 | void ScreenSensorMgr::UnRegisterPostureCallback() | 126 | void ScreenSensorMgr::UnRegisterPostureCallback() |
| 118 | { | 127 | { |
| 128 | + if (!ProductConfig::GetInstance().IsSingleDisplaySuperFoldDevice()) { | ||
| 129 | + if (ProductConfig::GetInstance().IsSecondaryDisplayFoldDevice()) { | ||
| 130 | + SecondaryFoldSensorManager::GetInstance().UnRegisterPostureCallback(); | ||
| 131 | + } else { | ||
| 132 | + FoldScreenSensorManager::GetInstance().UnRegisterPostureCallback(); | ||
| 133 | + } | ||
| 134 | + return; | ||
| 135 | + } | ||
| 136 | + | ||
| 119 | int ret = UnSubscribeSensorCallback(SENSOR_TYPE_ID_POSTURE); | 137 | int ret = UnSubscribeSensorCallback(SENSOR_TYPE_ID_POSTURE); |
| 120 | if (ret == SENSOR_SUCCESS) { | 138 | if (ret == SENSOR_SUCCESS) { |
| 121 | registerPosture_ = false; | 139 | registerPosture_ = false; |
| @@ -87,6 +87,17 @@ void FoldScreenSensorManager::RegisterHallCallback() | |||
| 87 | } | 87 | } |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | +void FoldScreenSensorManager::UnRegisterHallCallback() | ||
| 91 | +{ | ||
| 92 | + int ret = DMS::ScreenSensorMgr::GetInstance().UnSubscribeSensorCallback(SENSOR_TYPE_ID_HALL_EXT); | ||
| 93 | + if (ret == SENSOR_SUCCESS) { | ||
| 94 | + registerHall_ = false; | ||
| 95 | + TLOGI(WmsLogTag::DMS, "success."); | ||
| 96 | + } else { | ||
| 97 | + TLOGE(WmsLogTag::DMS, "failed with ret: %{public}d", ret); | ||
| 98 | + } | ||
| 99 | +} | ||
| 100 | + | ||
| 90 | void FoldScreenSensorManager::RegisterPostureCallback() | 101 | void FoldScreenSensorManager::RegisterPostureCallback() |
| 91 | { | 102 | { |
| 92 | int ret = DMS::ScreenSensorMgr::GetInstance().SubscribeSensorCallback( | 103 | int ret = DMS::ScreenSensorMgr::GetInstance().SubscribeSensorCallback( |
| @@ -100,6 +111,17 @@ void FoldScreenSensorManager::RegisterPostureCallback() | |||
| 100 | } | 111 | } |
| 101 | } | 112 | } |
| 102 | 113 | ||
| 114 | +void FoldScreenSensorManager::UnRegisterPostureCallback() | ||
| 115 | +{ | ||
| 116 | + int ret = DMS::ScreenSensorMgr::GetInstance().UnSubscribeSensorCallback(SENSOR_TYPE_ID_POSTURE); | ||
| 117 | + if (ret == SENSOR_SUCCESS) { | ||
| 118 | + registerPosture_ = false; | ||
| 119 | + TLOGI(WmsLogTag::DMS, "success."); | ||
| 120 | + } else { | ||
| 121 | + TLOGE(WmsLogTag::DMS, "failed with ret: %{public}d", ret); | ||
| 122 | + } | ||
| 123 | +} | ||
| 124 | + | ||
| 103 | void FoldScreenSensorManager::HandlePostureData(const SensorEvent* const event) | 125 | void FoldScreenSensorManager::HandlePostureData(const SensorEvent* const event) |
| 104 | { | 126 | { |
| 105 | if (event == nullptr) { | 127 | if (event == nullptr) { |
Mwindow_scene/screen_session_manager/src/fold_screen_controller/secondary_fold_sensor_manager.cpp+21-0
| @@ -88,6 +88,17 @@ void SecondaryFoldSensorManager::RegisterPostureCallback() | |||
| 88 | } | 88 | } |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | +void SecondaryFoldSensorManager::UnRegisterPostureCallback() | ||
| 92 | +{ | ||
| 93 | + int ret = DMS::ScreenSensorMgr::GetInstance().UnSubscribeSensorCallback(SENSOR_TYPE_ID_POSTURE); | ||
| 94 | + if (ret == SENSOR_SUCCESS) { | ||
| 95 | + registerPosture_ = false; | ||
| 96 | + TLOGI(WmsLogTag::DMS, "success."); | ||
| 97 | + } else { | ||
| 98 | + TLOGE(WmsLogTag::DMS, "failed with ret: %{public}d", ret); | ||
| 99 | + } | ||
| 100 | +} | ||
| 101 | + | ||
| 91 | void SecondaryFoldSensorManager::RegisterHallCallback() | 102 | void SecondaryFoldSensorManager::RegisterHallCallback() |
| 92 | { | 103 | { |
| 93 | int32_t ret = DMS::ScreenSensorMgr::GetInstance().SubscribeSensorCallback( | 104 | int32_t ret = DMS::ScreenSensorMgr::GetInstance().SubscribeSensorCallback( |
| @@ -97,6 +108,16 @@ void SecondaryFoldSensorManager::RegisterHallCallback() | |||
| 97 | } | 108 | } |
| 98 | } | 109 | } |
| 99 | 110 | ||
| 111 | +void SecondaryFoldSensorManager::UnRegisterHallCallback() | ||
| 112 | +{ | ||
| 113 | + int ret = DMS::ScreenSensorMgr::GetInstance().UnSubscribeSensorCallback(SENSOR_TYPE_ID_HALL_EXT); | ||
| 114 | + if (ret == SENSOR_SUCCESS) { | ||
| 115 | + TLOGI(WmsLogTag::DMS, "success."); | ||
| 116 | + } else { | ||
| 117 | + TLOGE(WmsLogTag::DMS, "failed with ret: %{public}d", ret); | ||
| 118 | + } | ||
| 119 | +} | ||
| 120 | + | ||
| 100 | void SecondaryFoldSensorManager::HandlePostureData(const SensorEvent * const event) | 121 | void SecondaryFoldSensorManager::HandlePostureData(const SensorEvent * const event) |
| 101 | { | 122 | { |
| 102 | float postureBc = 0.0F; | 123 | float postureBc = 0.0F; |
| @@ -29,6 +29,7 @@ | |||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | + | ||
| 32 | 33 | ||
| 33 | 34 | ||
| 34 | 35 | ||
| @@ -322,8 +323,67 @@ HWTEST_F(ScreenSensorMgrTest, UnRegisterPostureCallbackTest02, TestSize.Level1) | |||
| 322 | { | 323 | { |
| 323 | g_logMsg.clear(); | 324 | g_logMsg.clear(); |
| 324 | LOG_SetCallback(MyLogCallback); | 325 | LOG_SetCallback(MyLogCallback); |
| 326 | + MockProductConfig mockObj; | ||
| 327 | + EXPECT_CALL(mockObj, IsSingleDisplaySuperFoldDevice()).WillRepeatedly(Return(true)); | ||
| 328 | + ProductConfig::singleton_ = &mockObj; | ||
| 329 | + | ||
| 325 | ScreenSensorMgr::GetInstance().UnRegisterPostureCallback(); | 330 | ScreenSensorMgr::GetInstance().UnRegisterPostureCallback(); |
| 326 | EXPECT_TRUE(g_logMsg.find("UnRegisterPostureCallback failed") != std::string::npos); | 331 | EXPECT_TRUE(g_logMsg.find("UnRegisterPostureCallback failed") != std::string::npos); |
| 332 | + ProductConfig::singleton_ = nullptr; | ||
| 333 | +} | ||
| 334 | + | ||
| 335 | +/** | ||
| 336 | + * @tc.name: UnRegisterPostureCallbackTest03 | ||
| 337 | + * @tc.desc: test function : SecondaryDisplayFoldDevice unregister posture callback test | ||
| 338 | + * @tc.type: FUNC | ||
| 339 | + */ | ||
| 340 | +HWTEST_F(ScreenSensorMgrTest, UnRegisterPostureCallbackTest03, TestSize.Level1) | ||
| 341 | +{ | ||
| 342 | + g_logMsg.clear(); | ||
| 343 | + LOG_SetCallback(MyLogCallback); | ||
| 344 | + MockProductConfig mockObj; | ||
| 345 | + EXPECT_CALL(mockObj, IsSingleDisplaySuperFoldDevice()).WillRepeatedly(Return(false)); | ||
| 346 | + EXPECT_CALL(mockObj, IsSecondaryDisplayFoldDevice()).WillRepeatedly(Return(true)); | ||
| 347 | + ProductConfig::singleton_ = &mockObj; | ||
| 348 | + | ||
| 349 | + ScreenSensorMgr::GetInstance().RegisterPostureCallback(); | ||
| 350 | + EXPECT_TRUE(SecondaryFoldSensorManager::GetInstance().registerPosture_); | ||
| 351 | + | ||
| 352 | + ScreenSensorMgr::GetInstance().UnRegisterPostureCallback(); | ||
| 353 | + EXPECT_TRUE(!SecondaryFoldSensorManager::GetInstance().registerPosture_); | ||
| 354 | + | ||
| 355 | + g_logMsg.clear(); | ||
| 356 | + ScreenSensorMgr::GetInstance().UnRegisterPostureCallback(); | ||
| 357 | + EXPECT_TRUE(g_logMsg.find("failed with ret: 1") != std::string::npos); | ||
| 358 | + | ||
| 359 | + ProductConfig::singleton_ = nullptr; | ||
| 360 | +} | ||
| 361 | + | ||
| 362 | +/** | ||
| 363 | + * @tc.name: UnRegisterPostureCallbackTest04 | ||
| 364 | + * @tc.desc: test function : SingleDispalyFoldDevice unregister posture callback test | ||
| 365 | + * @tc.type: FUNC | ||
| 366 | + */ | ||
| 367 | +HWTEST_F(ScreenSensorMgrTest, UnRegisterPostureCallbackTest04, TestSize.Level1) | ||
| 368 | +{ | ||
| 369 | + g_logMsg.clear(); | ||
| 370 | + LOG_SetCallback(MyLogCallback); | ||
| 371 | + MockProductConfig mockObj; | ||
| 372 | + EXPECT_CALL(mockObj, IsSingleDisplaySuperFoldDevice()).WillRepeatedly(Return(false)); | ||
| 373 | + EXPECT_CALL(mockObj, IsSecondaryDisplayFoldDevice()).WillRepeatedly(Return(false)); | ||
| 374 | + ProductConfig::singleton_ = &mockObj; | ||
| 375 | + | ||
| 376 | + ScreenSensorMgr::GetInstance().RegisterPostureCallback(); | ||
| 377 | + EXPECT_TRUE(FoldScreenSensorManager::GetInstance().registerPosture_); | ||
| 378 | + | ||
| 379 | + ScreenSensorMgr::GetInstance().UnRegisterPostureCallback(); | ||
| 380 | + EXPECT_TRUE(!FoldScreenSensorManager::GetInstance().registerPosture_); | ||
| 381 | + | ||
| 382 | + g_logMsg.clear(); | ||
| 383 | + ScreenSensorMgr::GetInstance().UnRegisterPostureCallback(); | ||
| 384 | + EXPECT_TRUE(g_logMsg.find("failed with ret: 1") != std::string::npos); | ||
| 385 | + | ||
| 386 | + ProductConfig::singleton_ = nullptr; | ||
| 327 | } | 387 | } |
| 328 | 388 | ||
| 329 | /** | 389 | /** |
| @@ -350,8 +410,69 @@ HWTEST_F(ScreenSensorMgrTest, UnRegisterHallCallbackTest02, TestSize.Level1) | |||
| 350 | { | 410 | { |
| 351 | g_logMsg.clear(); | 411 | g_logMsg.clear(); |
| 352 | LOG_SetCallback(MyLogCallback); | 412 | LOG_SetCallback(MyLogCallback); |
| 413 | + MockProductConfig mockObj; | ||
| 414 | + EXPECT_CALL(mockObj, IsSingleDisplaySuperFoldDevice()).WillRepeatedly(Return(true)); | ||
| 415 | + ProductConfig::singleton_ = &mockObj; | ||
| 416 | + | ||
| 353 | ScreenSensorMgr::GetInstance().UnRegisterHallCallback(); | 417 | ScreenSensorMgr::GetInstance().UnRegisterHallCallback(); |
| 354 | EXPECT_TRUE(g_logMsg.find("unregister hall sensor failed") != std::string::npos); | 418 | EXPECT_TRUE(g_logMsg.find("unregister hall sensor failed") != std::string::npos); |
| 419 | + ProductConfig::singleton_ = nullptr; | ||
| 420 | +} | ||
| 421 | + | ||
| 422 | +/** | ||
| 423 | + * @tc.name: UnRegisterHallCallbackTest03 | ||
| 424 | + * @tc.desc: test function : SecondaryDisplayFoldDevice unregister hall callback test | ||
| 425 | + * @tc.type: FUNC | ||
| 426 | + */ | ||
| 427 | +HWTEST_F(ScreenSensorMgrTest, UnRegisterHallCallbackTest03, TestSize.Level1) | ||
| 428 | +{ | ||
| 429 | + g_logMsg.clear(); | ||
| 430 | + LOG_SetCallback(MyLogCallback); | ||
| 431 | + MockProductConfig mockObj; | ||
| 432 | + EXPECT_CALL(mockObj, IsSingleDisplaySuperFoldDevice()).WillRepeatedly(Return(false)); | ||
| 433 | + EXPECT_CALL(mockObj, IsSecondaryDisplayFoldDevice()).WillRepeatedly(Return(true)); | ||
| 434 | + ProductConfig::singleton_ = &mockObj; | ||
| 435 | + | ||
| 436 | + g_logMsg.clear(); | ||
| 437 | + ScreenSensorMgr::GetInstance().RegisterHallCallback(); | ||
| 438 | + EXPECT_TRUE(g_logMsg.find("success") != std::string::npos); | ||
| 439 | + | ||
| 440 | + g_logMsg.clear(); | ||
| 441 | + ScreenSensorMgr::GetInstance().UnRegisterHallCallback(); | ||
| 442 | + EXPECT_TRUE(g_logMsg.find("success") != std::string::npos); | ||
| 443 | + | ||
| 444 | + g_logMsg.clear(); | ||
| 445 | + ScreenSensorMgr::GetInstance().UnRegisterHallCallback(); | ||
| 446 | + EXPECT_TRUE(g_logMsg.find("failed with ret: 1") != std::string::npos); | ||
| 447 | + | ||
| 448 | + ProductConfig::singleton_ = nullptr; | ||
| 449 | +} | ||
| 450 | + | ||
| 451 | +/** | ||
| 452 | + * @tc.name: UnRegisterHallCallbackTest04 | ||
| 453 | + * @tc.desc: test function : SingleDispalyFoldDevice unregister hall callback test | ||
| 454 | + * @tc.type: FUNC | ||
| 455 | + */ | ||
| 456 | +HWTEST_F(ScreenSensorMgrTest, UnRegisterHallCallbackTest04, TestSize.Level1) | ||
| 457 | +{ | ||
| 458 | + g_logMsg.clear(); | ||
| 459 | + LOG_SetCallback(MyLogCallback); | ||
| 460 | + MockProductConfig mockObj; | ||
| 461 | + EXPECT_CALL(mockObj, IsSingleDisplaySuperFoldDevice()).WillRepeatedly(Return(false)); | ||
| 462 | + EXPECT_CALL(mockObj, IsSecondaryDisplayFoldDevice()).WillRepeatedly(Return(false)); | ||
| 463 | + ProductConfig::singleton_ = &mockObj; | ||
| 464 | + | ||
| 465 | + ScreenSensorMgr::GetInstance().RegisterHallCallback(); | ||
| 466 | + EXPECT_TRUE(FoldScreenSensorManager::GetInstance().registerHall_); | ||
| 467 | + | ||
| 468 | + ScreenSensorMgr::GetInstance().UnRegisterHallCallback(); | ||
| 469 | + EXPECT_TRUE(!FoldScreenSensorManager::GetInstance().registerHall_); | ||
| 470 | + | ||
| 471 | + g_logMsg.clear(); | ||
| 472 | + ScreenSensorMgr::GetInstance().UnRegisterHallCallback(); | ||
| 473 | + EXPECT_TRUE(g_logMsg.find("failed with ret: 1") != std::string::npos); | ||
| 474 | + | ||
| 475 | + ProductConfig::singleton_ = nullptr; | ||
| 355 | } | 476 | } |
| 356 | 477 | ||
| 357 | /** | 478 | /** |