From 3875bf6c047b5e1e6a0bebe8f630b89fc60fd6f6 Mon Sep 17 00:00:00 2001 From: Snild Dolkow Date: Thu, 3 Sep 2015 11:50:05 +0200 Subject: [PATCH] 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 --- .../com/android/commands/appops/AppOpsCommand.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmds/appops/src/com/android/commands/appops/AppOpsCommand.java b/cmds/appops/src/com/android/commands/appops/AppOpsCommand.java index 3ec63b429a28e..98dc7528a74d7 100644 --- a/cmds/appops/src/com/android/commands/appops/AppOpsCommand.java +++ b/cmds/appops/src/com/android/commands/appops/AppOpsCommand.java @@ -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;