Bug 734177 - Add PARAM_IS_TEST to BrowserProvider (r=gpascutto)

This commit is contained in:
Lucas Rocha 2012-03-14 18:49:59 +00:00
Родитель bab8e61a52
Коммит d60d257f81
2 изменённых файлов: 17 добавлений и 6 удалений

Просмотреть файл

@ -59,6 +59,7 @@ public class BrowserContract {
public static final String PARAM_LIMIT = "limit"; public static final String PARAM_LIMIT = "limit";
public static final String PARAM_IS_SYNC = "sync"; public static final String PARAM_IS_SYNC = "sync";
public static final String PARAM_SHOW_DELETED = "show_deleted"; public static final String PARAM_SHOW_DELETED = "show_deleted";
public static final String PARAM_IS_TEST = "test";
public interface CommonColumns { public interface CommonColumns {
public static final String _ID = "_id"; public static final String _ID = "_id";

Просмотреть файл

@ -608,7 +608,7 @@ public class BrowserProvider extends ContentProvider {
} }
} }
private DatabaseHelper getDatabaseHelperForProfile(String profile) { private DatabaseHelper getDatabaseHelperForProfile(String profile, boolean isTest) {
// Each profile has a separate browser.db database. The target // Each profile has a separate browser.db database. The target
// profile is provided using a URI query argument in each request // profile is provided using a URI query argument in each request
// to our content provider. // to our content provider.
@ -624,7 +624,7 @@ public class BrowserProvider extends ContentProvider {
if (dbHelper != null) { if (dbHelper != null) {
return dbHelper; return dbHelper;
} }
dbHelper = new DatabaseHelper(getContext(), getDatabasePath(profile)); dbHelper = new DatabaseHelper(getContext(), getDatabasePath(profile, isTest));
mDatabasePerProfile.put(profile, dbHelper); mDatabasePerProfile.put(profile, dbHelper);
} }
@ -632,13 +632,15 @@ public class BrowserProvider extends ContentProvider {
return dbHelper; return dbHelper;
} }
private String getDatabasePath(String profile) { private String getDatabasePath(String profile, boolean isTest) {
trace("Getting database path for profile: " + profile); trace("Getting database path for profile: " + profile);
// On Android releases older than 2.3, it's not possible to use // On Android releases older than 2.3, it's not possible to use
// SQLiteOpenHelper with a full path. Fallback to using separate // SQLiteOpenHelper with a full path. Fallback to using separate
// db files per profile in the app directory. // db files per profile in the app directory.
if (Build.VERSION.SDK_INT <= 8) { if (isTest) {
return DATABASE_NAME;
} else if(Build.VERSION.SDK_INT <= 8) {
return "browser-" + profile + ".db"; return "browser-" + profile + ".db";
} }
@ -662,7 +664,7 @@ public class BrowserProvider extends ContentProvider {
if (uri != null) if (uri != null)
profile = uri.getQueryParameter(BrowserContract.PARAM_PROFILE); profile = uri.getQueryParameter(BrowserContract.PARAM_PROFILE);
return getDatabaseHelperForProfile(profile).getReadableDatabase(); return getDatabaseHelperForProfile(profile, isTest(uri)).getReadableDatabase();
} }
private SQLiteDatabase getWritableDatabase(Uri uri) { private SQLiteDatabase getWritableDatabase(Uri uri) {
@ -673,7 +675,7 @@ public class BrowserProvider extends ContentProvider {
if (uri != null) if (uri != null)
profile = uri.getQueryParameter(BrowserContract.PARAM_PROFILE); profile = uri.getQueryParameter(BrowserContract.PARAM_PROFILE);
return getDatabaseHelperForProfile(profile).getWritableDatabase(); return getDatabaseHelperForProfile(profile, isTest(uri)).getWritableDatabase();
} }
private void cleanupSomeDeletedRecords(Uri fromUri, Uri targetUri, String tableName) { private void cleanupSomeDeletedRecords(Uri fromUri, Uri targetUri, String tableName) {
@ -693,6 +695,9 @@ public class BrowserProvider extends ContentProvider {
if (!TextUtils.isEmpty(profile)) if (!TextUtils.isEmpty(profile))
uriBuilder = uriBuilder.appendQueryParameter(BrowserContract.PARAM_PROFILE, profile); uriBuilder = uriBuilder.appendQueryParameter(BrowserContract.PARAM_PROFILE, profile);
if (isTest(fromUri))
uriBuilder = uriBuilder.appendQueryParameter(BrowserContract.PARAM_IS_TEST, "1");
Uri uriWithArgs = uriBuilder.build(); Uri uriWithArgs = uriBuilder.build();
Cursor cursor = null; Cursor cursor = null;
@ -725,6 +730,11 @@ public class BrowserProvider extends ContentProvider {
return !TextUtils.isEmpty(isSync); return !TextUtils.isEmpty(isSync);
} }
private boolean isTest(Uri uri) {
String isTest = uri.getQueryParameter(BrowserContract.PARAM_IS_TEST);
return !TextUtils.isEmpty(isTest);
}
private boolean shouldShowDeleted(Uri uri) { private boolean shouldShowDeleted(Uri uri) {
String showDeleted = uri.getQueryParameter(BrowserContract.PARAM_SHOW_DELETED); String showDeleted = uri.getQueryParameter(BrowserContract.PARAM_SHOW_DELETED);
return !TextUtils.isEmpty(showDeleted); return !TextUtils.isEmpty(showDeleted);