use of org.fdroid.fdroid.data.App in project fdroidclient by f-droid.
the class IndexUpdater 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. There is also a compile-time option as a failsafe.
*/
void processRepoPushRequests(List<RepoPushRequest> requestEntries) {
try {
if (!context.getResources().getBoolean(R.bool.config_allowPushRequests)) {
return;
}
} catch (NotFoundException e) {
Utils.debugLog(TAG, "allowPushRequests configuration not found, defaulting to false");
return;
}
for (RepoPushRequest repoPushRequest : requestEntries) {
String packageName = repoPushRequest.packageName;
PackageInfo packageInfo = Utils.getPackageInfo(context, packageName);
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.autoInstallVersionCode;
} 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);
if (apk == null) {
Log.i(TAG, "Push " + repoPushRequest.packageName + " request not found in any repo!");
} else {
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 LocalRepoManager method copyIconsToRepo.
public void copyIconsToRepo() {
ApplicationInfo appInfo;
for (final App app : apps.values()) {
if (app.installedApk != null) {
try {
appInfo = pm.getApplicationInfo(app.packageName, PackageManager.GET_META_DATA);
copyIconToRepo(appInfo.loadIcon(pm), app.packageName, app.installedApk.versionCode);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Error getting app icon", e);
}
}
}
}
use of org.fdroid.fdroid.data.App in project fdroidclient by f-droid.
the class IndexV1UpdaterTest method testInstanceVariablesAreProperlyMarked.
@Test
public void testInstanceVariablesAreProperlyMarked() throws IOException {
ObjectMapper mapper = IndexV1Updater.getObjectMapperInstance(FAKE_REPO_ID);
JsonFactory f = mapper.getFactory();
JsonParser parser = f.createParser(TestUtils.copyResourceToTempFile("all_fields_index-v1.json"));
Repo repo = null;
App[] apps = null;
Map<String, List<Apk>> packages = null;
// go into the main object block
parser.nextToken();
while (true) {
String fieldName = parser.nextFieldName();
if (fieldName == null) {
break;
}
switch(fieldName) {
case "repo":
repo = parseRepo(mapper, parser);
break;
case "apps":
apps = parseApps(mapper, parser);
break;
case "packages":
packages = parsePackages(mapper, parser);
break;
}
}
// ensure resources get cleaned up timely and properly
parser.close();
assertEquals(1, apps.length);
assertEquals(1, packages.size());
List<Apk> cacerts = packages.get("info.guardianproject.cacert");
assertEquals(2, cacerts.size());
assertEquals(1488828510109L, repo.timestamp);
assertEquals("GPLv3", apps[0].license);
// these should never be set from the JSON, only by fdroidclient
assertEquals(Repo.PUSH_REQUEST_IGNORE, repo.pushRequests);
assertFalse(repo.inuse);
assertFalse(repo.isSwap);
assertNotEquals(99999, repo.priority);
assertNotEquals("foobar", repo.lastetag);
Set<String> appFields = getFields(apps[0]);
for (String field : appFields) {
assertNotEquals("secret", field);
}
Apk apk = cacerts.get(0);
assertEquals("e013db095e8da843fae5ac44be6152e51377ee717e5c8a7b6d913d7720566b5a", apk.hash);
Set<String> packageFields = getFields(apk);
for (String field : packageFields) {
assertNotEquals("secret", field);
}
apk = cacerts.get(1);
assertEquals("2353d1235e8da843fae5ac44be6152e513123e717e5c8a7b6d913d7720566b5a", apk.hash);
assertNull(apk.versionName);
}
use of org.fdroid.fdroid.data.App in project fdroidclient by f-droid.
the class IndexV1UpdaterTest method testJacksonParsing.
@Test
public void testJacksonParsing() throws IOException {
ObjectMapper mapper = IndexV1Updater.getObjectMapperInstance(FAKE_REPO_ID);
// the app ignores all unknown fields when complete, do not ignore during dev to catch mistakes
mapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
JsonFactory f = mapper.getFactory();
JsonParser parser = f.createParser(TestUtils.copyResourceToTempFile("guardianproject_index-v1.json"));
Repo repo = null;
App[] apps = null;
Map<String, String[]> requests = null;
Map<String, List<Apk>> packages = null;
// go into the main object block
parser.nextToken();
while (true) {
String fieldName = parser.nextFieldName();
if (fieldName == null) {
break;
}
switch(fieldName) {
case "repo":
repo = parseRepo(mapper, parser);
break;
case "requests":
requests = parseRequests(mapper, parser);
break;
case "apps":
apps = parseApps(mapper, parser);
break;
case "packages":
packages = parsePackages(mapper, parser);
break;
}
}
// ensure resources get cleaned up timely and properly
parser.close();
// test LiberapayID: -> Liberapay: migration
for (App app : apps) {
if ("org.witness.informacam.app".equals(app.packageName)) {
assertEquals("GuardianProject", app.liberapay);
} else if ("info.guardianproject.cacert".equals(app.packageName)) {
assertEquals("~1337", app.liberapay);
} else {
assertNull(app.liberapay);
}
}
RepoDetails indexV0Details = getFromFile("guardianproject_index.xml", Repo.PUSH_REQUEST_ACCEPT_ALWAYS);
indexV0Details.apps.size();
assertEquals(indexV0Details.apps.size(), apps.length);
assertEquals(apps.length, packages.size());
int totalApks = 0;
for (String packageName : packages.keySet()) {
totalApks += packages.get(packageName).size();
}
assertEquals(totalApks, indexV0Details.apks.size());
assertEquals(indexV0Details.icon, repo.icon);
// V1 is in millis
assertEquals(indexV0Details.timestamp, repo.timestamp / 1000);
assertEquals(indexV0Details.name, repo.name);
assertArrayEquals(indexV0Details.mirrors, repo.mirrors);
ArrayList<String> installRequests = new ArrayList<>();
for (RepoPushRequest repoPushRequest : indexV0Details.repoPushRequestList) {
if ("install".equals(repoPushRequest.request)) {
installRequests.add(repoPushRequest.packageName);
}
}
assertArrayEquals(installRequests.toArray(), requests.get("install"));
}
use of org.fdroid.fdroid.data.App in project fdroidclient by f-droid.
the class ProperMultiIndexUpdaterTest method assertAdbMetadata.
private void assertAdbMetadata(Repo repo, @RepoIdentifier String id) {
App adb = AppProvider.Helper.findSpecificApp(context.getContentResolver(), "siir.es.adbWireless", repo.getId(), AppMetadataTable.Cols.ALL);
assertAdbMetadata(adb, id);
}
Aggregations