50 Commits

Author SHA1 Message Date
Daniel Martí
9efe173380 checkstyle: Finally add proper indentation checks
Somewhat painful conversion, but should go much smoother from here
onward.
2015-12-29 22:00:23 +01:00
Peter Serwylo
c36529f445 Renaming id -> packageName in local variables/method args/comments/etc. 2015-12-26 15:12:58 +11:00
Peter Serwylo
038816e32a Renamed Apk.id to Apk.packageName 2015-12-25 08:04:52 +11:00
Peter Serwylo
5779736913 Renamed App.id to App.packageName 2015-12-25 08:04:48 +11:00
Peter Serwylo
756df4d635 Renamed Java constant APP_ID to PACKAGE_NAME
In both the ApkProvider and the AppProvider.

Left the underlying database name as 'id' for now because it is
not as important or visible.
2015-12-25 08:04:41 +11:00
Daniel Martí
e20188b804 Use more switches 2015-12-07 21:20:11 +01:00
Peter Serwylo
7c99b6ce91 Merge branch 'fix-324--memory-issue-repo-update' into 'master'
Fix 324 : Out of memory errors while updating repos.

Fixes #324, but in the process makes the updater take a lot longer. My benchmarks tell me that an update which used to take approx 30 seconds on my Nexus 4 now takes about 50-55 seconds. This is because it first inserts the apps into the database (in a temp table) and then subsequently copies that table to the actual table. This means there is a lot more disk access than before.

I'm open for discussion on whether this tradeoff is worth it - however I'll caution that there is always going to be a tradeoff between faster and more memory vs slower and less memory. This is the case with all software, and perhaps more so with memory constrained devices such as phones. Also, as the repo index grows (until perhaps we are able to extract the app descriptions in the future), this will become more of an issue.

I'd also like this to be CR'ed properly before merging, because it changes some important code around the repo updater. It is important because security, and it is also important because it is the main thing that F-Droid needs to do (get a list of apps to show the user).

See merge request !173
2015-12-07 13:57:14 +00:00
Daniel Martí
8405ba7d87 checkstyle: proper multiple empty line check
Hopefully checkstyle could catch all of these on its own one day. For
now, help it via a multiline regex.
2015-11-30 11:30:49 +01:00
Daniel Martí
f2212e33d7 Make newer checkstyle happy
Mostly just dropping public from constructors.
2015-11-30 10:37:43 +01:00
Peter Serwylo
1d951e7689 Fixed repo updater tests. Fix to temp app/apk providers.
The repo xml handler now has a different mechanism for returning
data about the parsed xml file. This is done via a callback, rather
than storing the data in member variables. The tests now deal with
this correctly.

The update/delete operations of the TempAp[pk]Provider's didn't
work, so that has now been fixed.
2015-11-30 18:16:02 +11:00
Peter Serwylo
b989ef3ecc WIP: Stream index details to database rather than waiting until end.
Refactored repo update to stream apks from network -> jar file reader ->
xml parser -> database. No longer build up large lists of app metadata
to save. Saves memory, but is MUCH slower.

Does sig verification properly, but does it at the END of the process
and DOESN'T ROLL BACK on failure.

Quick and dirty benchmarks show an increase in time from ~25 seconds
to ~30 seconds on my Nexus 4 with Android 5.0. This doesn't seem so
bad to me, for the tradeoff that people on low end devices can actually
update now.

Also, as @eighthave pointed out, if we are able to stream the download
directly from the internet, then that time will drop to essentially
the time it takes to download the index.
2015-11-30 18:14:42 +11:00
Daniel Martí
11e2fb7540 test: close all cursors
This makes lint happy and avoids tons of warnings on the logcat due to
StrictMode.
2015-11-14 14:18:08 +01:00
Daniel Martí
9fc1aba8bc Checkstyle fix 2015-11-13 20:46:52 +01:00
Daniel Martí
04e7b8d7ab Collapse identical catch statements in tests 2015-11-13 18:51:28 +01:00
Daniel Martí
52ada0131a Deduplicate types in tests 2015-11-13 18:50:43 +01:00
Daniel Martí
04a2c4b70d Fix tests by never caching a null signature
This also keeps us from future possible NPE or null signature issues, if
we ever call getPackageSig on a PackageInfo with no signatures.
2015-11-13 11:42:47 +01:00
Peter Serwylo
12d5c5c7b4 Format to make checkstyle happy. Remove unused code. 2015-11-07 09:40:44 +11:00
Peter Serwylo
938c992023 Comment out tests for future, desirable behaviour.
Leave only the ones which align with the current multi-repo behaviour
that F-Droid exhibits.

