前边经过重重关卡,终于构建好了OpenHarmony系统。而编译好系统只是万里长征走完了第一步,真正的目的是为了实际的项目,以及在完成项目过程中完成具体的任务和实际解决的问题。

这里就开始介绍实际遇到的问题,以及对于它们的分析与解决。

在实际项目中,发现烧录系统后,对于语音唤醒功能进行测试时,并不能正常唤醒,此功能失效。关于语音唤醒这一部分的介绍参见:

鸿蒙(OpenHarmony)系统之智能语音部件(1)

由于笔者也是初次接触OpenHarmony,因此对于此问题采用最直接的方法,从系统日志入手。日志(log)如下(日志文件内容很大,只贴出相关的部分内容):

01-01 08:00:15.048 1340-1340/? I C03900/Ace: [text_pattern.cpp(InitSurfacePositionChangedCallback)-(0)] Add position changed callback id 20
01-01 08:00:15.049 641-641/? E C015c0/dsoftbus: [LNN][LlGetDeviceUdid:91]get local udid invalid!
01-01 08:00:15.049 641-641/? E C015c0/dsoftbus: [COMM][GetNodeKeyInfoInner:873]GetNodeKeyInfoInner get key info failed!
01-01 08:00:15.049 284-296/? E C01510/BinderInvoker: 124: SendRequest: handle=5 result = -267386855
01-01 08:00:15.049 284-296/? E C015c0/dsoftbus: [LNN][GetNodeKeyInfo:438]GetNodeKeyInfo send request failed!
01-01 08:00:15.049 284-296/? E C015c0/dsoftbus: [LNN][ServerIpcGetNodeKeyInfo:115]ServerIpcGetNodeKeyInfo get node key info failed!
01-01 08:00:15.049 284-296/? E C015c0/dsoftbus: [LNN][GetNodeKeyInfoInner:454]Server GetNodeKeyInfo failed, ret = -268369887
01-01 08:00:15.049 284-296/? E C04100/DHDM: [devicemanagerservice][GetUdidByNetworkId]:[SOFTBUS]GetNodeKeyInfo failed, ret: -268369887.
01-01 08:00:15.049 1340-1396/? I C01510/IPCObjectProxy: 58: handle = 18 create, descriptor: IPCObjectProxy18
01-01 08:00:15.049 638-1160/? E C01611/ZDD: DeviceManagerAdapter::GetUdidByNetworkId: failed, result:0, networkId:2aa***2a6
01-01 08:00:15.049 638-1160/? I C01611/ZDD: DeviceManagerAdapter::GetLocalDevice: [LocalDevice] uuid:01c***040, name:OpenHarmony 3.2, type:0
01-01 08:00:15.049 1251-1251/? I C03900/Ace: [resource_adapter_impl.cpp(GetTheme)-(4)] themeId=125829872, ret=0, attr size=1, pattern size=53
01-01 08:00:15.049 638-1160/? I C01611/ZDD: UserDelegate::UpdateUsers: begin, device:01c***040, users:2
01-01 08:00:15.049 638-1228/? I C04100/DHDM: [devicemanagerkit][GetLocalDeviceInfo]:DeviceManagerImpl::GetLocalDeviceInfo start, pkgName: ohos.distributeddata.service
01-01 08:00:15.049 638-1228/? I C04100/DHDM: [devicemanagerkit][SendRequest]:IpcClientManager::SendRequest in
01-01 08:00:15.049 638-1228/? I C04100/DHDM: [devicemanagerkit][SendRequest]:IpcClientManager::SendRequest cmdCode: 4
01-01 08:00:15.049 638-1160/? I C01611/ZDD: UserDelegate::operator(): end, device:01c***040, users:2
01-01 08:00:15.049 638-1160/? I C01611/ZDD: UserDelegate::InitLocalUserMeta: put user meta data save meta data
01-01 08:00:15.049 1340-1340/? I C03900/Ace: [text_pattern.cpp(InitSurfacePositionChangedCallback)-(0)] Add position changed callback id 22
01-01 08:00:15.049 284-296/? I C04100/DHDM: [devicemanagerservice][GetLocalDeviceInfo]:DeviceManagerService::GetLocalDeviceInfo begin.
01-01 08:00:15.049 284-296/? W C015c0/dsoftbus: mutex is already init
01-01 08:00:15.049 617-718/? E C02500/"TriggerManagerImpl": [LoadAdapter][line:109]: get adapter device from hal failed, ret:0
01-01 08:00:15.049 617-718/? E C02500/intell_voice_trigger_manager_st: IntellVoiceTriggerManagerStubLoadAdapter_ failed, error code is -1
01-01 08:00:15.049 1340-1340/? I C03900/Ace: [text_pattern.cpp(InitSurfacePositionChangedCallback)-(0)] Add position changed callback id 24
01-01 08:00:15.049 415-1358/? E C01510/BinderInvoker: 124: SendRequest: handle=4 result = -1
01-01 08:00:15.049 415-1358/? E C02500/intell_voice_trigger_manager_pr: LoadAdapter_ failed, error code is -1
01-01 08:00:15.049 415-1358/? E C02500/TriggerConnector: [TriggerConnector:42]: failed to load adapter, adapterName is primary
01-01 08:00:15.049 415-1358/? W C01510/IPCObjectProxy: 63: handle = 4 destroyed, descriptor: IPCObjectProxy4
01-01 08:00:15.049 1340-1396/? E C01400/OHOS::ROSEN: print log error in vsprintf_s
01-01 08:00:15.050 280-674/? I C01510/IPCObjectProxy: 58: handle = 48 create, descriptor: IPCObjectProxy48
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status hdf_device_manager
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status hci_interface_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status codec_image_jpeg_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status user_auth_interface_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status usb_pnp_manager
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status codec_hdi_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status wlan_interface_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status usb_ddk_service
01-01 08:00:15.050 415-415/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:hdf_device_manager, status:0
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status codec_component_manager_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status intell_voice_trigger_manager_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status codec_hdi_omx_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status usb_interface_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status allocator_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status display_composer_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status camera_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status thermal_interface_service
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status battery_interface_service
01-01 08:00:15.050 415-415/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:hci_interface_service, status:0
01-01 08:00:15.050 280-674/? I C02500/servstat: notify service status power_interface_service
01-01 08:00:15.050 280-674/? I C02500/devsvc_manager_stub: register servstat listener success
01-01 08:00:15.050 641-641/? I C015c0/dsoftbus: [COMM][OnRemoteRequest:204]SoftBusServerStub::OnReceived, code = 149
01-01 08:00:15.050 415-1358/? I C01800/SAMGR: [PerformanceTest] SA:312 OpenSo spend 207 ms
01-01 08:00:15.050 415-1358/? I C01800/SAFWK: LocalAbilityManager::StartOndemandSystemAbility [PerformanceTest] SAFWK ondemand LoadSaLib systemAbilityId:312, spend:207 ms
01-01 08:00:15.050 1340-1340/? I C03900/Ace: [text_pattern.cpp(InitSurfacePositionChangedCallback)-(0)] Add position changed callback id 26
01-01 08:00:15.050 415-415/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:codec_image_jpeg_service, status:0
01-01 08:00:15.050 1340-1340/? I C03900/Ace: [text_pattern.cpp(InitSurfacePositionChangedCallback)-(0)] Add position changed callback id 28
01-01 08:00:15.050 415-415/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:user_auth_interface_service, status:0
01-01 08:00:15.050 638-1228/? I C04100/DHDM: [devicemanagerkit][GetLocalDeviceInfo]:DeviceManagerImpl::GetLocalDeviceInfo completed, pkgname = ohos.distributeddata.service
01-01 08:00:15.050 638-1228/? E C04100/DHDM: [devicemanagerkit][SysEventWrite]:GET_LOCAL_DEVICE_INFO_SUCCESS Write HiSysEvent error, res:-6
01-01 08:00:15.050 638-1228/? I C04100/DHDM: [devicemanagerkit][GetUuidByNetworkId]:GetUuidByNetworkId start, pkgName: ohos.distributeddata.service
01-01 08:00:15.050 638-1228/? I C04100/DHDM: [devicemanagerkit][SendRequest]:IpcClientManager::SendRequest in
01-01 08:00:15.050 638-1228/? I C04100/DHDM: [devicemanagerkit][SendRequest]:IpcClientManager::SendRequest cmdCode: 10
01-01 08:00:15.050 415-452/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:usb_pnp_manager, status:0
01-01 08:00:15.050 415-452/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:codec_hdi_service, status:0
01-01 08:00:15.050 415-452/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:wlan_interface_service, status:0
01-01 08:00:15.050 415-452/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:usb_ddk_service, status:0
01-01 08:00:15.050 415-452/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:codec_component_manager_service, status:0
01-01 08:00:15.050 415-452/? I C02500/TriggerConnector: [OnReceive:90]: enter, service name:intell_voice_trigger_manager_service, status:0
01-01 08:00:15.050 287-294/? I C02c03/PARAM_WATCHER: [watcher_manager.cpp:104]Add watcher debug.graphic.overdraw remoteWatcherId: 13 groupId 8 success
01-01 08:00:15.050 286-1204/? E C01800/SAMGR: [SA Scheduler][SA: 5100] not in SA profiles
01-01 08:00:15.051 284-296/? I C04100/DHDM: [devicemanagerservice][CheckPermission]:Enter PermissionManager::CheckPermission
01-01 08:00:15.051 284-296/? I C04100/DHDM: [devicemanagerservice][CheckPermission]:PermissionManager::tokenCaller ID == 671522511
01-01 08:00:15.051 284-296/? I C04100/DHDM: [devicemanagerservice][GetUuidByNetworkId]:DeviceManagerService::GetUuidByNetworkId begin for pkgName = ohos.distributeddata.service
01-01 08:00:15.051 284-296/? W C015c0/dsoftbus: mutex is already init
01-01 08:00:15.051 1340-1396/? I C02c03/PARAM_WATCHER: [watcher_manager_kits.cpp:171]Add watcher keyPrefix debug.graphic.overdraw remoteWatcherId 13 success
01-01 08:00:15.051 641-641/? I C015c0/dsoftbus: [COMM][OnRemoteRequest:204]SoftBusServerStub::OnReceived, code = 150
01-01 08:00:15.051 1340-1340/? I C03900/Ace: [text_pattern.cpp(InitSurfacePositionChangedCallback)-(0)] Add position changed callback id 30
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [rosen_window.cpp(SetRootFrameNode)-(4)] Rosenwindow set root frame node
01-01 08:00:15.051 286-311/? E C01800/SAMGR: [SA Scheduler][SA: 5100] not in SA profiles
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [pipeline_context.cpp(SetupRootElement)-(4)] SetupRootElement success!
01-01 08:00:15.051 1251-1251/? I C01d03/accessibility_acfwk: [accessibility_config_impl.cpp(SubscribeConfigObserver:321)]id = [3]
01-01 08:00:15.051 287-294/? I C02c03/PARAM_WATCHER: [watcher_manager.cpp:104]Add watcher debug.graphic.colors_overdraw remoteWatcherId: 13 groupId 9 success
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [pipeline_context.cpp(SetRootRect)-(4)] SetRootRect width 0.000000, height 0.000000, 0.000000
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [ui_content_impl.cpp(CommonInitialize)-(4)] SetMinPlatformVersion code is 9
01-01 08:00:15.051 1340-1340/? I C03900/Ace: [text_pattern.cpp(InitSurfacePositionChangedCallback)-(0)] Add position changed callback id 32
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [layout_inspector.cpp(SetCallback)-(4)] SetCallback start
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [ui_content_impl.cpp(CommonInitialize)-(4)] Initialize UIContentImpl end.
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [ui_content_impl.cpp(Initialize)-(-1)] Initialize startUrl = pages/PrivacyIndicatorComponent
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [frontend_delegate_declarative.cpp(RunPage)-(4)] FrontendDelegateDeclarative RunPage url=pages/PrivacyIndicatorComponent
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [hap_asset_provider.cpp(GetAsMapping)-(4)] Cannot find base path of manifest.json
01-01 08:00:15.051 1340-1396/? I C02c03/PARAM_WATCHER: [watcher_manager_kits.cpp:171]Add watcher keyPrefix debug.graphic.colors_overdraw remoteWatcherId 13 success
01-01 08:00:15.051 1251-1251/? W C03900/Ace: [flutter_asset_manager.cpp(GetAsset)-(4)] find asset failed, name = manifest.json
01-01 08:00:15.051 1251-1251/? W C03900/Ace: [utils.h(GetAssetContentImpl)-(4)] uri:manifest.json Asset is null
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [frontend_delegate_declarative.cpp(RunPage)-(4)] Parse profile main_pages.json
01-01 08:00:15.051 1251-1251/? I C03900/Ace: [ui_content_impl.cpp(UpdateWindowMode)-(-1)] UIContentImpl: UpdateWindowMode, window mode is 1, hasDeco is 0
01-01 08:00:15.052 280-674/? I C02500/devsvc_manager_stub: StubGetService service intell_voice_trigger_manager_service found
01-01 08:00:15.052 638-1228/? I C04100/DHDM: [devicemanagerkit][GetUdidByNetworkId]:GetUdidByNetworkId start, pkgName: ohos.distributeddata.service
01-01 08:00:15.052 1251-1251/? I A0001a/SystemUI_Default: WindowManager --> create window[SystemUi_PrivacyIndicator] success.
01-01 08:00:15.052 415-452/? I C01510/IPCObjectProxy: 58: handle = 4 create, descriptor: IPCObjectProxy4
01-01 08:00:15.052 638-1228/? I C04100/DHDM: [devicemanagerkit][SendRequest]:IpcClientManager::SendRequest in
01-01 08:00:15.052 638-1228/? I C04100/DHDM: [devicemanagerkit][SendRequest]:IpcClientManager::SendRequest cmdCode: 9
01-01 08:00:15.052 1251-1251/? I A0001a/SystemUI_Default: NavigationBar_ServiceExtAbility --> addPrivacyIndicator window has created
01-01 08:00:15.052 1251-1251/? I C04200/JsWindowManager: <533>Window name = SystemUi_PrivacyIndicator, err = 0
01-01 08:00:15.052 638-1160/? I C01630/DistributedDB: [Syncer] LocalDataChanged no online standard devices, Label=7EDC83
01-01 08:00:15.052 284-284/? I C04100/DHDM: [devicemanagerservice][CheckPermission]:Enter PermissionManager::CheckPermission
01-01 08:00:15.052 617-718/? E C02500/"TriggerManagerImpl": [LoadAdapter][line:109]: get adapter device from hal failed, ret:0
01-01 08:00:15.052 617-718/? E C02500/intell_voice_trigger_manager_st: IntellVoiceTriggerManagerStubLoadAdapter_ failed, error code is -1
01-01 08:00:15.052 284-284/? I C04100/DHDM: [devicemanagerservice][CheckPermission]:PermissionMa

