314 Commits

Author SHA1 Message Date
Peter Serwylo
f9bcf33d50 WIP: Fixed minor UI issues.
"Confirm swap" background was white but should have been blue.

SwapWorkflowActivity now extends ActionBarActivity instead of
FragmentActivity so older devices have an action bar (though it is
not styled with blue action buttons on android-10 devices).
2015-06-03 23:55:11 +10:00
Peter Serwylo
d9f91da9a6 WIP: Added logging, removed dead code, fixed minor bugs.
Logging to help understand when the service is started, stopped,
restarted, and when individual components (e.g. web server, bonjour)
are started/stopped.

Fixed bug where service was moved to foreground during "restartIfEnabled"
because that is unneccesary if it is already in the foreground.
2015-06-03 23:41:51 +10:00
Peter Serwylo
2553b8520c WIP: Move swap starting/stopping to async task.
There is now a private [en|dis]ableSwappingSynchronous() method, to go
along with the public [en|dis]ableSwapping() method. The public method
knows about not spinning up tasks if already enabled, and also about
pushing the invocation to a background task. The private method just
blindly does what it is asked, without checking if it should be done,
and without running on a background task.

The same goes for the restartIfEnabled() method, it is responsible for
creating a single background task which runs in order: disable, and
then enable. This is actually the reason for having the synchronous
methods, rather than having, e.g., the public [en|dis]ableSwapping()
method know about threads. If that was the case, then restarting would
consist of starting, waiting for some form of notification that the
background task has completed, and then scheduling the enable task.
Now, it is a matter of calling both *SwappingSynchronous methods in
succession.
2015-06-03 17:55:36 +10:00
Peter Serwylo
7c9492e6b4 WIP: Refactoring swap service.
Removed LocalRepoService, replaced with SwapService.

Still TODO:
  Manage threads. Currently everything is called from the
  UI thread, which is a regression from the previous behaviour.
  I'd like to manage this so that the code interacting with the
  SwapManager doesn't need to bother itself with whether it is calling
  from the UI thread or not.

The local repo service had many different methods and properties for
dealing with starting and stopping various things (webserver, bonjour,
in the future it will also need to know about bluetooth and Wifi AP).

The SwapService handles this stuff by delegating to specific classes
that are only responsible for one of these. Hopefully this will make
the process of enabling and disabling swap repos easier to reason
about.

The local repo service was also stopped and started quite regularly.
This meant it was up to the code making use of the service to know if
it was running or not, and to enable it if required.
The new SwapService is only started once (when the singleton
SwapManager is created for the first time). It should not use any more
resources, because it is a background service most the time, and it
is responsible for moving itself to the foreground when required (the
burden is not on the code consuming this service to know when to do
this).

By having the service running more often, it doesn't need to'
continually figure out if it  needs to register or unregister listeners
for various properties (e.g. https enabled) or wifi broadcasts. The
listeners can stay active, and do nothing once notified if swapping is
not enabled.

Moved the timeout timer (which cancels the swap service after 15 mins)
into the SwapService, rather than being managed by the
SwapWorkflowActivity. Seems more appropriate for the service to know to
time itself out rather than the Activity, seeing as the Activity can
die and get GC'ed while the service is still running.

Finally, although there is nothing stopping code in F-Droid from
talking to the service directly, it is now handled by the SwapManager
singleton. This means that details such as using a Messenger or Handler
object in order to communicate via arg1 and arg2 is no longer required,
and instead methods with proper type signatures can be used. This is
similar (but not exactly the same) to how Android system services work.
That is, ask for a "Manager" object using getSystemService(), and then
use that to perform functionality and query state via that object,
which delegates to the service. Then we get the best of both worlds:

 * Reasonable and type safe method signatures
 * Services that are not tied to activity lifecycles, which persist
   beyond the closing of the swap activity.
2015-06-02 00:18:37 +10:00
Peter Serwylo
0e16eae5bc Minor fixes to swap after refactor.
List views need to have their header view set _before_ an adapter is
assigned to them.

Was incorrectly passing an application context instead of an Activity
context to the progress dialog for swap.

Extend ActionBarActivity rather than FragmentActivity.

