summaryrefslogtreecommitdiffstats
path: root/packages/SettingsProvider/src
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-03-04 17:48:13 -0800
committerBrad Fitzpatrick <bradfitz@android.com>2010-03-05 12:08:39 -0800
commit1877d0158b529663b8315482e7346a7bcaa96166 (patch)
tree5194b59937b70c2f48366f27a4458d4043957d16 /packages/SettingsProvider/src
parentcd47f11dfad012be1b176ea06904a00da157ed7b (diff)
downloadframeworks_base-1877d0158b529663b8315482e7346a7bcaa96166.zip
frameworks_base-1877d0158b529663b8315482e7346a7bcaa96166.tar.gz
frameworks_base-1877d0158b529663b8315482e7346a7bcaa96166.tar.bz2
Add "call" method on ContentProvider.
This permits implementing interfaces which are faster than using remote Cursors. It then uses it for Settings & SettingProvider, which together account for ~50% of total ContentProvider event loop stalls across Froyo dogfooders. For fetching Settings this looks like it should reduce average Settings lookup from 10 ms to 0.4 ms on Sholes, once the SettingsProvider serves most gets from in-memory cache. Currently it brings the Sholes average down from 10ms to 2.5 ms while still using SQLite queries on each get.
Diffstat (limited to 'packages/SettingsProvider/src')
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index db802d3..4f1146b 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -30,9 +30,11 @@ import android.content.pm.PackageManager;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteQueryBuilder;
import android.media.RingtoneManager;
import android.net.Uri;
+import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.SystemProperties;
import android.provider.DrmStore;
@@ -48,6 +50,8 @@ public class SettingsProvider extends ContentProvider {
private static final String TABLE_FAVORITES = "favorites";
private static final String TABLE_OLD_FAVORITES = "old_favorites";
+ private static final String[] COLUMN_VALUE = new String[] { "value" };
+
protected DatabaseHelper mOpenHelper;
private BackupManager mBackupManager;
@@ -220,6 +224,44 @@ public class SettingsProvider extends ContentProvider {
}
}
+ /**
+ * Fast path that avoids the use of chatty remoted Cursors.
+ */
+ @Override
+ public Bundle call(String method, String request, Bundle args) {
+ if (Settings.CALL_METHOD_GET_SYSTEM.equals(method)) {
+ return lookupValue("system", request);
+ }
+
+ if (Settings.CALL_METHOD_GET_SECURE.equals(method)) {
+ return lookupValue("secure", request);
+ }
+ return null;
+ }
+
+ // Looks up value 'key' in 'table' and returns either a single-pair Bundle,
+ // possibly with a null value, or null on failure.
+ private Bundle lookupValue(String table, String key) {
+ // TODO: avoid database lookup and serve from in-process cache.
+ SQLiteDatabase db = mOpenHelper.getReadableDatabase();
+ Cursor cursor = null;
+ try {
+ cursor = db.query(table, COLUMN_VALUE, "name=?", new String[]{key},
+ null, null, null, null);
+ if (cursor != null && cursor.getCount() == 1) {
+ cursor.moveToFirst();
+ String value = cursor.getString(0);
+ return Bundle.forPair("value", value);
+ }
+ } catch (SQLiteException e) {
+ Log.w(TAG, "settings lookup error", e);
+ return null;
+ } finally {
+ if (cursor != null) cursor.close();
+ }
+ return Bundle.forPair("value", null);
+ }
+
@Override
public Cursor query(Uri url, String[] select, String where, String[] whereArgs, String sort) {
SqlArguments args = new SqlArguments(url, where, whereArgs);