From 6963ba1523b3e97670559ca91b689eb9b720c257 Mon Sep 17 00:00:00 2001 From: Du Jiang Date: Wed, 19 Jan 2022 15:55:50 +0800 Subject: [PATCH 1/4] Add power dialog which is triggered by power key Change-Id: I0cc3fd9b7a924e03c53f31e0468496257d208062 Signed-off-by: Du Jiang --- frameworks/dialog/dialog_ui/js/BUILD.gn | 27 ++++++++++++++ .../dialog/dialog_ui/js/common/unused.png | 0 .../dialog/dialog_ui/js/i18n/en-US.json | 5 +++ .../dialog/dialog_ui/js/i18n/zh-CN.json | 5 +++ .../dialog/dialog_ui/js/pages/index/index.css | 35 ++++++++++++++++++ .../dialog/dialog_ui/js/pages/index/index.hml | 14 ++++++++ .../dialog/dialog_ui/js/pages/index/index.js | 21 +++++++++++ services/BUILD.gn | 7 +++- services/native/include/power_mgr_service.h | 1 + .../native/include/powerms_event_handler.h | 1 + services/native/src/power_mgr_service.cpp | 36 ++++++++++++++++++- services/native/src/powerms_event_handler.cpp | 4 +++ 12 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 frameworks/dialog/dialog_ui/js/BUILD.gn create mode 100644 frameworks/dialog/dialog_ui/js/common/unused.png create mode 100644 frameworks/dialog/dialog_ui/js/i18n/en-US.json create mode 100644 frameworks/dialog/dialog_ui/js/i18n/zh-CN.json create mode 100644 frameworks/dialog/dialog_ui/js/pages/index/index.css create mode 100644 frameworks/dialog/dialog_ui/js/pages/index/index.hml create mode 100644 frameworks/dialog/dialog_ui/js/pages/index/index.js diff --git a/frameworks/dialog/dialog_ui/js/BUILD.gn b/frameworks/dialog/dialog_ui/js/BUILD.gn new file mode 100644 index 00000000..c485c0da --- /dev/null +++ b/frameworks/dialog/dialog_ui/js/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/powermgr/power_manager/powermgr.gni") +import("//foundation/ace/ace_engine/build/ace_gen_sa_dialog_js.gni") + +gen_sa_dialog_js("dialog_js_files_etc") { + project_path = "//base/powermgr/power_manager/frameworks/dialog/dialog_ui/js" + i18n_files = [ + "i18n/en-US.json", + "i18n/zh-CN.json", + ] + common_files = [] + dialog_name = "power_dialog" + part_name = "${powermgr_native_part_name}" + subsystem_name = "powermgr" +} diff --git a/frameworks/dialog/dialog_ui/js/common/unused.png b/frameworks/dialog/dialog_ui/js/common/unused.png new file mode 100644 index 00000000..e69de29b diff --git a/frameworks/dialog/dialog_ui/js/i18n/en-US.json b/frameworks/dialog/dialog_ui/js/i18n/en-US.json new file mode 100644 index 00000000..8971f6a9 --- /dev/null +++ b/frameworks/dialog/dialog_ui/js/i18n/en-US.json @@ -0,0 +1,5 @@ +{ + "message":{ + "shutdown": "Do you want to shut down ?" + } +} diff --git a/frameworks/dialog/dialog_ui/js/i18n/zh-CN.json b/frameworks/dialog/dialog_ui/js/i18n/zh-CN.json new file mode 100644 index 00000000..142ecdce --- /dev/null +++ b/frameworks/dialog/dialog_ui/js/i18n/zh-CN.json @@ -0,0 +1,5 @@ +{ + "message": { + "shutdown": "请确认是否关机" + } +} diff --git a/frameworks/dialog/dialog_ui/js/pages/index/index.css b/frameworks/dialog/dialog_ui/js/pages/index/index.css new file mode 100644 index 00000000..8921a187 --- /dev/null +++ b/frameworks/dialog/dialog_ui/js/pages/index/index.css @@ -0,0 +1,35 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +.btn { + width: 50%; + height: 100px; + font-size: 40px; +} + +.img { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 20%; +} diff --git a/frameworks/dialog/dialog_ui/js/pages/index/index.hml b/frameworks/dialog/dialog_ui/js/pages/index/index.hml new file mode 100644 index 00000000..172051c3 --- /dev/null +++ b/frameworks/dialog/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,14 @@ +
+ + {{ $t('message.shutdown') }} {{ title }} + + + {{ message }} + + + +
diff --git a/frameworks/dialog/dialog_ui/js/pages/index/index.js b/frameworks/dialog/dialog_ui/js/pages/index/index.js new file mode 100644 index 00000000..8d15a371 --- /dev/null +++ b/frameworks/dialog/dialog_ui/js/pages/index/index.js @@ -0,0 +1,21 @@ +import router from '@ohos.router' + +export default { + data: { + message: router.getParams().message, + confirmButton: router.getParams().confirmButton, + cancelButton: router.getParams().cancelButton, + }, + onInit() { + this.title = this.$t('message.shutdown'); + console.info('getParams: ' + router.getParams()); + }, + onConfirm() { + console.info('click confirm'); + callNativeHandler("EVENT_CONFIRM", "confirm"); + }, + onCancel() { + console.info('click cancel'); + callNativeHandler("EVENT_CANCEL", "cancel"); + } +} diff --git a/services/BUILD.gn b/services/BUILD.gn index 5c6bfdb2..fab8fc55 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -15,9 +15,12 @@ import("//base/powermgr/power_manager/powermgr.gni") config("powermgr_private_config") { include_dirs = [ - "//utils/system/safwk/native/include", + "//base/global/resmgr_standard/interfaces/innerkits/include/", "//base/sensors/sensor/interfaces/native/include", "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", + "//foundation/windowmanager/interfaces/innerkits/wm/", + "//third_party/flutter/skia/", + "//utils/system/safwk/native/include", ] } @@ -57,10 +60,12 @@ ohos_shared_library("powermgrservice") { public_configs = [ ":powermgr_public_config" ] deps = [ + "${powermgr_framework_path}/dialog/dialog_ui/js:dialog_js_files_etc", "${powermgr_native_innerkits_path}:powermgr_client", "${powermgr_utils_path}:powermgr_utils", "native/src/actions:powermgr_actions", "//drivers/peripheral/display/hal:hdi_display_device", + "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr", "//utils/native/base:utils", ] diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h index 84d38cf1..b953653c 100644 --- a/services/native/include/power_mgr_service.h +++ b/services/native/include/power_mgr_service.h @@ -78,6 +78,7 @@ public: virtual void SetDeviceMode(const uint32_t& mode) override; virtual uint32_t GetDeviceMode() override; + void HandleShowdownRequest(); void HandleKeyEvent(int32_t keyCode); void HandlePointEvent(); std::shared_ptr GetHandler() const diff --git a/services/native/include/powerms_event_handler.h b/services/native/include/powerms_event_handler.h index b1312887..ab5f8dd2 100644 --- a/services/native/include/powerms_event_handler.h +++ b/services/native/include/powerms_event_handler.h @@ -32,6 +32,7 @@ public: CHECK_USER_ACTIVITY_SLEEP_TIMEOUT_MSG = 4, SYSTEM_WAKE_UP_MSG = 5, POWER_KEY_TIMEOUT_MSG = 6, + SHUTDOWN_REQUEST_MSG = 7, }; PowermsEventHandler(const std::shared_ptr& runner, diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index 9cd937d9..4928a3d1 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -29,6 +29,8 @@ #include "permission.h" #include "power_common.h" #include "power_mgr_dumper.h" +#include "ui_service_mgr_client.h" +#include "wm_common.h" namespace OHOS { namespace PowerMgr { @@ -163,7 +165,7 @@ void PowerMgrService::KeyMonitorInit() int32_t id = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [this](std::shared_ptr keyEvent) { POWER_HILOGI(MODULE_SERVICE, "Receive long press powerkey"); - this->ShutDownDevice(REASON_POWER_KEY); + handler_->RemoveEvent(PowermsEventHandler::SHUTDOWN_REQUEST_MSG); }); keyOption.reset(); @@ -199,6 +201,38 @@ void PowerMgrService::KeyMonitorInit() InputManager::GetInstance()->AddMonitor(std::static_pointer_cast(callback)); } +void PowerMgrService::HandleShowdownRequest() +{ + POWER_HILOGI(MODULE_SERVICE, "HandleShutdown"); + // show dialog + const std::string params = "{\"title\":\"Show down!\"," \ + "\"message\":\"Do you want to shut down?\"," \ + "\"confirmButton\":\"Confirm\", \"cancelButton\":\"Cancel\"}"; + const int POSTION_X = 200; + const int POSTION_Y = 200; + const int WIDTH = 500; + const int HEIGHT = 500; + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "power_dialog", + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + POSTION_X, + POSTION_Y, + WIDTH, + HEIGHT, + [this](int32_t id, const std::string& event, const std::string& params) { + POWER_HILOGI(MODULE_SERVICE, "Dialog callback: %{public}s, %{public}s", + event.c_str(), params.c_str()); + if (event == "EVENT_CONFIRM") { + this->ShutDownDevice(REASON_POWER_KEY); + } else if (event == "EVENT_CANCEL") { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + } + }); + + return; +} + void PowerMgrService::HandlePowerKeyUp() { POWER_HILOGI(MODULE_SERVICE, "Receive release powerkey"); diff --git a/services/native/src/powerms_event_handler.cpp b/services/native/src/powerms_event_handler.cpp index ffaecc64..0509d23e 100644 --- a/services/native/src/powerms_event_handler.cpp +++ b/services/native/src/powerms_event_handler.cpp @@ -59,6 +59,10 @@ void PowermsEventHandler::ProcessEvent([[maybe_unused]] const AppExecFwk::InnerE pmsptr->HandlePowerKeyTimeout(); break; } + case SHUTDOWN_REQUEST_MSG: { + pmsptr->HandleShowdownRequest(); + break; + } default: POWER_HILOGD(MODULE_SERVICE, "PowermsEventHandler::no event id matched."); } -- Gitee From 54410f528351c80910665df1cec47f47962acf41 Mon Sep 17 00:00:00 2001 From: Du Jiang Date: Wed, 19 Jan 2022 16:40:56 +0800 Subject: [PATCH 2/4] Show 3 buttons in power dialog There are 3 bottuns in dialog : shutdown, reboot, cancel Change-Id: Ib54310139123399c8742537875d2000330029554 Signed-off-by: Du Jiang --- frameworks/dialog/dialog_ui/js/i18n/en-US.json | 5 ++++- frameworks/dialog/dialog_ui/js/i18n/zh-CN.json | 5 ++++- .../dialog/dialog_ui/js/pages/index/index.hml | 13 +++++-------- .../dialog/dialog_ui/js/pages/index/index.js | 14 +++++++++----- services/native/src/power_mgr_service.cpp | 8 +++++--- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/frameworks/dialog/dialog_ui/js/i18n/en-US.json b/frameworks/dialog/dialog_ui/js/i18n/en-US.json index 8971f6a9..6f4ec153 100644 --- a/frameworks/dialog/dialog_ui/js/i18n/en-US.json +++ b/frameworks/dialog/dialog_ui/js/i18n/en-US.json @@ -1,5 +1,8 @@ { "message":{ - "shutdown": "Do you want to shut down ?" + "title": "Do you want to shut down ?", + "shutdownButton": "SHUT DOWN", + "rebootButton": "REBOOT", + "cancelButton": "CANCEL" } } diff --git a/frameworks/dialog/dialog_ui/js/i18n/zh-CN.json b/frameworks/dialog/dialog_ui/js/i18n/zh-CN.json index 142ecdce..61eb14b4 100644 --- a/frameworks/dialog/dialog_ui/js/i18n/zh-CN.json +++ b/frameworks/dialog/dialog_ui/js/i18n/zh-CN.json @@ -1,5 +1,8 @@ { "message": { - "shutdown": "请确认是否关机" + "title": "请确认是否关机", + "shutdownButton": "关机", + "rebootButton": "重启", + "cancelButton": "取消" } } diff --git a/frameworks/dialog/dialog_ui/js/pages/index/index.hml b/frameworks/dialog/dialog_ui/js/pages/index/index.hml index 172051c3..6e164313 100644 --- a/frameworks/dialog/dialog_ui/js/pages/index/index.hml +++ b/frameworks/dialog/dialog_ui/js/pages/index/index.hml @@ -1,12 +1,9 @@
- - {{ $t('message.shutdown') }} {{ title }} - - - {{ message }} - - + - -
-- Gitee