fix: add new feature

Signed-off-by: yanghang <kongwei13@h-partners.com>
This commit is contained in:
yanghang 2024-11-13 18:00:12 +08:00
parent 7f054dd7ed
commit 34edf20acc
6 changed files with 42 additions and 1 deletions

View File

@ -36,7 +36,8 @@
"power_manager_feature_screen_on_timeout_check",
"power_manager_feature_dialog_path",
"power_manager_feature_charging_type_setting",
"power_manager_feature_external_screen_management"
"power_manager_feature_external_screen_management",
"power_manager_feature_block_long_press"
],
"adapted_system_type": [
"standard"

View File

@ -30,6 +30,7 @@ declare_args() {
power_manager_feature_movement = true
power_manager_feature_charging_type_setting = false
power_manager_feature_external_screen_management = false
power_manager_feature_block_long_press = false
}
defines = []

View File

@ -220,6 +220,10 @@ ohos_shared_library("powermgrservice") {
defines += [ "POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT" ]
}
if (power_manager_feature_block_long_press) {
defines += [ "POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS" ]
}
if (factory == true) {
defines += [ "CONFIG_FACTORY_MODE" ]
}

View File

@ -560,5 +560,18 @@ void SettingHelper::SetSettingWakeupLid(bool enable)
int32_t value = enable ? WAKEUP_SOURCE_OPEN : WAKEUP_SOURCE_CLOSE;
SetSettingIntValue(SETTING_POWER_WAKEUP_LID_KEY, value);
}
#ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS
const std::string SettingHelper::GetBlockLongPress()
{
SettingProvider& SettingProvider = SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
std::string longPress;
ErrCode ret = settingProvider.GetStringValue(SETTING_POWER_BLOCK_LONG_PRESS_KEY, longPress);
if (ret != ERR_OK) {
POWER_HILOGE(COMP_UTILS, "get setting power long press key failed, ret =%{public}d", ret);
}
return longPress;
}
#endif
} // namespace PowerMgr
} // namespace OHOS

View File

@ -105,6 +105,9 @@ public:
static bool GetSettingWakeupLid(const std::string& key = SETTING_POWER_WAKEUP_LID_KEY);
static void SetSettingWakeupLid(bool enable);
static bool IsWakeupLidSettingValid();
#ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS
static const std::string GetBlockLongPress();
#endif
private:
static bool IsSettingKeyValid(const std::string& key);
@ -127,6 +130,10 @@ private:
static constexpr const char* SETTING_DISPLAY_OFF_TIME_KEY {"settings.display.screen_off_timeout"};
static constexpr const char* SETTING_POWER_SUSPEND_SOURCES_KEY {"settings.power.suspend_sources"};
#endif
#ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS
static constexpr const char* SETTING_POWER_BLOCK_LONG_PRESS_KEY {"settings.power.block_long_press"};
#endif
static constexpr const char* SETTING_AUTO_ADJUST_BRIGHTNESS_KEY {"settings.display.auto_screen_brightness"};
static constexpr const char* SETTING_BRIGHTNESS_KEY {"settings.display.screen_brightness_status"};
static constexpr const char* SETTING_VIBRATION_KEY {"physic_navi_haptic_feedback_enabled"};

View File

@ -36,6 +36,10 @@
#include "power_mgr_service.h"
#include "power_vibrator.h"
#ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS
#include "setting_helper.h"
#endif
using namespace OHOS::MMI;
using namespace OHOS::AAFwk;
@ -52,6 +56,9 @@ std::atomic_bool g_longPressShow = false;
int32_t g_retryCount = 1;
sptr<IRemoteObject> g_remoteObject = nullptr;
const std::string DIALOG_CONFIG_PATH = "etc/systemui/poweroff_config.json";
#ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS
const std::string BLOCK_LONG_PRESS = "1";
#endif
} // namespace
std::string ShutdownDialog::bundleName_ = "com.ohos.powerdialog";
@ -81,6 +88,14 @@ void ShutdownDialog::KeyMonitorInit()
longPressId_ =
InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [this](std::shared_ptr<KeyEvent> keyEvent) {
POWER_HILOGI(FEATURE_SHUTDOWN, "Receive long press powerkey");
#ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS
//If the power button is shielded, the shutdown screen is not displayed.
auto longPress = SettingHelper::GetBlockLongPress();
if (longPress == BLOCK_LONG_PRESS) {
POWER_HILOGI(FEATURE_SHUTDOWN, "need block power.");
return;
}
#endif
ConnectSystemUi();
StartVibrator();
});