7

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nguyen Minh Binh
  • 23,891
  • 30
  • 115
  • 165

2 Answers2

8

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...

Community
  • 1
  • 1
mcia
  • 151
  • 4
  • AFAIK, No API to capture screenshot. So, I try to execute screencap via shell command. But I can't execute it without root permission. – Nguyen Minh Binh Sep 27 '12 at 07:30
  • It seems so. There is no API and you need root to run screencap. I've found this library http://code.google.com/p/android-screenshot-library/ with this you should be able to take screenshots without root. It installs a native service, started at boot through adb shell. So its capable to take screenshots. – mcia Sep 27 '12 at 08:06
  • I have tried it before. It doesn't work on android 3.x and android 4.x since framebuffer was broken there. The acceptable way now is that call screencap via shell command (under root permisson) – Nguyen Minh Binh Sep 27 '12 at 08:15
  • I have used same command in a same way as mentioned above, but I got following error: E/SurfaceFlinger(36): Permission Denial: can't read framebuffer pid=18735, uid=10053 Please help me. – Parveen Sep 05 '13 at 12:39
  • Thanks for your answer. But I don't understand how the hardware buttons do it on not rooted devices. Do you have any idea how the screen capture works in those cases? – rkachach Apr 03 '18 at 13:36
2

Is there any way to run android system app without root permission?

It have to be NO, but some times, some functions which are not for public use still can be used. I've seen examples using java reflection.

I can execute system app via adb such as: ...

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?

I think, no.

The thing is adb shell and user app have different security levels based on User and Group IDs (UID and GID).

More info: http://android-dls.com/wiki/index.php?title=Android_UIDs_and_GIDs

Besides, there are limitations via app permissions and hiden & internal classes, procedures, etc which made for internal use.

P.S.: About screenshots. On android market (google play) there are few apps which provide screenshots without ROOT access. So, it's possible. Although, since Android 4.0 screenshots are available "from box".

Community
  • 1
  • 1
Inoy
  • 1,065
  • 1
  • 17
  • 24