The commented out tests can be uncommented in the future when working
on proper multi-repo support.
2015-11-07 08:05:13 +11:00
Peter Serwylo
1c179848b7 Added tests for current multi-repo behaviour.
This is the bare minimum of what must be maintained going forward.
Ideally the behaviour sohould be better, but that is for the future.
2015-11-07 08:05:13 +11:00
Peter Serwylo
0685c16efe More work on multi-repo tests, currently broken due to F-Droid being broken.
(One of) the problems with F-Droid's multiple support is that there is
a primary key on the fdroid_apk table which is a composite of:

 * id
 * vercode

Which means that two repos providing the same version means one will
update the other, rather than ending up with two different versions.

Instead, there should be some other way to differentiate apks from
different sources. Firstly, it should take into account the signing
cert. Secondly, it may taken into account the hash, because two people
could sign different apks with the same cert and then we are back at
square one.
2015-11-07 08:05:13 +11:00
Peter Serwylo
f794d1e7a5 Infrastructure for doing test driven development to support multiple repo dev.
The new test skeletons right now update three different repos
in different configurations. They do so such that the order of updates
changes and therefore the way in which conflicts between repos are
dealt with are tested.

They should all have the same result (though I'm not sure exactly what
that should be yet).
2015-11-07 08:05:13 +11:00
Peter Serwylo
8d1e20b7fd Remove TargetApi(8) because that is our min-sdk now. 2015-11-07 08:05:13 +11:00
Daniel Martí
92713acdce Fix tests after e085e039
We already had a getPackageInfo, but it wasn't the proper one with flags so
that our new code could use it.
2015-10-25 13:13:55 +01:00
Daniel Martí
b60afa2dc0 checkstyle: Also check test sources 2015-10-09 11:19:41 +02:00
Daniel Martí
bc283304df Fix tests compilation after 5c4de9a1 2015-10-08 13:28:35 +02:00
Daniel Martí
faecbd03a0 Unify and deduplicate gitignores 2015-09-09 21:24:36 -07:00
Daniel Martí
16a0344ceb Update RepoXMLHandlerTest to make tests pass 2015-09-03 18:02:57 -07:00
Daniel Martí
c725b36ff8 Move RepoXMLHandlerTest into the proper directory
This was probably due to a faulty rebase/merge.
2015-09-03 18:02:57 -07:00
Daniel Martí
96906ec35a Remove test jar libs since gradle pulls them from jcenter 2015-07-25 21:13:55 -07:00
Daniel Martí
5e0683df23 Remove ant stuff from the test project
Forgot to get rid of those when removing ant support
2015-07-25 21:06:53 -07:00
Hans-Christoph Steiner
4f2650cd47 update logic to match only parsing signed index files
Now that there is only ever the index.jar, the whole flow of RepoUpdater
has changed quite a bit.  This updates the logic for deciding when to store
the current repo's pubkey in the database for future reference.

This changes the flow to stop writing the unpacked index.xml and instead
stream it directly to the XML parser from the index.jar.  This should speed
things up some.
refs #259 https://gitlab.com/fdroid/fdroidclient/issues/259

This is also work towards running the whole thing in the background:
refs #103 https://gitlab.com/fdroid/fdroidclient/issues/103

