mirror of
https://github.com/openharmony/ai_intelligent_voice_framework.git
synced 2026-07-01 20:24:01 -04:00
@@ -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": {
|
||||
|
||||
@@ -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) &&
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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" ]
|
||||
|
||||
@@ -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<EngineBase> EngineFactory::CreateEngineInst(IntellVoiceEngineType type, con
|
||||
engine = SptrFactory<EngineBase, EnrollEngine>::CreateInstance(param);
|
||||
break;
|
||||
case INTELL_VOICE_WAKEUP:
|
||||
#ifdef ONLY_SECOND_STAGE
|
||||
engine = SptrFactory<EngineBase, HighPowerWakeupEngine>::CreateInstance(param);
|
||||
#else
|
||||
engine = SptrFactory<EngineBase, WakeupEngineObj>::CreateInstance(param);
|
||||
#endif
|
||||
break;
|
||||
case INTELL_VOICE_UPDATE:
|
||||
engine = SptrFactory<EngineBase, UpdateEngine>::CreateInstance(param, reEnroll);
|
||||
|
||||
+2
-28
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -27,8 +27,6 @@ public:
|
||||
UpdatePriority GetUpdatePriority() override;
|
||||
int GetRetryTimes() override;
|
||||
int OnUpdateCompleteCallback(const int result, bool isLast) override;
|
||||
private:
|
||||
static void NotifyUpdateFail();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+104
@@ -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<IIntelligentVoiceEngineCallback> &cb)
|
||||
{
|
||||
INTELL_VOICE_LOG_INFO("enter");
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<IntellVoiceEngineCallBackEvent>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#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<IIntelligentVoiceEngineCallback> &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<IIntelligentVoiceEngineCallback> cb_ = nullptr;
|
||||
std::shared_ptr<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent> historyEvent_ = nullptr;
|
||||
uint64_t historyMsgTime_;
|
||||
};
|
||||
} // namespace IntellVoice
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -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<HighPowerAdapterListener>();
|
||||
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<IRemoteObject> object)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
sptr<IIntelligentVoiceEngineCallback> callback = iface_cast<IIntelligentVoiceEngineCallback>(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<std::mutex> 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<IIntellVoiceEngineCallback>(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
|
||||
@@ -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 <string>
|
||||
#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<IRemoteObject> 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<uint8_t> &data) override { return 0; };
|
||||
int32_t StartCapturer(int32_t channels) override { return 0; };
|
||||
int32_t Read(std::vector<uint8_t> &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<OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineCallback> callback_ = nullptr;
|
||||
std::shared_ptr<HighPowerAdapterListener> adapterListener_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#ifndef INTELL_VOICE_DEFINITIONS_H
|
||||
#define INTELL_VOICE_DEFINITIONS_H
|
||||
#include <string>
|
||||
#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";
|
||||
|
||||
@@ -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<T, E>::IsSwitchError(const std::string &key)
|
||||
return switchProvider_->IsSwitchError(key);
|
||||
}
|
||||
|
||||
template<typename T, typename E>
|
||||
void IntellVoiceServiceManager<T, E>::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<typename T, typename E>
|
||||
void IntellVoiceServiceManager<T, E>::OnSwitchChange(const std::string &switchKey)
|
||||
{
|
||||
@@ -459,10 +433,12 @@ int32_t IntellVoiceServiceManager<T, E>::SwitchOnProc(int32_t uuid, bool needUpd
|
||||
template<typename T, typename E>
|
||||
void IntellVoiceServiceManager<T, E>::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<T, E>::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<T, E>::OnSingleLevelDetected()
|
||||
INTELL_VOICE_LOG_INFO("single level detected");
|
||||
recordStart_ = -1;
|
||||
StopWakeupSource();
|
||||
NotifyEvent("single_level_event");
|
||||
IntellVoiceUtil::StartAbility("single_level_event");
|
||||
HandleRecordStartInfoChange();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user