/usr/bin/ubiquity-bluetooth-agent is in ubiquity 2.21.63.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #!/usr/bin/python3
import os
import sys
import dbus
import dbus.service
import dbus.mainloop.glib
from gi.repository import GLib
class Rejected(dbus.DBusException):
    _dbus_error_name = "org.bluez.Error.Rejected"
class Agent(dbus.service.Object):
    exit_on_release = True
    def set_exit_on_release(self, exit_on_release):
        self.exit_on_release = exit_on_release
    @dbus.service.method("org.bluez.Agent", in_signature="", out_signature="")
    def Release(self):
        if self.exit_on_release:
            mainloop.quit()
    @dbus.service.method("org.bluez.Agent",
                         in_signature="os", out_signature="")
    def Authorize(self, device, uuid):
        bus = dbus.SystemBus()
        attr = dbus.Interface(
            bus.get_object("org.bluez", device),
            "org.bluez.Device").GetProperties()
        # Only accept input (HID) devices
        if 'Class' in attr:
            if (attr['Class'] & 0x500) == 0x500:
                dbus.Interface(
                    bus.get_object("org.bluez", device),
                    "org.bluez.Device").SetProperty("Trusted", True)
                return
        raise Rejected("Connection rejected by user")
    @dbus.service.method("org.bluez.Agent",
                         in_signature="o", out_signature="s")
    def RequestPinCode(self, device):
        return "0000"
    @dbus.service.method("org.bluez.Agent",
                         in_signature="o", out_signature="u")
    def RequestPasskey(self, device):
        return dbus.UInt32(0000)
    @dbus.service.method("org.bluez.Agent",
                         in_signature="ou", out_signature="")
    def DisplayPasskey(self, device, passkey):
        return
    @dbus.service.method("org.bluez.Agent",
                         in_signature="ou", out_signature="")
    def RequestConfirmation(self, device, passkey):
        return
    @dbus.service.method("org.bluez.Agent", in_signature="s", out_signature="")
    def ConfirmModeChange(self, mode):
        return
    @dbus.service.method("org.bluez.Agent", in_signature="", out_signature="")
    def Cancel(self):
        return
def exit_handler():
    if not os.path.exists("/tmp/ubiquity-bluetooth-done"):
        with open("/tmp/ubiquity-bluetooth-done", "w+"):
            pass
    if os.path.exists("/usr/bin/bluetooth-applet.orig"):
        os.execl("/usr/bin/bluetooth-applet.orig", "bluetooth-applet")
    elif os.path.exists("/usr/bin/bluetooth-applet"):
        os.execl("/usr/bin/bluetooth-applet", "bluetooth-applet")
    else:
        sys.exit(0)
    return False
if os.path.exists("/tmp/ubiquity-bluetooth-done"):
    exit_handler()
try:
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    bus = dbus.SystemBus()
    manager = dbus.Interface(
        bus.get_object("org.bluez", "/"), "org.bluez.Manager")
    adapter = dbus.Interface(
        bus.get_object("org.bluez", manager.DefaultAdapter()),
        "org.bluez.Adapter")
    agent = Agent(bus, "/ubiquity/bluetooth/agent")
    mainloop = GLib.MainLoop()
    adapter.RegisterAgent("/ubiquity/bluetooth/agent", "DisplayYesNo")
except dbus.exceptions.DBusException:
    exit_handler()
GLib.timeout_add(300000, exit_handler)
mainloop.run()
 |