857 Commits

Author SHA1 Message Date
Hans-Christoph Steiner
b7f0195234 add "HTTP Proxy" preference to support Tor, I2P, or any other proxy
This is the most basic support for channeling all downloads through Tor or
I2P.  This does not include Orbot integration, so the use will have to know
to start Orbot before using this.  I don't know anything about I2P.

closes #2367 https://dev.guardianproject.info/issues/2367
https://f-droid.org/repository/issues/?do=view_issue&issue=404
https://f-droid.org/repository/issues/?do=view_issue&issue=424
2014-06-05 17:23:44 -04:00
Peter Serwylo
b82be525b9 Rotation of app details with fragments implemented.
This was a bit more complex than all the other views, because it supports
rotation, and different views for when it is rotated. The end result is
that the way in which the views were constructed needed to be completely
redone.

In the process, I also moved the layout of the app summary to a Relative
Layout. This adds more flexibility, and is also the suggested layout
for complex views (as apposed to nested linear layouts). I believe this
is due to the performance of relative vs linear layotus.

It was aprticularly hard to figure out what was going on
when rotating an Activity which had a list fragment
that had another fragment as a header. I don't think fragments
were designed to work like this, but I believe it is all working
as expected now.

Conflicts:
	src/org/fdroid/fdroid/Preferences.java
2014-06-04 23:19:54 -04:00
Peter Serwylo
659b46fd4e Fix to sdkLoc in build. Added light (without dark action bar) theme.
NOTE: I don't know how android will go with adding a new property
to a string-array resource, but not having it translated everywhere.
Will it struggle because the EN version has three values for "theme",
but other translations only have two?
2014-06-04 23:19:54 -04:00
Peter Serwylo
3050e3dbc5 Migrating activities to appcompat-v7
The only remaining activity is the AppDetails acvitity, which will require
a little more than just making it extend ActionBarActivity. Currently,
it extends ListActivity. To support appcompat-v7, it really should have
two fragments - the details one and the list one. Then, when the orientation
is changed, it should load a different layout with the fragments side by side.

Although Google is encouraging people to make old devices run apps
with the action bar (via appcompat-v7), they haven't provided a way
for people to create preference/setting screens with an action bar.

There are plenty of issues in the Android issue tracker relating
to this, but it doesn't yet seem to be on the radar of the Android
devs.

Until there is a native implementation of PreferenceFragment in
the appcompat-v7 support library, this submodule provides is a 3rd
party solution. It is actually a fork of the first repo in github,
though that was a bit of an upload and dump, without accepting MR's.
This fork includes gradle support.
2014-06-04 23:19:37 -04:00
Peter Serwylo
92421bac05 WIP: Migrating activities to appcompat-v7.
Conflicts:
	src/org/fdroid/fdroid/FDroidApp.java
	src/org/fdroid/fdroid/views/LocalRepoActivity.java
	src/org/fdroid/fdroid/views/QrWizardDownloadActivity.java
2014-06-03 08:13:53 +09:30
Hans-Christoph Steiner
c1b5bf5279 implemented IconDownloader for UIL downloads with FDroid classes
This lets UniversalImageLoader (UIL) use FDroid's generic Downloader
infrastucture so that connection configuration all happens based on the URL
in DownloaderFactory.

refs #2598 https://dev.guardianproject.info/issues/2598
refs #2367 https://dev.guardianproject.info/issues/2367
2014-05-30 15:23:33 -04:00
Hans-Christoph Steiner
d19e77049a rename Downloader.inputStream() to getInputStream()
This follows:
URLConnection.getInputStream()
BaseImageDownloader.getStream()
2014-05-30 15:23:33 -04:00
Hans-Christoph Steiner
b619716669 add TorHttpDownloader for handling repos on Tor Hidden Services
Tor Hidden Services are on domain names that always end in .onion, so there
is a URL pattern matcher that chooses which Downloader subclass to use
based on testing for .onion.  This is a quick, dumb implementation.  It
does make any attempt to see if Tor is running or even installed.  That
can come once NetCipher is easy to handle in the context of FDroid.

