diff --git a/bundle.json b/bundle.json index 59e75cc38c5fa332a709288c0c51227dcd24f2cc..cc8bd5f2412f0cd17a237433183ce4eed9c92c04 100644 --- a/bundle.json +++ b/bundle.json @@ -76,7 +76,8 @@ "faultloggerd", "ffrt", "graphic_2d_ext", - "drivers_interface_rtos_extra", + "audio_framework", + "drivers_interface_tros_extra", "hdf_core" ], "third_party": [ diff --git a/multimodalinput.cfg b/multimodalinput.cfg index 9de5761015d05471d2ae9579fba231e7c736a932..29918ecec6c9cfc63242ed057754b81183fbb1bc 100644 --- a/multimodalinput.cfg +++ b/multimodalinput.cfg @@ -38,7 +38,8 @@ "ohos.permission.GET_RUNNING_INFO", "ohos.permission.REPORT_RESOURCE_SCHEDULE_EVENT", "ohos.permission.RUNNING_STATE_OBSERVER", - "ohos.permission.START_SYSTEM_DIALOG" + "ohos.permission.START_SYSTEM_DIALOG", + "ohos.permission.ACCESS_NOTIFICATION_POLICY" ], "start-mode" : "condition", "secon" : "u:r:multimodalinput:s0" diff --git a/multimodalinput_mini.gni b/multimodalinput_mini.gni index 91599deeb18ed9ba420a69b1b684e4d3d025045c..6b0fcb52ad14989a6cff7b3f8a4df3cb8cb74495 100644 --- a/multimodalinput_mini.gni +++ b/multimodalinput_mini.gni @@ -91,6 +91,7 @@ declare_args() { "delegate_task/src/delegate_tasks.cpp", "device_config/src/device_config_file_parser.cpp", "device_manager/src/input_device_manager.cpp", + "device_state_manager/src/device_event_monitor.cpp", "dfx/src/dfx_hisysevent.cpp", "display_state_manager/src/display_event_monitor.cpp", "event_dispatch/src/event_dispatch_handler.cpp", diff --git a/service/BUILD.gn b/service/BUILD.gn index 5a22ab66c99351ce979928a32d12144008169e89..3fba04b1dff26cf05b255ac001206c8f4b4f07e7 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", @@ -248,6 +250,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 0000000000000000000000000000000000000000..01543ebb6c2479265314a87c63691ac65b2fe41b --- /dev/null +++ b/service/device_state_manager/include/device_event_monitor.h @@ -0,0 +1,62 @@ +/* + * 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 "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(); + void SetCallState(const EventFwk::CommonEventData &eventData, int32_t callState); + int32_t GetCallState(); + void SetHasHandleRingMute(bool hasHandleRingMute); + private: + bool hasInit_ { false }; + int32_t callState_ { -1 }; + bool hasHandleRingMute_ { false }; + std::mutex stateMutex_; +}; +#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 0000000000000000000000000000000000000000..bf8c8495d3be271d92f05c794baf8a29b7a51f9c --- /dev/null +++ b/service/device_state_manager/src/device_event_monitor.cpp @@ -0,0 +1,107 @@ +/* + * 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 "audio_system_manager.h" +#include "device_event_monitor.h" + +#include "mmi_log.h" +#include "want.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "DeviceEventMonitor" + +namespace OHOS { +namespace MMI { +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 { + MMI_HILOGW("Device 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); + EventFwk::CommonEventSubscribeInfo commonEventSubscribeInfo(matchingSkills); + hasInit_ = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent( + std::make_shared(commonEventSubscribeInfo)); +} + +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); + if (hasHandleRingMute_ && callState_ == CALL_STATUS_INCOMING && + (callState == CALL_STATUS_ACTIVE || callState == CALL_STATUS_DISCONNECTED + || callState == CALL_STATUS_DISCONNECTING)) { + int32_t ret = AudioStandard::AudioSystemManager::GetInstance()->SetMute( + AudioStandard::AudioVolumeType::STREAM_RING, false); + if (ret != ERR_OK) { + MMI_HILOGE("Mute reply fail, ret:%{public}d", ret); + return; + } + MMI_HILOGI("Mute reply success"); + hasHandleRingMute_ = false; + } + callState_ = callState; +} + +int32_t DeviceEventMonitor::GetCallState() +{ + CALL_DEBUG_ENTER; + std::lock_guard lock(stateMutex_); + return callState_; +} + +void DeviceEventMonitor::SetHasHandleRingMute(bool hasHandleRingMute) +{ + hasHandleRingMute_ = hasHandleRingMute; +} +} // 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 f8c3fcddc98b5529fbbf403cecef2ef28565f8f5..4a1842b1c7a70cfd1c5bc66764953ec48b3c11eb 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" #ifdef OHOS_BUILD_ENABLE_INFRARED_EMITTER @@ -1238,6 +1239,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 62e9aa822abda64b150b354dd77150bf536b1621..5705b6072cdffd626c3c7b9e87ef999df3e47e84 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); @@ -115,6 +116,7 @@ private: bool enableCombineKey_ { true }; std::set foregroundPids_ {}; bool isForegroundExits_ { false }; + bool needSkipPowerKeyUp_ { false }; }; } // namespace MMI } // namespace OHOS diff --git a/service/subscriber/src/key_subscriber_handler.cpp b/service/subscriber/src/key_subscriber_handler.cpp index e2d0cde0b4efe81c0ae29e7f4321dbe47f578535..28cfe727f032b1bbacbf7a15239626f9afb39d92 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" @@ -261,10 +263,51 @@ 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; + } + int32_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 != ERR_OK) { + MMI_HILOGE("Set mute fail, ret:%{public}d", ret); + return false; + } + MMI_HILOGI("Set mute success"); + DEVICE_MONITOR->SetHasHandleRingMute(true); + if (keyEvent->GetKeyCode() == KeyEvent::KEYCODE_POWER) { + needSkipPowerKeyUp_ = true; + } + return true; + } else { + if (keyEvent->GetKeyCode() != KeyEvent::KEYCODE_POWER) { + MMI_HILOGD("Set mute success, block volumeKey"); + return true; + } + } + } + return false; +} + 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; @@ -277,6 +320,12 @@ bool KeySubscriberHandler::OnSubscribeKeyEvent(std::shared_ptr keyEven int32_t keyAction = keyEvent->GetKeyAction(); MMI_HILOGD("keyCode:%{public}d, keyAction:%{public}s", keyEvent->GetKeyCode(), KeyEvent::ActionToString(keyAction)); + if (needSkipPowerKeyUp_ && keyEvent->GetKeyCode() == KeyEvent::KEYCODE_POWER + && keyAction == KeyEvent::KEY_ACTION_UP) { + MMI_HILOGD("Skip power key up"); + needSkipPowerKeyUp_ = false; + return true; + } for (const auto &keyCode : keyEvent->GetPressedKeys()) { MMI_HILOGD("Pressed KeyCode:%{public}d", keyCode); }