Search in sources :

Example 56 with Apk

use of org.fdroid.fdroid.data.Apk 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);
        }
    }
}
Also used : App(org.fdroid.fdroid.data.App) PackageInfo(android.content.pm.PackageInfo) NotFoundException(android.content.res.Resources.NotFoundException) RepoPushRequest(org.fdroid.fdroid.data.RepoPushRequest) Apk(org.fdroid.fdroid.data.Apk) ContentResolver(android.content.ContentResolver)

Example 57 with Apk

use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.

the class AppUpdateStatusManager method addApks.

public void addApks(List<Apk> apksToUpdate, Status status) {
    startBatchUpdates();
    for (Apk apk : apksToUpdate) {
        addApk(apk, status, null);
    }
    endBatchUpdates(status);
}
Also used : Apk(org.fdroid.fdroid.data.Apk)

Example 58 with Apk

use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.

the class IndexV1UpdaterTest method testJsonIgnoreApk.

/**
 * 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 Apk}.  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 testJsonIgnoreApk() throws JsonProcessingException {
    String[] allowedInApk = new String[] { "added", "antiFeatures", "apkName", "appId", "features", "hash", "hashType", "incompatibleReasons", "isApk", "maxSdkVersion", "minSdkVersion", "nativecode", "obbMainFile", "obbMainFileSha256", "obbPatchFile", "obbPatchFileSha256", "packageName", "repoId", "requestedPermissions", "sig", "size", "srcname", "targetSdkVersion", "versionCode", "versionName" };
    String[] ignoredInApk = new String[] { "compatible", "CREATOR", "installedFile", "repoAddress", "repoVersion", "SDK_VERSION_MAX_VALUE", "SDK_VERSION_MIN_VALUE", "url" };
    runJsonIgnoreTest(new Apk(), allowedInApk, ignoredInApk);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Apk(org.fdroid.fdroid.data.Apk) RepoXMLHandlerTest(org.fdroid.fdroid.data.RepoXMLHandlerTest) FDroidProviderTest(org.fdroid.fdroid.data.FDroidProviderTest) Test(org.junit.Test)

Example 59 with Apk

use of org.fdroid.fdroid.data.Apk 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);
}
Also used : App(org.fdroid.fdroid.data.App) Repo(org.fdroid.fdroid.data.Repo) JsonFactory(com.fasterxml.jackson.core.JsonFactory) List(java.util.List) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Apk(org.fdroid.fdroid.data.Apk) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) RepoXMLHandlerTest(org.fdroid.fdroid.data.RepoXMLHandlerTest) FDroidProviderTest(org.fdroid.fdroid.data.FDroidProviderTest) Test(org.junit.Test)

Example 60 with Apk

use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.

the class MultiIndexUpdaterTest method assertApksExist.

/**
 * Checks that each version of appId as specified in versionCodes is present in apksToCheck.
 */
protected void assertApksExist(List<Apk> apksToCheck, String appId, int[] versionCodes) {
    for (int versionCode : versionCodes) {
        boolean found = false;
        for (Apk apk : apksToCheck) {
            if (apk.versionCode == versionCode && apk.packageName.equals(appId)) {
                found = true;
                break;
            }
        }
        assertTrue("Couldn't find app " + appId + ", v" + versionCode, found);
    }
}
Also used : Apk(org.fdroid.fdroid.data.Apk)

Aggregations

Apk (org.fdroid.fdroid.data.Apk)63 Test (org.junit.Test)17 Uri (android.net.Uri)16 File (java.io.File)12 Intent (android.content.Intent)11 App (org.fdroid.fdroid.data.App)10 Repo (org.fdroid.fdroid.data.Repo)10 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Context (android.content.Context)7 PackageInfo (android.content.pm.PackageInfo)7 FileCompatTest (org.fdroid.fdroid.compat.FileCompatTest)7 BroadcastReceiver (android.content.BroadcastReceiver)6 PackageManager (android.content.pm.PackageManager)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 FDroidProviderTest (org.fdroid.fdroid.data.FDroidProviderTest)4 LocalBroadcastManager (androidx.localbroadcastmanager.content.LocalBroadcastManager)3 RepoDetails (org.fdroid.fdroid.mock.RepoDetails)3 SuppressLint (android.annotation.SuppressLint)2