Merge branch 'fix-909--repo-priorities' into 'master'

Repos added later should take higher priority.

Closes #909

See merge request !462
This commit is contained in:
Hans-Christoph Steiner 2017-04-06 10:26:19 +00:00
commit 8ca795e307
4 changed files with 44 additions and 19 deletions

View File

@ -960,7 +960,7 @@ public class AppProvider extends FDroidProvider {
final String app = getTableName(); final String app = getTableName();
final String highestPriority = final String highestPriority =
"SELECT MIN(r." + RepoTable.Cols.PRIORITY + ") " + "SELECT MAX(r." + RepoTable.Cols.PRIORITY + ") " +
"FROM " + RepoTable.NAME + " AS r " + "FROM " + RepoTable.NAME + " AS r " +
"JOIN " + getTableName() + " AS m ON (m." + Cols.REPO_ID + " = r." + RepoTable.Cols._ID + ") " + "JOIN " + getTableName() + " AS m ON (m." + Cols.REPO_ID + " = r." + RepoTable.Cols._ID + ") " +
"WHERE m." + Cols.PACKAGE_ID + " = " + "metadata." + Cols.PACKAGE_ID; "WHERE m." + Cols.PACKAGE_ID + " = " + "metadata." + Cols.PACKAGE_ID;

View File

@ -190,7 +190,7 @@ class DBHelper extends SQLiteOpenHelper {
+ InstalledAppTable.Cols.HASH + " TEXT NOT NULL" + InstalledAppTable.Cols.HASH + " TEXT NOT NULL"
+ " );"; + " );";
protected static final int DB_VERSION = 67; protected static final int DB_VERSION = 68;
private final Context context; private final Context context;
@ -272,6 +272,16 @@ class DBHelper extends SQLiteOpenHelper {
addCategoryTables(db, oldVersion); addCategoryTables(db, oldVersion);
addIndexV1Fields(db, oldVersion); addIndexV1Fields(db, oldVersion);
addIndexV1AppFields(db, oldVersion); addIndexV1AppFields(db, oldVersion);
recalculatePreferredMetadata(db, oldVersion);
}
private void recalculatePreferredMetadata(SQLiteDatabase db, int oldVersion) {
if (oldVersion >= 68) {
return;
}
Log.i(TAG, "Previously, the repository metadata was being interpreted backwards. Need to force a repo refresh to fix this.");
resetTransient(db);
} }
private void addIndexV1AppFields(SQLiteDatabase db, int oldVersion) { private void addIndexV1AppFields(SQLiteDatabase db, int oldVersion) {

View File

@ -44,8 +44,7 @@ public class CategoryProviderTest extends FDroidProviderTest {
insertAppWithCategory("com.dog.rock.apple", "Dog-Rock-Apple", "Animal,Mineral,Vegetable", mainRepo); insertAppWithCategory("com.dog.rock.apple", "Dog-Rock-Apple", "Animal,Mineral,Vegetable", mainRepo);
insertAppWithCategory("com.banana.apple", "Banana", "Vegetable,Vegetable", mainRepo); insertAppWithCategory("com.banana.apple", "Banana", "Vegetable,Vegetable", mainRepo);
List<String> categories = CategoryProvider.Helper.categories(context); String[] expectedFDroid = new String[] {
String[] expected = new String[] {
context.getResources().getString(R.string.category_Whats_New), context.getResources().getString(R.string.category_Whats_New),
context.getResources().getString(R.string.category_Recently_Updated), context.getResources().getString(R.string.category_Recently_Updated),
context.getResources().getString(R.string.category_All), context.getResources().getString(R.string.category_All),
@ -56,13 +55,8 @@ public class CategoryProviderTest extends FDroidProviderTest {
"Vegetable", "Vegetable",
"Writing", "Writing",
}; };
assertContainsOnly(categories, expected);
insertAppWithCategory("info.guardianproject.notepadbot", "NoteCipher", "Office,GuardianProject", gpRepo); String[] expectedGP = new String[] {
assertContainsOnly(CategoryProvider.Helper.categories(context), expected);
RepoProvider.Helper.purgeApps(context, new MockRepo(mainRepo));
String[] expectedGp = new String[] {
context.getResources().getString(R.string.category_Whats_New), context.getResources().getString(R.string.category_Whats_New),
context.getResources().getString(R.string.category_Recently_Updated), context.getResources().getString(R.string.category_Recently_Updated),
context.getResources().getString(R.string.category_All), context.getResources().getString(R.string.category_All),
@ -70,8 +64,29 @@ public class CategoryProviderTest extends FDroidProviderTest {
"GuardianProject", "GuardianProject",
"Office", "Office",
}; };
// We overwrite "Security" + "Writing" with "GuardianProject" + "Office"
String[] expectedBoth = new String[] {
context.getResources().getString(R.string.category_Whats_New),
context.getResources().getString(R.string.category_Recently_Updated),
context.getResources().getString(R.string.category_All),
"Animal",
"Mineral",
"Vegetable",
"GuardianProject",
"Office",
};
assertContainsOnly(CategoryProvider.Helper.categories(context), expectedFDroid);
insertAppWithCategory("info.guardianproject.notepadbot", "NoteCipher", "Office,GuardianProject", gpRepo);
assertContainsOnly(CategoryProvider.Helper.categories(context), expectedBoth);
RepoProvider.Helper.purgeApps(context, new MockRepo(mainRepo));
List<String> categoriesAfterPurge = CategoryProvider.Helper.categories(context); List<String> categoriesAfterPurge = CategoryProvider.Helper.categories(context);
assertContainsOnly(categoriesAfterPurge, expectedGp); assertContainsOnly(categoriesAfterPurge, expectedGP);
} }
@Test @Test

View File

@ -95,15 +95,15 @@ public class ProperMultiRepoUpdaterTest extends MultiRepoUpdaterTest {
@Test @Test
public void metadataWithRepoPriority() throws RepoUpdater.UpdateException { public void metadataWithRepoPriority() throws RepoUpdater.UpdateException {
updateConflicting();
updateMain(); updateMain();
updateArchive(); updateArchive();
updateConflicting();
Repo conflictingRepo = RepoProvider.Helper.findByAddress(context, REPO_CONFLICTING_URI); Repo mainRepo = RepoProvider.Helper.findByAddress(context, REPO_MAIN_URI);
assertEquals(1, conflictingRepo.priority); assertEquals(1, mainRepo.priority);
assertEquals(2, RepoProvider.Helper.findByAddress(context, REPO_MAIN_URI).priority); assertEquals(2, RepoProvider.Helper.findByAddress(context, REPO_ARCHIVE_URI).priority);
assertEquals(3, RepoProvider.Helper.findByAddress(context, REPO_ARCHIVE_URI).priority); assertEquals(3, RepoProvider.Helper.findByAddress(context, REPO_CONFLICTING_URI).priority);
assertMainRepo(); assertMainRepo();
assertMainArchiveRepoMetadata(); assertMainArchiveRepoMetadata();
@ -114,9 +114,9 @@ public class ProperMultiRepoUpdaterTest extends MultiRepoUpdaterTest {
// Make the conflicting repo less important than the main repo. // Make the conflicting repo less important than the main repo.
ContentValues values = new ContentValues(1); ContentValues values = new ContentValues(1);
values.put(Cols.PRIORITY, 5); values.put(Cols.PRIORITY, 5);
RepoProvider.Helper.update(context, conflictingRepo, values); RepoProvider.Helper.update(context, mainRepo, values);
Repo updatedConflictingRepo = RepoProvider.Helper.findByAddress(context, REPO_CONFLICTING_URI); Repo updatedMainRepo = RepoProvider.Helper.findByAddress(context, REPO_MAIN_URI);
assertEquals(5, updatedConflictingRepo.priority); assertEquals(5, updatedMainRepo.priority);
assertRepoTakesPriority("Normal"); assertRepoTakesPriority("Normal");
} }