summaryrefslogtreecommitdiff
path: root/cmds/content
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2016-08-31 15:14:10 -0700
committerMakoto Onuki <omakoto@google.com>2016-09-02 13:10:49 -0700
commitce34881b19f8e8aef1af35254c6a249f7e4801b8 (patch)
treef5c6704bd7c3d0a10e0440aba940c0c3c161c187 /cmds/content
parent79758c8e7706f3cce265a881cc66df8771d3c456 (diff)
Add "adb shell content gettype" support
Change-Id: I902d66b5c8ee45411ba6b82dd1b0bb7506d1f117
Diffstat (limited to 'cmds/content')
-rw-r--r--cmds/content/src/com/android/commands/content/Content.java146
1 files changed, 93 insertions, 53 deletions
diff --git a/cmds/content/src/com/android/commands/content/Content.java b/cmds/content/src/com/android/commands/content/Content.java
index d43b8c564e96..c7474a11651c 100644
--- a/cmds/content/src/com/android/commands/content/Content.java
+++ b/cmds/content/src/com/android/commands/content/Content.java
@@ -72,59 +72,64 @@ import libcore.io.IoUtils;
public class Content {
private static final String USAGE =
- "usage: adb shell content [subcommand] [options]\n"
- + "\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"
- + " <TYPE> specifies data type such as:\n"
- + " b - boolean, s - string, i - integer, l - long, f - float, d - double\n"
- + " Note: Omit the value for passing an empty string, e.g column:s:\n"
- + " Example:\n"
- + " # Add \"new_setting\" secure setting with value \"new_value\".\n"
- + " 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> [--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"
- + " # Change \"new_setting\" secure setting to \"newer_value\".\n"
- + " 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> [--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> [--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_ORDER> is the order in which rows in the result should be sorted.\n"
- + " Example:\n"
- + " # Select \"name\" and \"value\" columns from secure settings where \"name\" is "
- + "equal to \"new_setting\" and sort the result by name in ascending order.\n"
- + " adb shell content query --uri content://settings/secure --projection name:value"
- + " --where \"name=\'new_setting\'\" --sort \"name ASC\"\n"
- + "\n"
- + "usage: adb shell content call --uri <URI> --method <METHOD> [--arg <ARG>]\n"
- + " [--extra <BINDING> ...]\n"
- + " <METHOD> is the name of a provider-defined method\n"
- + " <ARG> is an optional string argument\n"
- + " <BINDING> is like --bind above, typed data of the form <KEY>:{b,s,i,l,f,d}:<VAL>\n"
- + "\n"
- + "usage: adb shell content read --uri <URI> [--user <USER_ID>]\n"
- + " Example:\n"
- + " # cat default ringtone to a file, then pull to host\n"
- + " adb shell 'content read --uri content://settings/system/ringtone >"
- + " /mnt/sdcard/tmp.ogg' && adb pull /mnt/sdcard/tmp.ogg\n"
- + "\n";
+ "usage: adb shell content [subcommand] [options]\n"
+ + "\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"
+ + " <TYPE> specifies data type such as:\n"
+ + " b - boolean, s - string, i - integer, l - long, f - float, d - double\n"
+ + " Note: Omit the value for passing an empty string, e.g column:s:\n"
+ + " Example:\n"
+ + " # Add \"new_setting\" secure setting with value \"new_value\".\n"
+ + " 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> [--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"
+ + " # Change \"new_setting\" secure setting to \"newer_value\".\n"
+ + " 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> [--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> [--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_ORDER> is the order in which rows in the result should be sorted.\n"
+ + " Example:\n"
+ + " # Select \"name\" and \"value\" columns from secure settings where \"name\" is "
+ + "equal to \"new_setting\" and sort the result by name in ascending order.\n"
+ + " adb shell content query --uri content://settings/secure --projection name:value"
+ + " --where \"name=\'new_setting\'\" --sort \"name ASC\"\n"
+ + "\n"
+ + "usage: adb shell content call --uri <URI> --method <METHOD> [--arg <ARG>]\n"
+ + " [--extra <BINDING> ...]\n"
+ + " <METHOD> is the name of a provider-defined method\n"
+ + " <ARG> is an optional string argument\n"
+ + " <BINDING> is like --bind above, typed data of the form <KEY>:{b,s,i,l,f,d}:<VAL>\n"
+ + "\n"
+ + "usage: adb shell content read --uri <URI> [--user <USER_ID>]\n"
+ + " Example:\n"
+ + " # cat default ringtone to a file, then pull to host\n"
+ + " adb shell 'content read --uri content://settings/system/ringtone >"
+ + " /mnt/sdcard/tmp.ogg' && adb pull /mnt/sdcard/tmp.ogg\n"
+ + "\n"
+ + "usage: adb shell content gettype --uri <URI> [--user <USER_ID>]\n"
+ + " Example:\n"
+ + " # Show the mime-type of the URI\n"
+ + " adb shell content gettype --uri content://media/internal/audio/media/\n"
+ + "\n";
private static class Parser {
private static final String ARGUMENT_INSERT = "insert";
@@ -133,6 +138,7 @@ public class Content {
private static final String ARGUMENT_QUERY = "query";
private static final String ARGUMENT_CALL = "call";
private static final String ARGUMENT_READ = "read";
+ private static final String ARGUMENT_GET_TYPE = "gettype";
private static final String ARGUMENT_WHERE = "--where";
private static final String ARGUMENT_BIND = "--bind";
private static final String ARGUMENT_URI = "--uri";
@@ -172,6 +178,8 @@ public class Content {
return parseCallCommand();
} else if (ARGUMENT_READ.equals(operation)) {
return parseReadCommand();
+ } else if (ARGUMENT_GET_TYPE.equals(operation)) {
+ return parseGetTypeCommand();
} else {
throw new IllegalArgumentException("Unsupported operation: " + operation);
}
@@ -291,6 +299,26 @@ public class Content {
return new CallCommand(uri, userId, method, arg, values);
}
+ private GetTypeCommand parseGetTypeCommand() {
+ Uri uri = null;
+ int userId = UserHandle.USER_SYSTEM;
+
+ 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 {
+ throw new IllegalArgumentException("Unsupported argument: " + argument);
+ }
+ }
+ if (uri == null) {
+ throw new IllegalArgumentException("Content provider URI not specified."
+ + " Did you specify --uri argument?");
+ }
+ return new GetTypeCommand(uri, userId);
+ }
+
private ReadCommand parseReadCommand() {
Uri uri = null;
int userId = UserHandle.USER_SYSTEM;
@@ -511,6 +539,18 @@ public class Content {
}
}
+ private static class GetTypeCommand extends Command {
+ public GetTypeCommand(Uri uri, int userId) {
+ super(uri, userId);
+ }
+
+ @Override
+ public void onExecute(IContentProvider provider) throws Exception {
+ String type = provider.getType(mUri);
+ System.out.println("Result: " + type);
+ }
+ }
+
private static class ReadCommand extends Command {
public ReadCommand(Uri uri, int userId) {
super(uri, userId);