use of org.fdroid.fdroid.data.App in project fdroidclient by f-droid.
the class RepoUpdater method processRepoPushRequests.
/**
* Server index XML can include optional {@code install} and {@code uninstall}
* requests. This processes those requests, figuring out whether the client
* should always accept, prompt the user, or ignore those requests on a
* per repo basis.
*/
void processRepoPushRequests() {
PackageManager pm = context.getPackageManager();
for (RepoPushRequest repoPushRequest : repoPushRequestList) {
String packageName = repoPushRequest.packageName;
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
// ignored
}
if (RepoPushRequest.INSTALL.equals(repoPushRequest.request)) {
ContentResolver cr = context.getContentResolver();
// TODO: In the future, this needs to be able to specify which repository to get
// the package from. Better yet, we should be able to specify the hash of a package
// to install (especially when we move to using hashes more as identifiers than we
// do right now).
App app = AppProvider.Helper.findHighestPriorityMetadata(cr, packageName);
if (app == null) {
Utils.debugLog(TAG, packageName + " not in local database, ignoring request to" + repoPushRequest.request);
continue;
}
int versionCode;
if (repoPushRequest.versionCode == null) {
versionCode = app.suggestedVersionCode;
} else {
versionCode = repoPushRequest.versionCode;
}
if (packageInfo != null && versionCode == packageInfo.versionCode) {
Utils.debugLog(TAG, repoPushRequest + " already installed, ignoring");
} else {
Apk apk = ApkProvider.Helper.findApkFromAnyRepo(context, packageName, versionCode);
InstallManagerService.queue(context, app, apk);
}
} else if (RepoPushRequest.UNINSTALL.equals(repoPushRequest.request)) {
if (packageInfo == null) {
Utils.debugLog(TAG, "ignoring request, not installed: " + repoPushRequest);
continue;
}
if (repoPushRequest.versionCode == null || repoPushRequest.versionCode == packageInfo.versionCode) {
Apk apk = ApkProvider.Helper.findApkFromAnyRepo(context, repoPushRequest.packageName, packageInfo.versionCode);
InstallerService.uninstall(context, apk);
} else {
Utils.debugLog(TAG, "ignoring request based on versionCode:" + repoPushRequest);
}
} else {
Utils.debugLog(TAG, "Unknown Repo Push Request: " + repoPushRequest.request);
}
}
}
use of org.fdroid.fdroid.data.App in project fdroidclient by f-droid.
the class AppIconsTest method assertIconUrl.
private void assertIconUrl(String expectedUrl) {
App app = AppProvider.Helper.findHighestPriorityMetadata(context.getContentResolver(), "org.adaway", new String[] { Schema.AppMetadataTable.Cols.ICON_URL, Schema.AppMetadataTable.Cols.ICON, Schema.AppMetadataTable.Cols.REPO_ID });
assertThat(app.getIconUrl(context), MatchesPattern.matchesPattern(expectedUrl));
}
use of org.fdroid.fdroid.data.App in project fdroidclient by f-droid.
the class IndexV1UpdaterTest method testJsonIgnoreApp.
/**
* Test that all the fields are properly marked as whether Jackson should ignore them
* or not. Technically this test goes the opposite direction of how its being used:
* it writes out {@link App} and {@link Apk} instances to JSON using Jackson. With the
* index parsing, Jackson is always reading JSON into {@link App} and {@link Apk}
* instances. {@code @JsonIgnoreProperties} applies to both directions.
* <p>
* If this test fails for you, then it probably means you are adding a new instance
* variable to {@link App}. In that case, you need to add it to the appropriate
* list here. If it is allowed, make sure this new instance variable is in sync with
* {@code index-v1.json} and {@code fdroidserver}.
*/
@Test
public void testJsonIgnoreApp() throws JsonProcessingException {
String[] allowedInApp = new String[] { "added", "antiFeatures", "authorEmail", "authorName", "autoInstallVersionCode", "autoInstallVersionName", "bitcoin", "categories", "changelog", "description", "donate", "featureGraphic", "flattrID", "iconFromApk", "iconUrl", "issueTracker", "lastUpdated", "liberapay", "license", "litecoin", "name", "openCollective", "packageName", "phoneScreenshots", "promoGraphic", "repoId", "requirements", "sevenInchScreenshots", "sourceCode", "suggestedVersionCode", "suggestedVersionName", "summary", "tenInchScreenshots", "translation", "tvBanner", "tvScreenshots", "video", "wearScreenshots", "webSite", "whatsNew" };
String[] ignoredInApp = new String[] { "compatible", "CREATOR", "id", "installedApk", "installedSig", "installedVersionCode", "installedVersionName", "isApk", "isLocalized", "preferredSigner", "prefs", "systemLocaleList", "TAG" };
runJsonIgnoreTest(new App(), allowedInApp, ignoredInApp);
}
use of org.fdroid.fdroid.data.App in project fdroidclient by f-droid.
the class IndexV1UpdaterTest method testIndexV1Processing.
@Test
public void testIndexV1Processing() throws IOException, IndexUpdater.UpdateException {
List<Repo> repos = RepoProvider.Helper.all(context);
for (Repo repo : repos) {
RepoProvider.Helper.remove(context, repo.getId());
}
assertEquals("No repos present", 0, RepoProvider.Helper.all(context).size());
assertEquals("No apps present", 0, AppProvider.Helper.all(context.getContentResolver()).size());
Repo repo = MultiIndexUpdaterTest.createRepo("Testy", TESTY_CANONICAL_URL, context, TESTY_CERT);
repo.timestamp = 1481222110;
IndexV1Updater updater = new IndexV1Updater(context, repo);
JarFile jarFile = new JarFile(TestUtils.copyResourceToTempFile(TESTY_JAR), true);
Log.i(TAG, "jarFile " + jarFile);
JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
InputStream indexInputStream = jarFile.getInputStream(indexEntry);
updater.processIndexV1(indexInputStream, indexEntry, "fakeEtag");
IOUtils.closeQuietly(indexInputStream);
List<App> apps = AppProvider.Helper.all(context.getContentResolver());
assertEquals("63 apps present", 63, apps.size());
// these should never be set from the JSON, only by fdroidclient
assertEquals(Repo.PUSH_REQUEST_IGNORE, repo.pushRequests);
assertFalse(repo.isSwap);
assertNotEquals(99999, repo.priority);
String[] packages = { "fake.app.one", "org.adaway", "This_does_not_exist" };
for (String id : packages) {
assertEquals("No apks for " + id, 0, ApkProvider.Helper.findByPackageName(context, id).size());
}
for (App app : apps) {
assertTrue("Some apks for " + app.packageName, ApkProvider.Helper.findByPackageName(context, app.packageName).size() > 0);
}
repos = RepoProvider.Helper.all(context);
assertEquals("One repo", 1, repos.size());
Repo repoFromDb = repos.get(0);
assertEquals("repo.timestamp should be set", 1497639511, repoFromDb.timestamp);
assertEquals("repo.address should be the same", repo.address, repoFromDb.address);
assertEquals("repo.name should be set", "non-public test repo", repoFromDb.name);
assertEquals("repo.maxage should be set", 0, repoFromDb.maxage);
assertEquals("repo.version should be set", 18, repoFromDb.version);
assertEquals("repo.icon should be set", "fdroid-icon.png", repoFromDb.icon);
// NOCHECKSTYLE LineLength
String description = "This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/u/fdroid. ";
assertEquals("repo.description should be set", description, repoFromDb.description);
assertEquals("repo.mirrors should have items", 2, repo.mirrors.length);
assertEquals("second URL in index-v1, but canonical is first", TESTY_CANONICAL_URL, repo.mirrors[0]);
assertEquals("first URL in index-v1", "http://frkcchxlcvnb4m5a.onion/fdroid/repo", repo.mirrors[1]);
// Make sure the per-apk anti features which are new in index v1 get added correctly.
assertEquals(0, AppProvider.Helper.findInstalledAppsWithKnownVulns(context).size());
InstalledAppTestUtils.install(context, "com.waze", 1019841, "v3.9.5.4", "362488e7be5ea0689b4e97d989ae1404", "cbbdb8c5dafeccd7dd7b642dde0477d3489e18ac366e3c8473d5c07e5f735a95");
assertEquals(1, AppProvider.Helper.findInstalledAppsWithKnownVulns(context).size());
Apk apk = ApkProvider.Helper.findApkFromAnyRepo(context, "io.proto.player", 1110);
assertNotNull("We should find this APK", apk);
assertEquals("io.proto.player-1.apk", apk.apkName);
HashSet<String> requestedPermissions = new HashSet<>(Arrays.asList(apk.requestedPermissions));
assertTrue(requestedPermissions.contains(android.Manifest.permission.READ_EXTERNAL_STORAGE));
assertTrue(requestedPermissions.contains(android.Manifest.permission.WRITE_EXTERNAL_STORAGE));
assertFalse(requestedPermissions.contains(android.Manifest.permission.READ_CALENDAR));
App app = AppProvider.Helper.findHighestPriorityMetadata(context.getContentResolver(), "com.autonavi.minimap", new String[] { Schema.AppMetadataTable.Cols.ICON_URL, Schema.AppMetadataTable.Cols.ICON, Schema.AppMetadataTable.Cols.REPO_ID, Schema.AppMetadataTable.Cols.Package.PACKAGE_NAME });
assertEquals("localized icon takes precedence", TESTY_CANONICAL_URL + "/" + app.packageName + "/en-US/icon.png", app.getIconUrl(context));
}
use of org.fdroid.fdroid.data.App in project fdroidclient by f-droid.
the class ProperMultiIndexUpdaterTest method assertCalendarMetadata.
private void assertCalendarMetadata(Repo repo, @RepoIdentifier String id) {
App calendar = AppProvider.Helper.findSpecificApp(context.getContentResolver(), "org.dgtale.icsimport", repo.getId(), AppMetadataTable.Cols.ALL);
assertCalendarMetadata(calendar, id);
}
Aggregations