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

QGeoPositionInfoSource does not work from Android service

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.2.0
    • 5.11.2
    • Positioning
    • None
    • * Host: Windows 10 64 bit
      * Qt 5.11.2 Android x86 (official)
      * NDK 16b
      * SDK 28
      * Target Android x86 8.1 - rc1 (running on VM on a host)
      * Android API 21
    • Android
    • 13
    • Qt6_Foundation_Sprint 36

    Description

      This code (running as a service) does nothing:

      #include <QAndroidService>
      #include <QGeoPositionInfoSource>
      #include <QLoggingCategory>
      #include <QTimer>
      
      Q_LOGGING_CATEGORY(APP, "bug.svc")
      
      int main(int argc, char *argv[])
      {
          QAndroidService::setAttribute(Qt::AA_EnableHighDpiScaling);
          QAndroidService app(argc, argv);
      
          qCDebug(APP) << "I'm service";
      
          const auto t = new QTimer(qApp);
          QCoreApplication::connect(t, &QTimer::timeout, []() {
              static int counter = 0;
              qCWarning(APP) << "CNT:" << counter;
              ++counter;
          });
          t->start(1000);
      
          const auto ps = QGeoPositionInfoSource::createDefaultSource(qApp);
          if (!ps) {
              qCCritical(APP) << "OOPS, unable to create a position source";
          } else {
              QCoreApplication::connect(ps, &QGeoPositionInfoSource::positionUpdated,
                                        [](const QGeoPositionInfo &update) {
                  const auto coord = update.coordinate();
                  qCDebug(APP) << "CRD:" << coord;
              });
              ps->setUpdateInterval(3000);
              ps->startUpdates();
          }
      
          return app.exec();
      }
      

      I mean that:

      1) I did not see any timer's counter traces in a console logcat output.

      2) I did not see any position source traces in a console logcat output.

      I have attached an compilable example which contains both app and service parts.

      How to reproduce an issue:

      1. Run 'adb logcat'
      2. Startup an application.
      3. Make sure that "I'm application" trace is present.
      4. Make sure that all 'CNT' and 'CRD' traces are available (because an application running as an 'app' in that time).
      5. Go application to background (e.g. by clicking on 'HOME' button).
      6. Make sure that the 'Went to background' trace is present.
      7. Make sure that "I'm service" trace is present.

      Next, observe that no any traces are present (after p.7), as no timer's traces andas no position source's traces (please, see an attached log)!

      Seems, it is a bug!

      PS: If to comments out a part of a code, related to the position source from the service, and repeat a previous points, then you can see that a timer's traces are available when a service is running.

       

      UPD: To simulate a GPS coordinates (for Android x86 running on a VM) I use the "Fake GPS" application.

       

      Attachments

        1. qtbug-73396.zip
          7 kB
        2. logcat.log.txt
          8 kB
        3. qtbug-71396-qt6.zip
          8 kB

        Issue Links

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

          Activity

            People

              ivan.solovev Ivan Solovev
              kuzulis Denis Shienkov
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes