summaryrefslogtreecommitdiffstats
path: root/cmds/settings/src/com/android/commands/settings/SettingsCmd.java
diff options
context:
space:
mode:
Diffstat (limited to 'cmds/settings/src/com/android/commands/settings/SettingsCmd.java')
-rw-r--r--cmds/settings/src/com/android/commands/settings/SettingsCmd.java94
1 files changed, 75 insertions, 19 deletions
diff --git a/cmds/settings/src/com/android/commands/settings/SettingsCmd.java b/cmds/settings/src/com/android/commands/settings/SettingsCmd.java
index c27d0c0..64610fe 100644
--- a/cmds/settings/src/com/android/commands/settings/SettingsCmd.java
+++ b/cmds/settings/src/com/android/commands/settings/SettingsCmd.java
@@ -29,6 +29,8 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
+import android.text.TextUtils;
+import cyanogenmod.providers.CMSettings;
import java.util.ArrayList;
import java.util.Collections;
@@ -36,6 +38,9 @@ import java.util.List;
public final class SettingsCmd {
+ private static final String SETTINGS_AUTHORITY = Settings.AUTHORITY;
+ private static final String CMSETTINGS_AUTHORITY = CMSettings.AUTHORITY;
+
enum CommandVerb {
UNSPECIFIED,
GET,
@@ -51,6 +56,7 @@ public final class SettingsCmd {
String mTable = null;
String mKey = null;
String mValue = null;
+ boolean mUseCMSettingsProvider = false;
public static void main(String[] args) {
if (args == null || args.length < 2) {
@@ -77,6 +83,8 @@ public final class SettingsCmd {
break;
}
mUser = Integer.parseInt(nextArg());
+ } else if ("--cm".equals(arg)) {
+ mUseCMSettingsProvider = true;
} else if (mVerb == CommandVerb.UNSPECIFIED) {
if ("get".equalsIgnoreCase(arg)) {
mVerb = CommandVerb.GET;
@@ -133,13 +141,21 @@ public final class SettingsCmd {
mUser = UserHandle.USER_OWNER;
}
+ // Implicitly use CMSettings provider if the setting is a legacy setting
+ if (!mUseCMSettingsProvider && isLegacySetting(mTable, mKey)) {
+ System.err.println("'" + mKey + "' has moved to CMSettings. Use --cm to avoid " +
+ "this warning in the future.");
+ mUseCMSettingsProvider = true;
+ }
+
try {
IActivityManager activityManager = ActivityManagerNative.getDefault();
IContentProvider provider = null;
IBinder token = new Binder();
try {
ContentProviderHolder holder = activityManager.getContentProviderExternal(
- "settings", UserHandle.USER_OWNER, token);
+ mUseCMSettingsProvider ? CMSETTINGS_AUTHORITY : SETTINGS_AUTHORITY,
+ UserHandle.USER_OWNER, token);
if (holder == null) {
throw new IllegalStateException("Could not find settings provider");
}
@@ -182,9 +198,15 @@ 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
+ final Uri systemUri = mUseCMSettingsProvider ? CMSettings.System.CONTENT_URI
+ : Settings.System.CONTENT_URI;
+ final Uri secureUri = mUseCMSettingsProvider ? CMSettings.Secure.CONTENT_URI
+ : Settings.Secure.CONTENT_URI;
+ final Uri globalUri = mUseCMSettingsProvider ? CMSettings.Global.CONTENT_URI
+ : Settings.Global.CONTENT_URI;
+ final Uri uri = "system".equals(table) ? systemUri
+ : "secure".equals(table) ? secureUri
+ : "global".equals(table) ? globalUri
: null;
final ArrayList<String> lines = new ArrayList<String>();
if (uri == null) {
@@ -220,10 +242,16 @@ public final class SettingsCmd {
String getForUser(IContentProvider provider, int userHandle,
final String table, final String key) {
+ final String systemGetCommand = mUseCMSettingsProvider ? CMSettings.CALL_METHOD_GET_SYSTEM
+ : Settings.CALL_METHOD_GET_SYSTEM;
+ final String secureGetCommand = mUseCMSettingsProvider ? CMSettings.CALL_METHOD_GET_SECURE
+ : Settings.CALL_METHOD_GET_SECURE;
+ final String globalGetCommand = mUseCMSettingsProvider ? CMSettings.CALL_METHOD_GET_GLOBAL
+ : Settings.CALL_METHOD_GET_GLOBAL;
final String callGetCommand;
- if ("system".equals(table)) callGetCommand = Settings.CALL_METHOD_GET_SYSTEM;
- else if ("secure".equals(table)) callGetCommand = Settings.CALL_METHOD_GET_SECURE;
- else if ("global".equals(table)) callGetCommand = Settings.CALL_METHOD_GET_GLOBAL;
+ if ("system".equals(table)) callGetCommand = systemGetCommand;
+ else if ("secure".equals(table)) callGetCommand = secureGetCommand;
+ else if ("global".equals(table)) callGetCommand = globalGetCommand;
else {
System.err.println("Invalid table; no put performed");
throw new IllegalArgumentException("Invalid table " + table);
@@ -232,7 +260,8 @@ public final class SettingsCmd {
String result = null;
try {
Bundle arg = new Bundle();
- arg.putInt(Settings.CALL_METHOD_USER_KEY, userHandle);
+ arg.putInt(mUseCMSettingsProvider ? CMSettings.CALL_METHOD_USER_KEY
+ : Settings.CALL_METHOD_USER_KEY, userHandle);
Bundle b = provider.call(resolveCallingPackage(), callGetCommand, key, arg);
if (b != null) {
result = b.getPairValue();
@@ -245,10 +274,16 @@ public final class SettingsCmd {
void putForUser(IContentProvider provider, int userHandle,
final String table, final String key, final String value) {
+ final String systemPutCommand = mUseCMSettingsProvider ? CMSettings.CALL_METHOD_PUT_SYSTEM
+ : Settings.CALL_METHOD_PUT_SYSTEM;
+ final String securePutCommand = mUseCMSettingsProvider ? CMSettings.CALL_METHOD_PUT_SECURE
+ : Settings.CALL_METHOD_PUT_SECURE;
+ final String globalPutCommand = mUseCMSettingsProvider ? CMSettings.CALL_METHOD_PUT_GLOBAL
+ : Settings.CALL_METHOD_PUT_GLOBAL;
final String callPutCommand;
- if ("system".equals(table)) callPutCommand = Settings.CALL_METHOD_PUT_SYSTEM;
- else if ("secure".equals(table)) callPutCommand = Settings.CALL_METHOD_PUT_SECURE;
- else if ("global".equals(table)) callPutCommand = Settings.CALL_METHOD_PUT_GLOBAL;
+ if ("system".equals(table)) callPutCommand = systemPutCommand;
+ else if ("secure".equals(table)) callPutCommand = securePutCommand;
+ else if ("global".equals(table)) callPutCommand = globalPutCommand;
else {
System.err.println("Invalid table; no put performed");
return;
@@ -257,7 +292,8 @@ public final class SettingsCmd {
try {
Bundle arg = new Bundle();
arg.putString(Settings.NameValueTable.VALUE, value);
- arg.putInt(Settings.CALL_METHOD_USER_KEY, userHandle);
+ arg.putInt(mUseCMSettingsProvider ? CMSettings.CALL_METHOD_USER_KEY
+ : Settings.CALL_METHOD_USER_KEY, userHandle);
provider.call(resolveCallingPackage(), callPutCommand, key, arg);
} catch (RemoteException e) {
System.err.println("Can't set key " + key + " in " + table + " for user " + userHandle);
@@ -266,10 +302,16 @@ public final class SettingsCmd {
int deleteForUser(IContentProvider provider, int userHandle,
final String table, final String key) {
+ final Uri systemUri = mUseCMSettingsProvider ? CMSettings.System.getUriFor(key)
+ : Settings.System.getUriFor(key);
+ final Uri secureUri = mUseCMSettingsProvider ? CMSettings.Secure.getUriFor(key)
+ : Settings.Secure.getUriFor(key);
+ final Uri globalUri = mUseCMSettingsProvider ? CMSettings.Global.getUriFor(key)
+ : Settings.Global.getUriFor(key);
Uri targetUri;
- if ("system".equals(table)) targetUri = Settings.System.getUriFor(key);
- else if ("secure".equals(table)) targetUri = Settings.Secure.getUriFor(key);
- else if ("global".equals(table)) targetUri = Settings.Global.getUriFor(key);
+ if ("system".equals(table)) targetUri = systemUri;
+ else if ("secure".equals(table)) targetUri = secureUri;
+ else if ("global".equals(table)) targetUri = globalUri;
else {
System.err.println("Invalid table; no delete performed");
throw new IllegalArgumentException("Invalid table " + table);
@@ -286,12 +328,26 @@ public final class SettingsCmd {
}
private static void printUsage() {
- 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("usage: settings [--user NUM] [--cm] get namespace key");
+ System.err.println(" settings [--user NUM] [--cm] put namespace key value");
+ System.err.println(" settings [--user NUM] [--cm] delete namespace key");
+ System.err.println(" settings [--user NUM] [--cm] 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.");
+ System.err.println("If '--cm' is given, the operations are performed on the CMSettings provider.");
+ }
+
+ private static boolean isLegacySetting(String table, String key) {
+ if (!TextUtils.isEmpty(key)) {
+ if ("system".equals(table)) {
+ return CMSettings.System.isLegacySetting(key);
+ } else if ("secure".equals(table)) {
+ return CMSettings.Secure.isLegacySetting(key);
+ } else if ("global".equals(table)) {
+ return CMSettings.Global.isLegacySetting(key);
+ }
+ }
+ return false;
}
public static String resolveCallingPackage() {