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

[6.5 LTS][Android] Qt app cannot know if the user rejected Bluetooth permissions, and cannot respond appropriately

    XMLWordPrintable

Details

    • Android

    Description

      Code

      #include <QApplication>
      #include <QVBoxLayout>
      #include <QPushButton>
      #include <QBluetoothDeviceDiscoveryAgent>
      #include <QPermissions>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QBluetoothPermission p;
          qDebug() << "Bluetooth permission status:" << app.checkPermission(p);
      
          QBluetoothDeviceDiscoveryAgent agent;
          QObject::connect(&agent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, &app, [](const QBluetoothDeviceInfo& info){
              qDebug() << "Discovered device:" << info.name();
          });
      
          QWidget win;
          auto layout = new QVBoxLayout(&win);
          auto btn_req = new QPushButton ("Request Bluetooth Permissions");
          auto btn_scan = new QPushButton ("Start Scanning");
          layout->addWidget(btn_req);
          layout->addWidget(btn_scan);
          win.show();
      
          QObject::connect(btn_req, &QPushButton::clicked, &app, [&] {
              app.requestPermission(p, &app, [&]{
                  qDebug() << "Permission requested.";
                  qDebug() << "Bluetooth permission status:" << app.checkPermission(p);
              });
          });
          QObject::connect(btn_scan, &QPushButton::clicked, &app, [&] {
              agent.start();
              qDebug() << "Started trying to scan";
              qDebug() << "Bluetooth permission status:" << app.checkPermission(p);
          });
      
          return app.exec();
      }
      

      Steps to reproduce

      1. Build and run the code above
      2. Click "Start Scanning"
      3. When the (automatic) permission dialog pops up, select "Don't allow"

       

      Outcomes
      At startup (Step #1), we immediately see Bluetooth permission status: Qt::PermissionStatus::Granted. (The expected status is Qt::PermissionStatus::Undetermined)

       

      After Step #2, we see the following debug output:

      W qt.bluetooth.android: : Search not possible due to missing permission (ACCESS_FINE_LOCATION)
      D libBluetoothPermissionsStudy_arm64-v8a.so: Started trying to scan
      D libBluetoothPermissionsStudy_arm64-v8a.so: Bluetooth permission status: Qt::PermissionStatus::Granted
      

      (The expected status is Qt::PermissionStatus::Denied)

       

      After Step #3, the permission dialog does not appear again, yet we see the following debug output:

      D libBluetoothPermissionsStudy_arm64-v8a.so: Permission requested.
      D libBluetoothPermissionsStudy_arm64-v8a.so: Bluetooth permission status: Qt::PermissionStatus::Granted
      

      (The expected status is Qt::PermissionStatus::Denied)

       

      Summary
      The Qt app will work fine if the user provides all the necessary permissions. But if the user denies a Bluetooth-related permission, the Qt app is still told that the permission is granted. It has no way of gracefully switching to reduced-functionality mode, or informing the user of the missing permission.

       

      Qt 6.7 and newer behaves correctly.

      Attachments

        Issue Links

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

          Activity

            People

              ablasche Alex Blasche
              skoh-qt Sze Howe Koh
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes