mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-06-18 12:49:59 -04:00
Ensure swapping doesn't get confused by apks in different repos.
While investigating #1086 which was about swap being busted, I discovered that we recently introduced a worse bug when working with multi sig stuff. The swap process, when installing an app (or even when listening for if a user started installing - before they even did anything), would ask for an apk from any repo. This is wrong, because we should only ask for the apks from the swap repo when presented with a swap dialog. By fixing this so that it asks for a specific apk, this may also fix the issue in #1086, because that was about us not asking for enough info from the database for each Apk which was returned. Now we just return all columns, because the performance overhead should be minimal, but it prevents this class of bugs, where we didn't fully populate our value object. However, I'm not confident that it is fixed, because I was unable to reproduce it due to the other crash fixed in this change. Relevant crash: ``` java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.fdroid.fdroid.data.Apk.getUrl()' on a null object reference at org.fdroid.fdroid.views.swap.SwapAppsView$AppListAdapter$ViewHolder.setApp(SwapAppsView.java:311) at org.fdroid.fdroid.views.swap.SwapAppsView$AppListAdapter.bindView(SwapAppsView.java:422) at org.fdroid.fdroid.views.swap.SwapAppsView$AppListAdapter.newView(SwapAppsView.java:414) at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:269) at android.widget.AbsListView.obtainView(AbsListView.java:2349) at android.widget.ListView.makeAndAddView(ListView.java:1864) at android.widget.ListView.fillDown(ListView.java:698) ... ```
This commit is contained in:
@@ -9,6 +9,7 @@ import org.fdroid.fdroid.data.ApkProvider;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.InstalledAppProvider;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.Schema.ApkTable;
|
||||
import org.fdroid.fdroid.data.Schema.AppMetadataTable;
|
||||
import org.fdroid.fdroid.data.Schema.InstalledAppTable;
|
||||
@@ -181,6 +182,12 @@ public class Assert {
|
||||
return insertApp(context, packageName, name, new ContentValues());
|
||||
}
|
||||
|
||||
public static App insertApp(Context context, String packageName, String name, Repo repo) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(AppMetadataTable.Cols.REPO_ID, repo.getId());
|
||||
return insertApp(context, packageName, name, values);
|
||||
}
|
||||
|
||||
public static App insertApp(Context context, String packageName, String name, ContentValues additionalValues) {
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
@@ -6,7 +6,10 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.fdroid.fdroid.data.Apk;
|
||||
import org.fdroid.fdroid.data.ApkProvider;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
@@ -81,10 +84,14 @@ public class TestUtils {
|
||||
assertEquals(message, formatSigForDebugging(expected), formatSigForDebugging(actual));
|
||||
}
|
||||
|
||||
public static void insertApk(Context context, App app, int versionCode, String signature) {
|
||||
public static Apk insertApk(Context context, App app, int versionCode, String signature) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Schema.ApkTable.Cols.SIGNATURE, signature);
|
||||
Assert.insertApk(context, app, versionCode, values);
|
||||
|
||||
long repoId = app.repoId > 0 ? app.repoId : 1;
|
||||
values.put(Schema.ApkTable.Cols.REPO_ID, repoId);
|
||||
Uri uri = Assert.insertApk(context, app, versionCode, values);
|
||||
return ApkProvider.Helper.findByUri(context, uri, Schema.ApkTable.Cols.ALL);
|
||||
}
|
||||
|
||||
public static App insertApp(Context context, String packageName, String appName, int upstreamVersionCode,
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import org.fdroid.fdroid.Assert;
|
||||
import org.fdroid.fdroid.BuildConfig;
|
||||
import org.fdroid.fdroid.TestUtils;
|
||||
import org.fdroid.fdroid.data.Schema.ApkTable.Cols;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable;
|
||||
import org.fdroid.fdroid.mock.MockApk;
|
||||
@@ -271,6 +272,27 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
assertBelongsToApp(thingoApks, "com.apk.thingo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findApksForAppInSpecificRepo() {
|
||||
Repo fdroidRepo = RepoProvider.Helper.findByAddress(context, "https://f-droid.org/repo");
|
||||
Repo swapRepo = RepoProviderTest.insertRepo(context, "http://192.168.1.3/fdroid/repo", "", "22", "", true);
|
||||
|
||||
App officialFDroid = insertApp(context, "org.fdroid.fdroid", "F-Droid (Official)", fdroidRepo);
|
||||
TestUtils.insertApk(context, officialFDroid, 4, TestUtils.FDROID_SIG);
|
||||
TestUtils.insertApk(context, officialFDroid, 5, TestUtils.FDROID_SIG);
|
||||
|
||||
App debugSwapFDroid = insertApp(context, "org.fdroid.fdroid", "F-Droid (Debug)", swapRepo);
|
||||
TestUtils.insertApk(context, debugSwapFDroid, 6, TestUtils.THIRD_PARTY_SIG);
|
||||
|
||||
List<Apk> foundOfficialApks = ApkProvider.Helper.findAppVersionsByRepo(context, officialFDroid, fdroidRepo);
|
||||
assertEquals(2, foundOfficialApks.size());
|
||||
|
||||
List<Apk> debugSwapApks = ApkProvider.Helper.findAppVersionsByRepo(context, officialFDroid, swapRepo);
|
||||
assertEquals(1, debugSwapApks.size());
|
||||
assertEquals(debugSwapFDroid.getId(), debugSwapApks.get(0).appId);
|
||||
assertEquals(6, debugSwapApks.get(0).versionCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
|
||||
|
||||
@@ -256,11 +256,17 @@ public class RepoProviderTest extends FDroidProviderTest {
|
||||
|
||||
public static Repo insertRepo(Context context, String address, String description,
|
||||
String fingerprint, @Nullable String name) {
|
||||
return insertRepo(context, address, description, fingerprint, name, false);
|
||||
}
|
||||
|
||||
public static Repo insertRepo(Context context, String address, String description,
|
||||
String fingerprint, @Nullable String name, boolean isSwap) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(RepoTable.Cols.ADDRESS, address);
|
||||
values.put(RepoTable.Cols.DESCRIPTION, description);
|
||||
values.put(RepoTable.Cols.FINGERPRINT, fingerprint);
|
||||
values.put(RepoTable.Cols.NAME, name);
|
||||
values.put(RepoTable.Cols.IS_SWAP, isSwap);
|
||||
|
||||
RepoProvider.Helper.insert(context, values);
|
||||
return RepoProvider.Helper.findByAddress(context, address);
|
||||
|
||||
Reference in New Issue
Block a user