762 Commits

Author SHA1 Message Date
Paresh Chouhan
c5aa3f91b1 CodeStyle : Fixed inconsistent variable name, changed mctx to mCtx 2016-03-08 12:47:35 +05:30
Peter Serwylo
0f64f2c181 Clarify threading when loading categories
Previously, it was not explicit that the `onCreate` happened to be invoked
in the UI thread. Now it is, due to passing `new Handler(Looper.getMainLooper())`.
Also, the categories are now loaded in a background task, and then the UI is
updated on the UI thread.
2016-03-07 23:46:06 +11:00
Peter Serwylo
7421d33c3a Expand null check to include isAdded() check
Also, don't call `getActivity()` in the separate thread. Instead, use the
`Activity` which we have already checked and ensured is not null.
2016-03-07 23:45:58 +11:00
Paresh Chouhan
683ba8d20f Enhancement|UI : Repository URL added to APK's on AppDetails Activity.
Fixes issue #527.
Repository URL's now shown as Provided By domain.name/repo
2016-03-06 01:23:13 +05:30
Daniel Martí
fbeb6d140f PMD: Enable java-android, fix issues 2016-03-01 17:46:38 +00:00
relan
77074f83e2 Remove PackageInfo.REQUESTED_PERMISSION_REQUIRED
This flag existed in Android 4.2-5.1 and has always been set. Stop
checking it.
2016-03-01 12:33:21 +03:00
Daniel Martí
a203545e48 Bump checkstyle to 6.16
Due to fixes and improvements, some new checkstyle changes are due.
2016-02-28 16:44:44 +00:00
Daniel Martí
d061dafcd7 Remove a few extra spaces that checkstyle missed
There's also a change in a SQL string, but it should be safe.
2016-02-28 14:29:51 +00:00
Daniel Martí
3af5f55abd Remove unused repo field
Found by Android Studio.
2016-02-28 14:22:27 +00:00
Daniel Martí
9c86655af0 Make some declaration accesses weaker
As suggested by Android Studio.
2016-02-28 14:19:02 +00:00
Peter Serwylo
ad63e52e50 Extract BroadcastReceivers to member variables, so they can be unregistered correctly.
Previously, they were registered, then forgotten. This means that each time
the start swap view was run, another receiver was registered. As a result,
they were being invoked multiple times.

It doesn't appear that this had any specific side effects which were terrible,
but they definitely have the potential to going forward.

Note that because we are not using `Fragments` with their convoluted, but at
least well documented API, I'm not 100% certain that I've unregistered the
receivers at the right location.
2016-02-28 13:58:49 +11:00
Peter Serwylo
1323e800b7 Temporarily disable listeners when updating switch state in response to background process.
Previously, something like this would happen:
 * Swap service is cancelled
 * WiFi swap is asked to stop
 * Event is broadcast when done
 * UI listens to this event
 * Upon receiving the event, it updates the UI
 * Updating the UI triggers an event, causing the process to happen again

An alternative solution to this would have been for the UI to stop listening
to listeners before WiFi swap is shut down, but that is then only specific
to the case when the swap view is being destroyed/removed. This could also
happen in other situations however, such as when the swap service times out.
2016-02-28 13:43:07 +11:00
Peter Serwylo
209afd6bf2 Extract switch change listeners to member variables, so that they can be unregistered.
When the view is detached, then the listeners will be unregistered.
This will also help in the future so that they can be temporarily
unregistered when manually changing the state of the switches.
2016-02-28 12:49:50 +11:00
Peter Serwylo
62b080a8d9 Rename logging tag to make logcat debugging clearer. 2016-02-28 12:36:06 +11:00
Hans-Christoph Steiner
fd03ebd764 annotate swap methods that require android-10
swap only works on >= android-10 anyway

closes #581 https://gitlab.com/fdroid/fdroidclient/issues/581
2016-02-27 11:05:16 +01:00
Hans-Christoph Steiner
26b35723d3 use AsyncTask for SwapType operations to run in background
Thread runs at normal priority by default.  AsyncTasks are integrated into
Android for handling things running in the background while keeping the UI
responsive.

This reverts most of commit 828cc272ee5235f868104b009349cc7e835e144f.
2016-02-27 11:05:16 +01:00
Hans-Christoph Steiner
96fe1f9584 do not show "Swap" as an option on less than android-10
Swap requires lots of APIs that are only all available in android-10, so
hide the menu item on older platforms.

