Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Root access on Android
Forum Updated to NodeBB v4.3 + New Features

Root access on Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 3 Posters 1.6k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    St.Stanislav
    wrote on last edited by
    #1

    I have read a tons of forums and materials about this thing, but I have no correct idea how to do this. I'm working on some soft based on 5.15.* Qt version. Porting to Android was successful, but I have some problems with QSerialPort. As far I understand some issues can be solved with rooted devices. I have one and successfully can catch usb attaching event. Moreover QSerialPort::availablePorts() finds some ports, but QSerialPortError::PersmissionDenied is caught.

    So I want try to run my program with root privileges, but don't know how to do this. I would be appreciate for any help.

    jsulmJ KroMignonK 2 Replies Last reply
    0
    • S St.Stanislav

      I have read a tons of forums and materials about this thing, but I have no correct idea how to do this. I'm working on some soft based on 5.15.* Qt version. Porting to Android was successful, but I have some problems with QSerialPort. As far I understand some issues can be solved with rooted devices. I have one and successfully can catch usb attaching event. Moreover QSerialPort::availablePorts() finds some ports, but QSerialPortError::PersmissionDenied is caught.

      So I want try to run my program with root privileges, but don't know how to do this. I would be appreciate for any help.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @St-Stanislav So, did you root this device?
      To run an application as root you usually do:

      sudo ./MyApp
      # Or
      su
      ./MyApp
      

      Also, it is actually better to give the user running the app needed access rights instead of running whole application as root. For that you need to add your user to the group which is set on the device file.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • S St.Stanislav

        I have read a tons of forums and materials about this thing, but I have no correct idea how to do this. I'm working on some soft based on 5.15.* Qt version. Porting to Android was successful, but I have some problems with QSerialPort. As far I understand some issues can be solved with rooted devices. I have one and successfully can catch usb attaching event. Moreover QSerialPort::availablePorts() finds some ports, but QSerialPortError::PersmissionDenied is caught.

        So I want try to run my program with root privileges, but don't know how to do this. I would be appreciate for any help.

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @St-Stanislav said in Root access on Android:

        So I want try to run my program with root privileges, but don't know how to do this. I would be appreciate for any help.

        I think you take the problem from the wrong side, as @jsulm suggest, this is a permission issue. Which often happens with Android, depending on which API level your device is using!

        Have you checked if you have request corresponding permission in your manifest file?

        <uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />
        

        ==> https://developer.android.com/things/sdk/pio/uart

        I suppose your device is rooted, so you can try to install your app as system app ==> https://stackoverflow.com/questions/28302833/how-to-install-an-app-in-system-app-while-developing-from-android-studio

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        S 1 Reply Last reply
        2
        • jsulmJ jsulm

          @St-Stanislav So, did you root this device?
          To run an application as root you usually do:

          sudo ./MyApp
          # Or
          su
          ./MyApp
          

          Also, it is actually better to give the user running the app needed access rights instead of running whole application as root. For that you need to add your user to the group which is set on the device file.

          S Offline
          S Offline
          St.Stanislav
          wrote on last edited by
          #4

          @jsulm Yes, device is rooted and I have checked some applications, that request root privileges with popup on Android. Now I am able to show the same popup with

          QProcess serialProcess;
          serialProcess.start("su");
          serialProcess.waitForStarted(10000);
          serialProcess.waitForFinished();
          

          This trick shows permission's popup, but already found serial ports can not be opened anyway. I think that it's so due to main process stays non-root.

          jsulmJ 1 Reply Last reply
          0
          • S St.Stanislav

            @jsulm Yes, device is rooted and I have checked some applications, that request root privileges with popup on Android. Now I am able to show the same popup with

            QProcess serialProcess;
            serialProcess.start("su");
            serialProcess.waitForStarted(10000);
            serialProcess.waitForFinished();
            

            This trick shows permission's popup, but already found serial ports can not be opened anyway. I think that it's so due to main process stays non-root.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @St-Stanislav I suggest you first try to change access rights for the device, then there is no need for root at all.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • KroMignonK KroMignon

              @St-Stanislav said in Root access on Android:

              So I want try to run my program with root privileges, but don't know how to do this. I would be appreciate for any help.

              I think you take the problem from the wrong side, as @jsulm suggest, this is a permission issue. Which often happens with Android, depending on which API level your device is using!

              Have you checked if you have request corresponding permission in your manifest file?

              <uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />
              

              ==> https://developer.android.com/things/sdk/pio/uart

              I suppose your device is rooted, so you can try to install your app as system app ==> https://stackoverflow.com/questions/28302833/how-to-install-an-app-in-system-app-while-developing-from-android-studio

              S Offline
              S Offline
              St.Stanislav
              wrote on last edited by St.Stanislav
              #6

              @KroMignon @jsulm Yes, I have the following permissions in the manifest file

              <uses-permission android:name="android.permission.USB_PERMISSION"/>
              <uses-permission android:name="android.permission.BLUETOOTH"/>
              <uses-permission android:name="android.permission.CAMERA"/>
              <uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />
              

              Then I catch usb attaching event:

              <intent-filter>
              <action android:name="android.intent.action.MAIN"/>
              <category android:name="android.intent.category.LAUNCHER"/>
              <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
              </intent-filter>
              

              And filter devices by PID and VID:

              <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" />
              

              It works, when I attach my serial convertor with OTG, popup is opened and I can chose my program to be opened. But I don't really know, where my devices is mounted. Now I looking for any information with dmesg on my tablet.

              Thank you for your link, I will try it out.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved