Search code examples
androidlinuxpermissionsscreenshotadb

Android Screenshot and Screencap Permissions


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 ?


Solution

  • 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);
    }