closes #581 https://gitlab.com/fdroid/fdroidclient/issues/581
closes #575 https://gitlab.com/fdroid/fdroidclient/issues/575
2016-02-27 11:04:08 +01:00
Hans-Christoph Steiner
38e4b38602 Re-enable NetCipher to provide decent TLS on all Android versions
Revert "Revert netcipher to fix SNI regression"
This reverts commit 6c8e726aadbe6714d6295882c5be87a7bf81a9f0.

NetCipher is important for making sure that the client running on older
versions of Android is not using extremely crappy default TLS settings.  It
also streamlines the Tor support.

closes #431 https://gitlab.com/fdroid/fdroidclient/issues/431
closes #576 https://gitlab.com/fdroid/fdroidclient/issues/576
2016-02-27 11:04:08 +01:00
Hans-Christoph Steiner
eed0070d4b do not bail out of wifi settings if there is no DhcpInfo
There is still much useful information to be had without DhcpInfo.
2016-02-27 11:04:08 +01:00
Peter Serwylo
db120133b9 Don't try to start bonjour without an IP.
Although not reproduced, it looks very much like this would be related
to, and should subsequently fix #556.
2016-02-27 09:28:17 +11:00
Peter Serwylo
3dd0589b08 Don't say wifi is connected until both wifi + bonjour are ready.
Although I can't reproduce reliably, I am hopeful that this will resolve
a lot of the errors such as #557.
2016-02-27 09:28:17 +11:00
Peter Serwylo
cd3a064a5a Don't call unregisterService(...) then unregisterAllSerivces().
The later will unregister the service we were explicitly unregistering anyway.
2016-02-27 09:28:17 +11:00
Peter Serwylo
1505d21781 Set connected status after disconnecting from wifi swap. 2016-02-27 09:28:17 +11:00
Peter Serwylo
2ed6110ae5 Cleanup looper after shutting down. 2016-02-27 09:28:17 +11:00
Peter Serwylo
18f97602e8 Don't start swap wifi when there is no network.
Not sure if we should be here or not in this situation, so this is
a little bit defensive. Can't bind to an IP address of `null`, so
don't bother starting LocalHTTP server unless we have an IP.
2016-02-27 09:28:17 +11:00
Peter Serwylo
ddbd9e2ea9 Actually run thread in background.
`Thread.run()` is not the correct call, changed to the correct `Thread.start()`.
Also, explicitly indicate that we want the stopping of wifi to happen in the
background.
2016-02-27 09:28:17 +11:00
Peter Serwylo
1eae135929 Add user feedback for when WiFi is being disabled.
On some devices this can take some time (i.e. a second) and the UI needs
to be disabled for that time. This should stop users quickly stopping and
starting regularly, queuing up many "start jmdns, stop jmdns, start jmdns"
calls.
2016-02-27 09:28:17 +11:00
Peter Serwylo
8364aa15f1 Don't try to start swap again if we have gone from network -> no network. 2016-02-27 09:27:57 +11:00
Daniel Martí
5179e032db Fix NewApi bug introduced in 8e193cec 2016-02-26 14:39:02 +00:00
Daniel Martí
17c731ef1d checkstyle: obey ConstantName 2016-02-17 15:59:04 +00:00
Daniel Martí
a6b804e93a checkstyle: obey NeedBraces on multi-line stmts
We still allow them in single-line statements, like:

	if (foo) bar;
	for (int i : ints) bar;

Everything else should use braces to help readability and avoid silly
human mistakes that might result in bugs.

These changes were completely automated via a python script.
2016-02-17 12:04:36 +00:00
Daniel Martí
e066ed04dc Search: clear focus when enter/return is pressed
Fixes #572.
2016-02-15 16:47:25 +00:00
Peter Serwylo
88b4e1ff31 Merge branch 'fix-554' into 'master'
Work around dead activity issue in AppDetails

It seems like install() sometimes runs when the AppDetails activity is
finished or finishing. This results in the windows (dialogs) failing to
show, and a BadTokenException to fire:

    android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@d6e3570 is not valid; is your activity running?

This seems to be the culprit:

    at org.fdroid.fdroid.AppDetails.install(AppDetails.java:840)
    at org.fdroid.fdroid.AppDetails$AppDetailsListFragment.install(AppDetails.java:1657)
    at org.fdroid.fdroid.AppDetails$AppDetailsListFragment.onListItemClick(AppDetails.java:1721)