Don't persist swap workflow state to disk, only store it in the
singleton.
2015-05-28 23:34:03 +10:00
Peter Serwylo
ea61e8f2d3 Organised SwapState class, moved methods around to make more sense.
Put all of the step handling code in one place, added some comments to
make sense of the different parts of the claass and their
responsibilities.
2015-05-25 16:20:56 +10:00
Peter Serwylo
c26c6b9e89 Removed old SwapActivity + Fragments.
All the code from the activity and the fragments has been successfully
ported to the SwapWorkflowActivity + Views. Thus, the code is no longer
useful, as it was only kept over the previous WIP commits so that it
can be referred to to help re-implement fragments with views.
2015-05-25 16:07:49 +10:00
Peter Serwylo
f325e9d057 WIP: Moved start/stop local repo code from static FDroidApp to SwapState
Didn't change any behaviour, but wanted to start unifying swap state
management in one location.
2015-05-25 08:39:31 +10:00
Peter Serwylo
68c6648da5 WIP: Store selected apps in SwapState. Handle back presses for swap.
Currently the view to show after pressing the back button is defined
by individual InnerView classes. For example, the JoinWifiView always
says its previous step is the SelectAppsView. This works for the most
part, but doesn't work for:

 * The first StartSwapView class (instead handled by a special case in
   the Activity).

 * WifiQrView which could either be going back to the NfcView or the
   JoinWifiView, depending on a few cases, which the WifiQrView probably
   shouldn't care about.
2015-05-25 08:17:09 +10:00
Peter Serwylo
38059ec324 WIP: Initial state handling for swap process.
The state is saved to a preference file, but that is abstracted from
the SwapWorkflowActivity. It interacts with a SwapState object, which
is relatively safe in that you should not be able to save it into an
invalid state.

Note: At this point it is not tied to any service. I'm not sure it will
ever have to be either, as the service needs to persist state somewhere
anyway, so that will probably also end up saving to a preferences file
too.
2015-05-23 13:17:33 +10:00
Peter Serwylo
1b2678d6ed WIP: Applying styles correctly to views refactored from fragments. 2015-05-23 01:25:06 +10:00
Peter Serwylo
38eafdeedd WIP: Refactored wifi QR fragment into view.
As per the select apps list, there is quite a bit of business logic
in this class, which is now spread between the activity and the view.
The activity needs to handle some stuff, because the zxing library
routes intents to either an activity or a fragment.
2015-05-23 01:11:16 +10:00
Peter Serwylo
97994c5e43 WIP: Refactored NFC fragment to view. 2015-05-23 00:55:39 +10:00
Peter Serwylo
1fd6e447af WIP: Refactored join wifi fragment into view.
There is quite a lot of business logic that was moved directly from
the fragment to the view. Before this feature is complete, that logic
should either be moved into the activity, or into some sort of
associated Presenter class for the JoinWifiView.
2015-05-23 00:46:40 +10:00
Peter Serwylo
4f7f7b2cb5 WIP: Refactored select apps to swap into view.
Not worrying about styling yet, just functionality. Added an InnerView
interface that these views can implement. Currently it asks them to
populate the menu. It may be slightly inefficient if we end up with a
popup menu, because it is called onPrepareOptionsMenu, but expects the
inner view to inflate the menu. However, for swap this shouldn't be an
issue, as all the menus pretty much fit in the action bar of most screen
sizes.
2015-05-23 00:10:50 +10:00
Peter Serwylo
b6415dadb4 WIP: Refactored start swap fragment into a view.
Added a SwapWorkflowActivity to re-implement the SwapActivity.
Once all the fragments have been refactored into views, then the
SwapActivity will be removed.
2015-05-23 00:10:07 +10:00
Peter Serwylo
f298ed7156 Merge branch 'fix-263/explicitly-add-swap-repo' into integration 2015-05-21 07:52:35 +10:00
Peter Serwylo
3aac399456 Merge branch 'fix-267/nfc-swap' into integration 2015-05-21 07:52:10 +10:00
Daniel Martí
8fd1bc39f3 Remove unused reset() from Hasher 2015-05-20 19:05:24 +02:00
Daniel Martí
8a3001465f Take some suggestions from PMD 2015-05-20 19:01:23 +02:00
Daniel Martí
3eab46d7f9 Group compileOptions together 2015-05-20 18:37:05 +02:00
Peter Serwylo
9824e8df09 NFC swap now goes to confirm swap, not manage repos activity.
The NFC message now is handled by the FDroid activity, so it is treated
the same way as every other incoming repo URL. Because FDroid handles
incoming intents correctly, the NFC one just magically works when
the <intent-filter> is moved from ManageReposAcivity to FDroid without
further code changes.

