Merge branch 'fix_iconquery' into 'master'

Fix iconquery

Closes #1108

See merge request fdroid/fdroidclient!715
This commit is contained in:
Marcus 2018-12-23 11:06:16 +00:00
commit 928042540f
4 changed files with 81 additions and 13 deletions

View File

@ -363,7 +363,7 @@ public class IndexV1Updater extends IndexUpdater {
contentValues.put(Schema.RepoTable.Cols.MIRRORS, Utils.serializeCommaSeparatedString(repo.mirrors)); contentValues.put(Schema.RepoTable.Cols.MIRRORS, Utils.serializeCommaSeparatedString(repo.mirrors));
} }
repoPersister.commit(contentValues, repo.getId()); repoPersister.commit(contentValues, repo.getId());
profiler.log("Persited to database."); profiler.log("Persisted to database.");
if (repo.pushRequests == Repo.PUSH_REQUEST_ACCEPT_ALWAYS) { if (repo.pushRequests == Repo.PUSH_REQUEST_ACCEPT_ALWAYS) {
processRepoPushRequests(requests); processRepoPushRequests(requests);

View File

@ -81,7 +81,7 @@ public class ApkProvider extends FDroidProvider {
} }
/** /**
* Find an app which is closest to the version code suggested by the server, with some caveates: * Find an app which is closest to the version code suggested by the server, with some caveats:
* <ul> * <ul>
* <li>If installed, limit to apks signed by the same signer as the installed apk.</li> * <li>If installed, limit to apks signed by the same signer as the installed apk.</li>
* <li>Otherwise, limit to apks signed by the "preferred" signer (see {@link App#preferredSigner}).</li> * <li>Otherwise, limit to apks signed by the "preferred" signer (see {@link App#preferredSigner}).</li>

View File

@ -145,7 +145,7 @@ public class AppProvider extends FDroidProvider {
/** /**
* A QuerySelection which is aware of the option/need to join onto the * A QuerySelection which is aware of the option/need to join onto the
* installed apps table. Not that the base classes * installed apps table. Note that the base classes
* {@link org.fdroid.fdroid.data.QuerySelection#add(QuerySelection)} and * {@link org.fdroid.fdroid.data.QuerySelection#add(QuerySelection)} and
* {@link org.fdroid.fdroid.data.QuerySelection#add(String, String[])} methods * {@link org.fdroid.fdroid.data.QuerySelection#add(String, String[])} methods
* will only return the base class {@link org.fdroid.fdroid.data.QuerySelection} * will only return the base class {@link org.fdroid.fdroid.data.QuerySelection}
@ -1193,12 +1193,11 @@ public class AppProvider extends FDroidProvider {
private void updateIconUrls() { private void updateIconUrls() {
final String appTable = getTableName(); final String appTable = getTableName();
final String apkTable = getApkTableName();
final String iconsDir = Utils.getIconsDir(getContext(), 1.0); final String iconsDir = Utils.getIconsDir(getContext(), 1.0);
String repoVersion = Integer.toString(Repo.VERSION_DENSITY_SPECIFIC_ICONS); String repoVersion = Integer.toString(Repo.VERSION_DENSITY_SPECIFIC_ICONS);
Utils.debugLog(TAG, "Updating icon paths for apps belonging to repos with version >= " + repoVersion); Utils.debugLog(TAG, "Updating icon paths for apps belonging to repos with version >= " + repoVersion);
Utils.debugLog(TAG, "Using icons dir '" + iconsDir + "'"); Utils.debugLog(TAG, "Using icons dir '" + iconsDir + "'");
String query = getIconUpdateQuery(appTable, apkTable); String query = getIconUpdateQuery(appTable);
final String[] params = { final String[] params = {
repoVersion, iconsDir, Utils.FALLBACK_ICONS_DIR, repoVersion, iconsDir, Utils.FALLBACK_ICONS_DIR,
}; };
@ -1206,11 +1205,11 @@ public class AppProvider extends FDroidProvider {
} }
/** /**
* Returns a query which requires two parameters to be bdeatound. These are (in order): * Returns a query which requires two parameters to be bound. These are (in order):
* 1) The repo version that introduced density specific icons * 1) The repo version that introduced density specific icons
* 2) The dir to density specific icons for the current device. * 2) The dir to density specific icons for the current device.
*/ */
private static String getIconUpdateQuery(String app, String apk) { private static String getIconUpdateQuery(String app) {
final String repo = RepoTable.NAME; final String repo = RepoTable.NAME;
@ -1233,12 +1232,7 @@ public class AppProvider extends FDroidProvider {
app + "." + Cols.ICON + app + "." + Cols.ICON +
") " + ") " +
" FROM " + " FROM " +
apk + repo + " WHERE " + repo + "." + RepoTable.Cols._ID + " = " + app + "." + Cols.REPO_ID;
" JOIN " + repo + " ON (" + repo + "." + RepoTable.Cols._ID + " = " + apk + "." + ApkTable.Cols.REPO_ID + ") " +
" WHERE " +
app + "." + Cols.ROW_ID + " = " + apk + "." + ApkTable.Cols.APP_ID + " AND " +
apk + "." + ApkTable.Cols.VERSION_CODE + " = " + app + "." + Cols.SUGGESTED_VERSION_CODE;
return "UPDATE " + app + " SET " return "UPDATE " + app + " SET "
+ Cols.ICON_URL + " = ( " + iconUrlQuery + " )"; + Cols.ICON_URL + " = ( " + iconUrlQuery + " )";
} }

View File

@ -0,0 +1,74 @@
package org.fdroid.fdroid.updater;
import android.content.ContentValues;
import org.fdroid.fdroid.BuildConfig;
import org.fdroid.fdroid.IndexUpdater;
import org.fdroid.fdroid.data.App;
import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.data.RepoProvider;
import org.fdroid.fdroid.data.Schema;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals;
/**
* Check whether app icons are loaded from the correct repository. The repository with the
* highest priority should be where we decide to load icons from.
*/
@Config(constants = BuildConfig.class)
@RunWith(RobolectricTestRunner.class)
@SuppressWarnings("LineLength")
public class AppIconsTest extends MultiIndexUpdaterTest {
private static final int HIGH_PRIORITY = 2;
private static final int LOW_PRIORITY = 1;
@Before
public void setupMainAndArchiveRepo() {
createRepo(REPO_MAIN, REPO_MAIN_URI, context);
createRepo(REPO_ARCHIVE, REPO_ARCHIVE_URI, context);
}
@Test
public void mainRepo() throws IndexUpdater.UpdateException {
setRepoPriority(REPO_MAIN_URI, HIGH_PRIORITY);
setRepoPriority(REPO_ARCHIVE_URI, LOW_PRIORITY);
updateMain();
updateArchive();
assertIconUrl("https://f-droid.org/repo/icons/org.adaway.54.png");
}
@Test
public void archiveRepo() throws IndexUpdater.UpdateException {
setRepoPriority(REPO_MAIN_URI, LOW_PRIORITY);
setRepoPriority(REPO_ARCHIVE_URI, HIGH_PRIORITY);
updateMain();
updateArchive();
assertIconUrl("https://f-droid.org/archive/icons/org.adaway.54.png");
}
private void setRepoPriority(String repoUri, int priority) {
ContentValues values = new ContentValues(1);
values.put(Schema.RepoTable.Cols.PRIORITY, priority);
Repo repo = RepoProvider.Helper.findByAddress(context, repoUri);
RepoProvider.Helper.update(context, repo, values);
}
private void assertIconUrl(String expectedUrl) {
App app = AppProvider.Helper.findHighestPriorityMetadata(context.getContentResolver(),
"org.adaway", new String[] {Schema.AppMetadataTable.Cols.ICON_URL});
assertEquals(app.iconUrl, expectedUrl);
}
}