Run Android application as Shell User

2020-03-30 05:55发布

问题:

In my application, I need to start a native binary that opens and read from some /sys/kernel files. If I launch the native binary by connecting using adb shell (launching manually from /data/local/tmp), then everything works fine.

I would like the App to programmatically do two things,

  1. Copy the binary to /data/local/tmp/. Again this wont work as the normal android app doesnt have enough privileges.

  2. Start the binary as a shell user so I can have the necessary privileges. I have tried using android:sharedUserId="android.uid.shell , but that doesnt seem to work.

Please note that I don't need root to open the /sys files.
All I need is to be shell user.
Any thoughts will be greatly appreciated.

Thanks

回答1:

The shell UID is reserved for development and testing. Running an app with shell privileges is circumventing Google's security model. So you will not be able do it on a secured commercial device without rooting it.

A possible temporary (non-persistent between reboots) workaround would be:

  1. Use adb shell to start a background service process, running as shell UID

  2. In your application, using IPC to ask the service to perform special task for you