虽然只是截取了很少的一部分日志,内容也是比较多的,其中有很多不相关内容需要过滤掉,只关注直接相关的。经过笔者认真观察和手工过滤(搜索“intell_voice”关键字),最为核心的相关内容如下:

01-01 08:00:15.049 617-718/? E C02500/"TriggerManagerImpl": [LoadAdapter][line:109]: get adapter device from hal failed, ret:0
01-01 08:00:15.049 617-718/? E C02500/intell_voice_trigger_manager_st: IntellVoiceTriggerManagerStubLoadAdapter_ failed, error code is -1
01-01 08:00:15.049 1340-1340/? I C03900/Ace: [text_pattern.cpp(InitSurfacePositionChangedCallback)-(0)] Add position changed callback id 24
01-01 08:00:15.049 415-1358/? E C01510/BinderInvoker: 124: SendRequest: handle=4 result = -1
01-01 08:00:15.049 415-1358/? E C02500/intell_voice_trigger_manager_pr: LoadAdapter_ failed, error code is -1
01-01 08:00:15.049 415-1358/? E C02500/TriggerConnector: [TriggerConnector:42]: failed to load adapter, adapterName is primary
01-01 08:00:15.049 415-1358/? W C01510/IPCObjectProxy: 63: handle = 4 destroyed, descriptor: IPCObjectProxy4
01-01 08:00:15.049 1340-1396/? E C01400/OHOS::ROSEN: print log error in vsprintf_s

