summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2015-03-04 14:55:37 -0500
committerJohn Spurlock <jspurlock@google.com>2015-03-05 08:35:37 -0500
commit0510c2ee6014a3e1914c1e2474f08ed1e9aaaf89 (patch)
tree9e0ba7f39f33071b5d536e90489fb03afdb0a204 /cmds
parent20d58e2af7738209b068038197db516d365d887a (diff)
downloadframeworks_base-0510c2ee6014a3e1914c1e2474f08ed1e9aaaf89.zip
frameworks_base-0510c2ee6014a3e1914c1e2474f08ed1e9aaaf89.tar.gz
frameworks_base-0510c2ee6014a3e1914c1e2474f08ed1e9aaaf89.tar.bz2
Add a list verb to the settings cmd.
Change-Id: I8a203eefced3431085fd1981b1d120baab2cb77a
Diffstat (limited to 'cmds')
-rw-r--r--cmds/settings/src/com/android/commands/settings/SettingsCmd.java50
1 files changed, 48 insertions, 2 deletions
diff --git a/cmds/settings/src/com/android/commands/settings/SettingsCmd.java b/cmds/settings/src/com/android/commands/settings/SettingsCmd.java
index a31b150..c27d0c0 100644
--- a/cmds/settings/src/com/android/commands/settings/SettingsCmd.java
+++ b/cmds/settings/src/com/android/commands/settings/SettingsCmd.java
@@ -20,6 +20,7 @@ import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.app.IActivityManager.ContentProviderHolder;
import android.content.IContentProvider;
+import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
@@ -29,13 +30,18 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
public final class SettingsCmd {
enum CommandVerb {
UNSPECIFIED,
GET,
PUT,
- DELETE
+ DELETE,
+ LIST,
}
static String[] mArgs;
@@ -47,7 +53,7 @@ public final class SettingsCmd {
String mValue = null;
public static void main(String[] args) {
- if (args == null || args.length < 3) {
+ if (args == null || args.length < 2) {
printUsage();
return;
}
@@ -78,6 +84,8 @@ public final class SettingsCmd {
mVerb = CommandVerb.PUT;
} else if ("delete".equalsIgnoreCase(arg)) {
mVerb = CommandVerb.DELETE;
+ } else if ("list".equalsIgnoreCase(arg)) {
+ mVerb = CommandVerb.LIST;
} else {
// invalid
System.err.println("Invalid command: " + arg);
@@ -91,6 +99,10 @@ public final class SettingsCmd {
break; // invalid
}
mTable = arg.toLowerCase();
+ if (mVerb == CommandVerb.LIST) {
+ valid = true;
+ break;
+ }
} else if (mVerb == CommandVerb.GET || mVerb == CommandVerb.DELETE) {
mKey = arg;
if (mNextArg >= mArgs.length) {
@@ -144,6 +156,11 @@ public final class SettingsCmd {
System.out.println("Deleted "
+ deleteForUser(provider, mUser, mTable, mKey) + " rows");
break;
+ case LIST:
+ for (String line : listForUser(provider, mUser, mTable)) {
+ System.out.println(line);
+ }
+ break;
default:
System.err.println("Unspecified command");
break;
@@ -164,6 +181,34 @@ public final class SettingsCmd {
}
}
+ private List<String> listForUser(IContentProvider provider, int userHandle, String table) {
+ final Uri uri = "system".equals(table) ? Settings.System.CONTENT_URI
+ : "secure".equals(table) ? Settings.Secure.CONTENT_URI
+ : "global".equals(table) ? Settings.Global.CONTENT_URI
+ : null;
+ final ArrayList<String> lines = new ArrayList<String>();
+ if (uri == null) {
+ return lines;
+ }
+ try {
+ final Cursor cursor = provider.query(resolveCallingPackage(), uri, null, null, null,
+ null, null);
+ try {
+ while (cursor != null && cursor.moveToNext()) {
+ lines.add(cursor.getString(1) + "=" + cursor.getString(2));
+ }
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+ Collections.sort(lines);
+ } catch (RemoteException e) {
+ System.err.println("List failed in " + table + " for user " + userHandle);
+ }
+ return lines;
+ }
+
private String nextArg() {
if (mNextArg >= mArgs.length) {
return null;
@@ -244,6 +289,7 @@ public final class SettingsCmd {
System.err.println("usage: settings [--user NUM] get namespace key");
System.err.println(" settings [--user NUM] put namespace key value");
System.err.println(" settings [--user NUM] delete namespace key");
+ System.err.println(" settings [--user NUM] list namespace");
System.err.println("\n'namespace' is one of {system, secure, global}, case-insensitive");
System.err.println("If '--user NUM' is not given, the operations are performed on the owner user.");
}