2

I'm trying to take a screensshot over adb logged as root and I'm getting a "Permission Denied" error.

screenshot -i /sdcard/screen.png
error: writing file /sdcard/screen.png: Permission denied

But if I use screencap it works.

screencap -p /sdcard/screen.png

Why is this happening ?

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268

2 Answers2

2

According to the source code screenshot sets UID to AID_SHELL (shell user) before writing the file:

/* switch to non-root user and group */
gid_t groups[] = { AID_LOG, AID_SDCARD_RW };
setgroups(sizeof(groups)/sizeof(groups[0]), groups);
setuid(AID_SHELL);

png = fopen(outfile, "w");
if (!png) {
    fprintf(stderr, "error: writing file %s: %s\n",
            outfile, strerror(errno));
    exit(1);
}
Alex P.
  • 30,437
  • 17
  • 118
  • 169
0

You just modify the property of directory '/sdcard'

 chmod 777 /sdcard

This works in my phone.

davejal
  • 6,009
  • 10
  • 39
  • 82
zqer
  • 115
  • 10