This also removes the progress stuff since it will need to change a lot to
work with the streaming mode
2015-07-13 10:32:07 -07:00
Hans-Christoph Steiner
d7efc99bdb simplify RepoUpdater to remove cruft from previous code structure
Before, there was an abstract RepoUpdater class with two subclasses, one
for signed and unsigned.  Now there is just a single class, and it only
ever starts with the index.jar.  So this removes lots of code that was
there to handle that more complicated structure.  For example, there is no
longer the need to separately work on the index.xml vs index.jar.
2015-07-13 10:32:07 -07:00
Hans-Christoph Steiner
3c6389c004 fix failing symlink test
the dest.txt  symlink was produced, but it was pointing to a non-existent
file.
2015-07-13 10:32:07 -07:00
Peter Serwylo
7c49f03f21 Updated readme with instructions for running tests. Fixed for Andoid-10
Updated the README with details of how to run the tests. Also added a
minor fix to allow tests to run on pre-honeycomb devices. However their
behaviour may not be 100% defined - because the contentproviders are
not shuttind down correctly due to lack of an API to do so.
2015-06-24 21:36:36 +10:00
Peter Serwylo
78b5f489ef Merge branch 'fix-263/explicitly-add-swap-repo' into 'master'
Fix #263 "cannot manually add repo that was swapped before"

Pretends that the swap repo never existed, by deleting it before adding
the new repo, and showing the same message that is shown when a new
repo is added. This does not change behaviour for existing non-swap
repos. They are not deleted before being added again, or else we would
lose the ability to verify the fingerprint of an existing repo is the
same as a newly added one with the same URL.

Note that this has the effect that the fingerprint/pubkey of the swap
repo is nuked when adding that repo manually.

Internationalised the string "BAD FINGERPRINT" while I was at it.

To test it out, here is some instructions to make life easier:

Firstly, go into manage repos and delete the guardian project main repo (going to pretend to use this for swapping to make life easier).

Then if you run `sqlite3 /data/data/org.fdroid.fdroid/databases/fdroid` and execute the query:

`select substr(fingerprint, 0, 10), substr(pubkey, 70, 10), address, isSwap from fdroid_repo order by fingerprint desc;`

You should see:

```
B7C2EEFD8|081ad310b3|https://guardianproject.info/fdroid/archive|0
43238D512|071310b300|https://f-droid.org/archive|0
43238D512|071310b300|https://f-droid.org/repo/|0
```

Now simulate a swap session like so:

```
adb shell am start -a android.intent.action.VIEW -d 'https://guardianproject.info/fdroid/repo?swap=1'
```

Which results in the following database:

```
B7C2EEFD8|081ad310b3|https://guardianproject.info/fdroid/archive|0
B7C2EEFD8|081ad310b3|https://guardianproject.info/fdroid/repo|1
43238D512|071310b300|https://f-droid.org/archive|0
43238D512|071310b300|https://f-droid.org/repo/|0
```

Note the last column (`isSwap`) is `1` for the newly added swap repo. Now we will add the repo (without a fingerprint) to the Manage Repo activity. If you are feeling lazy, execute:

```
adb shell am start -a android.intent.action.VIEW -d https://guardianproject.info/fdroid/repo
```

The repo will be removed, then re-added as a TOFU repo:

```
B7C2EEFD8|081ad310b3|https://guardianproject.info/fdroid/archive|0
43238D512|071310b300|https://f-droid.org/archive|0
43238D512|071310b300|https://f-droid.org/repo/|0
||https://guardianproject.info/fdroid/repo/|0
```

I noticed some bugginess with sending the same intent and it being ignored, I'll have to look at this another day (not caused by this change, it already existed in master).

See merge request !90
2015-06-15 09:33:06 +00:00
Daniel Martí
8e62d9ae7e Add install confirm+perms screen to SystemInstaller 2015-05-20 21:59:24 +02:00
Peter Serwylo
5065c37e13 Fix #263 "cannot manually add repo that was swapped before"
Pretends that the swap repo never existed, by deleting it before adding
the new repo, and showing the same message that is shown when a new
repo is added. This does not change behaviour for existing non-swap
repos. They are not deleted before being added again, or else we would
lose the ability to verify the fingerprint of an existing repo is the
same as a newly added one with the same URL.

Note that this has the effect that the fingerprint/pubkey of the swap
repo is nuked when adding that repo manually.

