回退 'Pull Request !1344 : [Bug]: 运动场景防误触接口修改'

This commit is contained in:
oh_ci 2024-09-30 02:09:06 +00:00 committed by Gitee
parent 1d138c359d
commit 0a2c8939ce
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 116 additions and 68 deletions

View File

@ -26,18 +26,12 @@ declare_args() {
power_manager_feature_screen_on_timeout_check = false power_manager_feature_screen_on_timeout_check = false
power_manager_feature_doubleclick_or_pickup = true power_manager_feature_doubleclick_or_pickup = true
power_manager_feature_force_sleep_broadcast = false power_manager_feature_force_sleep_broadcast = false
power_manager_feature_movement = false power_manager_feature_movement = true
power_manager_feature_charging_type_setting = false power_manager_feature_charging_type_setting = false
power_manager_feature_external_screen_management = false power_manager_feature_external_screen_management = false
} }
defines = [] defines = []
if (!defined(global_parts_info) || defined(global_parts_info.msdp_movement)) {
has_msdp_movement_part = true
} else {
has_msdp_movement_part = false
}
if (!defined(global_parts_info) || if (!defined(global_parts_info) ||
defined(global_parts_info.powermgr_display_manager)) { defined(global_parts_info.powermgr_display_manager)) {
has_display_manager_part = true has_display_manager_part = true

View File

@ -129,7 +129,7 @@ ohos_shared_library("powermgrservice") {
external_deps += [ "hitrace:hitrace_meter" ] external_deps += [ "hitrace:hitrace_meter" ]
} }
if (power_manager_feature_movement && has_msdp_movement_part) { if (power_manager_feature_movement) {
defines += [ "MSDP_MOVEMENT_ENABLE" ] defines += [ "MSDP_MOVEMENT_ENABLE" ]
} }

View File

@ -327,8 +327,9 @@ private:
RunningLockParam FillRunningLockParam(const RunningLockInfo& info, const uint64_t lockid, int32_t timeOutMS = -1); RunningLockParam FillRunningLockParam(const RunningLockInfo& info, const uint64_t lockid, int32_t timeOutMS = -1);
void SubscribeCommonEvent(); void SubscribeCommonEvent();
#ifdef MSDP_MOVEMENT_ENABLE #ifdef MSDP_MOVEMENT_ENABLE
void PowerExRegisterListener(); void RegisterMovementCallback();
void PowerExUnregisterListener(); void UnRegisterMovementCallback();
void ResetMovementState();
#endif #endif
#ifdef HAS_SENSORS_SENSOR_PART #ifdef HAS_SENSORS_SENSOR_PART
bool IsSupportSensor(SensorTypeId); bool IsSupportSensor(SensorTypeId);

View File

@ -99,7 +99,7 @@ void PowerMgrService::OnStart()
AddSystemAbilityListener(DISPLAY_MANAGER_SERVICE_ID); AddSystemAbilityListener(DISPLAY_MANAGER_SERVICE_ID);
AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID);
#ifdef MSDP_MOVEMENT_ENABLE #ifdef MSDP_MOVEMENT_ENABLE
PowerExRegisterListener(); AddSystemAbilityListener(MSDP_MOVEMENT_SERVICE_ID);
#endif #endif
SystemSuspendController::GetInstance().RegisterHdiStatusListener(); SystemSuspendController::GetInstance().RegisterHdiStatusListener();
if (!Publish(DelayedSpSingleton<PowerMgrService>::GetInstance())) { if (!Publish(DelayedSpSingleton<PowerMgrService>::GetInstance())) {
@ -597,7 +597,7 @@ void PowerMgrService::OnStop()
RemoveSystemAbilityListener(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID); RemoveSystemAbilityListener(DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID);
RemoveSystemAbilityListener(DISPLAY_MANAGER_SERVICE_ID); RemoveSystemAbilityListener(DISPLAY_MANAGER_SERVICE_ID);
#ifdef MSDP_MOVEMENT_ENABLE #ifdef MSDP_MOVEMENT_ENABLE
PowerExUnregisterListener(); RemoveSystemAbilityListener(MSDP_MOVEMENT_SERVICE_ID);
#endif #endif
#ifdef POWER_WAKEUPDOUBLE_OR_PICKUP_ENABLE #ifdef POWER_WAKEUPDOUBLE_OR_PICKUP_ENABLE
SettingHelper::UnregisterSettingWakeupDoubleObserver(); SettingHelper::UnregisterSettingWakeupDoubleObserver();
@ -608,61 +608,10 @@ void PowerMgrService::OnStop()
if (!OHOS::EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriberPtr_)) { if (!OHOS::EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriberPtr_)) {
POWER_HILOGE(COMP_SVC, "Power Onstop unregister to commonevent manager failed!"); POWER_HILOGE(COMP_SVC, "Power Onstop unregister to commonevent manager failed!");
} }
}
#ifdef MSDP_MOVEMENT_ENABLE #ifdef MSDP_MOVEMENT_ENABLE
static const char* MOVEMENT_SUBSCRIBER_CONFIG = "PowerExRegisterListener"; UnRegisterMovementCallback();
static const char* MOVEMENT_UNSUBSCRIBER_CONFIG = "PowerExUnregisterListener";
static const char* POWER_MANAGER_EXT_PATH = "libpower_manager_ext.z.so";
typedef void(*FuncMsdpRegisterListener)();
typedef void(*FuncMsdpUnregisterListener)();
void PowerMgrService::PowerExRegisterListener()
{
POWER_HILOGI(COMP_SVC, "Start to PowerExRegisterListener");
void *registerHandler = dlopen(POWER_MANAGER_EXT_PATH, RTLD_LAZY | RTLD_NODELETE);
if (registerHandler == nullptr) {
POWER_HILOGE(COMP_SVC, "Dlopen PowerExRegisterListener failed, reason : %{public}s", dlerror());
return;
}
FuncMsdpRegisterListener MsdpRegisterListenerFlag =
reinterpret_cast<FuncMsdpRegisterListener>(dlsym(registerHandler, MOVEMENT_SUBSCRIBER_CONFIG));
if (MsdpRegisterListenerFlag == nullptr) {
POWER_HILOGE(COMP_SVC, "PowerExRegisterListener is null, reason : %{public}s", dlerror());
dlclose(registerHandler);
registerHandler = nullptr;
return;
}
MsdpRegisterListenerFlag();
POWER_HILOGI(COMP_SVC, "PowerExRegisterListener Success");
dlclose(registerHandler);
registerHandler = nullptr;
return;
}
void PowerMgrService::PowerExUnregisterListener()
{
POWER_HILOGI(COMP_SVC, "Start to PowerExUnregisterListener");
void *unRegisterHandler = dlopen(POWER_MANAGER_EXT_PATH, RTLD_LAZY | RTLD_NODELETE);
if (unRegisterHandler == nullptr) {
POWER_HILOGE(COMP_SVC, "Dlopen PowerExUnregisterListener failed, reason : %{public}s", dlerror());
return;
}
FuncMsdpUnregisterListener MovementUnregisterListenerFlag =
reinterpret_cast<FuncMsdpUnregisterListener>(dlsym(unRegisterHandler, MOVEMENT_UNSUBSCRIBER_CONFIG));
if (MovementUnregisterListenerFlag == nullptr) {
POWER_HILOGE(COMP_SVC, "PowerExUnregisterListener is null, reason : %{public}s", dlerror());
dlclose(unRegisterHandler);
unRegisterHandler = nullptr;
return;
}
MovementUnregisterListenerFlag();
POWER_HILOGI(COMP_SVC, "PowerExUnregisterListener Success");
dlclose(unRegisterHandler);
unRegisterHandler = nullptr;
return;
}
#endif #endif
}
void PowerMgrService::Reset() void PowerMgrService::Reset()
{ {
@ -690,6 +639,16 @@ void PowerMgrService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::
std::lock_guard lock(lockMutex_); std::lock_guard lock(lockMutex_);
runningLockMgr_->ResetRunningLocks(); runningLockMgr_->ResetRunningLocks();
} }
#ifdef MSDP_MOVEMENT_ENABLE
if (systemAbilityId == MSDP_MOVEMENT_SERVICE_ID) {
auto power = DelayedSpSingleton<PowerMgrService>::GetInstance();
if (power == nullptr) {
POWER_HILOGI(COMP_SVC, "get PowerMgrService fail");
return;
}
power->ResetMovementState();
}
#endif
} }
void PowerMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) void PowerMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
@ -704,7 +663,100 @@ void PowerMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::str
if (systemAbilityId == DISPLAY_MANAGER_SERVICE_ID) { if (systemAbilityId == DISPLAY_MANAGER_SERVICE_ID) {
RegisterBootCompletedCallback(); RegisterBootCompletedCallback();
} }
#ifdef MSDP_MOVEMENT_ENABLE
if (systemAbilityId == MSDP_MOVEMENT_SERVICE_ID) {
auto power = DelayedSpSingleton<PowerMgrService>::GetInstance();
if (power == nullptr) {
POWER_HILOGI(COMP_SVC, "get PowerMgrService fail");
return;
} }
power->UnRegisterMovementCallback();
power->RegisterMovementCallback();
}
#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";
static const char* POWER_MANAGER_EXT_PATH = "libpower_manager_ext.z.so";
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 MovementSubscriberFlag =
reinterpret_cast<FuncMovementSubscriber>(dlsym(subscriberHandler, MOVEMENT_SUBSCRIBER_CONFIG));
if (MovementSubscriberFlag == nullptr) {
POWER_HILOGE(COMP_SVC, "RegisterMovementCallback is null, reason : %{public}s", dlerror());
dlclose(subscriberHandler);
subscriberHandler = nullptr;
return;
}
MovementSubscriberFlag();
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 MovementUnsubscriberFlag =
reinterpret_cast<FuncMovementUnsubscriber>(dlsym(unSubscriberHandler, MOVEMENT_UNSUBSCRIBER_CONFIG));
if (MovementUnsubscriberFlag == nullptr) {
POWER_HILOGE(COMP_SVC, "UnRegisterMovementCallback is null, reason : %{public}s", dlerror());
dlclose(unSubscriberHandler);
unSubscriberHandler = nullptr;
return;
}
MovementUnsubscriberFlag();
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 ResetMovementStateFlag =
reinterpret_cast<FuncResetMovementState>(dlsym(resetMovementStateHandler, RESET_MOVEMENT_STATE_CONFIG));
if (ResetMovementStateFlag == nullptr) {
POWER_HILOGE(COMP_SVC, "ResetMovementState is null, reason : %{public}s", dlerror());
dlclose(resetMovementStateHandler);
resetMovementStateHandler = nullptr;
return;
}
ResetMovementStateFlag();
POWER_HILOGI(COMP_SVC, "ResetMovementState Success");
dlclose(resetMovementStateHandler);
resetMovementStateHandler = nullptr;
return;
}
#endif
int32_t PowerMgrService::Dump(int32_t fd, const std::vector<std::u16string>& args) int32_t PowerMgrService::Dump(int32_t fd, const std::vector<std::u16string>& args)
{ {

View File

@ -296,10 +296,11 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative012, TestSize.Level0)
POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative012 begin."); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative012 begin.");
#ifdef MSDP_MOVEMENT_ENABLE #ifdef MSDP_MOVEMENT_ENABLE
auto stateMachine = std::make_shared<PowerStateMachine>(g_pmsTest); auto stateMachine = std::make_shared<PowerStateMachine>(g_pmsTest);
g_pmsTest->PowerExRegisterListener(); g_pmsTest->RegisterMovementCallback();
g_pmsTest->PowerExUnregisterListener(); g_pmsTest->UnRegisterMovementCallback();
g_pmsTest->ResetMovementState();
bool ret = stateMachine->IsMovementStateOn(); bool ret = stateMachine->IsMovementStateOn();
EXPECT_TRUE(ret == false || ret == true); EXPECT_TRUE(ret == false);
#endif #endif
POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative012 end."); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative012 end.");
} }