Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-64796

[bluez] QBluetoothLocalDevice not emit any errors

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.9.1
    • None
      • Fedora 26 64 bit XFCE
      • connman installed
      • bluez5

    Description

      In case, e.g. when the 'rfkill' utility blocks the bluetooth adapter, then the QBluetoothLocalDevice::setHostMode() does nothing (e.g. at trying to set power on),  and does not emit any errors (though they are present).

      Reason is that QBluetoothLocalDevice uses 'direct' adapter properties control, e.g.:

      d_ptr->adapterBluez5->setPowered(true);

      which is silence.

      If try to change the adapter properties with OrgFreedesktopDBusPropertiesInterface then it failed with:

      "org.bluez.Error.BlockedBlocked through rfkill"
      

      So, we can watch for errors and pass them to the QBluetoothLocalDevice::error() signal.

      I also write a custom own code for this, that works (at least for power control):

          const auto adapterPath = DbusUtils::defaultAdapterObjectPath();
          d->adapter = new OrgBluezAdapter1Interface(
                      QStringLiteral("org.bluez"),
                      adapterPath,
                      QDBusConnection::systemBus(),
                      this);
      
          d->adapterProperties = new OrgFreedesktopDBusPropertiesInterface(
                      QStringLiteral("org.bluez"),
                      d->adapter->path(),
                      QDBusConnection::systemBus(),
                      this);
      
          connect(d->adapterProperties, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged,
                  [this](const QString &interface, const QVariantMap &changedProperties,
                  const QStringList &invalidatedProperties) {
              qCDebug(btDiscoveryAgent) << "Props changed" << interface << changedProperties;
          });
      
          // Set powered on
          qCDebug(btDiscoveryAgent) << "Starting async set power on";
      
          const auto result = d->adapterProperties->Set(
                      QLatin1String("org.bluez.Adapter1"),
                      QLatin1String("Powered"),
                      QDBusVariant(QVariant::fromValue(true)));
          const auto watcher = new QDBusPendingCallWatcher(result, this);
      
          connect(watcher, &QDBusPendingCallWatcher::finished,
                  [this](QDBusPendingCallWatcher *watcher) {
      
              const QDBusPendingReply<> reply = *watcher;
              if (reply.isError()) {
                  const auto errorMsg = reply.error().name()
                          + reply.reply().errorMessage();
                  qCWarning(btDiscoveryAgent) << "Async set power on failed"
                                              << errorMsg;
              } else {
                  qCDebug(btDiscoveryAgent) << "Async set power on completed";
              }
      
              watcher->deleteLater();
          });
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            ablasche Alex Blasche
            kuzulis Denis Shienkov
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes