From 1b18940a076f8495ac1de23799b4a58cdc4a0675 Mon Sep 17 00:00:00 2001 From: lvqiang214 Date: Mon, 21 Apr 2025 20:35:47 +0800 Subject: [PATCH] sync Signed-off-by: lvqiang214 --- bundle.json | 1 + intell_voice_service.gni | 1 + services/BUILD.gn | 1 - services/intell_voice_engine/BUILD.gn | 12 ++ .../server/base/engine_factory.cpp | 5 + .../strategy/silence_update_strategy.cpp | 30 +---- .../strategy/silence_update_strategy.h | 2 - .../high_power_adapter_listener.cpp | 104 +++++++++++++++ .../high_power/high_power_adapter_listener.h | 47 +++++++ .../high_power/high_power_wakeup_engine.cpp | 125 ++++++++++++++++++ .../high_power/high_power_wakeup_engine.h | 57 ++++++++ .../server/wakeup/wakeup_engine.cpp | 31 +---- .../server/wakeup/wakeup_engine.h | 1 - services/intell_voice_service/BUILD.gn | 1 + .../inc/intell_voice_definitions.h | 3 +- .../sa/intell_voice_service_manager.cpp | 32 +---- .../server/sa/intell_voice_service_manager.h | 1 - services/intell_voice_trigger/BUILD.gn | 1 - .../server/trigger_helper.cpp | 4 +- utils/BUILD.gn | 1 + utils/intell_voice_util.cpp | 26 ++++ utils/intell_voice_util.h | 3 + 22 files changed, 396 insertions(+), 93 deletions(-) create mode 100644 services/intell_voice_engine/server/wakeup/high_power/high_power_adapter_listener.cpp create mode 100644 services/intell_voice_engine/server/wakeup/high_power/high_power_adapter_listener.h create mode 100644 services/intell_voice_engine/server/wakeup/high_power/high_power_wakeup_engine.cpp create mode 100644 services/intell_voice_engine/server/wakeup/high_power/high_power_wakeup_engine.h diff --git a/bundle.json b/bundle.json index 77f5e22..9270aba 100755 --- a/bundle.json +++ b/bundle.json @@ -50,6 +50,7 @@ "intelligent_voice_framework_trigger_enable", "intelligent_voice_framework_engine_enable", "intelligent_voice_framework_only_first_stage", + "intelligent_voice_framework_only_second_stage", "intelligent_voice_framework_window_manager_enable" ], "build": { diff --git a/intell_voice_service.gni b/intell_voice_service.gni index ff62e54..94930f1 100644 --- a/intell_voice_service.gni +++ b/intell_voice_service.gni @@ -16,6 +16,7 @@ declare_args() { intelligent_voice_framework_trigger_enable = true intelligent_voice_framework_engine_enable = true intelligent_voice_framework_only_first_stage = false + intelligent_voice_framework_only_second_stage = false intelligent_voice_framework_window_manager_enable = false if (defined(global_parts_info) && defined(global_parts_info.telephony_state_registry) && diff --git a/services/BUILD.gn b/services/BUILD.gn index 22cd1ee..179e865 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -42,7 +42,6 @@ ohos_shared_library("intell_voice_proxy") { "drivers_interface_intelligent_voice:libintell_voice_engine_proxy_1.0", "drivers_interface_intelligent_voice:libintell_voice_engine_proxy_1.1", "drivers_interface_intelligent_voice:libintell_voice_engine_proxy_1.2", - "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", "hdf_core:libhdi", diff --git a/services/intell_voice_engine/BUILD.gn b/services/intell_voice_engine/BUILD.gn index 1329ba8..586bb34 100644 --- a/services/intell_voice_engine/BUILD.gn +++ b/services/intell_voice_engine/BUILD.gn @@ -56,6 +56,13 @@ ohos_source_set("engine_source") { "server/wakeup/wakeup_source_stop_callback.cpp", ] + if (intelligent_voice_framework_only_second_stage) { + sources += [ + "server/wakeup/high_power/high_power_adapter_listener.cpp", + "server/wakeup/high_power/high_power_wakeup_engine.cpp", + ] + } + include_dirs = [ "inc", "../../../../ai/intelligent_voice_framework/utils", @@ -71,6 +78,7 @@ ohos_source_set("engine_source") { "server/utils", "server/wakeup", "server/wakeup/headset", + "server/wakeup/high_power", ] external_deps = [ @@ -113,6 +121,10 @@ ohos_source_set("engine_source") { "-DUSE_FFRT", ] + if (intelligent_voice_framework_only_second_stage) { + cflags_cc += [ "-DONLY_SECOND_STAGE" ] + } + defines = [] if (build_variant == "root") { defines += [ "INTELL_VOICE_BUILD_VARIANT_ROOT" ] diff --git a/services/intell_voice_engine/server/base/engine_factory.cpp b/services/intell_voice_engine/server/base/engine_factory.cpp index a68e08e..31f3a58 100755 --- a/services/intell_voice_engine/server/base/engine_factory.cpp +++ b/services/intell_voice_engine/server/base/engine_factory.cpp @@ -17,6 +17,7 @@ #include "enroll_engine.h" #include "wakeup_engine_obj.h" #include "update_engine.h" +#include "high_power_wakeup_engine.h" #include "intell_voice_log.h" #include "intell_voice_generic_factory.h" @@ -33,7 +34,11 @@ sptr EngineFactory::CreateEngineInst(IntellVoiceEngineType type, con engine = SptrFactory::CreateInstance(param); break; case INTELL_VOICE_WAKEUP: +#ifdef ONLY_SECOND_STAGE + engine = SptrFactory::CreateInstance(param); +#else engine = SptrFactory::CreateInstance(param); +#endif break; case INTELL_VOICE_UPDATE: engine = SptrFactory::CreateInstance(param, reEnroll); diff --git a/services/intell_voice_engine/server/update/controller/strategy/silence_update_strategy.cpp b/services/intell_voice_engine/server/update/controller/strategy/silence_update_strategy.cpp index 7f4a67b..e950f7d 100644 --- a/services/intell_voice_engine/server/update/controller/strategy/silence_update_strategy.cpp +++ b/services/intell_voice_engine/server/update/controller/strategy/silence_update_strategy.cpp @@ -18,9 +18,7 @@ #include "intell_voice_log.h" #include "scope_guard.h" #include "update_engine_utils.h" -#include "history_info_mgr.h" -#include "ability_manager_client.h" -#include "intell_voice_definitions.h" +#include "intell_voice_util.h" #define LOG_TAG "SilenceUpdateStrategy" @@ -53,30 +51,6 @@ int SilenceUpdateStrategy::GetRetryTimes() return SILENCE_UPDATE_RETRY_TIMES; } -void SilenceUpdateStrategy::NotifyUpdateFail() -{ - AAFwk::Want want; - HistoryInfoMgr &historyInfoMgr = HistoryInfoMgr::GetInstance(); - - std::string bundleName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_BUNDLE_NAME); - std::string abilityName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_ABILITY_NAME); - INTELL_VOICE_LOG_INFO("bundleName:%{public}s, abilityName:%{public}s", bundleName.c_str(), abilityName.c_str()); - if (bundleName.empty() || abilityName.empty()) { - INTELL_VOICE_LOG_ERROR("bundle name is empty or ability name is empty"); - return; - } - want.SetElementName(bundleName, abilityName); - want.SetParam("serviceName", std::string("intell_voice")); - want.SetParam("servicePid", getpid()); - want.SetParam("eventType", std::string("update_event")); - auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance(); - if (abilityManagerClient == nullptr) { - INTELL_VOICE_LOG_ERROR("abilityManagerClient is nullptr"); - return; - } - abilityManagerClient->StartAbility(want); -} - int SilenceUpdateStrategy::OnUpdateCompleteCallback(const int result, bool isLast) { if (!isLast || result == 0) { @@ -84,7 +58,7 @@ int SilenceUpdateStrategy::OnUpdateCompleteCallback(const int result, bool isLas } INTELL_VOICE_LOG_INFO("notify silence update fail"); - NotifyUpdateFail(); + IntellVoiceUtil::StartAbility("update_event"); return 0; } } diff --git a/services/intell_voice_engine/server/update/controller/strategy/silence_update_strategy.h b/services/intell_voice_engine/server/update/controller/strategy/silence_update_strategy.h index 73cb219..c80ab05 100644 --- a/services/intell_voice_engine/server/update/controller/strategy/silence_update_strategy.h +++ b/services/intell_voice_engine/server/update/controller/strategy/silence_update_strategy.h @@ -27,8 +27,6 @@ public: UpdatePriority GetUpdatePriority() override; int GetRetryTimes() override; int OnUpdateCompleteCallback(const int result, bool isLast) override; -private: - static void NotifyUpdateFail(); }; } } diff --git a/services/intell_voice_engine/server/wakeup/high_power/high_power_adapter_listener.cpp b/services/intell_voice_engine/server/wakeup/high_power/high_power_adapter_listener.cpp new file mode 100644 index 0000000..e6e5049 --- /dev/null +++ b/services/intell_voice_engine/server/wakeup/high_power/high_power_adapter_listener.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2025 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 "high_power_adapter_listener.h" +#include "intell_voice_log.h" +#include "v1_2/intell_voice_engine_types.h" +#include "intell_voice_util.h" + +#define LOG_TAG "HighPowerAdapterListener" + +using namespace OHOS::IntellVoiceUtils; +using namespace OHOS::HDI::IntelligentVoice::Engine::V1_2; + +namespace OHOS { +namespace IntellVoiceEngine { +static const std::string PRE_WAKEUP_EVENT = "pre_wakeup_event"; + +HighPowerAdapterListener::HighPowerAdapterListener() +{ + INTELL_VOICE_LOG_INFO("constructor"); +} + +HighPowerAdapterListener::~HighPowerAdapterListener() +{ + INTELL_VOICE_LOG_INFO("destructor"); +} + +void HighPowerAdapterListener::SetCallback(const sptr &cb) +{ + INTELL_VOICE_LOG_INFO("enter"); + std::lock_guard lock(mutex_); + if (cb == nullptr) { + INTELL_VOICE_LOG_INFO("clear callback"); + cb_ = nullptr; + return; + } + cb_ = cb; + if (historyEvent_ != nullptr) { + uint64_t rightnow = TimeUtil::GetCurrentTimeMs(); + cb_->OnIntellVoiceEngineEvent(*(historyEvent_.get())); + INTELL_VOICE_LOG_WARN("callback delayed %lu ms", rightnow - historyMsgTime_); + historyEvent_ = nullptr; + } +} + +std::string HighPowerAdapterListener::GetCallbackStatus() +{ + INTELL_VOICE_LOG_INFO("enter"); + std::lock_guard lock(mutex_); + if (cb_ == nullptr) { + INTELL_VOICE_LOG_WARN("cb_ is nullptr"); + return "false"; + } + return "true"; +} + +void HighPowerAdapterListener::OnIntellVoiceHdiEvent(const IntellVoiceEngineCallBackEvent &event) +{ + INTELL_VOICE_LOG_INFO("enter"); + if (event.msgId == OHOS::HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_INIT_DONE) { + IntellVoiceUtil::StartAbility(PRE_WAKEUP_EVENT); + } else if (event.msgId == OHOS::HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE) { + if (cb_ == nullptr) { + INTELL_VOICE_LOG_WARN("cb_ is nullptr"); + BackupCallBackEvent(event); + return; + } + cb_->OnIntellVoiceEngineEvent(event); + } else { + INTELL_VOICE_LOG_WARN("unknow msg id:%{public}d", event.msgId); + } +} + +void HighPowerAdapterListener::BackupCallBackEvent(const IntellVoiceEngineCallBackEvent &event) +{ + if (event.msgId == OHOS::HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE) { + INTELL_VOICE_LOG_INFO("backup callBackEvent, msg id:%{public}d", event.msgId); + + historyEvent_ = std::make_shared(); + if (historyEvent_ == nullptr) { + INTELL_VOICE_LOG_INFO("historyEvent_ is nullptr"); + return; + } + historyEvent_->msgId = event.msgId; + historyEvent_->result = event.result; + historyEvent_->info = event.info; + historyMsgTime_ = TimeUtil::GetCurrentTimeMs(); + } else { + INTELL_VOICE_LOG_WARN("unknow msg id:%{public}d", event.msgId); + } +} +} +} \ No newline at end of file diff --git a/services/intell_voice_engine/server/wakeup/high_power/high_power_adapter_listener.h b/services/intell_voice_engine/server/wakeup/high_power/high_power_adapter_listener.h new file mode 100644 index 0000000..af18a3d --- /dev/null +++ b/services/intell_voice_engine/server/wakeup/high_power/high_power_adapter_listener.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 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 HIGH_POWER_ADAPTER_LISTENER_H +#define HIGH_POWER_ADAPTER_LISTENER_H + +#include +#include +#include +#include "time_util.h" +#include "intell_voice_adapter_listener.h" +#include "i_intell_voice_engine_callback.h" + +namespace OHOS { +namespace IntellVoiceEngine { + +class HighPowerAdapterListener : public IntellVoiceAdapterListener { +public: + explicit HighPowerAdapterListener(); + ~HighPowerAdapterListener(); + void SetCallback(const sptr &cb); + std::string GetCallbackStatus(); + void OnIntellVoiceHdiEvent( + const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event) override; +private: + void BackupCallBackEvent(const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event); + +private: + std::mutex mutex_; + sptr cb_ = nullptr; + std::shared_ptr historyEvent_ = nullptr; + uint64_t historyMsgTime_; +}; +} // namespace IntellVoice +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/intell_voice_engine/server/wakeup/high_power/high_power_wakeup_engine.cpp b/services/intell_voice_engine/server/wakeup/high_power/high_power_wakeup_engine.cpp new file mode 100644 index 0000000..9e492a0 --- /dev/null +++ b/services/intell_voice_engine/server/wakeup/high_power/high_power_wakeup_engine.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2025 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 "high_power_wakeup_engine.h" +#include "idevmgr_hdi.h" +#include "ipc_skeleton.h" +#include "v1_2/intell_voice_engine_types.h" +#include "intell_voice_engine_manager.h" +#include "intell_voice_log.h" +#include "engine_host_manager.h" +#include "adapter_callback_service.h" + +#define LOG_TAG "HighPowerWakeupEngine" + +using namespace OHOS::IntellVoiceUtils; +using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; +using namespace OHOS::HDI::IntelligentVoice::Engine::V1_0; + +namespace OHOS { +namespace IntellVoiceEngine { +static const std::string CALLBACK_EXIST = "is_callback_exist"; +static const std::string HIGH_POWER_THREAD_NAME = "HighPowerEngThread"; +static constexpr uint32_t MAX_WAKEUP_TASK_NUM = 200; + +HighPowerWakeupEngine::HighPowerWakeupEngine() +{ + INTELL_VOICE_LOG_INFO("enter"); + adapterListener_ = std::make_shared(); + if (adapterListener_ == nullptr) { + INTELL_VOICE_LOG_ERROR("adapterListener_ is nullptr"); + } +} + +HighPowerWakeupEngine::~HighPowerWakeupEngine() +{ + INTELL_VOICE_LOG_INFO("enter"); +} + +bool HighPowerWakeupEngine::Init(const std::string & /* param */, bool reEnroll) +{ + INTELL_VOICE_LOG_INFO("enter"); + if (!EngineUtil::CreateAdapterInner(EngineHostManager::GetInstance(), WAKEUP_ADAPTER_TYPE)) { + INTELL_VOICE_LOG_ERROR("failed to create adapter"); + return -1; + } + + if (!SetCallbackInner()) { + INTELL_VOICE_LOG_ERROR("failed to set callback"); + return -1; + } + return true; +} + +void HighPowerWakeupEngine::SetCallback(sptr object) +{ + std::unique_lock lock(mutex_); + sptr callback = iface_cast(object); + if (callback == nullptr) { + INTELL_VOICE_LOG_WARN("clear callback"); + } + if (adapterListener_ == nullptr) { + INTELL_VOICE_LOG_ERROR("adapterListener_ is nullptr"); + return; + } + adapterListener_->SetCallback(callback); +} + +std::string HighPowerWakeupEngine::GetParameter(const std::string &key) +{ + if (key == CALLBACK_EXIST) { + if (adapterListener_ == nullptr) { + INTELL_VOICE_LOG_ERROR("adapterListener_ is nullptr"); + return "false"; + } else { + return adapterListener_->GetCallbackStatus(); + } + } + return ""; +} + +int32_t HighPowerWakeupEngine::Detach(void) +{ + std::unique_lock lock(mutex_); + if (adapter_ != nullptr) { + adapter_->Detach(); + ReleaseAdapterInner(EngineHostManager::GetInstance()); + } + return 0; +} + +bool HighPowerWakeupEngine::SetCallbackInner() +{ + INTELL_VOICE_LOG_INFO("enter"); + if (adapter_ == nullptr) { + INTELL_VOICE_LOG_ERROR("adapter is nullptr"); + return false; + } + + if (adapterListener_ == nullptr) { + INTELL_VOICE_LOG_ERROR("adapter listener is nullptr"); + return false; + } + + callback_ = sptr(new (std::nothrow) AdapterCallbackService(adapterListener_)); + if (callback_ == nullptr) { + INTELL_VOICE_LOG_ERROR("callback_ is nullptr"); + return false; + } + + adapter_->SetCallback(callback_); + return true; +} +} // namespace IntellVoice +} // namespace OHOS diff --git a/services/intell_voice_engine/server/wakeup/high_power/high_power_wakeup_engine.h b/services/intell_voice_engine/server/wakeup/high_power/high_power_wakeup_engine.h new file mode 100644 index 0000000..5cfea02 --- /dev/null +++ b/services/intell_voice_engine/server/wakeup/high_power/high_power_wakeup_engine.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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 HIGH_POWER_WAKEUP_ENGINE_H +#define HIGH_POWER_WAKEUP_ENGINE_H + +#include +#include "engine_base.h" +#include "task_executor.h" +#include "engine_util.h" +#include "i_intell_voice_engine.h" +#include "high_power_adapter_listener.h" + +namespace OHOS { +namespace IntellVoiceEngine { + +class HighPowerWakeupEngine : public EngineBase, private EngineUtil { +public: + HighPowerWakeupEngine(); + ~HighPowerWakeupEngine(); + bool Init(const std::string ¶m, bool reEnroll = false) override; + void SetCallback(sptr object) override; + int32_t Attach(const IntellVoiceEngineInfo &info) override { return 0; }; + int32_t Detach(void) override; + int32_t Start(bool isLast) override { return 0; }; + int32_t SetParameter(const std::string &keyValueList) override { return 0; }; + std::string GetParameter(const std::string &key) override; + int32_t Stop() override { return 0; }; + int32_t GetWakeupPcm(std::vector &data) override { return 0; }; + int32_t StartCapturer(int32_t channels) override { return 0; }; + int32_t Read(std::vector &data) override { return 0; }; + int32_t StopCapturer() override { return 0; }; + int32_t NotifyHeadsetWakeEvent() override { return 0; }; + int32_t NotifyHeadsetHostEvent(HeadsetHostEventType event) override { return 0; }; + +private: + bool SetCallbackInner(); + +private: + std::mutex mutex_; + sptr callback_ = nullptr; + std::shared_ptr adapterListener_ = nullptr; +}; +} +} +#endif \ No newline at end of file diff --git a/services/intell_voice_engine/server/wakeup/wakeup_engine.cpp b/services/intell_voice_engine/server/wakeup/wakeup_engine.cpp index 8a3c1a4..a9e3331 100755 --- a/services/intell_voice_engine/server/wakeup/wakeup_engine.cpp +++ b/services/intell_voice_engine/server/wakeup/wakeup_engine.cpp @@ -13,14 +13,13 @@ * limitations under the License. */ #include "wakeup_engine.h" -#include "ability_manager_client.h" #include "idevmgr_hdi.h" #include "intell_voice_engine_manager.h" #include "intell_voice_log.h" #include "headset_host_manager.h" #include "headset_wakeup_wrapper.h" #include "engine_callback_message.h" -#include "history_info_mgr.h" +#include "intell_voice_util.h" #define LOG_TAG "WakeupEngine" @@ -52,7 +51,7 @@ void WakeupEngine::OnDetected(int32_t uuid) } detectDeviceType_.store(DETECT_TYPE_PHONE); - std::thread([uuid]() { WakeupEngine::StartAbility(GetEventValue(uuid)); }).detach(); + std::thread([uuid]() { IntellVoiceUtil::StartAbility(GetEventValue(uuid)); }).detach(); StateMsg msg(START_RECOGNIZE, &uuid, sizeof(int32_t)); if (ROLE(WakeupEngineImpl).Handle(msg) != 0) { INTELL_VOICE_LOG_WARN("start failed"); @@ -143,7 +142,7 @@ int32_t WakeupEngine::NotifyHeadsetWakeEvent() return -1; } - std::thread([]() { WakeupEngine::StartAbility("headset_event"); }).detach(); + std::thread([]() { IntellVoiceUtil::StartAbility("headset_event"); }).detach(); detectDeviceType_.store(DETECT_TYPE_HEADSET); StateMsg msg(START_RECOGNIZE); @@ -287,30 +286,6 @@ std::string WakeupEngine::GetEventValue(int32_t uuid) return "recognition_event"; } -void WakeupEngine::StartAbility(const std::string &event) -{ - AAFwk::Want want; - HistoryInfoMgr &historyInfoMgr = HistoryInfoMgr::GetInstance(); - - std::string bundleName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_BUNDLE_NAME); - std::string abilityName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_ABILITY_NAME); - INTELL_VOICE_LOG_INFO("bundleName:%{public}s, abilityName:%{public}s", bundleName.c_str(), abilityName.c_str()); - if (bundleName.empty() || abilityName.empty()) { - INTELL_VOICE_LOG_ERROR("bundle name is empty or ability name is empty"); - return; - } - want.SetElementName(bundleName, abilityName); - want.SetParam("serviceName", std::string("intell_voice")); - want.SetParam("servicePid", getpid()); - want.SetParam("eventType", event); - auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance(); - if (abilityManagerClient == nullptr) { - INTELL_VOICE_LOG_ERROR("abilityManagerClient is nullptr"); - return; - } - abilityManagerClient->StartAbility(want); -} - bool WakeupEngine::ResetAdapter() { StateMsg msg(RESET_ADAPTER); diff --git a/services/intell_voice_engine/server/wakeup/wakeup_engine.h b/services/intell_voice_engine/server/wakeup/wakeup_engine.h index 51ab0ce..f4c8046 100755 --- a/services/intell_voice_engine/server/wakeup/wakeup_engine.h +++ b/services/intell_voice_engine/server/wakeup/wakeup_engine.h @@ -54,7 +54,6 @@ public: int32_t NotifyHeadsetHostEvent(HeadsetHostEventType event) override; private: - static void StartAbility(const std::string &event); static std::string GetEventValue(int32_t uuid); int32_t HandleHeadsetOff(); int32_t HandleHeadsetOn(); diff --git a/services/intell_voice_service/BUILD.gn b/services/intell_voice_service/BUILD.gn index 21034c5..fffdd51 100644 --- a/services/intell_voice_service/BUILD.gn +++ b/services/intell_voice_service/BUILD.gn @@ -87,6 +87,7 @@ ohos_source_set("server_source") { if (intelligent_voice_framework_only_first_stage) { cflags_cc += [ "-DONLY_FIRST_STAGE" ] } + subsystem_name = "ai" part_name = "intelligent_voice_framework" } diff --git a/services/intell_voice_service/inc/intell_voice_definitions.h b/services/intell_voice_service/inc/intell_voice_definitions.h index a7f2f0f..59bcf88 100644 --- a/services/intell_voice_service/inc/intell_voice_definitions.h +++ b/services/intell_voice_service/inc/intell_voice_definitions.h @@ -15,6 +15,7 @@ #ifndef INTELL_VOICE_DEFINITIONS_H #define INTELL_VOICE_DEFINITIONS_H #include +#include "intell_voice_util.h" namespace OHOS { namespace IntellVoiceEngine { constexpr int32_t VOICE_WAKEUP_MODEL_UUID = 1; @@ -25,8 +26,6 @@ const std::string SHORTWORD_KEY = "intell_voice_trigger_shortword"; const std::string SENSIBILITY_TEXT = "sensibility="; const std::string KEY_GET_WAKEUP_FEATURE = "wakeup_features"; -const std::string KEY_WAKEUP_ENGINE_BUNDLE_NAME = "WakeupEngineBundleName"; -const std::string KEY_WAKEUP_ENGINE_ABILITY_NAME = "WakeupEngineAbilityName"; const std::string KEY_WAKEUP_VESRION = "WakeupVersion"; const std::string KEY_LANGUAGE = "Language"; const std::string KEY_AREA = "Area"; diff --git a/services/intell_voice_service/server/sa/intell_voice_service_manager.cpp b/services/intell_voice_service/server/sa/intell_voice_service_manager.cpp index a9bce81..35a37ba 100644 --- a/services/intell_voice_service/server/sa/intell_voice_service_manager.cpp +++ b/services/intell_voice_service/server/sa/intell_voice_service_manager.cpp @@ -27,7 +27,6 @@ #include "string_util.h" #include "json/json.h" #include "history_info_mgr.h" -#include "ability_manager_client.h" #define LOG_TAG "IntellVoiceServiceManager" @@ -176,31 +175,6 @@ bool IntellVoiceServiceManager::IsSwitchError(const std::string &key) return switchProvider_->IsSwitchError(key); } -template -void IntellVoiceServiceManager::NotifyEvent(const std::string &eventType) -{ - AAFwk::Want want; - HistoryInfoMgr &historyInfoMgr = HistoryInfoMgr::GetInstance(); - - std::string bundleName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_BUNDLE_NAME); - std::string abilityName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_ABILITY_NAME); - INTELL_VOICE_LOG_INFO("bundleName:%{public}s, abilityName:%{public}s", bundleName.c_str(), abilityName.c_str()); - if (bundleName.empty() || abilityName.empty()) { - INTELL_VOICE_LOG_ERROR("bundle name is empty or ability name is empty"); - return; - } - want.SetElementName(bundleName, abilityName); - want.SetParam("serviceName", std::string("intell_voice")); - want.SetParam("servicePid", getpid()); - want.SetParam("eventType", eventType); - auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance(); - if (abilityManagerClient == nullptr) { - INTELL_VOICE_LOG_ERROR("abilityManagerClient is nullptr"); - return; - } - abilityManagerClient->StartAbility(want); -} - template void IntellVoiceServiceManager::OnSwitchChange(const std::string &switchKey) { @@ -459,10 +433,12 @@ int32_t IntellVoiceServiceManager::SwitchOnProc(int32_t uuid, bool needUpd template void IntellVoiceServiceManager::CreateAndStartServiceObject(int32_t uuid, bool needResetAdapter) { +#ifdef TRIGGER_ENABLE if (!T::IsModelExist(uuid)) { INTELL_VOICE_LOG_INFO("no model"); return; } +#endif if (!QuerySwitchByUuid(uuid)) { INTELL_VOICE_LOG_INFO("switch is off, uuid is %{public}d", uuid); @@ -639,7 +615,7 @@ void IntellVoiceServiceManager::HandleServiceStop() }); if (IsSwitchError(WAKEUP_KEY)) { INTELL_VOICE_LOG_WARN("db is abnormal, can not find wakeup switch, notify db error"); - NotifyEvent("db_error"); + IntellVoiceUtil::StartAbility("db_error"); } } @@ -870,7 +846,7 @@ void IntellVoiceServiceManager::OnSingleLevelDetected() INTELL_VOICE_LOG_INFO("single level detected"); recordStart_ = -1; StopWakeupSource(); - NotifyEvent("single_level_event"); + IntellVoiceUtil::StartAbility("single_level_event"); HandleRecordStartInfoChange(); return; } diff --git a/services/intell_voice_service/server/sa/intell_voice_service_manager.h b/services/intell_voice_service/server/sa/intell_voice_service_manager.h index 0dbb1fb..56269a3 100644 --- a/services/intell_voice_service/server/sa/intell_voice_service_manager.h +++ b/services/intell_voice_service/server/sa/intell_voice_service_manager.h @@ -125,7 +125,6 @@ private: bool AddStartDetectionTask(int32_t uuid); void DelStartDetectionTask(int32_t uuid); bool IsSwitchError(const std::string &key); - void NotifyEvent(const std::string &eventType); void StopWakeupSource(); void ResetSingleLevelWakeup(const std::string &value); bool HasReceviedRecordStartMsg(); diff --git a/services/intell_voice_trigger/BUILD.gn b/services/intell_voice_trigger/BUILD.gn index 16db6ac..949848e 100644 --- a/services/intell_voice_trigger/BUILD.gn +++ b/services/intell_voice_trigger/BUILD.gn @@ -53,7 +53,6 @@ ohos_source_set("trigger_source") { "drivers_interface_intelligent_voice:libintell_voice_trigger_proxy_1.1", "eventhandler:libeventhandler", "ffrt:libffrt", - "hdf_core:libhdf_host", "hdf_core:libhdi", "huks:libhukssdk", "ipc:ipc_core", diff --git a/services/intell_voice_trigger/server/trigger_helper.cpp b/services/intell_voice_trigger/server/trigger_helper.cpp index 68750e0..c90f8a0 100755 --- a/services/intell_voice_trigger/server/trigger_helper.cpp +++ b/services/intell_voice_trigger/server/trigger_helper.cpp @@ -931,7 +931,9 @@ void TriggerHelper::StartAllRecognition() INTELL_VOICE_LOG_INFO("audio_fold_status no need start uuid: %{public}d", iter.first); continue; } - + if (PrepareForRecognition(iter.second) != 0) { + return; + } StartRecognition(iter.second); } } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 0dd3118..9e668c6 100755 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("intell_voice_utils") { } external_deps = [ + "ability_runtime:ability_manager", "access_token:libaccesstoken_sdk", "access_token:libprivacy_sdk", "access_token:libtokenid_sdk", diff --git a/utils/intell_voice_util.cpp b/utils/intell_voice_util.cpp index 99b362e..391a226 100644 --- a/utils/intell_voice_util.cpp +++ b/utils/intell_voice_util.cpp @@ -29,6 +29,8 @@ #include "privacy_error.h" #include "intell_voice_log.h" #include "intell_voice_info.h" +#include "ability_manager_client.h" +#include "history_info_mgr.h" #define LOG_TAG "IntellVoiceUtil" @@ -200,5 +202,29 @@ bool IntellVoiceUtil::RecordPermissionPrivacy(const std::string &permissionName, return true; } + +void IntellVoiceUtil::StartAbility(const std::string &event) +{ + AAFwk::Want want; + HistoryInfoMgr &historyInfoMgr = HistoryInfoMgr::GetInstance(); + + std::string bundleName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_BUNDLE_NAME); + std::string abilityName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_ABILITY_NAME); + INTELL_VOICE_LOG_INFO("bundleName:%{public}s, abilityName:%{public}s", bundleName.c_str(), abilityName.c_str()); + if (bundleName.empty() || abilityName.empty()) { + INTELL_VOICE_LOG_ERROR("bundle name is empty or ability name is empty"); + return; + } + want.SetElementName(bundleName, abilityName); + want.SetParam("serviceName", std::string("intell_voice")); + want.SetParam("servicePid", getpid()); + want.SetParam("eventType", event); + auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance(); + if (abilityManagerClient == nullptr) { + INTELL_VOICE_LOG_ERROR("abilityManagerClient is nullptr"); + return; + } + abilityManagerClient->StartAbility(want); +} } } diff --git a/utils/intell_voice_util.h b/utils/intell_voice_util.h index 6528bc3..6106c25 100644 --- a/utils/intell_voice_util.h +++ b/utils/intell_voice_util.h @@ -23,6 +23,8 @@ namespace OHOS { namespace IntellVoiceUtils { const std::string OHOS_MICROPHONE_PERMISSION = "ohos.permission.MICROPHONE"; +const std::string KEY_WAKEUP_ENGINE_BUNDLE_NAME = "WakeupEngineBundleName"; +const std::string KEY_WAKEUP_ENGINE_ABILITY_NAME = "WakeupEngineAbilityName"; enum IntellVoicePermissionState { INTELL_VOICE_PERMISSION_START = 0, @@ -40,6 +42,7 @@ public: static bool IsFileExist(const std::string &filePath); static bool RecordPermissionPrivacy(const std::string &permissionName, uint32_t targetTokenId, IntellVoicePermissionState state); + static void StartAbility(const std::string &event); private: static bool VerifyClientPermission(const std::string &permissionName);