From a8c6111a88df157240ea40e61f46df8366b1b945 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Mon, 2 Mar 2015 16:21:35 -0800 Subject: Content and settings shell commands passing invalid calling package. Change-Id: Ia80099ba0afba054b70511c0d95265ec303446e0 --- .../src/com/android/commands/content/Content.java | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'cmds/content/src') diff --git a/cmds/content/src/com/android/commands/content/Content.java b/cmds/content/src/com/android/commands/content/Content.java index bd34a9c2ed4b..c0ed8935dc2c 100644 --- a/cmds/content/src/com/android/commands/content/Content.java +++ b/cmds/content/src/com/android/commands/content/Content.java @@ -27,6 +27,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.IBinder; import android.os.ParcelFileDescriptor; +import android.os.Process; import android.os.UserHandle; import android.text.TextUtils; @@ -426,6 +427,22 @@ public class Content { } } + public static String resolveCallingPackage() { + switch (Process.myUid()) { + case Process.ROOT_UID: { + return "root"; + } + + case Process.SHELL_UID: { + return "com.android.shell"; + } + + default: { + return null; + } + } + } + protected abstract void onExecute(IContentProvider provider) throws Exception; } @@ -439,7 +456,7 @@ public class Content { @Override public void onExecute(IContentProvider provider) throws Exception { - provider.insert(null, mUri, mContentValues); + provider.insert(resolveCallingPackage(), mUri, mContentValues); } } @@ -453,7 +470,7 @@ public class Content { @Override public void onExecute(IContentProvider provider) throws Exception { - provider.delete(null, mUri, mWhere, null); + provider.delete(resolveCallingPackage(), mUri, mWhere, null); } } @@ -532,7 +549,8 @@ public class Content { @Override public void onExecute(IContentProvider provider) throws Exception { - Cursor cursor = provider.query(null, mUri, mProjection, mWhere, null, mSortOrder, null); + Cursor cursor = provider.query(resolveCallingPackage(), mUri, mProjection, mWhere, + null, mSortOrder, null); if (cursor == null) { System.out.println("No result found."); return; @@ -594,7 +612,7 @@ public class Content { @Override public void onExecute(IContentProvider provider) throws Exception { - provider.update(null, mUri, mContentValues, mWhere, null); + provider.update(resolveCallingPackage(), mUri, mContentValues, mWhere, null); } } -- cgit v1.2.3-59-g8ed1b