Skip to content

Commit 35dd752

Browse files
Christopher TateAndroid (Google) Code Review
authored andcommitted
Merge "Rewrite raw insert()s and some raw query()s of moved-to-global keys" into jb-mr1-dev
2 parents a6cab32 + c221d2b commit 35dd752

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
@@ -135,6 +135,7 @@ private static class SqlArguments {
135135
/** Operate on existing rows. */
136136
SqlArguments(Uri url, String where, String[] args) {
137137
if (url.getPathSegments().size() == 1) {
138+
// of the form content://settings/secure, arbitrary where clause
138139
this.table = url.getPathSegments().get(0);
139140
if (!DatabaseHelper.isValidTable(this.table)) {
140141
throw new IllegalArgumentException("Bad root path: " + this.table);
@@ -146,15 +147,24 @@ private static class SqlArguments {
146147
} else if (!TextUtils.isEmpty(where)) {
147148
throw new UnsupportedOperationException("WHERE clause not supported: " + url);
148149
} else {
150+
// of the form content://settings/secure/element_name, no where clause
149151
this.table = url.getPathSegments().get(0);
150152
if (!DatabaseHelper.isValidTable(this.table)) {
151153
throw new IllegalArgumentException("Bad root path: " + this.table);
152154
}
153155
if (TABLE_SYSTEM.equals(this.table) || TABLE_SECURE.equals(this.table) ||
154156
TABLE_GLOBAL.equals(this.table)) {
155157
this.where = Settings.NameValueTable.NAME + "=?";
156-
this.args = new String[] { url.getPathSegments().get(1) };
158+
final String name = url.getPathSegments().get(1);
159+
this.args = new String[] { name };
160+
// Rewrite the table for known-migrated names
161+
if (TABLE_SYSTEM.equals(this.table) || TABLE_SECURE.equals(this.table)) {
162+
if (sSecureGlobalKeys.contains(name) || sSystemGlobalKeys.contains(name)) {
163+
this.table = TABLE_GLOBAL;
164+
}
165+
}
157166
} else {
167+
// of the form content://bookmarks/19
158168
this.where = "_id=" + ContentUris.parseId(url);
159169
this.args = null;
160170
}
@@ -848,6 +858,17 @@ private Uri insertForUser(Uri url, ContentValues initialValues, int desiredUserH
848858
if (!parseProviderList(url, initialValues)) return null;
849859
}
850860

861+
// If this is an insert() of a key that has been migrated to the global store,
862+
// redirect the operation to that store
863+
if (name != null) {
864+
if (sSecureGlobalKeys.contains(name) || sSystemGlobalKeys.contains(name)) {
865+
if (!TABLE_GLOBAL.equals(args.table)) {
866+
if (LOCAL_LOGV) Slog.i(TAG, "Rewrite of insert() of now-global key " + name);
867+
}
868+
args.table = TABLE_GLOBAL; // next condition will rewrite the user handle
869+
}
870+
}
871+
851872
// The global table is stored under the owner, always
852873
if (TABLE_GLOBAL.equals(args.table)) {
853874
desiredUserHandle = UserHandle.USER_OWNER;

0 commit comments

Comments
 (0)