The other change is that the two way swap only happens when both are
actually swapping. Otherwise, we will send a request for someone to
swap with us, when we are incapable of swapping with them.

Fixes #267.
2015-05-20 22:10:18 +10: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
Hans-Christoph Steiner
c39e1cab6e Merge branch 'fix-117/landscape-swap' into 'master'
Force entire swap process to be portrait.

Although this is usually regarded as poor form, it is currently better
than the alternative which is the whole swap process poohing itself
when a device is rotated. In the future, it may be worthwhile investing
in designing a proper UX for landscape swap too. However the process
of swapping can be quite complex if not presented well, and so it might
end up being too much work to maintain two different UXes for landscape
and portrait.

See merge request !89
2015-05-19 18:07:42 +00:00
Daniel Martí
f5ce844803 Add some missing spacings 2015-05-19 14:40:59 +02:00
Peter Serwylo
3df1327b9b Force entire swap process to be portrait.
Although this is usually regarded as poor form, it is currently better
than the alternative which is the whole swap process poohing itself
when a device is rotated. In the future, it may be worthwhile investing
in designing a proper UX for landscape swap too. However the process
of swapping can be quite complex if not presented well, and so it might
end up being too much work to maintain two different UXes for landscape
and portrait.
2015-05-19 21:41:38 +10:00
Daniel Martí
cbf59f9dd0 Fix minsdk to be 8 instead of 7
Java 1.7 is supported from 8, not 7, so we dropped support for 7 long ago.
Very few devices run 7 and quite a few things wouldn't work on 7 anyway.
2015-05-19 13:08:55 +02:00
Daniel Martí
fc52e3e1c0 Bump to 0.91 2015-05-18 23:08:32 +02:00
Daniel Martí
f41be4bbe4 Bump to 0.90-test 2015-05-15 17:37:53 +02:00
Peter Serwylo
f8578b178e Fix #254 - regression where TOFU repos were not working.
The code for promoting an untrusted repo with no fingerprint, to
a repo with a pubkey and a fingerprint, was still there. The problem
was that it was being executed after we verified the index.jar cert
against the pubkey stored against the repo (which is empty for TOFU
repos).

This change makes it so that if we are updating a repo without a
fingerprint, then it is a TOFU request, and we don't try to verify
the certificates.

closes #85 https://gitlab.com/fdroid/fdroidclient/merge_requests/85
closes #254 https://gitlab.com/fdroid/fdroidclient/issues/254
2015-05-14 23:23:14 -04:00
Daniel Martí
c5bb3adfdc Following 09444b0 - also use maxSdk when building an index 2015-05-14 17:11:14 +02:00
Daniel Martí
a936b5d070 Properly list maxSdkVersion as an incompatible reason 2015-05-14 17:07:32 +02:00
Daniel Martí
09444b0181 Also populate maxSdkVersion when parsing a package
There is no reason why this should fail, so make the default be 0.
2015-05-14 17:03:33 +02:00
Daniel Martí
70a93b01db Don't crash if links on descriptions cannot be handled
Basically the same safety net for ActivityNotFoundException that we had for
links in the menus, but for links in the descriptions too now.
2015-05-14 16:39:11 +02:00
Peter Serwylo
40925009bb Shortened log tags to below 23 chars (required by lint) 2015-05-14 22:24:40 +10:00
Peter Serwylo
52c4554877 Removed localrepo classes that were used before "swap".
All of the relevant code from them has been ported across to swap,
and they are no longer needed as a reference for how to implement
app swapping.
2015-05-14 22:24:40 +10:00
Daniel Martí
ec44c1efe5 ACCESS_SUPERUSER permission is now deprecated 2015-05-14 12:29:52 +02:00
Peter Serwylo
c33cacedaf Merge branch 'master' into 'master'
improved, but still rudimentary, hotspot handling in swap

My previous merge request fdroid/fdroidclient!78 was based on one broken assumption: `WIFI_STATE_UNKNOWN` means that the hotspot is active.  Apparently, that's not always the case.  Also, sometimes when the hotspot is active, its `WIFI_STATE_DISABLED`.  Even worse, there is no broadcast message sent on final config of the hotspot.  There is only a `WIFI_STATE_DISABLING` from turning off the wifi, but then never a broadcast for `WIFI_STATE_UNKNOWN` and/or `WIFI_STATE_DISABLED`.  But I found some tricks that seem to work for now.  We'll need to use your library, @mvdan, to really get good support of hotspots.

