Clarify that sometimes we don't know which repos apk we are asking for.

Many times in the past, we would ask for an apk based on its package name
and its version code. However multiple repositories provide apks with the
same package name and version code, and such queries would (seemingly)
nondeterministically choose one of these matching apks. This clarifies the
wording in the code around when we explicitly ask for a given apk, and
when we kind of guess which one we want.

Most the time we have an `App` handy, which has a specific repo associated
with it. This allows us to be more specific about requesting `Apk`s.

The times we are kind of guessing is when we rely on the "suggested version
code" of an apk by clicking the misc "Install" or "Upgrade" button in
app details. In the future, we'll need to clear this up so that a more
specific apk is chosen when touching these buttons.
This commit is contained in:
Peter Serwylo
2016-09-30 00:06:08 +10:00
parent 3a24d21f59
commit d062af0975
7 changed files with 79 additions and 34 deletions

View File

@@ -201,7 +201,7 @@ public class Assert {
return AppProvider.Helper.findSpecificApp(context.getContentResolver(), packageName, 1, AppMetadataTable.Cols.ALL);
}
private static App ensureApp(Context context, String packageName) {
public static App ensureApp(Context context, String packageName) {
App app = AppProvider.Helper.findSpecificApp(context.getContentResolver(), packageName, 1, AppMetadataTable.Cols.ALL);
if (app == null) {
insertApp(context, packageName, packageName);

View File

@@ -242,41 +242,45 @@ public class ApkProviderTest extends FDroidProviderTest {
@Test
public void testKnownApks() {
App fdroid = Assert.ensureApp(context, "org.fdroid.fdroid");
for (int i = 0; i < 7; i++) {
Assert.insertApk(context, "org.fdroid.fdroid", i);
Assert.insertApk(context, fdroid, i);
}
App exampleOrg = Assert.ensureApp(context, "org.example");
for (int i = 0; i < 9; i++) {
Assert.insertApk(context, "org.example", i);
Assert.insertApk(context, exampleOrg, i);
}
App exampleCom = Assert.ensureApp(context, "com.example");
for (int i = 0; i < 3; i++) {
Assert.insertApk(context, "com.example", i);
Assert.insertApk(context, exampleCom, i);
}
Assert.insertApk(context, "com.apk.thingo", 1);
App thingo = Assert.ensureApp(context, "com.apk.thingo");
Assert.insertApk(context, thingo, 1);
Apk[] known = {
new MockApk("org.fdroid.fdroid", 1),
new MockApk("org.fdroid.fdroid", 3),
new MockApk("org.fdroid.fdroid", 5),
new MockApk(fdroid, 1),
new MockApk(fdroid, 3),
new MockApk(fdroid, 5),
new MockApk("com.example", 1),
new MockApk("com.example", 2),
new MockApk(exampleCom, 1),
new MockApk(exampleCom, 2),
};
Apk[] unknown = {
new MockApk("org.fdroid.fdroid", 7),
new MockApk("org.fdroid.fdroid", 9),
new MockApk("org.fdroid.fdroid", 11),
new MockApk("org.fdroid.fdroid", 13),
new MockApk(fdroid, 7),
new MockApk(fdroid, 9),
new MockApk(fdroid, 11),
new MockApk(fdroid, 13),
new MockApk("com.example", 3),
new MockApk("com.example", 4),
new MockApk("com.example", 5),
new MockApk(exampleCom, 3),
new MockApk(exampleCom, 4),
new MockApk(exampleCom, 5),
new MockApk("info.example", 1),
new MockApk("info.example", 2),
new MockApk(-10, 1),
new MockApk(-10, 2),
};
List<Apk> apksToCheck = new ArrayList<>(known.length + unknown.length);
@@ -285,6 +289,7 @@ public class ApkProviderTest extends FDroidProviderTest {
String[] projection = {
Cols.Package.PACKAGE_NAME,
Cols.APP_ID,
Cols.VERSION_CODE,
};

View File

@@ -135,9 +135,9 @@ public class ProviderUriTests {
assertValidUri(resolver, ApkProvider.getContentUri(), "content://org.fdroid.fdroid.data.ApkProvider", projection);
assertValidUri(resolver, ApkProvider.getAppUri("org.fdroid.fdroid"), "content://org.fdroid.fdroid.data.ApkProvider/app/org.fdroid.fdroid", projection);
assertValidUri(resolver, ApkProvider.getApkFromAnyRepoUri(new MockApk("org.fdroid.fdroid", 100)), "content://org.fdroid.fdroid.data.ApkProvider/apk/100/org.fdroid.fdroid", projection);
assertValidUri(resolver, ApkProvider.getApkFromAnyRepoUri(new MockApk("org.fdroid.fdroid", 100)), "content://org.fdroid.fdroid.data.ApkProvider/apk-any-repo/100/org.fdroid.fdroid", projection);
assertValidUri(resolver, ApkProvider.getContentUri(apks), projection);
assertValidUri(resolver, ApkProvider.getApkFromAnyRepoUri("org.fdroid.fdroid", 100), "content://org.fdroid.fdroid.data.ApkProvider/apk/100/org.fdroid.fdroid", projection);
assertValidUri(resolver, ApkProvider.getApkFromAnyRepoUri("org.fdroid.fdroid", 100), "content://org.fdroid.fdroid.data.ApkProvider/apk-any-repo/100/org.fdroid.fdroid", projection);
assertValidUri(resolver, ApkProvider.getRepoUri(1000), "content://org.fdroid.fdroid.data.ApkProvider/repo/1000", projection);
}

View File

@@ -1,6 +1,7 @@
package org.fdroid.fdroid.mock;
import org.fdroid.fdroid.data.Apk;
import org.fdroid.fdroid.data.App;
public class MockApk extends Apk {
@@ -9,4 +10,14 @@ public class MockApk extends Apk {
this.versionCode = versionCode;
}
public MockApk(App app, int versionCode) {
this.appId = app.getId();
this.versionCode = versionCode;
}
public MockApk(long appId, int versionCode) {
this.appId = appId;
this.versionCode = versionCode;
}
}