refs #2367 https://dev.guardianproject.info/issues/2367
2014-05-30 15:23:33 -04:00
Hans-Christoph Steiner
910f9a68a6 make DownloaderFactory for creating any kind of Downloader
This will ultimately be used to create the right Downloader subclass
instance based on the URL of the file to download (i.e. rfcomm://, .onion
address, ssh://, new socket protocols, etc).

Also delete unused constructors, they can trivially be readded if they are
ever used, and they are currently just clutter.
2014-05-30 15:23:33 -04:00
Hans-Christoph Steiner
91e06b8496 new Wifi event cancels active processing of previous event
If a new "wifi connected" event comes in while a previous one is still
being processed, then cancel the current one as soon as possible.  This
prevents the events from being processed in an interleaved manner, causing
chaos and crashes.  Hopefully this will fix the jmdns crashes, since that
is triggered by onPostExecute() via FDroidApp.restartLocalRepoService().

java.lang.IllegalStateException: A service information can only be registered with a single instamce of JmDNS.
   at javax.jmdns.impl.JmDNSImpl.registerService(JmDNSImpl.java:1005)
   at org.fdroid.fdroid.localrepo.LocalRepoService$5.run(LocalRepoService.java:239)
   at java.lang.Thread.run(Thread.java:856)
2014-05-30 15:23:33 -04:00
Hans-Christoph Steiner
f51d192e13 move all mDNS service creation into the Thread
Upon looking at this, ServiceInfo.create() also might take a while to run
so might as well run it in the Thread with the other JmDNS stuff.
2014-05-30 15:23:33 -04:00
Hans-Christoph Steiner
ba028408a1 registerMDNSService() overwrites any existing registration
There is only ever a single service to advertise via mDNS, so when a new
registration is requested, remove any existing ones.  This should eliminate
these stacktraces:

java.lang.IllegalStateException: A service information can only be registered with a single instamce of JmDNS.
    at javax.jmdns.impl.JmDNSImpl.registerService(JmDNSImpl.java:1005)
    at org.fdroid.fdroid.localrepo.LocalRepoService$5.run(LocalRepoService.java:239)
    at java.lang.Thread.run(Thread.java:856)
2014-05-30 15:23:32 -04:00
Hans-Christoph Steiner
fdaa2ad106 update IP-related settings whenever the HTTPS pref changes
WifiStateChangeService handles updating lots of IP-related things, then
things that depend on it listen to the broadcast from that Service. The
most straightforward way to update HTTPS or HTTP throughout the app is to
trigger this Service.  It runs its stuff in an AsyncTask so it is all low
priority.
2014-05-30 15:23:32 -04:00
Hans-Christoph Steiner
c4b059502c better LocalRepoService singleton enforcement
We only ever want a single LocalRepoService.  Use the values returned by
the standard methods for start/stop and bind/unbind as the test for whether
the Service is indeed running.
2014-05-30 15:23:32 -04:00
Daniel Martí
a08963f0e5 Merge branch 'feature/refactor-downloaders-async' of https://gitlab.com/pserwylo/fdroidclient 2014-05-27 19:20:10 +02:00
Hans-Christoph Steiner
09db3524cf use getApplicationContext() when storing a passed in Context
getApplicationContext() returns the Context of the application, which is
guaranteed to have the same life as the app itself.  Other Contexts, like
an Activity, might go away during runtime.
2014-05-25 22:53:19 -04:00
Hans-Christoph Steiner
09fb7969b4 do not include URL in index.xml because it will get out of date
As far as I can tell, the 'url' metadata in index.xml is not used at all by
the client.  In order to keep it up-to-date in the local repo, it would
have to regenerate index.xml and index.jar each time the IP address
changed.  That would mean a decent amount of work happening in the
background, all the update an unused field in index.xml.
2014-05-25 22:53:19 -04:00
Hans-Christoph Steiner
0c039a6b5e make writeIndexJar() call writeIndexXML(): only create signed repos!
There is no longer a reason to expose writeIndexXML() since FDroid should
always generate a signed repo.  So make writeIndexXML() be called as part
of writeIndexJar().
2014-05-25 22:53:19 -04:00
Hans-Christoph Steiner
91fc0f5383 generate HTTPS certificate after wifi change
Since the HTTPS certificate includes the current IP address in it, it needs
to be regenerated each time that the IP address changes.  It also can take
a long time to run, especially on the first time, since it had to do things
like create a key pair and make the certificate.  Therefore it should be in
a Service/AsyncTask.
2014-05-25 22:53:19 -04:00
Hans-Christoph Steiner
b70986ef16 LocalRepoKeyStore.setupHTTPSCertificate() handles all exceptions itself
Since there is nothing happening with the Exceptions anyway, they should be
handled in this method so that this method is easy to use elsewhere.
2014-05-25 22:53:19 -04:00
Hans-Christoph Steiner
d5488fc5f1 LocalRepoKeyStore move all creation logic to the constructor
This just makes the code clearer, and the get() method dead simple.
2014-05-25 22:53:19 -04:00
Hans-Christoph Steiner
b7aad893a3 convert LocalRepoManager to a proper singleton
This gives us lazy initialization that happens the first time an instance
is needed.  And Peter asked to have this more this way :)
2014-05-25 22:53:19 -04:00
Hans-Christoph Steiner
568e82c07e if LocalHTTPD fails to instantiate, log error and stop trying 2014-05-25 22:53:18 -04:00
Hans-Christoph Steiner
b7339e9423 support HTTPS:// for local repo in a preference
Allow the local repo to use HTTPS:// instead of HTTP://.  This is currently
default off since handling the self-signed certificate is not currently
graceful.  In the future, the SPKI that AndroidPinning uses should be
included in the repo meta data, then when someone marks a repo as trusted,
that local repo's SPKI should be added to the list of trusted keys in
AndroidPinning.

