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 highestPriority =
"SELECT MIN(r." + RepoTable.Cols.PRIORITY + ") " +
"SELECT MAX(r." + RepoTable.Cols.PRIORITY + ") " +
"FROM " + RepoTable.NAME + " AS r " +
"JOIN " + getTableName() + " AS m ON (m." + Cols.REPO_ID + " = r." + RepoTable.Cols._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"
+ " );";
protected static final int DB_VERSION = 67;
protected static final int DB_VERSION = 68;
private final Context context;
@ -272,6 +272,16 @@ class DBHelper extends SQLiteOpenHelper {
addCategoryTables(db, oldVersion);
addIndexV1Fields(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) {

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.banana.apple", "Banana", "Vegetable,Vegetable", mainRepo);
List<String> categories = CategoryProvider.Helper.categories(context);
String[] expected = new String[] {
String[] expectedFDroid = 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),
@ -56,13 +55,8 @@ public class CategoryProviderTest extends FDroidProviderTest {
"Vegetable",
"Writing",
};
assertContainsOnly(categories, expected);
insertAppWithCategory("info.guardianproject.notepadbot", "NoteCipher", "Office,GuardianProject", gpRepo);
assertContainsOnly(CategoryProvider.Helper.categories(context), expected);
RepoProvider.Helper.purgeApps(context, new MockRepo(mainRepo));
String[] expectedGp = new String[] {
String[] expectedGP = 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),
@ -70,8 +64,29 @@ public class CategoryProviderTest extends FDroidProviderTest {
"GuardianProject",
"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);
assertContainsOnly(categoriesAfterPurge, expectedGp);
assertContainsOnly(categoriesAfterPurge, expectedGP);
}
@Test

View File

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