Search in sources :

Example 1 with RepoPushRequest

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

the class RepoXMLHandlerTest method testPushRequestsRepoIgnore.

@Test
public void testPushRequestsRepoIgnore() {
    Repo expectedRepo = new Repo();
    expectedRepo.name = "non-public test repo";
    // NOCHECKSTYLE LineLength
    expectedRepo.signingCertificate = "308204e1308202c9a0030201020204483450fa300d06092a864886f70d01010b050030213110300e060355040b1307462d44726f6964310d300b06035504031304736f7661301e170d3136303832333133333131365a170d3434303130393133333131365a30213110300e060355040b1307462d44726f6964310d300b06035504031304736f766130820222300d06092a864886f70d01010105000382020f003082020a0282020100dfdcd120f3ab224999dddf4ea33ea588d295e4d7130bef48c143e9d76e5c0e0e9e5d45e64208e35feebc79a83f08939dd6a343b7d1e2179930a105a1249ccd36d88ff3feffc6e4dc53dae0163a7876dd45ecc1ddb0adf5099aa56c1a84b52affcd45d0711ffa4de864f35ac0333ebe61ea8673eeda35a88f6af678cc4d0f80b089338ac8f2a8279a64195c611d19445cab3fd1a020afed9bd739bb95142fb2c00a8f847db5ef3325c814f8eb741bacf86ed3907bfe6e4564d2de5895df0c263824e0b75407589bae2d3a4666c13b92102d8781a8ee9bb4a5a1a78c4a9c21efdaf5584da42e84418b28f5a81d0456a3dc5b420991801e6b21e38c99bbe018a5b2d690894a114bc860d35601416aa4dc52216aff8a288d4775cddf8b72d45fd2f87303a8e9c0d67e442530be28eaf139894337266e0b33d57f949256ab32083bcc545bc18a83c9ab8247c12aea037e2b68dee31c734cb1f04f241d3b94caa3a2b258ffaf8e6eae9fbbe029a934dc0a0859c5f120334812693a1c09352340a39f2a678dbc1afa2a978bfee43afefcb7e224a58af2f3d647e5745db59061236b8af6fcfd93b3602f9e456978534f3a7851e800071bf56da80401c81d91c45f82568373af0576b1cc5eef9b85654124b6319770be3cdba3fbebe3715e8918fb6c8966624f3d0e815effac3d2ee06dd34ab9c693218b2c7c06ba99d6b74d4f17b8c3cb0203010001a321301f301d0603551d0e04160414d62bee9f3798509546acc62eb1de14b08b954d4f300d06092a864886f70d01010b05000382020100743f7c5692085895f9d1fffad390fb4202c15f123ed094df259185960fd6dadf66cb19851070f180297bba4e6996a4434616573b375cfee94fee73a4505a7ec29136b7e6c22e6436290e3686fe4379d4e3140ec6a08e70cfd3ed5b634a5eb5136efaaabf5f38e0432d3d79568a556970b8cfba2972f5d23a3856d8a981b9e9bbbbb88f35e708bde9cbc5f681cbd974085b9da28911296fe2579fa64bbe9fa0b93475a7a8db051080b0c5fade0d1c018e7858cd4cbe95145b0620e2f632cbe0f8af9cbf22e2fdaa72245ae31b0877b07181cc69dd2df74454251d8de58d25e76354abe7eb690f22e59b08795a8f2c98c578e0599503d9085927634072c82c9f82abd50fd12b8fd1a9d1954eb5cc0b4cfb5796b5aaec0356643b4a65a368442d92ef94edd3ac6a2b7fe3571b8cf9f462729228aab023ef9183f73792f5379633ccac51079177d604c6bc1873ada6f07d8da6d68c897e88a5fa5d63fdb8df820f46090e0716e7562dd3c140ba279a65b996f60addb0abe29d4bf2f5abe89480771d492307b926d91f02f341b2148502903c43d40f3c6c86a811d060711f0698b384acdcc0add44eb54e42962d3d041accc715afd49407715adc09350cb55e8d9281a3b0b6b5fcd91726eede9b7c8b13afdebb2c2b377629595f1096ba62fb14946dbac5f3c5f0b4e5b712e7acc7dcf6c46cdc5e6d6dfdeee55a0c92c2d70f080ac6";
    // NOCHECKSTYLE LineLength
    expectedRepo.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.";
    expectedRepo.timestamp = 1472071347;
    RepoDetails actualDetails = getFromFile("pushRequestsIndex.xml", Repo.PUSH_REQUEST_IGNORE);
    handlerTestSuite(expectedRepo, actualDetails, 2, 14, -1, 17);
    checkPushRequests(actualDetails);
    List<RepoPushRequest> repoPushRequests = actualDetails.repoPushRequestList;
    assertNotNull(repoPushRequests);
    assertEquals(0, repoPushRequests.size());
}
Also used : Repo(org.fdroid.fdroid.data.Repo) RepoPushRequest(org.fdroid.fdroid.data.RepoPushRequest) RepoDetails(org.fdroid.fdroid.mock.RepoDetails) Test(org.junit.Test)

