summaryrefslogtreecommitdiffstats
path: root/cmds/content
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2012-09-20 16:06:08 -0700
committerJeff Sharkey <jsharkey@android.com>2012-09-21 19:49:43 -0700
commit6d51571835737c7502a2e111ee9dc2527ebad984 (patch)
tree8298f3a36bdfbdb95a4fdd52681f82e7f396d31b /cmds/content
parent08681adda06f4699f85838861170fbb062c9fdfe (diff)
downloadframeworks_base-6d51571835737c7502a2e111ee9dc2527ebad984.zip
frameworks_base-6d51571835737c7502a2e111ee9dc2527ebad984.tar.gz
frameworks_base-6d51571835737c7502a2e111ee9dc2527ebad984.tar.bz2
Allow acquiring ContentProviders across users.
Otherwise services like SystemUI will always open content://-style Uris as USER_OWNER. Surfaces through createPackageContextAsUser() which points all ContentResolver operations towards a given user. Start using in RemoteViews, so that Notifications correctly resolve image Uris to the sending user. Also add user support for "content" shell tool. Bug: 7202982 Change-Id: I8cb7fb8a812e825bb0b5833799dba87055ff8699
Diffstat (limited to 'cmds/content')
-rw-r--r--cmds/content/src/com/android/commands/content/Content.java56
1 files changed, 37 insertions, 19 deletions
diff --git a/cmds/content/src/com/android/commands/content/Content.java b/cmds/content/src/com/android/commands/content/Content.java
index bd9eb9a..787fbdb 100644
--- a/cmds/content/src/com/android/commands/content/Content.java
+++ b/cmds/content/src/com/android/commands/content/Content.java
@@ -25,6 +25,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
import android.os.IBinder;
+import android.os.UserHandle;
import android.text.TextUtils;
/**
@@ -63,7 +64,8 @@ public class Content {
private static final String USAGE =
"usage: adb shell content [subcommand] [options]\n"
+ "\n"
- + "usage: adb shell content insert --uri <URI> --bind <BINDING> [--bind <BINDING>...]\n"
+ + "usage: adb shell content insert --uri <URI> [--user <USER_ID>]"
+ + " --bind <BINDING> [--bind <BINDING>...]\n"
+ " <URI> a content provider URI.\n"
+ " <BINDING> binds a typed value to a column and is formatted:\n"
+ " <COLUMN_NAME>:<TYPE>:<COLUMN_VALUE> where:\n"
@@ -75,7 +77,7 @@ public class Content {
+ " adb shell content insert --uri content://settings/secure --bind name:s:new_setting"
+ " --bind value:s:new_value\n"
+ "\n"
- + "usage: adb shell content update --uri <URI> [--where <WHERE>]\n"
+ + "usage: adb shell content update --uri <URI> [--user <USER_ID>] [--where <WHERE>]\n"
+ " <WHERE> is a SQL style where clause in quotes (You have to escape single quotes"
+ " - see example below).\n"
+ " Example:\n"
@@ -83,15 +85,15 @@ public class Content {
+ " adb shell content update --uri content://settings/secure --bind"
+ " value:s:newer_value --where \"name=\'new_setting\'\"\n"
+ "\n"
- + "usage: adb shell content delete --uri <URI> --bind <BINDING>"
+ + "usage: adb shell content delete --uri <URI> [--user <USER_ID>] --bind <BINDING>"
+ " [--bind <BINDING>...] [--where <WHERE>]\n"
+ " Example:\n"
+ " # Remove \"new_setting\" secure setting.\n"
+ " adb shell content delete --uri content://settings/secure "
+ "--where \"name=\'new_setting\'\"\n"
+ "\n"
- + "usage: adb shell content query --uri <URI> [--projection <PROJECTION>]"
- + " [--where <WHERE>] [--sort <SORT_ORDER>]\n"
+ + "usage: adb shell content query --uri <URI> [--user <USER_ID>]"
+ + " [--projection <PROJECTION>] [--where <WHERE>] [--sort <SORT_ORDER>]\n"
+ " <PROJECTION> is a list of colon separated column names and is formatted:\n"
+ " <COLUMN_NAME>[:<COLUMN_NAME>...]\n"
+ " <SORT_OREDER> is the order in which rows in the result should be sorted.\n"
@@ -110,6 +112,7 @@ public class Content {
private static final String ARGUMENT_WHERE = "--where";
private static final String ARGUMENT_BIND = "--bind";
private static final String ARGUMENT_URI = "--uri";
+ private static final String ARGUMENT_USER = "--user";
private static final String ARGUMENT_PROJECTION = "--projection";
private static final String ARGUMENT_SORT = "--sort";
private static final String TYPE_BOOLEAN = "b";
@@ -150,10 +153,13 @@ public class Content {
private InsertCommand parseInsertCommand() {
Uri uri = null;
+ int userId = UserHandle.USER_OWNER;
ContentValues values = new ContentValues();
for (String argument; (argument = mTokenizer.nextArg()) != null;) {
if (ARGUMENT_URI.equals(argument)) {
uri = Uri.parse(argumentValueRequired(argument));
+ } else if (ARGUMENT_USER.equals(argument)) {
+ userId = Integer.parseInt(argumentValueRequired(argument));
} else if (ARGUMENT_BIND.equals(argument)) {
parseBindValue(values);
} else {
@@ -168,15 +174,18 @@ public class Content {
throw new IllegalArgumentException("Bindings not specified."
+ " Did you specify --bind argument(s)?");
}
- return new InsertCommand(uri, values);
+ return new InsertCommand(uri, userId, values);
}
private DeleteCommand parseDeleteCommand() {
Uri uri = null;
+ int userId = UserHandle.USER_OWNER;
String where = null;
for (String argument; (argument = mTokenizer.nextArg())!= null;) {
if (ARGUMENT_URI.equals(argument)) {
uri = Uri.parse(argumentValueRequired(argument));
+ } else if (ARGUMENT_USER.equals(argument)) {
+ userId = Integer.parseInt(argumentValueRequired(argument));
} else if (ARGUMENT_WHERE.equals(argument)) {
where = argumentValueRequired(argument);
} else {
@@ -187,16 +196,19 @@ public class Content {
throw new IllegalArgumentException("Content provider URI not specified."
+ " Did you specify --uri argument?");
}
- return new DeleteCommand(uri, where);
+ return new DeleteCommand(uri, userId, where);
}
private UpdateCommand parseUpdateCommand() {
Uri uri = null;
+ int userId = UserHandle.USER_OWNER;
String where = null;
ContentValues values = new ContentValues();
for (String argument; (argument = mTokenizer.nextArg())!= null;) {
if (ARGUMENT_URI.equals(argument)) {
uri = Uri.parse(argumentValueRequired(argument));
+ } else if (ARGUMENT_USER.equals(argument)) {
+ userId = Integer.parseInt(argumentValueRequired(argument));
} else if (ARGUMENT_WHERE.equals(argument)) {
where = argumentValueRequired(argument);
} else if (ARGUMENT_BIND.equals(argument)) {
@@ -213,17 +225,20 @@ public class Content {
throw new IllegalArgumentException("Bindings not specified."
+ " Did you specify --bind argument(s)?");
}
- return new UpdateCommand(uri, values, where);
+ return new UpdateCommand(uri, userId, values, where);
}
public QueryCommand parseQueryCommand() {
Uri uri = null;
+ int userId = UserHandle.USER_OWNER;
String[] projection = null;
String sort = null;
String where = null;
for (String argument; (argument = mTokenizer.nextArg())!= null;) {
if (ARGUMENT_URI.equals(argument)) {
uri = Uri.parse(argumentValueRequired(argument));
+ } else if (ARGUMENT_USER.equals(argument)) {
+ userId = Integer.parseInt(argumentValueRequired(argument));
} else if (ARGUMENT_WHERE.equals(argument)) {
where = argumentValueRequired(argument);
} else if (ARGUMENT_SORT.equals(argument)) {
@@ -238,7 +253,7 @@ public class Content {
throw new IllegalArgumentException("Content provider URI not specified."
+ " Did you specify --uri argument?");
}
- return new QueryCommand(uri, projection, where, sort);
+ return new QueryCommand(uri, userId, projection, where, sort);
}
private void parseBindValue(ContentValues values) {
@@ -298,9 +313,11 @@ public class Content {
private static abstract class Command {
final Uri mUri;
+ final int mUserId;
- public Command(Uri uri) {
+ public Command(Uri uri, int userId) {
mUri = uri;
+ mUserId = userId;
}
public final void execute() {
@@ -311,7 +328,7 @@ public class Content {
IBinder token = new Binder();
try {
ContentProviderHolder holder = activityManager.getContentProviderExternal(
- providerName, token);
+ providerName, mUserId, token);
if (holder == null) {
throw new IllegalStateException("Could not find provider: " + providerName);
}
@@ -334,8 +351,8 @@ public class Content {
private static class InsertCommand extends Command {
final ContentValues mContentValues;
- public InsertCommand(Uri uri, ContentValues contentValues) {
- super(uri);
+ public InsertCommand(Uri uri, int userId, ContentValues contentValues) {
+ super(uri, userId);
mContentValues = contentValues;
}
@@ -348,8 +365,8 @@ public class Content {
private static class DeleteCommand extends Command {
final String mWhere;
- public DeleteCommand(Uri uri, String where) {
- super(uri);
+ public DeleteCommand(Uri uri, int userId, String where) {
+ super(uri, userId);
mWhere = where;
}
@@ -363,8 +380,9 @@ public class Content {
final String[] mProjection;
final String mSortOrder;
- public QueryCommand(Uri uri, String[] projection, String where, String sortOrder) {
- super(uri, where);
+ public QueryCommand(
+ Uri uri, int userId, String[] projection, String where, String sortOrder) {
+ super(uri, userId, where);
mProjection = projection;
mSortOrder = sortOrder;
}
@@ -426,8 +444,8 @@ public class Content {
private static class UpdateCommand extends InsertCommand {
final String mWhere;
- public UpdateCommand(Uri uri, ContentValues contentValues, String where) {
- super(uri, contentValues);
+ public UpdateCommand(Uri uri, int userId, ContentValues contentValues, String where) {
+ super(uri, userId, contentValues);
mWhere = where;
}