diff options
-rw-r--r-- | cmds/content/src/com/android/commands/content/Content.java | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/cmds/content/src/com/android/commands/content/Content.java b/cmds/content/src/com/android/commands/content/Content.java index c0ed893..1d8b8b1 100644 --- a/cmds/content/src/com/android/commands/content/Content.java +++ b/cmds/content/src/com/android/commands/content/Content.java @@ -103,10 +103,12 @@ public class Content { + "--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 <PROJECTION>] [--where <WHERE>] [--sort <SORT_ORDER>] " + + " [--show-type <SHOW-TYPE>] \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" + + " <SHOW-TYPE> if true shows the type of value of each projection column" + " 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" @@ -142,6 +144,7 @@ public class Content { private static final String ARGUMENT_METHOD = "--method"; private static final String ARGUMENT_ARG = "--arg"; private static final String ARGUMENT_EXTRA = "--extra"; + private static final String ARGUMENT_SHOW_TYPE = "--show-type"; private static final String TYPE_BOOLEAN = "b"; private static final String TYPE_STRING = "s"; private static final String TYPE_INTEGER = "i"; @@ -316,6 +319,7 @@ public class Content { String[] projection = null; String sort = null; String where = null; + boolean showType = false; for (String argument; (argument = mTokenizer.nextArg())!= null;) { if (ARGUMENT_URI.equals(argument)) { uri = Uri.parse(argumentValueRequired(argument)); @@ -327,6 +331,8 @@ public class Content { sort = argumentValueRequired(argument); } else if (ARGUMENT_PROJECTION.equals(argument)) { projection = argumentValueRequired(argument).split("[\\s]*:[\\s]*"); + } else if (ARGUMENT_SHOW_TYPE.equals(argument)) { + showType = argumentValueRequiredForBoolean(argument); } else { throw new IllegalArgumentException("Unsupported argument: " + argument); } @@ -335,7 +341,7 @@ public class Content { throw new IllegalArgumentException("Content provider URI not specified." + " Did you specify --uri argument?"); } - return new QueryCommand(uri, userId, projection, where, sort); + return new QueryCommand(uri, userId, projection, where, sort, showType); } private void parseBindValue(ContentValues values) { @@ -367,6 +373,14 @@ public class Content { } } + private boolean argumentValueRequiredForBoolean(String argument) { + String value = mTokenizer.nextArg(); + if (TextUtils.isEmpty(value) || value.startsWith(ARGUMENT_PREFIX)) { + throw new IllegalArgumentException("No value for argument: " + argument); + } + return value.equals("true"); + } + private String argumentValueRequired(String argument) { String value = mTokenizer.nextArg(); if (TextUtils.isEmpty(value) || value.startsWith(ARGUMENT_PREFIX)) { @@ -539,12 +553,15 @@ public class Content { private static class QueryCommand extends DeleteCommand { final String[] mProjection; final String mSortOrder; + final boolean mShowType; public QueryCommand( - Uri uri, int userId, String[] projection, String where, String sortOrder) { + Uri uri, int userId, String[] projection, String where, String sortOrder, + boolean showType) { super(uri, userId, where); mProjection = projection; mSortOrder = sortOrder; + mShowType = showType; } @Override @@ -590,6 +607,7 @@ public class Content { break; } builder.append(columnName).append("=").append(columnValue); + if (mShowType) builder.append(", type=").append(type); } System.out.println(builder); } while (cursor.moveToNext()); |