Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3875bf6c authored by Snild Dolkow's avatar Snild Dolkow Committed by Zoran Jovanovic
Browse files

Handle 'root' pseudo-package in the appops command

The AppOpsService handles the 'root' pseudo-package as any other; it
gets no automatic allowances. This is reasonable, but it blocked me from
accessing the mms-sms provider through the 'content' command, even in a
root shell.

So I tried to change the rules:

$ adb root
$ adb shell appops set root WRITE_SMS allow
Error: No UID for root in user 0

This error occurs in the appops command because there isn't really a
package called root, so the UID lookup via PackageManager fails.

But we know that root is UID 0, so we can just skip the lookup.
(Also, AppOpsService handles the other way around in getOpsLocked method.)

Change-Id: Ie0cad67efa438a74a4d9921d29933610cfb13974
parent c9390c8b
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -168,7 +168,12 @@ public class AppOpsCommand extends BaseCommand {
        final IPackageManager pm = ActivityThread.getPackageManager();
        final IAppOpsService appOpsService = IAppOpsService.Stub.asInterface(
                ServiceManager.getService(Context.APP_OPS_SERVICE));
        final int uid = pm.getPackageUid(packageName, userId);
        final int uid;
        if ("root".equals(packageName)) {
            uid = 0;
        } else {
            uid = pm.getPackageUid(packageName, userId);
        }
        if (uid < 0) {
            System.err.println("Error: No UID for " + packageName + " in user " + userId);
            return;
@@ -211,7 +216,12 @@ public class AppOpsCommand extends BaseCommand {
        final IPackageManager pm = ActivityThread.getPackageManager();
        final IAppOpsService appOpsService = IAppOpsService.Stub.asInterface(
                ServiceManager.getService(Context.APP_OPS_SERVICE));
        final int uid = pm.getPackageUid(packageName, userId);
        final int uid;
        if ("root".equals(packageName)) {
            uid = 0;
        } else {
            uid = pm.getPackageUid(packageName, userId);
        }
        if (uid < 0) {
            System.err.println("Error: No UID for " + packageName + " in user " + userId);
            return;