From ba47a452a75517c3a1e5bf610ebd0a3129a07082 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Fri, 19 Apr 2024 14:31:21 +0800 Subject: [PATCH] =?UTF-8?q?RM003=20=E5=A4=9A=E6=A8=A1=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=94=B5=E6=BA=90=E9=94=AE=E5=92=8C=E9=9F=B3?= =?UTF-8?q?=E9=87=8F=E9=94=AE=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mayunteng_1 --- bundle.json | 3 +- multimodalinput_mini.gni | 1 + service/BUILD.gn | 3 + .../include/device_event_monitor.h | 67 +++++++++ .../src/device_event_monitor.cpp | 134 ++++++++++++++++++ service/module_loader/src/mmi_service.cpp | 5 + .../include/key_subscriber_handler.h | 1 + .../subscriber/src/key_subscriber_handler.cpp | 54 ++++++- 8 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 service/device_state_manager/include/device_event_monitor.h create mode 100644 service/device_state_manager/src/device_event_monitor.cpp diff --git a/bundle.json b/bundle.json index ad56c4f0c2..5eb6947c43 100644 --- a/bundle.json +++ b/bundle.json @@ -73,7 +73,8 @@ "relational_store", "faultloggerd", "ffrt", - "graphic_2d_ext" + "graphic_2d_ext", + "audio_framework" ], "third_party": [ "cJSON", diff --git a/multimodalinput_mini.gni b/multimodalinput_mini.gni index e6dec736e7..d30a484a4b 100644 --- a/multimodalinput_mini.gni +++ b/multimodalinput_mini.gni @@ -88,6 +88,7 @@ declare_args() { "app_state_manager/src/app_state_observer.cpp", "delegate_task/src/delegate_tasks.cpp", "device_config/src/device_config_file_parser.cpp", + "device_state_manager/src/device_event_monitor.cpp", "device_manager/src/input_device_manager.cpp", "dfx/src/dfx_hisysevent.cpp", "display_state_manager/src/display_event_monitor.cpp", diff --git a/service/BUILD.gn b/service/BUILD.gn index 37e1534f98..a1f9e9cb23 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -49,6 +49,7 @@ config("libmmi_server_config") { "device_config/include", "device_manager/include", "device_scalability/include", + "device_state_manager/include", "delegate_task/include", "display_state_manager/include", "event_dispatch/include", @@ -69,6 +70,7 @@ config("libmmi_server_config") { "timer_manager/include", "permission_helper/include", "${mmi_service_path}/connect_manager/include", + "${mmi_service_path}/device_state_manager/include", "${mmi_service_path}/filter/include", "${mmi_service_path}/module_loader/include", "${mmi_service_path}/nap_process/include", @@ -234,6 +236,7 @@ ohos_shared_library("libmmi-server") { "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "audio_framework:audio_client", "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", "data_share:datashare_consumer", diff --git a/service/device_state_manager/include/device_event_monitor.h b/service/device_state_manager/include/device_event_monitor.h new file mode 100644 index 0000000000..5a43adee06 --- /dev/null +++ b/service/device_state_manager/include/device_event_monitor.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2024 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. + */ + +#ifndef DEVICE_EVENT_MONITOR_H +#define DEVICE_EVENT_MONITOR_H + +#include "nocopyable.h" +#include "singleton.h" + +#include "common_event_data.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "define_multimodal.h" +#include "fingersense_manager.h" +#include "fingersense_wrapper.h" +#include "key_event_normalize.h" +#include "mmi_log.h" +#include "want.h" +#include "util.h" + +namespace OHOS { +namespace MMI { + +enum StateType { + CALL_STATUS_ACTIVE = 0, + CALL_STATUS_HOLDING = 1, + CALL_STATUS_DIALING = 2, + CALL_STATUS_ALERTING = 3, + CALL_STATUS_INCOMING = 4, + CALL_STATUS_WAITING = 5, + CALL_STATUS_DISCONNECTED = 6, + CALL_STATUS_DISCONNECTING = 7, + CALL_STATUS_IDLE = 8 +}; + +class DeviceEventMonitor final { + DECLARE_DELAYED_SINGLETON(DeviceEventMonitor); + public: + DISALLOW_COPY_AND_MOVE(DeviceEventMonitor); + + void InitCommonEventSubscriber(); + bool IsCommonEventSubscriberInit(); + void SetCallState(const EventFwk::CommonEventData &eventData, int32_t callState); + int32_t GetCallState(); + void UpdateShieldStatusOnScreenOn(); + void UpdateShieldStatusOnScreenOff(); + private: + int32_t shieldModeBeforeSreenOff_ { -1 }; + bool hasInit_ { false }; + int32_t callState_ { -1 }; +}; +#define DEVICE_MONITOR ::OHOS::DelayedSingleton::GetInstance() +} // namespace MMI +} // namespace OHOS +#endif // DEVICE_EVENT_MONITOR_H diff --git a/service/device_state_manager/src/device_event_monitor.cpp b/service/device_state_manager/src/device_event_monitor.cpp new file mode 100644 index 0000000000..2367234676 --- /dev/null +++ b/service/device_state_manager/src/device_event_monitor.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "device_event_monitor.h" + +#include "mmi_log.h" +#include "want.h" + +namespace OHOS { +namespace MMI { +namespace { + +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DeviceEventMonitor" }; +std::mutex stateMutex_; +} // namespace + +DeviceEventMonitor::DeviceEventMonitor() {} +DeviceEventMonitor::~DeviceEventMonitor() {} + +class DeviceChangedReceiver : public EventFwk::CommonEventSubscriber { +public: + explicit DeviceChangedReceiver(const OHOS::EventFwk::CommonEventSubscribeInfo& subscribeInfo) + : OHOS::EventFwk::CommonEventSubscriber(subscribeInfo) + { + MMI_HILOGD("DeviceEventMonitor register"); + } + + virtual ~DeviceChangedReceiver() = default; + __attribute__((no_sanitize("cfi"))) + + void OnReceiveEvent(const EventFwk::CommonEventData &eventData) + { + CALL_DEBUG_ENTER; + std::string action = eventData.GetWant().GetAction(); + if (action.empty()) { + MMI_HILOGE("action is empty"); + return; + } + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED) { + int32_t callState = 0; + DEVICE_MONITOR->SetCallState(eventData, callState); + MMI_HILOGI("state: %{public}d", callState); + } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON) { + MMI_HILOGD("display screen on"); + if (FINGERSENSE_WRAPPER->enableFingersense_ != nullptr) { + MMI_HILOGD("start enable fingersense"); + FINGERSENSE_WRAPPER->enableFingersense_(); + } + DEVICE_MONITOR->UpdateShieldStatusOnScreenOn(); + } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) { + MMI_HILOGD("display screen off"); + if (FINGERSENSE_WRAPPER->disableFingerSense_ != nullptr) { + FINGERSENSE_WRAPPER->disableFingerSense_(); + } + DEVICE_MONITOR->UpdateShieldStatusOnScreenOff(); + } else { + MMI_HILOGW("Screen changed receiver event: unknown"); + return; + } + } +}; + +void DeviceEventMonitor::InitCommonEventSubscriber() +{ + CALL_DEBUG_ENTER; + if (hasInit_) { + MMI_HILOGE("current common event has subscribered"); + return; + } + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); + EventFwk::CommonEventSubscribeInfo commonEventSubscribeInfo(matchingSkills); + hasInit_ = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent( + std::make_shared(commonEventSubscribeInfo)); +} + +bool DeviceEventMonitor::IsCommonEventSubscriberInit() +{ + return hasInit_; +} + +void DeviceEventMonitor::SetCallState(const EventFwk::CommonEventData &eventData, int32_t callState) +{ + CALL_DEBUG_ENTER; + std::lock_guard lock(stateMutex_); + callState = eventData.GetWant().GetIntParam("state", -1); + MMI_HILOGI("state %{public}d", callState); + callState_ = callState; +} + +int32_t DeviceEventMonitor::GetCallState() +{ + CALL_DEBUG_ENTER; + std::lock_guard lock(stateMutex_); + return callState_; +} + +void DeviceEventMonitor::UpdateShieldStatusOnScreenOn() +{ + CALL_DEBUG_ENTER; + if (shieldModeBeforeSreenOff_ != SHIELD_MODE::UNSET_MODE) { + KeyEventHdr->SetCurrentShieldMode(shieldModeBeforeSreenOff_); + } else { + MMI_HILOGD("shield mode before screen off: %{public}d", shieldModeBeforeSreenOff_); + } +} + +void DeviceEventMonitor::UpdateShieldStatusOnScreenOff() +{ + CALL_DEBUG_ENTER; + shieldModeBeforeSreenOff_ = KeyEventHdr->GetCurrentShieldMode(); + if (shieldModeBeforeSreenOff_ != SHIELD_MODE::UNSET_MODE) { + KeyEventHdr->SetCurrentShieldMode(SHIELD_MODE::UNSET_MODE); + } else { + MMI_HILOGD("shield mode before screen off: %{public}d", shieldModeBeforeSreenOff_); + } +} + +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/service/module_loader/src/mmi_service.cpp b/service/module_loader/src/mmi_service.cpp index 4a6e3dd8c2..c9899e3825 100644 --- a/service/module_loader/src/mmi_service.cpp +++ b/service/module_loader/src/mmi_service.cpp @@ -54,6 +54,7 @@ #include "key_command_handler.h" #include "touch_event_normalize.h" #include "display_event_monitor.h" +#include "device_event_monitor.h" #include "fingersense_wrapper.h" #include "multimodal_input_preferences_manager.h" @@ -1234,6 +1235,10 @@ void MMIService::OnAddSystemAbility(int32_t systemAbilityId, const std::string & MMI_HILOGI("Init app state observer start"); APP_OBSERVER_MGR->InitAppStateObserver(); } + if (systemAbilityId == COMMON_EVENT_SERVICE_ID) { + DEVICE_MONITOR->InitCommonEventSubscriber(); + MMI_HILOGD("Common event service started"); + } } int32_t MMIService::SubscribeKeyEvent(int32_t subscribeId, const std::shared_ptr option) diff --git a/service/subscriber/include/key_subscriber_handler.h b/service/subscriber/include/key_subscriber_handler.h index 2fe867d738..fb748c257b 100644 --- a/service/subscriber/include/key_subscriber_handler.h +++ b/service/subscriber/include/key_subscriber_handler.h @@ -70,6 +70,7 @@ private: bool HandleKeyDown(const std::shared_ptr &keyEvent); bool HandleKeyUp(const std::shared_ptr &keyEvent); bool HandleKeyCancel(const std::shared_ptr &keyEvent); + bool HandleRingMute(std::shared_ptr keyEvent); bool IsPreKeysMatch(const std::set &preKeys, const std::vector &pressedKeys) const; void NotifySubscriber(std::shared_ptr keyEvent, const std::shared_ptr &subscriber); diff --git a/service/subscriber/src/key_subscriber_handler.cpp b/service/subscriber/src/key_subscriber_handler.cpp index 8c46564921..a08f65879f 100644 --- a/service/subscriber/src/key_subscriber_handler.cpp +++ b/service/subscriber/src/key_subscriber_handler.cpp @@ -15,9 +15,11 @@ #include "key_subscriber_handler.h" +#include "audio_system_manager.h" #include "app_state_observer.h" #include "bytrace_adapter.h" #include "define_multimodal.h" +#include "device_event_monitor.h" #include "dfx_hisysevent.h" #include "error_multimodal.h" #include "input_event_data_transformation.h" @@ -245,10 +247,60 @@ bool KeySubscriberHandler::IsEnableCombineKeySwipe(const std::shared_ptr keyEvent) +{ + CALL_DEBUG_ENTER; + CHKPF(keyEvent); + if (keyEvent->GetKeyCode() != KeyEvent::KEYCODE_VOLUME_DOWN && + keyEvent->GetKeyCode() != KeyEvent::KEYCODE_VOLUME_UP && + keyEvent->GetKeyCode() != KeyEvent::KEYCODE_POWER) { + MMI_HILOGE("There is no need to set mute."); + return false; + } + uint32_t ret = -1; + if (DEVICE_MONITOR->GetCallState() == StateType::CALL_STATUS_INCOMING) { + if (!AudioStandard::AudioSystemManager::GetInstance()->IsStreamMute( + AudioStandard::AudioVolumeType::STREAM_RING)) { + ret = AudioStandard::AudioSystemManager::GetInstance()->SetMute( + AudioStandard::AudioVolumeType::STREAM_RING, true); + if (ret != 0) { + MMI_HILOGE("Set mute fail, ret:%{public}d", ret); + return false; + } + MMI_HILOGI("Set mute success!"); + } else { + if (keyEvent->GetKeyCode() == KeyEvent::KEYCODE_POWER) { + MMI_HILOGE("Set mute success keycode power miss!"); + return false; + } + MMI_HILOGI("Set mute success keycode power success!"); + } + } + if (DEVICE_MONITOR->GetCallState() == StateType::CALL_STATUS_ACTIVE || DEVICE_MONITOR->GetCallState() == + StateType::CALL_STATUS_DISCONNECTED + || DEVICE_MONITOR->GetCallState() == StateType::CALL_STATUS_DISCONNECTING) { + int32_t initVol = AudioStandard::AudioSystemManager::GetInstance()->GetVolume( + AudioStandard::AudioVolumeType::STREAM_RING); + ret = AudioStandard::AudioSystemManager::GetInstance()->SetMute( + AudioStandard::AudioVolumeType::STREAM_RING, false); + if (ret != 0) { + MMI_HILOGE("Mute reply fail, ret:%{public}d", ret); + return false; + } + MMI_HILOGI("Mute reply success."); + } + return true; +} + bool KeySubscriberHandler::OnSubscribeKeyEvent(std::shared_ptr keyEvent) { + CALL_DEBUG_ENTER; CHKPF(keyEvent); + if (HandleRingMute(keyEvent)) { + MMI_HILOGI("Mute Ring in subscribe keyEvent"); + return true; + } if (!IsEnableCombineKey(keyEvent)) { MMI_HILOGI("Combine key is taken over in subscribe keyEvent"); return false; -- Gitee