Example 2 with RepoPushRequest

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

Example 3 with RepoPushRequest

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

Example 4 with RepoPushRequest

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

the class RepoXMLHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    super.startElement(uri, localName, qName, attributes);
    if ("repo".equals(localName)) {
        repoSigningCert = attributes.getValue("", "pubkey");
        repoMaxAge = Utils.parseInt(attributes.getValue("", "maxage"), -1);
        repoVersion = Utils.parseInt(attributes.getValue("", "version"), -1);
        repoName = cleanWhiteSpace(attributes.getValue("", "name"));
        repoDescription = cleanWhiteSpace(attributes.getValue("", "description"));
        repoTimestamp = parseLong(attributes.getValue("", "timestamp"), 0);
        repoIcon = attributes.getValue("", "icon");
    } else if (RepoPushRequest.INSTALL.equals(localName) || RepoPushRequest.UNINSTALL.equals(localName)) {
        if (repo.pushRequests == Repo.PUSH_REQUEST_ACCEPT_ALWAYS) {
            RepoPushRequest r = new RepoPushRequest(localName, attributes.getValue("packageName"), attributes.getValue("versionCode"));
            onRepoPushRequestParsed(r);
        }
    } else if ("application".equals(localName) && curapp == null) {
        curapp = new App();
        curapp.repoId = repo.getId();
        curapp.packageName = attributes.getValue("", "id");
        // To appease the NON NULL constraint in the DB. Usually there is a description, and it
        // is quite difficult to get an app to _not_ have a description when using fdroidserver.
        // However, it shouldn't crash the client when this happens.
        curapp.description = "";
    } else if ("package".equals(localName) && curapp != null && curapk == null) {
        curapk = new Apk();
        curapk.packageName = curapp.packageName;
        curapk.repoId = repo.getId();
        currentApkHashType = null;
    } else if ("hash".equals(localName) && curapk != null) {
        currentApkHashType = attributes.getValue("", "type");
    } else if ("uses-permission".equals(localName) && curapk != null) {
        String maxSdkVersion = attributes.getValue("maxSdkVersion");
        if (maxSdkVersion == null || Build.VERSION.SDK_INT <= Integer.valueOf(maxSdkVersion)) {
            addRequestedPermission(attributes.getValue("name"));
        } else {
            removeRequestedPermission(attributes.getValue("name"));
        }
    } else if ("uses-permission-sdk-23".equals(localName) && curapk != null) {
        String maxSdkVersion = attributes.getValue("maxSdkVersion");
        if (Build.VERSION.SDK_INT >= 23 && (maxSdkVersion == null || Build.VERSION.SDK_INT <= Integer.valueOf(maxSdkVersion))) {
            addRequestedPermission(attributes.getValue("name"));
        } else {
            removeRequestedPermission(attributes.getValue("name"));
        }
    }
    curchars.setLength(0);
}
Also used : App(org.fdroid.fdroid.data.App) RepoPushRequest(org.fdroid.fdroid.data.RepoPushRequest) Apk(org.fdroid.fdroid.data.Apk)

Example 5 with RepoPushRequest

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

the class RepoXMLHandlerTest method checkPushRequests.

private void checkPushRequests(RepoDetails actualDetails) {
    final Object[] expectedPushRequestsIndex = new Object[] { "install", "org.fdroid.fdroid", 101002, "install", "org.fdroid.fdroid.privileged", null, "uninstall", "com.android.vending", null, "uninstall", "com.facebook.orca", -12345, // request with no data
    "uninstall", // request with no data
    null, // request with no data
    null, // non-existent app
    "install", // non-existent app
    "asdfasdfasdf", // non-existent app
    null };
    checkIncludedApps(actualDetails.apps, new String[] { "org.fdroid.fdroid", "org.fdroid.fdroid.privileged" });
    List<RepoPushRequest> repoPushRequestList = actualDetails.repoPushRequestList;
    int i = 0;
    for (RepoPushRequest repoPushRequest : repoPushRequestList) {
        assertEquals(repoPushRequest.request, expectedPushRequestsIndex[i]);
        assertEquals(repoPushRequest.packageName, expectedPushRequestsIndex[i + 1]);
        assertEquals(repoPushRequest.versionCode, expectedPushRequestsIndex[i + 2]);
        i += 3;
    }
}
Also used : RepoPushRequest(org.fdroid.fdroid.data.RepoPushRequest)

Aggregations

RepoPushRequest (org.fdroid.fdroid.data.RepoPushRequest)6 App (org.fdroid.fdroid.data.App)3 Repo (org.fdroid.fdroid.data.Repo)3 RepoDetails (org.fdroid.fdroid.mock.RepoDetails)3 Test (org.junit.Test)3 Apk (org.fdroid.fdroid.data.Apk)2 ContentResolver (android.content.ContentResolver)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FDroidProviderTest (org.fdroid.fdroid.data.FDroidProviderTest)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1