diff --git a/powermgr.gni b/powermgr.gni index 3671e9f2872f99b67b9cee8863087822e1d81919..f40d8a6e4222fc62059708371a3adef07aaf0018 100644 --- a/powermgr.gni +++ b/powermgr.gni @@ -32,7 +32,7 @@ declare_args() { power_manager_feature_doubleclick = true power_manager_feature_pickup = true power_manager_feature_force_sleep_broadcast = false - power_manager_feature_movement = true + power_manager_feature_movement = false power_manager_feature_charging_type_setting = false power_manager_feature_external_screen_management = false power_manager_feature_block_long_press = false diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h index 0741f57d33f22ef0d39160d81a186be76f7defde..738442c8ae3578a7d5447056cb6c8d52e3ee9a2b 100644 --- a/services/native/include/power_mgr_service.h +++ b/services/native/include/power_mgr_service.h @@ -346,11 +346,8 @@ private: std::string GetBundleNameByUid(const int32_t uid); RunningLockParam FillRunningLockParam(const RunningLockInfo& info, const uint64_t lockid, int32_t timeOutMS = -1); void SubscribeCommonEvent(); -#ifdef MSDP_MOVEMENT_ENABLE - void RegisterMovementCallback(); - void UnRegisterMovementCallback(); - void ResetMovementState(); -#endif + void PowerMovementSubscribe(); + void PowerMovementUnsubscribe(); #ifdef HAS_SENSORS_SENSOR_PART bool IsSupportSensor(SensorTypeId); #endif diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index f5b3c5638a1f55002ec18a8d6e5be8bec049697a..030820946bf869856bd181028ef93af0d4062c5f 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -56,9 +56,8 @@ #ifdef POWER_MANAGER_ENABLE_CHARGING_TYPE_SETTING #include "battery_srv_client.h" #endif -#ifdef MSDP_MOVEMENT_ENABLE #include -#endif +#include "power_hookmgr.h" using namespace OHOS::AppExecFwk; using namespace OHOS::AAFwk; @@ -120,9 +119,6 @@ void PowerMgrService::OnStart() AddSystemAbilityListener(DISPLAY_MANAGER_SERVICE_ID); AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); AddSystemAbilityListener(DISPLAY_MANAGER_SERVICE_SA_ID); -#ifdef MSDP_MOVEMENT_ENABLE - AddSystemAbilityListener(MSDP_MOVEMENT_SERVICE_ID); -#endif #ifdef POWER_PICKUP_ENABLE AddSystemAbilityListener(MSDP_MOTION_SERVICE_ID); #endif @@ -131,7 +127,10 @@ void PowerMgrService::OnStart() PowerExtIntfWrapper::Instance().Init(); g_moduleMgr = ModuleMgrScan(POWER_PLUGIN_AUTORUN_PATH); #endif - +#ifdef MSDP_MOVEMENT_ENABLE + PowerMovementSubscribe(); +#endif + if (!Publish(DelayedSpSingleton::GetInstance())) { POWER_HILOGE(COMP_SVC, "Register to system ability manager failed"); return; @@ -141,6 +140,18 @@ void PowerMgrService::OnStart() POWER_HILOGI(COMP_SVC, "Add system ability success"); } +void PowerMgrService::PowerMovementSubscribe() +{ + HOOK_MGR* hookMgr = GetPowerHookMgr(); + MOVEMENT_SUBSCRIBE_INFO movementSubscribeInfo = { .subscribeFlag = true }; + if (hookMgr) { + HookMgrExecute(hookMgr, static_cast(PowerHookStage::POWER_MOVEMENT_SUBSCRIBE), + (void*)&movementSubscribeInfo, nullptr); + } else { + POWER_HILOGE(COMP_SVC, "GetPowerHookMgr POWER_MOVEMENT_SUBSCRIBE true fail"); + } +} + bool PowerMgrService::Init() { POWER_HILOGI(COMP_SVC, "powermgr service init start"); @@ -658,7 +669,7 @@ void PowerMgrService::OnStop() RemoveSystemAbilityListener(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID); RemoveSystemAbilityListener(DISPLAY_MANAGER_SERVICE_ID); #ifdef MSDP_MOVEMENT_ENABLE - RemoveSystemAbilityListener(MSDP_MOVEMENT_SERVICE_ID); + PowerMovementUnsubscribe(); #endif #ifdef POWER_PICKUP_ENABLE RemoveSystemAbilityListener(MSDP_MOTION_SERVICE_ID); @@ -674,9 +685,6 @@ void PowerMgrService::OnStop() if (!OHOS::EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriberPtr_)) { POWER_HILOGE(COMP_SVC, "Power Onstop unregister to commonevent manager failed!"); } -#ifdef MSDP_MOVEMENT_ENABLE - UnRegisterMovementCallback(); -#endif UnregisterExternalCallback(); #ifndef FUZZ_TEST PowerExtIntfWrapper::Instance().DeInit(); @@ -685,6 +693,18 @@ void PowerMgrService::OnStop() #endif } +void PowerMgrService::PowerMovementUnsubscribe() +{ + HOOK_MGR* hookMgr = GetPowerHookMgr(); + MOVEMENT_SUBSCRIBE_INFO movementSubscribeInfo = { .subscribeFlag = false }; + if (hookMgr) { + HookMgrExecute(hookMgr, static_cast(PowerHookStage::POWER_MOVEMENT_SUBSCRIBE), + (void*)&movementSubscribeInfo, nullptr); + } else { + POWER_HILOGE(COMP_SVC, "GetPowerHookMgr POWER_MOVEMENT_SUBSCRIBE false fail"); + } +} + void PowerMgrService::Reset() { POWER_HILOGW(COMP_SVC, "start destruct ffrt_queue"); @@ -711,16 +731,6 @@ void PowerMgrService::OnRemoveSystemAbility(int32_t systemAbilityId, const std:: std::lock_guard lock(lockMutex_); runningLockMgr_->ResetRunningLocks(); } -#ifdef MSDP_MOVEMENT_ENABLE - if (systemAbilityId == MSDP_MOVEMENT_SERVICE_ID) { - auto power = DelayedSpSingleton::GetInstance(); - if (power == nullptr) { - POWER_HILOGI(COMP_SVC, "get PowerMgrService fail"); - return; - } - power->ResetMovementState(); - } -#endif if (systemAbilityId == DISPLAY_MANAGER_SERVICE_SA_ID) { std::lock_guard lock(powerInitMutex_); POWER_HILOGI(COMP_SVC, "get DISPLAY_MANAGER_SERVICE_SA_ID crash in PowerService."); @@ -753,17 +763,6 @@ void PowerMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::str displayManagerServiceCrash_ = false; } } -#ifdef MSDP_MOVEMENT_ENABLE - if (systemAbilityId == MSDP_MOVEMENT_SERVICE_ID) { - auto power = DelayedSpSingleton::GetInstance(); - if (power == nullptr) { - POWER_HILOGI(COMP_SVC, "get PowerMgrService fail"); - return; - } - power->UnRegisterMovementCallback(); - power->RegisterMovementCallback(); - } -#endif #ifdef POWER_PICKUP_ENABLE if (systemAbilityId == MSDP_MOTION_SERVICE_ID && g_isPickUpOpen == true) { WakeupController::PickupConnectMotionConfig(false); @@ -772,87 +771,6 @@ void PowerMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::str #endif } -#ifdef MSDP_MOVEMENT_ENABLE -static const char* MOVEMENT_SUBSCRIBER_CONFIG = "RegisterMovementCallback"; -static const char* MOVEMENT_UNSUBSCRIBER_CONFIG = "UnRegisterMovementCallback"; -static const char* RESET_MOVEMENT_STATE_CONFIG = "ResetMovementState"; -typedef void(*FuncMovementSubscriber)(); -typedef void(*FuncMovementUnsubscriber)(); -typedef void(*FuncResetMovementState)(); - -void PowerMgrService::RegisterMovementCallback() -{ - POWER_HILOGI(COMP_SVC, "Start to RegisterMovementCallback"); - void *subscriberHandler = dlopen(POWER_MANAGER_EXT_PATH, RTLD_LAZY | RTLD_NODELETE); - if (subscriberHandler == nullptr) { - POWER_HILOGE(COMP_SVC, "Dlopen RegisterMovementCallback failed, reason : %{public}s", dlerror()); - return; - } - - FuncMovementSubscriber MovementSubscriber = - reinterpret_cast(dlsym(subscriberHandler, MOVEMENT_SUBSCRIBER_CONFIG)); - if (MovementSubscriber == nullptr) { - POWER_HILOGE(COMP_SVC, "RegisterMovementCallback is null, reason : %{public}s", dlerror()); - dlclose(subscriberHandler); - subscriberHandler = nullptr; - return; - } - MovementSubscriber(); - POWER_HILOGI(COMP_SVC, "RegisterMovementCallback Success"); - dlclose(subscriberHandler); - subscriberHandler = nullptr; - return; -} - -void PowerMgrService::UnRegisterMovementCallback() -{ - POWER_HILOGI(COMP_SVC, "Start to UnRegisterMovementCallback"); - void *unSubscriberHandler = dlopen(POWER_MANAGER_EXT_PATH, RTLD_LAZY | RTLD_NODELETE); - if (unSubscriberHandler == nullptr) { - POWER_HILOGE(COMP_SVC, "Dlopen UnRegisterMovementCallback failed, reason : %{public}s", dlerror()); - return; - } - - FuncMovementUnsubscriber MovementUnsubscriber = - reinterpret_cast(dlsym(unSubscriberHandler, MOVEMENT_UNSUBSCRIBER_CONFIG)); - if (MovementUnsubscriber == nullptr) { - POWER_HILOGE(COMP_SVC, "UnRegisterMovementCallback is null, reason : %{public}s", dlerror()); - dlclose(unSubscriberHandler); - unSubscriberHandler = nullptr; - return; - } - MovementUnsubscriber(); - POWER_HILOGI(COMP_SVC, "UnRegisterMovementCallback Success"); - dlclose(unSubscriberHandler); - unSubscriberHandler = nullptr; - return; -} - -void PowerMgrService::ResetMovementState() -{ - POWER_HILOGI(COMP_SVC, "Start to ResetMovementState"); - void *resetMovementStateHandler = dlopen(POWER_MANAGER_EXT_PATH, RTLD_LAZY | RTLD_NODELETE); - if (resetMovementStateHandler == nullptr) { - POWER_HILOGE(COMP_SVC, "Dlopen ResetMovementState failed, reason : %{public}s", dlerror()); - return; - } - - FuncResetMovementState ResetMovementState = - reinterpret_cast(dlsym(resetMovementStateHandler, RESET_MOVEMENT_STATE_CONFIG)); - if (ResetMovementState == nullptr) { - POWER_HILOGE(COMP_SVC, "ResetMovementState is null, reason : %{public}s", dlerror()); - dlclose(resetMovementStateHandler); - resetMovementStateHandler = nullptr; - return; - } - ResetMovementState(); - POWER_HILOGI(COMP_SVC, "ResetMovementState Success"); - dlclose(resetMovementStateHandler); - resetMovementStateHandler = nullptr; - return; -} -#endif - static const char* REGISTER_EXTERNAL_CONFIG = "RegisterExternalCallback"; static const char* UNREGISTER_EXTERNAL_CONFIG = "UnregisterExternalCallback"; using WakeupFunc = std::function; diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index c09fb3b9ef2865782739995601f333275207c5b7..746bffae26650fdd43e9493b51db5654d5e2a984 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -39,7 +39,7 @@ #include "parameters.h" #endif #ifdef MSDP_MOVEMENT_ENABLE -#include +#include "power_hookmgr.h" #endif #include "customized_screen_event_rules.h" #include "display_manager_lite.h" @@ -184,31 +184,23 @@ void PowerStateMachine::InitTransitMap() } #ifdef MSDP_MOVEMENT_ENABLE -static const char* MOVEMENT_STATE_CONFIG = "GetMovementState"; -static const char* POWER_MANAGER_EXT_PATH = "libpower_manager_ext.z.so"; -typedef bool(*FuncMovementState)(); - bool PowerStateMachine::IsMovementStateOn() { POWER_HILOGD(FEATURE_POWER_STATE, "Start to GetMovementState"); - void *stateHandler = dlopen(POWER_MANAGER_EXT_PATH, RTLD_LAZY | RTLD_NODELETE); - if (stateHandler == nullptr) { - POWER_HILOGE(FEATURE_POWER_STATE, "Dlopen GetMovementState failed, reason : %{public}s", dlerror()); - return false; - } - - FuncMovementState MovementStateFlag = reinterpret_cast(dlsym(stateHandler, - MOVEMENT_STATE_CONFIG)); - if (MovementStateFlag == nullptr) { - POWER_HILOGE(FEATURE_POWER_STATE, "GetMovementState is null, reason : %{public}s", dlerror()); - dlclose(stateHandler); - stateHandler = nullptr; - return false; + HOOK_MGR* hookMgr = GetPowerHookMgr(); + MOVEMENT_STATE_INFO movementStateInfo = { .movementState = false }; + if (hookMgr) { + int ret = HookMgrExecute(hookMgr, static_cast(PowerHookStage::POWER_MOVEMENT_STATE), + (void*)&movementStateInfo, nullptr); + if (ret == ERR_OK) { + return movementStateInfo.movementState; + } else { + POWER_HILOGE(COMP_SVC, "HookMgrExecute POWER_MOVEMENT_STATE fail"); + } + } else { + POWER_HILOGE(COMP_SVC, "GetPowerHookMgr POWER_MOVEMENT_STATE fail"); } - bool ret = MovementStateFlag(); - dlclose(stateHandler); - stateHandler = nullptr; - return ret; + return false; } #endif diff --git a/test/unittest/src/power_mgr_service_native_test.cpp b/test/unittest/src/power_mgr_service_native_test.cpp index c6c6d3316602ec4f423a8413c633d71e8e20fb3f..80e5c4961006ccd57613b60948a40ed4624e9c9a 100644 --- a/test/unittest/src/power_mgr_service_native_test.cpp +++ b/test/unittest/src/power_mgr_service_native_test.cpp @@ -310,53 +310,32 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative011, TestSize.Level1) /** * @tc.name: PowerMgrServiceNative012 - * @tc.desc: test RegisterMovementCallback + * @tc.desc: test RegisterExternalScreenListener * @tc.type: FUNC */ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative012, TestSize.Level1) { GTEST_LOG_(INFO) << "PowerMgrServiceNative012 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative012 function start!"); -#ifdef MSDP_MOVEMENT_ENABLE - auto stateMachine = std::make_shared(g_pmsTest); - g_pmsTest->RegisterMovementCallback(); - g_pmsTest->UnRegisterMovementCallback(); - g_pmsTest->ResetMovementState(); - bool ret = stateMachine->IsMovementStateOn(); - EXPECT_TRUE(ret == false); -#endif - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative012 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative012 end."; -} - -/** - * @tc.name: PowerMgrServiceNative013 - * @tc.desc: test RegisterExternalScreenListener - * @tc.type: FUNC - */ -HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative013, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "PowerMgrServiceNative013 start."; - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative013 function start!"); #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT g_pmsTest->RegisterExternalScreenListener(); EXPECT_TRUE(g_pmsTest->externalScreenListener_ != nullptr); g_pmsTest->UnRegisterExternalScreenListener(); EXPECT_TRUE(g_pmsTest->externalScreenListener_ == nullptr); #endif - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative013 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative013 end."; + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative012 function end!"); + GTEST_LOG_(INFO) << "PowerMgrServiceNative012 end."; } /** - * @tc.name: PowerMgrServiceNative014 + * @tc.name: PowerMgrServiceNative013 * @tc.desc: test ExternalScreenListener OnConnect * @tc.type: FUNC */ -HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative014, TestSize.Level1) +HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative013, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative014 start."; - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative014 function start!"); + GTEST_LOG_(INFO) << "PowerMgrServiceNative013 start."; + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative013 function start!"); #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT g_pmsTest->SuspendControllerInit(); g_pmsTest->WakeupControllerInit(); @@ -370,7 +349,7 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative014, TestSize.Level1) // case 1: isSwitchOpen:true, isScreenOn:true powerStateMachine->SetSwitchState(true); g_pmsTest->WakeupDevice( - static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_SWITCH, "PowerMgrServiceNative014"); + static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_SWITCH, "PowerMgrServiceNative013"); EXPECT_TRUE(powerStateMachine->IsScreenOn()); g_pmsTest->externalScreenListener_->OnConnect(SCREEN_A_ID); EXPECT_TRUE(powerStateMachine->IsScreenOn()); @@ -395,19 +374,19 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative014, TestSize.Level1) g_pmsTest->UnRegisterExternalScreenListener(); EXPECT_TRUE(g_pmsTest->externalScreenListener_ == nullptr); #endif - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative014 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative014 end."; + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative013 function end!"); + GTEST_LOG_(INFO) << "PowerMgrServiceNative013 end."; } /** - * @tc.name: PowerMgrServiceNative015 + * @tc.name: PowerMgrServiceNative014 * @tc.desc: test ExternalScreenListener OnDisconnect * @tc.type: FUNC */ -HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative015, TestSize.Level1) +HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative014, TestSize.Level1) { - GTEST_LOG_(INFO) << "PowerMgrServiceNative015 start."; - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative015 function start!"); + GTEST_LOG_(INFO) << "PowerMgrServiceNative014 start."; + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative014 function start!"); #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT g_pmsTest->SuspendControllerInit(); g_pmsTest->WakeupControllerInit(); @@ -421,7 +400,7 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative015, TestSize.Level1) // case 1: isSwitchOpen:true, isScreenOn:true powerStateMachine->SetSwitchState(true); g_pmsTest->WakeupDevice( - static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_SWITCH, "PowerMgrServiceNative015"); + static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_SWITCH, "PowerMgrServiceNative014"); powerStateMachine->SetExternalScreenNumber(1); EXPECT_TRUE(powerStateMachine->IsScreenOn()); g_pmsTest->externalScreenListener_->OnDisconnect(SCREEN_A_ID); @@ -438,7 +417,7 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative015, TestSize.Level1) // Mock open switch to wakeup deivce powerStateMachine->SetSwitchState(true); g_service->WakeupDevice( - static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_SWITCH, "PowerMgrServiceNative015"); + static_cast(time(nullptr)), WakeupDeviceType::WAKEUP_DEVICE_SWITCH, "PowerMgrServiceNative014"); EXPECT_TRUE(powerStateMachine->IsScreenOn()); powerStateMachine->SetExternalScreenNumber(1); // Mock close switch to suspend device when switch's action is configured as ACTION_NONE @@ -453,8 +432,8 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative015, TestSize.Level1) g_pmsTest->UnRegisterExternalScreenListener(); EXPECT_TRUE(g_pmsTest->externalScreenListener_ == nullptr); #endif - POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative015 function end!"); - GTEST_LOG_(INFO) << "PowerMgrServiceNative015 end."; + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative014 function end!"); + GTEST_LOG_(INFO) << "PowerMgrServiceNative014 end."; } } // namespace diff --git a/utils/hookmgr/include/power_hookmgr.h b/utils/hookmgr/include/power_hookmgr.h index 713af02fef52a726005f4f4941aac908ae6263c2..28f4e6373adfeada0460689dbb692da273072c95 100644 --- a/utils/hookmgr/include/power_hookmgr.h +++ b/utils/hookmgr/include/power_hookmgr.h @@ -23,9 +23,19 @@ namespace OHOS { namespace PowerMgr { enum class PowerHookStage : int32_t { POWER_HDI_CALLBACK_WAKEUP = 0, + POWER_MOVEMENT_SUBSCRIBE, + POWER_MOVEMENT_STATE, POWER_HOOK_STAGE_MAX = 1000, }; +typedef struct MovementSubscribeInfo { + bool subscribeFlag; +} MOVEMENT_SUBSCRIBE_INFO; + +typedef struct MovementStateInfo { + bool movementState; +} MOVEMENT_STATE_INFO; + HOOK_MGR* GetPowerHookMgr(); } // namespace PowerMgr } // namespace OHOS