进而,通过日志可以推出条目前边的号(C02500)是一把“钥匙”,笔者目前理解这个号可能是进程号或者标识一个进程的标志(具体代表什么可以请懂的朋友指出,目前我是这样理解的,意思是这意思)。再以“C02500”关键字作为过滤器,就能够滤除与智能语音(强)相关的日志了。

(1)“get adapter device from hal failed, ret:0”

以“get adapter device from hal failed”为关键字,在OpenHarmony源码根目录下进行搜索,结果如下:

ph@ph-virtual-machine:~/OpenHarmony_Source$ grep -rn "get adapter device from" ./
./drivers/peripheral/intelligent_voice/hdi_service/trigger/intell_voice_trigger_manager_impl.cpp:109:        INTELLIGENT_VOICE_LOGE("get adapter device from hal failed, ret:%{public}d", ret);
./drivers/peripheral/intelligent_voice/hdi_service/engine/intell_voice_engine_manager_impl.cpp:101:        INTELLIGENT_VOICE_LOGE("get adapter device from hal failed");

由于日志中带有“ret:0”,因此是第1个搜素结果。看一下./drivers/peripheral/intelligent_voice/hdi_service/trigger/intell_voice_trigger_manager_impl.cpp文件第109行内容,代码如下:

int32_t IntellVoiceTriggerManagerImpl::LoadAdapter(const IntellVoiceTriggerAdapterDsecriptor &descriptor,
    sptr<IIntellVoiceTriggerAdapter> &adapter)
{
    std::lock_guard<std::mutex> lock(mutex_);

    if (inst_ == nullptr) {
        INTELLIGENT_VOICE_LOGE("inst is nullptr");
        return HDF_FAILURE;
    }

    auto it = halAdapters_.find(descriptor.adapterName);
    if (it != halAdapters_.end()) {
        INTELLIGENT_VOICE_LOGW("adapter %{public}s already exist", descriptor.adapterName.c_str());
        inst_->UnloadAdapter(descriptor);
        it->second = nullptr;
        halAdapters_.erase(it);
    }

    std::unique_ptr<ITrigger> triggerAdapterDevice = nullptr;
    int32_t ret = inst_->LoadAdapter(descriptor, triggerAdapterDevice);
    if (triggerAdapterDevice == nullptr) {
        INTELLIGENT_VOICE_LOGE("get adapter device from hal failed, ret:%{public}d", ret);
        return HDF_FAILURE;
    }

    adapter = sptr<IIntellVoiceTriggerAdapter>(new (std::nothrow) IntellVoiceTriggerAdapterImpl(
        std::move(triggerAdapterDevice)));
    if (adapter == nullptr) {
        INTELLIGENT_VOICE_LOGE("new adapter failed");
        return HDF_ERR_MALLOC_FAIL;
    }

    halAdapters_[descriptor.adapterName] = adapter;
    return HDF_SUCCESS;
}

