Skip to content

Commit c221d2b

Browse files
author
Christopher Tate
committed
Rewrite raw insert()s and some raw query()s of moved-to-global keys
The Settings put*() APIs fix up references via the old namespaces, but the raw insert() interface didn't. Now it does. Also, when possible we fix up direct query() operations on the old namespace to point to the correct one. At present that is only done for query() operations with Uris of the form content://secure/adb_enabled There is no rewriting done on queries of the form content://secure WHERE name='adb_enabled' since the app-supplied WHERE clause can be arbitrarily complex. Bug 7267568 Change-Id: I5c8cecbea7f5b1da6247a53b1428d3effb0bbca5
1 parent 7636693 commit c221d2b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ private static class SqlArguments {
134134
/** Operate on existing rows. */
135135
SqlArguments(Uri url, String where, String[] args) {
136136
if (url.getPathSegments().size() == 1) {
137+
// of the form content://settings/secure, arbitrary where clause
137138
this.table = url.getPathSegments().get(0);
138139
if (!DatabaseHelper.isValidTable(this.table)) {
139140
throw new IllegalArgumentException("Bad root path: " + this.table);
@@ -145,15 +146,24 @@ private static class SqlArguments {
145146
} else if (!TextUtils.isEmpty(where)) {
146147
throw new UnsupportedOperationException("WHERE clause not supported: " + url);
147148
} else {
149+
// of the form content://settings/secure/element_name, no where clause
148150
this.table = url.getPathSegments().get(0);
149151
if (!DatabaseHelper.isValidTable(this.table)) {
150152
throw new IllegalArgumentException("Bad root path: " + this.table);
151153
}
152154
if (TABLE_SYSTEM.equals(this.table) || TABLE_SECURE.equals(this.table) ||
153155
TABLE_GLOBAL.equals(this.table)) {
154156
this.where = Settings.NameValueTable.NAME + "=?";
155-
this.args = new String[] { url.getPathSegments().get(1) };
157+
final String name = url.getPathSegments().get(1);
158+
this.args = new String[] { name };
159+
// Rewrite the table for known-migrated names
160+
if (TABLE_SYSTEM.equals(this.table) || TABLE_SECURE.equals(this.table)) {
161+
if (sSecureGlobalKeys.contains(name) || sSystemGlobalKeys.contains(name)) {
162+
this.table = TABLE_GLOBAL;
163+
}
164+
}
156165
} else {
166+
// of the form content://bookmarks/19
157167
this.where = "_id=" + ContentUris.parseId(url);
158168
this.args = null;
159169
}
@@ -838,6 +848,17 @@ private Uri insertForUser(Uri url, ContentValues initialValues, int desiredUserH
838848
if (!parseProviderList(url, initialValues)) return null;
839849
}
840850

851+
// If this is an insert() of a key that has been migrated to the global store,
852+
// redirect the operation to that store
853+
if (name != null) {
854+
if (sSecureGlobalKeys.contains(name) || sSystemGlobalKeys.contains(name)) {
855+
if (!TABLE_GLOBAL.equals(args.table)) {
856+
if (LOCAL_LOGV) Slog.i(TAG, "Rewrite of insert() of now-global key " + name);
857+
}
858+
args.table = TABLE_GLOBAL; // next condition will rewrite the user handle
859+
}
860+
}
861+
841862
// The global table is stored under the owner, always
842863
if (TABLE_GLOBAL.equals(args.table)) {
843864
desiredUserHandle = UserHandle.USER_OWNER;

0 commit comments

Comments
 (0)