Apparently, you can check whether an activity/context is being finished:

https://stackoverflow.com/questions/7811993/error-binderproxy45d459c0-is-not-valid-is-your-activity-running

I cannot reproduce this issue, thus can't say whether this fixes it or
not. Either way, it can't hurt to try. This can be reverted if we see
ACRA reports of this in the future, and the issue reopened.

Fixes #565.

See merge request !204
2016-02-13 21:49:22 +00:00
Daniel Martí
f6724413b0 WifiStateChangeService: Avoid DhcpInfo NPE
Fixes #569.
2016-02-12 13:04:28 +00:00
Daniel Martí
1a1ece16cf Work around dead activity issue in AppDetails
It seems like install() sometimes runs when the AppDetails activity is
finished or finishing. This results in the windows (dialogs) failing to
show, and a BadTokenException to fire:

    android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@d6e3570 is not valid; is your activity running?

This seems to be the culprit:

    at org.fdroid.fdroid.AppDetails.install(AppDetails.java:840)
    at org.fdroid.fdroid.AppDetails$AppDetailsListFragment.install(AppDetails.java:1657)
    at org.fdroid.fdroid.AppDetails$AppDetailsListFragment.onListItemClick(AppDetails.java:1721)

Apparently, you can check whether an activity/context is being finished:

https://stackoverflow.com/questions/7811993/error-binderproxy45d459c0-is-not-valid-is-your-activity-running

I cannot reproduce this issue, thus can't say whether this fixes it or
not. Either way, it can't hurt to try. This can be reverted if we see
ACRA reports of this in the future, and the issue reopened.

Fixes #565.
2016-02-09 20:48:42 +00:00
Daniel Martí
401a1d473d Drop unnecessary elses after returns 2016-02-09 15:59:47 +00:00
Daniel Martí
9997b0f448 Merge branch 'fix-555--content-provider-invalid-uri' into 'master'
Fix 555  content provider invalid uri

Was not correctly encoding "/" characters when searching. This caused the Uri used by the Content Providers to include a slash, which makes it look like a separate segment of the path which was wrong. Now correctly encodes "/" characters. Also noticed one other place incorrectly encoding characters, where they would've been double encoded when added as query parameters to a Uri.

See merge request !203
2016-02-09 15:55:38 +00:00
Peter Serwylo
c0d752cce3 Merge branch 'reactivex--swap--peer-finders' into 'master'
Refactor swap "peer finders" to use ReactiveX

*NOTE: This includes the commit specified by !197.*

In the old code, there is a _lot_ of procedual style "Is this peer finder running, if so, do this". In addition, the choice to do things on background threads or not is a little ad-hoc. Finally, the `SwapService` needs to know about both bluetooth and wifi peer finders, whereas really they are both only there to emit "Peers", regardless of the type.

As such, some improvements in this change are:
 * The choice to run peer finding on a background thread is made once, at a higher level when starting the peer finder.
 * No longer does the UI code ask "Am I searching for peers". It instead waits to be told whether it is or isn't.
 * The addition of new types of peers in the future is the job of the Peer finder itself. It quietly aggregates all of the Peer Finders it knows about into a single observable that emits different types of peers.

This code doesn't fix any particular issue, but rather it is about making the entire swap workflow easier to reason about. I plan on migrating more of this workflow to this functional style in the future, and hopefully that will have benefits in terms of stability and code understanding.

See merge request !198
2016-02-07 00:08:03 +00:00
Peter Serwylo
d939e9dac9 Minor fixes due to CR. 2016-02-07 10:39:01 +11:00
Peter Serwylo
81b772c3fd Use appendPath(...) instead of appendEncodedPath(...).
I misread the documentation when first using the `appendEncodedPath` method,
because it expects the path to already be encoded. This causes a bug because
if you search for a '/'. The result is a malformed URI that has the path
'/search//' instead of '/search/%2F'.

Using `appendPath` will always encode the string given to it, which is desirable.

Also check for empty strings, and return a URI that gives all apps. This was
not strictly neccesary, because the code which invokes it checks for empty
strings, but if somewhere else in the future starts to use this code, they
would've had to know to check for empty strings first.

Fixes #555.
2016-02-06 14:02:54 +11:00
Peter Serwylo
5f08181f7d Remove unused SearchResultsFragment.
This is left over from when the search functionality was updated recently.
2016-02-06 13:33:36 +11:00
Daniel Martí
0646b6473e Merge branch 'fix-286--refreshHeader-crash' into 'master'
Put null check around access of `R.id.header` fragment.

Please note I haven't reproduced the specific problem. Also, the stack
traces being reported are only marginally informative, because they are
in response to a content providers firing events, and thus don't have
any context about when or where the event was fired from.

However, my looking at the code seems to indicate that this will prevent
NPE when the Activity is no longer visible but an app is finished
installing. Also, the view should still update correctly on resuming the
Activity because the `onResumeFragments()` methods will be invoked
which invokes the `refreshHeaders()` method.

Fixes #286.

See merge request !202
2016-02-06 00:04:26 +00:00
Peter Serwylo
d9f0c86c2e Put null check around access of R.id.header fragment.
Please note I haven't reproduced the specific problem. Also, the stack
traces being reported are only marginally informative, because they are
in response to a content providers firing events, and thus don't have
any context about when or where the event was fired from.

However, my looking at the code seems to indicate that this will prevent
NPE when the Activity is no longer visible but an app is finished
installing. Also, the view should still update correctly on resuming the
Activity because the `onResumeFragments()` methods will be invoked
which invokes the `refreshHeaders()` method.

Fixes #286.
2016-02-05 22:50:11 +11:00
Peter Serwylo
10ccd5c503 Reimplement "peer finder" logic using funcitonal ReactiveX style.
The benefits of this are as follows:

No longer need to worry about how many types of `Peer`s exist.
There is a single publicly accessible `PeerFinder` which aggregates
the results of both the Bluetooth and Bonjour peer finders. In the
future if another is added, the consumer of the peer finder
(i.e. `StartSwapView`) doesn't need to be aware of this. Neither does
the `SwapService` or `SwapActivity` or any other code.

Never ask "Are we searching" but instead receive push notifications
from the peer finder when it stops searching.

Don't worry about receiving the same peer multiple times, it will
automatically get filtered out.

Less concern about doing things in `AsyncTasks` (and knowing what to
do in an `AsyncTask`). The RXJava + RXAndroid libraries deal with this
by allowing the client consuming the `PeerFinder` to specify which
thread to perform the background task on, and also that the found
`Peer`s should be emitted on the UI thread.

In the future, can play with caching the results of a particular
sequence of found peers. However right now using the `Observable.cache()`
method means we can no longer unsubscribe from the peer finders
and thus they run longer than they need to when we move on from
the initial swap screen.
2016-02-05 15:39:40 +11:00
Peter Serwylo
8060ac88c3 Don't update search query unless it has changed meaningfully.
Changing the search query is quite an expensive operation, so this does some rudimentary
checking to see if the two queries are meaningfully different. At present, it trims the
strings and does a case insensitive comparison.

The query is eventually exploded based on whitespace, so leading and trailing white
space is not important. Also, sqlite `LIKE` clauses are case insensitive, so case
is unimportant. Having said that, I'm not sure how someone will be able to change
the queries case without first deleting and then adding characters (thus inducing
meaningfull changse).
2016-02-04 07:51:41 +11:00
Peter Serwylo
bd0e9e0a3c When no keywords to search, use an empty query selection that evaluates to "1".
This means that instead of building invalid SQL such as `WHERE (() OR ())` it
will build `WHERE((1) OR (1))` which, while non-optimal, is at least valid.

Fixes issue #560.
2016-02-04 07:51:37 +11:00
Daniel Martí
a028b3f6a2 Avoid NPE in Uri.getPath().replaceAll()
Fixes #533.
2016-02-02 21:55:45 +00:00
Daniel Martí
ff3cd9fb11 Drop visibility on some fields and classes
As suggested by Android Studio.
2016-02-01 15:07:14 +00:00
Daniel Martí
c198736cd1 Update ACRA to 4.8.0 2016-02-01 14:21:49 +00:00
Peter Serwylo
97cc279d99 Fix unit tests to work with a singleton DBHelper instance.
The fix for the database locking bug was to have a singleton
`DBHelper` instance. This breaks tests because multiple tests
share the same database. The solution is to:

 * Hack together a static method which clears the singleton,
   then invoke it in the `setUp()` method for relevant test cases.

 * Ensure the mock context provided to the providers during
   the tests is able to provide a context via `getApplicationContext()`.
   Without this, the mock context throws an `UnsupportedOperationException`
   when invoking this method.
2016-01-26 22:23:41 +11:00