IntellVoiceTriggerManagerImpl::LoadAdapter()中的以下一行打印出了日志信息:

INTELLIGENT_VOICE_LOGE("get adapter device from hal failed, ret:%{public}d", ret);

相关上下文如下:

    std::unique_ptr<ITrigger> triggerAdapterDevice = nullptr;
    int32_t ret = inst_->LoadAdapter(descriptor, triggerAdapterDevice);
    if (triggerAdapterDevice == nullptr) {
        INTELLIGENT_VOICE_LOGE("get adapter device from hal failed, ret:%{public}d", ret);
        return HDF_FAILURE;
    }

由代码可见,之所以会打印出此信息,是由于调用“inst_->LoadAdapter(descriptor, triggerAdapterDevice);”之后,triggerAdapterDevice仍然是nullptr。

(2)“intell_voice_trigger_manager_st: IntellVoiceTriggerManagerStubLoadAdapter_ failed, error code is -1”

这次不直接搜索,而是直接找到Open Harmony源码根目录/out/rk3588/gen/drivers/interface/intelligent_voice/trigger/v1_0/intell_voice_trigger_manager_stub.cpp文件 。并在其中以“failed, error code is”为关键字进行搜索,可知其在以下函数中:

int32_t OHOS::HDI::IntelligentVoice::Trigger::V1_0::IntellVoiceTriggerManagerStub::IntellVoiceTriggerManagerStubLoadAdapter_(MessageParcel& intellVoiceTriggerManagerData, MessageParcel& intellVoiceTriggerManagerReply, MessageOption& intellVoiceTriggerManagerOption, sptr<OHOS::HDI::IntelligentVoice::Trigger::V1_0::IIntellVoiceTriggerManager> impl)
{
    if (intellVoiceTriggerManagerData.ReadInterfaceToken() != OHOS::HDI::IntelligentVoice::Trigger::V1_0::IIntellVoiceTriggerManager::GetDescriptor()) {
        HDF_LOGE("%{public}s: interface token check failed!", __func__);
        return HDF_ERR_INVALID_PARAM;
    }

    IntellVoiceTriggerAdapterDsecriptor descriptor;
    if (!IntellVoiceTriggerAdapterDsecriptorBlockUnmarshalling(intellVoiceTriggerManagerData, descriptor)) {
        HDF_LOGE("%{public}s: read descriptor failed!", __func__);
        return HDF_ERR_INVALID_PARAM;
    }

    sptr<OHOS::HDI::IntelligentVoice::Trigger::V1_0::IIntellVoiceTriggerAdapter> adapter;

    if (impl == nullptr) {
        HDF_LOGE("%{public}s: impl is nullptr!", __func__);
        return HDF_ERR_INVALID_PARAM;
    }

    int32_t intellVoiceTriggerManagerRet = impl->LoadAdapter(descriptor, adapter);
    if (intellVoiceTriggerManagerRet != HDF_SUCCESS) {
        HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, intellVoiceTriggerManagerRet);
        return intellVoiceTriggerManagerRet;
    }

    if (adapter == nullptr) {
        HDF_LOGE("%{public}s: parameter adapter is nullptr!", __func__);
        return HDF_ERR_INVALID_PARAM;
    }

    if (!intellVoiceTriggerManagerReply.WriteRemoteObject(OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(adapter, OHOS::HDI::IntelligentVoice::Trigger::V1_0::IIntellVoiceTriggerAdapter::GetDescriptor()))) {
        HDF_LOGE("%{public}s: write adapter failed!", __func__);
        return HDF_ERR_INVALID_PARAM;
    }

    return intellVoiceTriggerManagerRet;
}

