ofono dbus 自省:找不到方法

ofono dbus Introspection: method not found

根据ofono 1.17的文档:

https://github.com/rilmodem/ofono/tree/master/doc

有两个免提接口:

我需要访问它们才能让 pulseaudio 正常工作。 它returns这个错误:

E: [pulseaudio] backend-ofono.c: Failed to register as a handsfree audio agent with ofono: org.freedesktop.DBus.Error.UnknownMethod: Method "Register" with signature "oay" on interface "org.ofono.HandsfreeAudioManager" doesn't exist

但是该方法存在(根据上面的文档)并且具有该签名:对象路径,array{byte}。

因此我猜它不是不存在而是不可访问。 我写了一个简单的 Python 脚本来列出可用的服务,org.ofono 就在那里。

然后我添加了列出对象的代码:

def list_obj(bus, service, object_path):
    print(object_path)
    obj = bus.get_object(service, object_path)
    iface = dbus.Interface(obj, 'org.freedesktop.DBus.Introspectable')
    xml_string = iface.Introspect()
    for child in ElementTree.fromstring(xml_string):
        if child.tag == 'node':
            if object_path == '/':
                object_path = ''
            new_path = '/'.join((object_path, child.attrib['name']))
            list_obj(bus, service, new_path)

bus = dbus.SystemBus()
list_obj(bus, 'org.ofono.HandsfreeAudioManager', '/')

但我收到以下错误:

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.ofono.HandsfreeAudioManager': no such name

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.ofono.HandsfreeAudioManager was not provided by any .service files

我还检查了 dbus 的用户策略,在 /etc/dbus-1/system.d/ofono.conf:

<policy user="user">
  <allow own="org.ofono"/>
  <allow send_destination="org.ofono"/>
  <allow send_interface="org.ofono.SimToolkitAgent"/>
  <allow send_interface="org.ofono.PushNotificationAgent"/>
  <allow send_interface="org.ofono.SmartMessagingAgent"/>
  <allow send_interface="org.ofono.PositioningRequestAgent"/>
  <allow send_interface="org.ofono.HandsfreeAudioManager"/>
  <allow send_interface="org.ofono.Handsfree"/>   
</policy>

<policy at_console="true">
 <allow send_destination="org.ofono"/>   
</policy>

<policy context="default">
  <deny send_destination="org.ofono"/>   
</policy>

当然我运行ofono 和上面的代码作为用户"user"。 我 运行 没主意了...我应该怎么做才能解决这个问题?

list_obj

https://github.com/rilmodem/ofono/blob/master/doc/handsfree-audio-api.txt描述了以下接口:

Service     org.ofono
Interface   org.ofono.HandsfreeAudioManager
Object path /

https://github.com/rilmodem/ofono/blob/master/doc/handsfree-api.txt描述了这个:

Service     org.ofono
Interface   org.ofono.Handsfree
Object path [variable prefix]/{modem0,modem1,...}

这意味着 bus.get_object 方法的服务参数必须是 "org.ofono",object_path 参数必须是 /(对于 HandsfreeAudioManager)或 [变量前缀]/ {modem0,modem1,...}(免提)。

因此,您应该使用 obj(bus, 'org.ofono', '/').

注册

我猜测可能是您的 org.ofono / 对象没有实现 org.ofono.HandsfreeAudioManager 接口,或者 Register 的签名与文档中描述的不同。

您可能想尝试 pydbus - https://github.com/LEW21/pydbus 而不是已弃用的 python-dbus 绑定。它支持在代理对象上使用 Python 的内置 help() 函数,这样您就可以轻松查看所有支持的接口及其所有方法的签名:

from pydbus import SystemBus
bus = SystemBus()
ofono = bus.get("org.ofono", "/")
help(ofono)

返回的ofono对象一次公开了所有实现的接口,所以如果对象实现了很多接口,可能会造成混淆。在那种情况下,您可以获得仅支持单个接口的代理对象(类似于 python-dbus 的 dbus.Interface):

manager = ofono["org.ofono.HandsfreeAudioManager"]
help(manager)

但是,与 dbus.Interface(静默失败)不同,如果对象未实现此接口,它将抛出 KeyError。

(免责声明:我是 pydbus 的作者)