Internationalised the string "BAD FINGERPRINT" while I was at it.
2015-05-20 08:26:57 +10:00
Daniel Martí
29b78df530 Remove "fdroid." from TAGs, add a comment on filtering by packagename 2015-05-08 23:28:32 +02:00
Hans-Christoph Steiner
367387f967 move RepoUpdaterTest to the same package as RepoUpdater 2015-05-08 12:51:46 -04:00
Hans-Christoph Steiner
157b1e242f remove support for unsigned repos
This has been discussed quite a bit now.  It is very easy to generate a
signed repo on the server, and supporting unsigned repos adds complexity
and security issues, including "BZ-01-002 TOFU Requests too easy to
recognize and intercept" from the audit.

https://gitlab.com/fdroid/fdroidserver/merge_requests/48
closes #12 https://gitlab.com/fdroid/fdroidclient/issues/12
2015-05-07 22:11:05 -04:00
Peter Serwylo
424839c793 Encapsulate functions which can produce invalid SQL.
Now the other content provider functions which can result in broken SQL
due to the number of arguments is private, and can only be accessed
from a public helper method which ensures that limit is never hit.
2015-04-21 22:27:58 +10:00
Daniel Martí
2365d314c6 Simplify some catch logic 2015-04-15 17:56:40 +02:00
Daniel Martí
0f18a0979d Run Android Studio's import optimizer
* Remove all wildcard imports
* Reorder alphabetically and by source
* Remove unused imports
2015-04-07 11:58:22 +02:00
Peter Serwylo
a2be7d9013 Fix update count, breakage from rebase, and broken tests.
The update count was broken because I added the join onto the
apk table, and in the process, forced a GROUP BY on the AppProvider
queries. This group by made the COUNT(*) actually count the number
of apks for each app, not the total rows.
2015-04-01 16:20:20 +11:00
Peter Serwylo
a16bc22c4a Fixed broken + commented out tests.
They were all due to the addition of "application label" to the
installed app cache. This commit adds a mock ApplicationInfo
to the mock package manager and also specifies the label while
inserting into the test content provider.
2015-04-01 15:33:58 +11:00
Peter Serwylo
9dfa18aead Make F-Droid tests runnable from Gradle.
This also makes AndroidStudio integration work better, which makes
running and debugging tests much nicer than the CLI.

Also cleaned up imports in one test, and made the symlink tests not
fail on older devices below API 19.
2015-04-01 15:33:51 +11:00
Peter Serwylo
08af7ee157 Change symlink implementation to use best available impl per platform.
* Android-21 introduced an API for symlinking.
 * Android-19 has an API which can be used via reflection.
 * Earlier versions use Runtime.exec('/system/bin/ln')

This also extends the SanitizedFile stuff so that the android < 19 can
safely use Runtime.exec() with less fear of command injection vulnerabilities.

Finally, some tests for the SanitizedFile and symlink stuff was added.
2015-01-27 22:47:32 +11:00
Peter Serwylo
afef5ea233 Added test for SanitizedFile class. 2015-01-26 13:53:16 +11:00
Peter Serwylo
37b3f1ff57 Cache .apks in internal storage before installing.
This prevents an app with "write external storage" permission from
being able to switch the legit app with a dodgey one between F-Droid
requesting an install, and the package manager actually showing the
install dialog to the user.

In order to make the file in private internal storage readable by
the package manager, its parent directories need to be world-executable,
and the file itself needs to be world-readable. It seems that the
"/data/data/org.fdroid.fdroid/cache" dir provided by the Context is
already world executable, but the "apks" subdirectory does not default
to this.

Also, to be compatible with android-8, a Runtime.getRuntime().exec()
call was added for such devices, which invokes /system/bin/chmod.
The effect of this was to require some level of file sanitization to
be made available using the Java type system to prevent command injection
attacks from weird apk names (as people are free to download metadata
from random internet people).
2015-01-26 09:36:56 +11:00
Daniel Martí
06dd4c8dcb Move F-Droid project into subdir, keeping a root gradle project
Also improved .gitignore a tad
2014-12-09 15:36:07 +01:00