fixes #2960 https://dev.guardianproject.info/issues/2960
2014-05-25 22:53:18 -04:00
Hans-Christoph Steiner
5f2efbb72a sign local repo based on key generated using spongycastle
This makes it so the local repo is always signed by a locally generated and
stored key.  That key will become the unique ID that represents a given
local repo.  It should seamlessly upgrade any existing unsigned local repo
next time that the user makes any changes to their local repo.

fixes #3380 https://dev.guardianproject.info/issues/3380
2014-05-25 22:53:18 -04:00
Hans-Christoph Steiner
22fb0337b9 clean up LocalRepoKeyStore code format
Make it match standard Java style.
2014-05-25 22:53:18 -04:00
Hans-Christoph Steiner
e41ae50812 make LocalRepoKeyStore into a proper singleton
Hopefully this makes Peter happy ;-)
2014-05-25 22:53:18 -04:00
Hans-Christoph Steiner
544b924ab9 copy org.fdroid.fdroid.localrepo.LocalRepoKeystore from Kerplapp
This is the keystore used for both the index.jar signing key and the key
and certificate needed to support HTTPS connections.

https://github.com/guardianproject/Kerplapp

refs #3380 https://dev.guardianproject.info/issues/3380
2014-05-25 22:53:18 -04:00
Hans-Christoph Steiner
b0c27869b6 new tricks to improve mDNS/Bonjour resolution
Before, it didn't seem to find anything unless I ran this on my laptop:
`avahi-browse -a -v`

So added two recommended practices from other jmdns code for Android:

* force full resolution on receiving serviceAdded()
* feed the WiFi's IP address to jmdns when creating an instance