相关代码片段如下:

    int32_t intellVoiceTriggerManagerRet = impl->LoadAdapter(descriptor, adapter);
    if (intellVoiceTriggerManagerRet != HDF_SUCCESS) {
        HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, intellVoiceTriggerManagerRet);
        return intellVoiceTriggerManagerRet;
    }

(3)“intell_voice_trigger_manager_pr: LoadAdapter_ failed, error code is -1”

以“intell_voice_trigger_manager_pr”为关键字,在OpenHarmony源码根目录下进行搜索,在众多结果中定位到:

./out/rk3588/gen/drivers/interface/intelligent_voice/trigger/v1_0/intell_voice_trigger_manager_proxy.cpp:16:#include "v1_0/intell_voice_trigger_manager_proxy.h"
./out/rk3588/gen/drivers/interface/intelligent_voice/trigger/v1_0/intell_voice_trigger_manager_proxy.cpp:26:#define HDF_LOG_TAG    intell_voice_trigger_manager_proxy

打开

./out/rk3588/gen/drivers/interface/intelligent_voice/trigger/v1_0/intell_voice_trigger_manager_proxy.cpp文件 ,并在其中以“failed, error code is”为关键字进行搜索,可知其在以下函数中:

int32_t OHOS::HDI::IntelligentVoice::Trigger::V1_0::IntellVoiceTriggerManagerProxy::LoadAdapter_(const IntellVoiceTriggerAdapterDsecriptor& descriptor, sptr<OHOS::HDI::IntelligentVoice::Trigger::V1_0::IIntellVoiceTriggerAdapter>& adapter, const sptr<IRemoteObject> remote)
{
    MessageParcel intellVoiceTriggerManagerData;
    MessageParcel intellVoiceTriggerManagerReply;
    MessageOption intellVoiceTriggerManagerOption(MessageOption::TF_SYNC);

    if (!intellVoiceTriggerManagerData.WriteInterfaceToken(OHOS::HDI::IntelligentVoice::Trigger::V1_0::IIntellVoiceTriggerManager::GetDescriptor())) {
        HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__);
        return HDF_ERR_INVALID_PARAM;
    }

    if (!IntellVoiceTriggerAdapterDsecriptorBlockMarshalling(intellVoiceTriggerManagerData, descriptor)) {
        HDF_LOGE("%{public}s: write descriptor failed!", __func__);
        return HDF_ERR_INVALID_PARAM;
    }

    int32_t intellVoiceTriggerManagerRet = remote->SendRequest(CMD_INTELL_VOICE_TRIGGER_MANAGER_LOAD_ADAPTER, intellVoiceTriggerManagerData, intellVoiceTriggerManagerReply, intellVoiceTriggerManagerOption);
    if (intellVoiceTriggerManagerRet != HDF_SUCCESS) {
        HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, intellVoiceTriggerManagerRet);
        return intellVoiceTriggerManagerRet;
    }

    if (!ReadInterface<OHOS::HDI::IntelligentVoice::Trigger::V1_0::IIntellVoiceTriggerAdapter>(intellVoiceTriggerManagerReply, adapter)) {
        HDF_LOGE("%{public}s: failed to read interface object", __func__);
        return HDF_ERR_INVALID_PARAM;
    }

    return intellVoiceTriggerManagerRet;
}

