Search code examples
androidshelladb

How to run Android system app without root permission?


Is there any way to run Android system app without root permission? I can execute system app via adb such as:

adb shell /system/bin/screencap -p /sdcard/screen.png

In my own application, I wanna run a shell command like that without "su" command. Is there any way? How does android prevent user apps to execute system app?


Solution

  • You should be able to run this command in java code:

    Runtime.getRuntime().exec("screencap -p /sdcard/screen.png");
    

    There are some shell commands you can execute without having root. So you don't need to run "su". I'm not sure if you can execute screencap. Certainly you need permission to write to the SD_CARD in your app.

    android.permission.WRITE_EXTERNAL_STORAGE
    

    But why you don't use the Android API to make your screenshot? For more information read this post on stackoverflow: How to programmatically take a screenshot in Android?

    Androids security model bases on user ids, like Linux does. Each app gets his own user id. So your app has a userid like 1001. If your user is allowed to run the command you can, otherwise you will receive an error.

    EDIT:
    You need root to take screenshots or be a system application. There is a permission READ_FRAME_BUFFER but you only can obtain it when you are a system application. Its a security problem when an app could take screenshots of your device.

    I've found this API http://code.google.com/p/android-screenshot-library/ which promises to take screenshots without root. I didn't test it. The library starts a native service which then takes the screenshots for you. But you have to run the service each time your phone boots. So it gets the system privileges. That's not really comfortable...

    Conclusion: There is no nice way to take screenshots without root from code...