This also includes some basic UI tweaks to represent the hotspot mode in the swap wifi screen.

See merge request !79
2015-05-10 22:39:12 +00:00
Daniel Martí
da9396fff1 Remove unnecessary and confusing import 2015-05-10 16:08:43 +02:00
Peter Serwylo
3df03bbb1e Fix #250. Fix #251. Normalize URLs before saving, and disallow invalid URLs.
Removes trailing slashes from URLs, replaces multiple consecutive forward
slashes in the path with a single slash. Canonicalizes the URL.

If the URL is invalid, display a message to the user and don't let it get
added.

NOTE: This does *not* normalize existing URLs in the database.
2015-05-10 23:22:35 +10:00
Peter Serwylo
93339cbbfb Fix issue 246: Rewrite process for verifying existing repos.
Previously it would only compare the details of a new repo to existing
ones if the new repo came via an intent. Now it does it whenever you
change the text in the new repo dialog (shouldn't be too much of a
performance hit, it isn't doing very much).

The things it (still) doesn't do is:
 * verify that the url looks like a url
 * sanitize the newly input uri and compare it to sanitized saved repos

The second point means that you can end up with:
 http://10.0.1.50/ and
 http://10.0.1.50

both in the list. I'm going to log an issue for this, because it should
be fixed, but doesn't need to hold this up.
2015-05-10 21:56:40 +10:00
Hans-Christoph Steiner
12b3a5af12 initial sketch of how to display hotspot mode on the swap wifi screen
This is really just a placeholder, there is lots of work to be done here.
Really, this screen should have the SSID of the hotspot, but we need to use
a private API to get that.  Coming soon...

The icon is free software from:
https://commons.wikimedia.org/wiki/File:Wifi.svg
2015-05-10 00:37:05 -04:00
Hans-Christoph Steiner
962a2fb3d6 improve detection of hotspot mode
hotspot mode is not well represented with the WifiState stuff.  It can be
active when the WifiState is DISABLED or UNKNOWN.  Also, when switching
from active wifi to hotspot mode, WIFI_STATE_DISABLING broadcasts will be
sent, but WIFI_STATE_DISABLED/WIFI_STATE_UNKNOWN will not.
2015-05-10 00:37:05 -04:00
Daniel Martí
0db225e07c Bump to 0.89-test 2015-05-09 22:34:04 +02:00
Daniel Martí
05332409be Suppress fallthrough java warning 2015-05-09 22:24:41 +02:00
Hans-Christoph Steiner
96b7c35a2a rework WifiStateChangeService to support hotspots (aka WiFi AP on device)
When a device is setup as a WiFi Access Point aka "hotspot", the standard
API for getting the WiFi settings returns nothing.  We have to use a
separate API to get the IP address of the WiFi AP.  As far as I could tell,
there is no public API for getting the SSID/BSSID of the WiFi AP, so for
now that is left blank.  That means the wifi screen in swap is confusing
because it will say it is not attached when the device is a hotspot

@mvdan's https://github.com/mvdan/libaccesspoint should help there

#193 https://gitlab.com/fdroid/fdroidclient/issues/193
2015-05-09 13:41:30 -04:00
Hans-Christoph Steiner
edb3564e29 unified IP/Wifi state handling in WifiStateChangeService
To handle hotspots, this code will become more complicated.  Therefore,
first simplify things by putting all of the logic into one place, rather
than spread out across FDroidApp, the receiver, and the service
2015-05-09 13:41:30 -04:00
Hans-Christoph Steiner
2b59644e02 eliminate nested try/catch blocks for clearer code 2015-05-09 13:41:30 -04:00
Hans-Christoph Steiner
6703fa3652 rename to FDroidApp.restartLocalRepoServiceIfRunning() for clarity
This method handles checking if the service is running, and only restarts
it if it was running.
2015-05-09 13:41:30 -04:00
Hans-Christoph Steiner
c1b0b854fc on launch, check wifi if WIFI_STATE_ENABLED, the receiver handles the rest
On launch, we need to get the current state of the Wifi.  We only need to
start the WifiStateChangeService on WIFI_STATE_ENABLED, since any other
wifi state will be received by WifiStateChangeReceiver, which will launch
WifiStateChangeService when appropriate.

This reduces the chance that WifiStateChangeService will start when it is
not needed.
2015-05-09 13:41:29 -04:00