fixes #3379 https://dev.guardianproject.info/issues/3379
2014-05-25 22:53:18 -04:00
Peter Serwylo
b2c63c6dc7 More robust multi-threaded downloading.
ApkDownloaders keep track of a unique id. This id is passed through with
each event coming from the downloader. When progress events are received,
if they don't have the same id as the current downloader, they are ignored.

When returning to the app details screen after leaving, if a download
completed in the mean time, automatically show the install screen. Otherwise,
when you, e.g. return to your devices home screen during a download, the
download keeps occuring in the background, but we are unable to make use of
the resulting downloaded file.
2014-05-24 08:42:49 +09:30
Peter Serwylo
009c8a6be5 Don't show progress in AppDetails when using a cached download.
The ApkDownloader now returns true or false depending on whether it
is using a cached version on disk, or hitting the network.
I was also a little more defensive about checking for if downloadHandler
is null before deciding to show a progress dialog.
2014-05-24 07:20:41 +09:30
Peter Serwylo
2f7d6f6452 Made constructor of ApkDownloader public.
Previously it was in the org.fdroid.fdroid package, along with
most other things. As such, it only need a package-local constructor.
However, now it has moved to the .net subpackage, and needs to be
made public.
2014-05-24 07:20:41 +09:30
Peter Serwylo
d9e5b07054 Removed unneeded todo's, add docs. 2014-05-24 07:20:41 +09:30
Peter Serwylo
75586ec4e5 Moved ApkDownloader to .net package
This is where it belongs, along with the other downloader code.
2014-05-24 07:20:41 +09:30
Peter Serwylo
1e1be1e73b Support orientation changes during app download.
Keep track of the downloader after an orientation change, and
make sure that there is always UI feedback beeing shown.

Removed resetRequired after merge conflict (the content observer
now deals with this for us in a much nicer way).

Conflicts:
	src/org/fdroid/fdroid/AppDetails.java
