• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
UBports Robot Logo UBports Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Ability to toggle airplane / flight mode within an app

Scheduled Pinned Locked Moved App Development
7 Posts 4 Posters 809 Views 5 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      AppLee
      last edited by 24 Mar 2019, 13:10

      Hi everyone,
      I'm new to UbPorts development and I'm wondering if it is possible for a QML app to toggle the flight mode?

      I searched the web and the forum and found nothing.
      By the way, let me introduce myself:
      I used to code in C/C++ and QT, I'm learning QML and UbPort development to create the missing apps for my UbPorts phone (Nexus 5).
      I switched to UbuntuTouch end of 2017 and I only created webapps for my personal use.
      I intend to contribute this year with full apps and few useful webapps for French people (banking, news, ...)

      My first project is a client for domoticz (https://www.domoticz.com server for home automation)

      A D 2 Replies Last reply 24 Mar 2019, 15:31 Reply Quote 0
      • A Offline
        AlainW94 @AppLee
        last edited by 24 Mar 2019, 15:31

        @AppLee Hi ! Maybe you can have a look to oFono, it is the app that is controlling the modem. In the documentation there is :

        Flight Mode

        • Flight Mode support. oFono uses the 'Online' property on the Modem interface
          that controls the state of the radio. When Online state is False, all
          interfaces that depend on the radio being on are removed. Other interfaces
          enter reduced functionality mode where only certain actions are available
          that do not depend on the radio. E.g. setting various settings on the local

        You can use D-bus message for putting the radio on or off:

        here you have the related d-Bus message :
        https://github.com/intgr/ofono/blob/master/doc/modem-api.txt

        Properties boolean Powered [readwrite]

        		Boolean representing the power state of the modem
        		device.
        
        	boolean Online [readwrite]
        
        		Boolean representing the rf state of the modem.
        

        Online is false in flight mode.

        Meizu Pro 5, Meizu Pro 5, Meizu Pro 5, Meizu Pro 5 (Yes I have 4 of them)
        Never forget that they are much more ideas inside two heads than in one...

        1 Reply Last reply Reply Quote 1
        • F Offline
          flohack
          last edited by 24 Mar 2019, 20:56

          And what about WiFi? Flight mode is more than just ofono radio πŸ™‚

          My languages: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

          1 Reply Last reply Reply Quote 1
          • D Offline
            dobey @AppLee
            last edited by 25 Mar 2019, 12:53

            @AppLee Why does your app need control of radio devices on the phone? Flight mode toggle is easily accessible from the top drop-down.

            If your app needs to check connectivity status, you should use the Ubuntu.Connectivity API from QML. You can check that network is available and show an error page when it's not, before performing tasks requiring network access.

            A 1 Reply Last reply 26 Mar 2019, 20:45 Reply Quote 0
            • A Offline
              AppLee @dobey
              last edited by 26 Mar 2019, 20:45

              @AlainW94 Thanks for the lead. I'm looking into this.
              @dobey I would like to trigger a network event on domoticz and right after toggle the flight mode.
              I would like the app to be able to switch it off if connectivity is unavailable.
              I already looked about Ubuntu.Connectivity to detect whether I can communicate with domoticz server or not.

              If you can think of a hack or something πŸ˜‰ I found it weird that this feature is unavailable to developers ???
              If there is a good reason I'm curious to know it, I like to understand when I'm stuck with a puzzle.

              Thanks for your help

              D 1 Reply Last reply 28 Mar 2019, 12:34 Reply Quote 0
              • D Offline
                dobey @AppLee
                last edited by 28 Mar 2019, 12:34

                @AppLee You cannot control flight mode from your app because that would allow your app to effect the connectivity of not only other apps, but the system itself.

                The app itself cannot disable flight mode, or connect to a network. However, you can show a warning and direct the user to enable network connectivity. Even if the radio is on, it doesn't guarantee you'll be able to connect to any specific domain. The route could be blocked for any number of reasons, and your app should deal with such errors in connection as well.

                Something like this as a component for swapping out an error page with real content when connectivity changes, should do.

                import QtQuick 2.7
                import Ubuntu.Connectivity 1.0
                
                Item {
                    Loader {
                        id: pageLoader
                        asynchronous: true
                        anchors.fill: parent
                        source: Connectivity.online ? "RealPage.qml" : "OfflinePage.qml"
                    }
                    Connections {
                        target: Connectivity
                        onOnlineChanged: {
                            pageLoader.setSource(Connectivity.online ? "Realpage.qml" : "OfflinePage.qml");
                        }
                    }
                }
                
                A 1 Reply Last reply 3 May 2019, 17:00 Reply Quote 1
                • A Offline
                  AppLee @dobey
                  last edited by 3 May 2019, 17:00

                  @dobey Thanks Dobey, now I understand why I cannot do it.

                  I published a first release of my app without this feature and after giving it more thoughts I'm not sure it would have been useful.
                  I appreciate the answer!

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post