相关代码片段如下:

    int32_t intellVoiceTriggerManagerRet = remote->SendRequest(CMD_INTELL_VOICE_TRIGGER_MANAGER_LOAD_ADAPTER, intellVoiceTriggerManagerData, intellVoiceTriggerManagerReply, intellVoiceTriggerManagerOption);
    if (intellVoiceTriggerManagerRet != HDF_SUCCESS) {
        HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, intellVoiceTriggerManagerRet);
        return intellVoiceTriggerManagerRet;
    }

(4)“TriggerConnector: [TriggerConnector:42]: failed to load adapter, adapterName is primary”

以“failed to load adapter, adapterName”为关键字,在OpenHarmony源码根目录下进行搜索,在众多结果中定位到:

./foundation/ai/intelligent_voice_framework/services/intell_voice_trigger/server/connector_mgr/trigger_connector.cpp:42:            INTELL_VOICE_LOG_ERROR("failed to load adapter, adapterName is %{public}s", desc_.adapterName.c_str());
./foundation/ai/intelligent_voice_framework/services/intell_voice_trigger/server/connector_mgr/trigger_connector.cpp:108:            INTELL_VOICE_LOG_ERROR("failed to load adapter, adapterName is %{public}s", desc_.adapterName.c_str());

打开

./foundation/ai/intelligent_voice_framework/services/intell_voice_trigger/server/connector_mgr/trigger_connector.cpp文件 。根据上边的信息,该文件中共有两处可以产生此日志。到底是哪一处?笔者更倾向于第一处,即构造函数中。代码如下:

TriggerConnector::TriggerConnector(const IntellVoiceTriggerAdapterDsecriptor &desc)
{
    desc_.adapterName = desc.adapterName;
    auto mgr = IIntellVoiceTriggerManager::Get();
    if (mgr != nullptr) {
        mgr->LoadAdapter(desc_, adapter_);
        if (adapter_ == nullptr) {
            INTELL_VOICE_LOG_ERROR("failed to load adapter, adapterName is %{public}s", desc_.adapterName.c_str());
        }
    } else {
        INTELL_VOICE_LOG_INFO("can not get intell voice trigger manager");
    }
}

至此,与语音唤醒即intelligent voice相关的日志及其出处(出自于哪个文件中的哪个函数)就弄清楚了。下一回开始对于函数的调用流程进行分析。

01-12 10:44