2014-05-24 07:20:41 +09:30
Peter Serwylo
11ddf0478c Better handling of cancelling of downloads.
One thing that still annoys me is that indeterminate progress dialog
still shows "0/100" due to the number formatter being used to display
the values in the TextView. Solution (from http://stackoverflow.com/a/6784180)
is to either make a custom dialog, or at the very least, in API 11 or higher
we can set the number formatter to display nothing.

Don't show the full download path of repo.
The full path includes the path to the index.jar, as well as ?clientVersion=*.
This is undesirable, the main purpose of even showing where we are downloading
from is to differentiate between multiple repos being updated at once.
2014-05-24 07:20:40 +09:30
Peter Serwylo
3ed2cde207 Added AsyncDownloadWrapper and used it in AppDetails to download apks.
This has a very different interface to the Downloader class, because
a handful of operations need to be run off the main thread (not just
download, but also totalDownloadSize and perhaps cache tag related
stuff). The AsyncDownloadWrapper provides its own listener, more
specific than just the progress listener, which invokes functions
at different points in time (e.g. download failed, completed, cancelled).

Refactored progress events to use string types instead of ints.
This way, it is less likely that two different events from
different processes will clash with each other.

Conflicts:
	src/org/fdroid/fdroid/AppDetails.java
2014-05-24 07:20:40 +09:30
Peter Serwylo
0e0e042cd0 Change DownloadHandler from using runOnUiThread() to send/handleMessage().
It still executes the download on another thread, and receives progress
events on that thread. However it now posts those events to the main UI
thread for them to get handled.

Also refactored Downloader/HttpDownloader a tad further. Some caching
stuff was pushed down from HttpDownloader -> Downloader (renamed from
eTag to just cacheTag). HttpDownloader.download() was recursively calling
itself, so I made the base class download() method abstract, and instead
the stream downloading is done in "protected void downloadFromStream()"

Other minor stuff:
 * Prefixed some log TAGs with package names, to make them easier to grep.
 * Removed a little bit of unused code (parameter to DownloadHandler).
2014-05-24 07:20:40 +09:30
Hans-Christoph Steiner
91f2f1014e SKETCH - DOES NOT WORK: move HTTP code into HttpDownloader
This is the beginning of moving to a Downloader class and subclasses that
are used everywhere for downloading APKs, indexes, and icons.

I think that the ETag value can probably be used everywhere as the
unique ID for testing whether to download content, so I moved that to the
super class Downloader. But that's just a guess as of now...
2014-05-24 07:20:40 +09:30
Hans-Christoph Steiner
084a048740 ApkDownloader: rename remoteFile() to getRemoteAddress()
Since it doesn't return a java.io.File but a String with the remote address
2014-05-24 07:20:40 +09:30
Peter Serwylo
19e722a9d7 wire up ProgressListener to new ApkDownloader structure
Conflicts:
	src/org/fdroid/fdroid/AppDetails.java
2014-05-24 07:20:40 +09:30
Hans-Christoph Steiner
9588f30778 normalize null checks for ProgressListeners
This removes the RepoUpdater.isInteractive() method to normalize the code
used to check whether a ProgressListener is null throughout the project.
2014-05-24 07:20:40 +09:30
Hans-Christoph Steiner
d9f9b682d4 simplify ProgressListener.Event creation and use
This aims to simplify the creation and use of Event objects among classes
that implement the ProgressListener Interface.  This is also needed in
order to split out the downloading support from various places and put it
all into a centralized

refs #2598 https://dev.guardianproject.info/issues/2598
https://gitorious.org/f-droid/fdroidclient/merge_requests/29
2014-05-24 07:20:39 +09:30
Peter Serwylo
a44ce0e4e7 Rough guess at what ApkDownloader refactor could look like. 2014-05-24 07:20:39 +09:30
Hans-Christoph Steiner
c4b0eb9b51 .Downloader --> .ApkDownloader to distinguish from .net.Downloader
org.fdroid.froid.Downloader is only used for downloading APKs, so name it
appropriately.

refs #2598 https://dev.guardianproject.info/issues/2598
2014-05-24 07:20:39 +09:30
Peter Serwylo
2c80f1a758 Split net.Downloader into abstract Downloader and concrete HttpDownloader.
This will allow the more general, non HTTP related stuff (progress events,
stream copying) to occur in a separate base class. HTTP specific stuff
(HTTP status codes, etag cache checking) is done in the HTTPDownloader
base class.
2014-05-24 07:20:39 +09:30
Hans-Christoph Steiner
8ebce69d5d use mDNS TXT records to detect FDroid repos, path, etc.
FDroid repos are advertised via Bonjour as plain HTTP or HTTPS services,
since they are browseable with a standard Web Browser. The "Find Local
Repos" browser in FDroid should only show FDroid repos, not any website,
so that is detected using a "type" TXT record in the FDroid broadcasts.
2014-05-20 18:44:47 -04:00
Hans-Christoph Steiner
30ecc1c9f6 use MulticastLock for better Bonjour/mDNS performance
Multicast transmission is subject to heavy power management on Android,
because it apparently can be a battery drain.  mDNS/Bonjour is based
entirely on multicast, so in order to have good Bonjour performance, there
needs to be good multicast performance.  MulticastLock provides that.

fixes #3381 https://dev.guardianproject.info/issues/3381
2014-05-20 18:44:47 -04:00
Hans-Christoph Steiner
f2994b0764 replace Android NSD browsing with jmdns
Android's NSD is only included in Android >= 16, and seems to be buggy. So
This replaces the NSD code entirely with jmdns, which works on all Android
versions.

fixes #2900 https://dev.guardianproject.info/issues/2900
fixes #3379 https://dev.guardianproject.info/issues/3379
2014-05-20 18:44:47 -04:00
Hans-Christoph Steiner
b5f7c0a481 preference for the "name" of the local repo
This name is used in the RepoList, the local repo website title, the
Bonjour broadcast, etc.  By default, a name is generated using the make and
model of the phone plus a random number.
2014-05-20 18:44:47 -04:00