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

QNetworkConfigurationManager::isOnline needs to be replaced with a set of more specific functions (isAirplaneModeEnabled, isWifiEnabled etc)

    XMLWordPrintable

Details

    Description

      References:
      > original issue https://bugreports.qt.io/browse/QTBUG-56151
      > relevant discussion in Qt Network Workshop at the last QtCon: https://wiki.qt.io/Qt_Network_Workshop_2016#Performance

      The problem is, the name of this method ("isOnline()") makes people think that this function is suitable for checking if the device has active connection to the Internet, and in fact it does something else:

      http://doc.qt.io/qt-5/qnetworkconfigurationmanager.html#isOnline

      Returns true if the system is considered to be connected to another device via an active network interface; otherwise returns false.
      This is equivalent to the following code snippet:

      QNetworkConfigurationManager mgr;
      QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active);
      if (activeConfigs.count() > 0)
          Q_ASSERT(mgr.isOnline());
      else
          Q_ASSERT(!mgr.isOnline());
      

      That logic does not work for iOS: starting since some iOS 9.x version, there is a "utun0" interface available which Apple uses for "Back to my mac" feature and this interface is always on. It is also used for VPN services on both macOS and iOS, so we can't just filter interfaces based on their names, because in this case isOnline() would give false positives in case if one had any VPN clients running on their system.
      It also not possible to determine with 100% probability whether device is connected to the Internet, because there are so many possible cases (device can be in airplane mode but wi-fi interface can be on at the same time; the fact that wi-fi is on and device is connected to some network still does not guarantee that device can actually reach any remote hosts because network might be captive as it often is in public places, when after you connect you can only access some certain websites and you only get full access after you enter your email address or pay), and this function only returns either true or false. From other side, if we tried to send a web request to some remote host, say google.com or apple.com and if the request would fail, that didn't mean network is not available either, because even google.com or apple.com might be down for a short period of time.

      Based on our discussion with jakepetroules, I suggest to deprecate isOnline() function and add a few new ones:
      1) bool isWifiEnabled()
      2) bool isHostReachable(QUrl)
      3) bool isAirplaneModeEnabled() - can be difficult to implement due to the fact that not all platforms have standardized "airplane mode" feature (linux) and some of those which do have this feature do not provide public API for querying that (iOS).

      Attachments

        Issue Links

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

          Activity

            People

              cnn Qt Core & Network
              wearyinside Oleg Yadrov
              Votes:
              7 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes