Creating database without localized collators on NYC and above

Android automatically creates and maintains a metaData table to
store the current device locale. This is used when fetching
sorted results. Since Laucher does not require string based
sorting on its tables, we can avoid unnecessary IO by disabling
this feature

Bug: 24608776
Change-Id: I8bbf5ca3abd505be95a85cfc99dd0438966575e9
This commit is contained in:
Sunny Goyal
2016-03-15 15:30:11 -07:00
parent 77b3e1a57b
commit bf67f3b184
3 changed files with 32 additions and 3 deletions
@@ -54,6 +54,7 @@ import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.util.ManagedProfileHeuristic;
import com.android.launcher3.util.NoLocaleSqliteContext;
import com.android.launcher3.util.Thunk;
import java.net.URISyntaxException;
@@ -526,7 +527,8 @@ public class LauncherProvider extends ContentProvider {
private long mMaxScreenId = -1;
DatabaseHelper(Context context, LauncherProvider provider) {
super(context, LauncherFiles.LAUNCHER_DB, null, DATABASE_VERSION);
super(new NoLocaleSqliteContext(context), LauncherFiles.LAUNCHER_DB,
null, DATABASE_VERSION);
mContext = context;
mProvider = provider;
@@ -556,7 +558,7 @@ public class LauncherProvider extends ContentProvider {
* Constructor used only in tests.
*/
public DatabaseHelper(Context context, LauncherProvider provider, String tableName) {
super(context, tableName, null, DATABASE_VERSION);
super(new NoLocaleSqliteContext(context), tableName, null, DATABASE_VERSION);
mContext = context;
mProvider = provider;
@@ -0,0 +1,27 @@
package com.android.launcher3.util;
import android.content.Context;
import android.content.ContextWrapper;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
/**
* A context wrapper which creates databases without support for localized collators.
*/
public class NoLocaleSqliteContext extends ContextWrapper {
// TODO: Use the flag defined in Context when the new SDK is available
private static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
public NoLocaleSqliteContext(Context context) {
super(context);
}
@Override
public SQLiteDatabase openOrCreateDatabase(
String name, int mode, CursorFactory factory, DatabaseErrorHandler errorHandler) {
return super.openOrCreateDatabase(
name, mode | MODE_NO_LOCALIZED_COLLATORS, factory, errorHandler);
}
}
@@ -98,7 +98,7 @@ public abstract class SQLiteCacheHelper {
private class MySQLiteOpenHelper extends SQLiteOpenHelper {
public MySQLiteOpenHelper(Context context, String name, int version) {
super(context, name, null, version);
super(new NoLocaleSqliteContext(context), name, null, version);
}
@Override