python - ofono dbus自省(introspection): method not found

标签 python dbus pulseaudio hfp

根据ofono 1.17的文档:

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

有两个免提接口(interface):

  • org.ofono.Handsfree
  • org.ofono.HandsfreeAudioManager

我需要访问它们才能使pulseaudio正常工作。 它返回此错误:

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

但是该方法存在(根据上面的文档)并且具有该签名:对象路径,数组{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>

当然,我以用户“user”身份运行 ofono 和上面的代码。 我已经没有想法了...我应该进一步做什么来解决这个问题?

最佳答案

列表_obj

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

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方法的service参数必须是“org.ofono”,object_path参数必须是/(对于HandsfreeAudioManager)或[变量前缀]/{modem0,modem1,... }(用于免提)。

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

注册

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

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

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

返回的 ofono 对象一次性公开了所有已实现的接口(interface),因此如果该对象实现了很多接口(interface),可能会造成困惑。在这种情况下,您可以获得仅支持单个接口(interface)的代理对象(例如 python-dbus 的 dbus.Interface):

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

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

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

关于python - ofono dbus自省(introspection): method not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37132033/

相关文章:

javascript - Node dbus-native - 使用 connMan 连接到 WiFi 服务时传递密码

c - 在cygwin中编译linux C程序时遇到问题

linux - X11没有模拟音频输出

java - 直接linux机器音频到java程序

python - PyMySQL - 转义标识符

python - 计算两个字符串之间距离的算法

python - 遍历 Spark RDD

python - 尝试在 Docker 中运行 Cloudera Image

c - 使用 glib 通过 DBus 发送包含数组的结构数组

检查D-Bus对象是否存在