Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Android slow startup of QNetworkAccessManager when offline



  • Hi,

    An example project can demonstrate that the application loads in 40 seconds when the device is offline (no network). The same code runs fine on iOS. What could be the workaround for Android to let the application start up fast?

    Qt 5.12.2 is in use.

    I don't have permission to upload the zip. I created it as a new empty QtQuick application.
    This is the main.cpp:

    #include <QGuiApplication>
    #include <QNetworkAccessManager>
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    
    int main(int argc, char *argv[])
    {
        int debugcounter=0;
        qint64 startsAt=QDateTime::currentMSecsSinceEpoch() ;
        qint64 timeStamp=startsAt;
        debugcounter++;qDebug() << "DEBUG " << debugcounter << ": APP STARTS at " << timeStamp;
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        timeStamp=QDateTime::currentMSecsSinceEpoch() ;
        debugcounter++;qDebug() << "DEBUG " << debugcounter << ": QNetworkAccessManager type pointer creation starts at " << timeStamp;
        QNetworkAccessManager *networkAccessManager_ ;
        timeStamp=QDateTime::currentMSecsSinceEpoch() ;
        debugcounter++;qDebug() << "DEBUG " << debugcounter << ": QGuiApplication creation starts at " << timeStamp;
        QGuiApplication app(argc, argv);
        timeStamp=QDateTime::currentMSecsSinceEpoch() ;
        debugcounter++;qDebug() << "DEBUG " << debugcounter << ": QNetworkAccessManager creation starts at " << timeStamp;
        networkAccessManager_ = new QNetworkAccessManager(&app);
        timeStamp=QDateTime::currentMSecsSinceEpoch() ;
        debugcounter++;qDebug() << "DEBUG " << debugcounter << ": QQmlApplicationEngine creation starts at " << timeStamp;
        QQmlApplicationEngine engine;
        QObject::connect(&engine, &QQmlApplicationEngine::quit, &QGuiApplication::quit);
        qint64 endsAt=QDateTime::currentMSecsSinceEpoch() ;
        qint64 startupTimeMiliSec=endsAt-startsAt;
        engine.rootContext()->setContextProperty("startupTimeMiliSec", startupTimeMiliSec);
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        if (engine.rootObjects().isEmpty())
            return -1;
    
        return app.exec();
    }
    
    

    And this is the main.qml:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        Text{
            text: "QNetworkAccessManager loaded in " + startupTimeMiliSec /1000+ " seconds."
        }
    }
    
    

    Android's logcat shows the following:

    D/        (31982): QML debugging is enabled. Only use this in a safe environment.
    D/dalvikvm(31982): Added shared lib /data/data/org.qtproject.example.AndroidStartupTimeOfflineQNA/lib/libAndroidStartupTimeOfflineQNA.so 0x4157ba28
    D/dalvikvm(31982): No JNI_OnLoad found in /data/data/org.qtproject.example.AndroidStartupTimeOfflineQNA/lib/libAndroidStartupTimeOfflineQNA.so 0x4157ba28, skipping init
    D/libEGL  (31982): loaded /system/lib/egl/libEGL_adreno200.so
    D/libEGL  (31982): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
    D/libEGL  (31982): loaded /system/lib/egl/libGLESv2_adreno200.so
    I/Adreno200-EGL(31982): <qeglDrvAPI_eglInitialize:269>: EGL 1.4 QUALCOMM build:  (CL2961769)
    I/Adreno200-EGL(31982): Build Date: 06/06/13 Thu
    I/Adreno200-EGL(31982): Local Branch: 17_182_qsida
    I/Adreno200-EGL(31982): Remote Branch: 
    I/Adreno200-EGL(31982): Local Patches: 
    I/Adreno200-EGL(31982): Reconstruct Branch: 
    D/OpenGLRenderer(31982): Enabling debug mode 0
    D/        (31982): DEBUG  1 : APP STARTS at  1558342827164
    D/        (31982): DEBUG  2 : QNetworkAccessManager type pointer creation starts at  1558342827165
    D/        (31982): DEBUG  3 : QGuiApplication creation starts at  1558342827165
    I/ClipboardService(23618): Got clipboard for user=0
    I/ActivityManager(23618): Displayed org.qtproject.example.AndroidStartupTimeOfflineQNA/org.qtproject.qt5.android.bindings.QtActivity: +2s389ms
    D/FakeHome(23732): onStop
    W/AlienService(23618): Remove AlienWorkerHandler.MSG_APP_WINDOW_DRAWN from queue!
    I/WLAlienSurface(23618): appWindowDrawn, mId = 14
    D/AlienRuntime(23618): updateOomScoreAdj() arrLength = 1
    D/alien_init(23408): Set process(pid = 31982) score_adj as [0]
    D/libAndroidStartupTimeOfflineQNA.so(31982): DEBUG  4 : QNetworkAccessManager creation starts at  1558342827355
    D/ConnectivityService(23618): activateNativeNetwork, uid:10025
    D/ConnectivityService(23618): getActiveNetworkInfo, topActivity pkg=org.qtproject.example.AndroidStartupTimeOfflineQNA
    D/ConnectivityService(23618): Find process:uid:10025; processName:org.qtproject.example.AndroidStartupTimeOfflineQNA
    D/AlienConnectivityService(23472): AlienConnectivityService checkAndActivate.
    D/AlienConnectivityService(23472): Connectivity::checkAndActivate,state =idle
    D/AlienConnectivityService(23472): using ping to triger message box for selecting network to popup.
    D/AlienRilInterfaceService(23472): onRequest RIL_REQUEST_SIGNAL_STRENGTH, strengthValue:67 convertValue:20
    D/StatusBar.NetworkController(23687): refreshViews: Data not connected!! Set no data type icon
    D/AlienRuntime(23618): _output_handle_geometry  
    D/AlienRuntime(23618): _output_handle_geometry 0x0
    D/AlienRuntime(23618): _output_handle_geometry 57x100
    D/AlienRuntime(23618): _output_handle_geometry transform = 3
    D/AlienRuntime(23618): setSailfishOrientation
    D/InputDispatcher(23618): setInputDispatchMode: Alien set to: enabled=1, frozen=0
    W/AlienEventHub(23618): ALIEN: setExcludedDevices is not supported
    I/InputReader(23618): Reconfiguring input devices.  changes=0x00000004
    I/InputReader(23618): Device reconfigured: id=1, name='alien_wayland_pointer', surface size is now 540x960, mode is 1
    W/AlienEventHub(23618): ALIEN: getVirtualKeyDefinitions is not supported
    I/InputReader(23618): Device reconfigured: id=2, name='alien_wayland_touch', surface size is now 540x960, mode is 1
    W/AlienEventHub(23618): ALIEN: getVirtualKeyDefinitions is not supported
    I/ActivityManager(23618): Config changed: {1.0 216mcc70mnc en_GB sw360dp w598dp h360dp nrml land ?uimode ?night finger qwerty/v/h dpad/v s.16}
    I/AlienServiceJNI(23618): appOrientationChanged:1
    D/AlienRuntime(23618): WLAlienRuntime::appOrientationChanged, angle = 1
    D/StatusBar.NetworkController(23687): refreshViews: Data not connected!! Set no data type icon
    I/dalvikvm(23618): Jit: resizing JitTable from 8192 to 16384
    D/InputDispatcher(23618): setInputDispatchMode: Alien set to: enabled=1, frozen=0
    D/AlienRilInterfaceService(23472): onRequest RIL_REQUEST_SIGNAL_STRENGTH, strengthValue:67 convertValue:20
    D/dalvikvm(23618): WAIT_FOR_CONCURRENT_GC blocked 0ms
    D/dalvikvm(23618): GC_EXPLICIT freed 543K, 29% free 10362K/14407K, paused 7ms+3ms, total 69ms
    D/libAndroidStartupTimeOfflineQNA.so(31982): DEBUG  5 : QQmlApplicationEngine creation starts at  1558342867447
    D/ConnectivityService(23618): activateNativeNetwork, uid:10025
    D/ConnectivityService(23618): getActiveNetworkInfo, topActivity pkg=org.qtproject.example.AndroidStartupTimeOfflineQNA
    D/ConnectivityService(23618): Find process:uid:10025; processName:org.qtproject.example.AndroidStartupTimeOfflineQNA
    D/AlienConnectivityService(23472): AlienConnectivityService checkAndActivate.
    D/AlienConnectivityService(23472): Connectivity::checkAndActivate,state =idle
    D/AlienConnectivityService(23472): using ping to triger message box for selecting network to popup.
    
    


  • Is there a mentor who would teach me how to identify this bug's root cause? Please let me know how much I should pay for it.


Log in to reply