127 Commits

Author SHA1 Message Date
Daniel Martí
50b2e6f7a5 PMD: Enable and obey SingularField 2016-04-23 17:27:22 +01:00
Daniel Martí
68db3ae353 PMD: Enable and obey ImmutableField 2016-04-23 17:27:22 +01:00
Daniel Martí
f655f49aee PMD: Enable and obey UnnecessaryConstructor 2016-04-23 16:17:55 +01:00
Daniel Martí
857b0ea1c7 PMD: Enable and obey AddEmptyString 2016-04-23 16:14:05 +01:00
Daniel Martí
5d3d8786e2 PMD: Enable and obey PrematureDeclaration 2016-04-23 16:06:41 +01:00
Daniel Martí
32c67d05ec PMD: XML config file, enable most of unnecessary 2016-04-23 15:59:04 +01:00
Daniel Martí
6a0eec1262 DBHelper: don't wrap entire func bodies in ifs
This removes tons of unnecessary indenting. Do it in smaller functions
too for consistency.
2016-04-23 15:40:09 +01:00
Daniel Martí
7f2a811541 RepoXMLHandler: make helper func static 2016-04-23 15:37:49 +01:00
Daniel Martí
942cfd3cd1 AppDetails: guard against null fragment on destroy
Fixes a crash reported by ACRA:

	java.lang.RuntimeException: Unable to destroy activity {org.fdroid.fdroid/org.fdroid.fdroid.AppDetails}: java.lang.NullPointerException
		at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3281)
		at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3299)
		at android.app.ActivityThread.access$1200(ActivityThread.java:133)
		at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
		at android.os.Handler.dispatchMessage(Handler.java:99)
		at android.os.Looper.loop(Looper.java:137)
		at android.app.ActivityThread.main(ActivityThread.java:4812)
		at java.lang.reflect.Method.invokeNative(Native Method)
		at java.lang.reflect.Method.invoke(Method.java:511)
		at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
		at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:559)
		at dalvik.system.NativeStart.main(Native Method)
	Caused by: java.lang.NullPointerException
		at org.fdroid.fdroid.AppDetails.cleanUpFinishedDownload(AppDetails.java:442)
		at org.fdroid.fdroid.AppDetails.onDestroy(AppDetails.java:567)
		at android.app.Activity.performDestroy(Activity.java:5366)
		at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1124)
		at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3268)
		... 11 more
2016-04-23 15:29:41 +01:00
Daniel Martí
99840b5bba Bump to 0.100-alpha5 2016-04-23 02:01:10 +01:00
F-Droid Translatebot
b1aac69989 Pull translation updates from Weblate
Translators:

Adrià García-Alzórriz      Catalan
Adrià García-Alzórriz      Spanish
mahmut özcan               Turkish
Marcelo Santana            Portuguese (Brazil)
Massimiliano Caniparoli    Italian
Mladen Pejaković           Serbian
Verdulo                    Esperanto
Verdulo                    Polish
2016-04-23 01:59:30 +01:00
Daniel Martí
a484c03816 PMD: Re-enable on test files
This used to be the case, which is why only minimal changes were
required to bring it back. This also makes it take the same files that
checkstyle does, which is more consistent.
2016-04-23 01:45:04 +01:00
Daniel Martí
2074718391 Get java code closer to obeying PMD's java-basic 2016-04-23 01:20:29 +01:00
Daniel Martí
7b70560c9b Remove unused class UnexpectedResponseException 2016-04-23 01:16:14 +01:00
Daniel Martí
3c63bd4b1c Various spacing fixes 2016-04-23 01:16:14 +01:00
Daniel Martí
df39b0fe40 Drop elses after returns 2016-04-23 01:16:14 +01:00
Daniel Martí
a8c5d8e765 Convert java file to unix format via dos2unix
I assume this file was copied over from a windows machine or created on
one. Use unix-style line endings throughout.
2016-04-23 01:16:14 +01:00
Daniel Martí
00c138e42f PMD: enable and obey java-unusedcode 2016-04-23 01:16:14 +01:00
Daniel Martí
c240283ad4 Merge branch 'download-service-pending-intent' into 'master'
Misc fixes/improvements to apk downloading

This started as a fix to #625, but quickly turned into a mini rampage to fix and/or improve a few different things in the `DownloaderService`. Hopefully the commits are self explanatory as to what they fix, but of course feel free to ask questions if you have any.

See merge request !265
2016-04-22 16:58:57 +00:00
Peter Serwylo
7e83189f5b Appese checkstyle + pmd. 2016-04-23 00:10:02 +10:00
Peter Serwylo
3ebeec0b87 Cleaned up logging in downloader service.
Most of the logging is purely for debugging purposes during development.
As such, it has been moved to `Utils.debugLog`. Also provided more context
in some of the descriptions, so devs reading the logs without the sourcecode
will hopefully be able to infer more about what is happening. Left the error
logging as `Log.e` as it may be more informative.
2016-04-23 00:10:02 +10:00
Peter Serwylo
a149ce54db Always stop notifications at the conclusion of a download.
Without this, if the first download in the queue is downloaded,
the notification will persist with details of that first download
until the next download begins. With this change, the notification
is remoived immediately after cancelling the download.
2016-04-23 00:10:01 +10:00
Peter Serwylo
b66810944f Remove download notification when last queued download cancelled.
There was a race condition such that when the cancel `Intent` is
received, it would queue up a message on the download thread to stop
downloading. This was followed by cancelling the notification on the
thread the `Intent` was received on. As a result of the message taking
some time to get to the other thread, it would likely cause another
progress notification to be shown after we had already removed that
notification - making it show again after being cancelled.

The code in the download thread progress handler, which updates the
notification with progress, is not perfect. It does a check before
deciding to broadcast progress and update the notification. However,
the check happens at the beginning of the group of expressions. As
such, there is likely a small change that `isActive` returns true,
then the notification is cancelled on the other thread, and finally,
the download thread updates the progress again. However this is better
than it was before where the notification didn't go away.

Previously, apks were not being removed from the queue once download
was completed, only when removed. It didn't cause any specific issues
here, but I removed downloads from the queue after completion to prevent
potential problems in the future. Now the queue is a better representation
of what is to be downloaded.
2016-04-23 00:09:36 +10:00
Peter Serwylo
bbf7cd81a6 Extract common code to isQueued and isActive. 2016-04-23 00:02:15 +10:00
Peter Serwylo
7f1155816e Show name of app being downloaded in notification.
If a non-apk download is taking place, revert to the current generic
"Downloading..." message.
2016-04-23 00:02:15 +10:00
Peter Serwylo
18f3d86b68 Show indeterminite progess for apks queued to download.
Previously, navigating back to an app which is in the queue
qould indeed grey out the "Install" button and show the text
"Downloading..." in that disabled button. However, it woulnd't show
any sort of progress. This change shows an indeterminite progress
bar with the text "Waiting to start download..." underneath.
Happy to receive input on the best terminology if that is not
desirable.

In order to do this, I had to be more specific about when
the header fragment is updated. Previously, `headerFragment.updateViews()`
would get called by the `onResumeFragments()` activity method.
This was redundant because the `onResume()` method of the fragment
also invokes `updateViews()`. Thus, that call was removed (though
we still need to obtain a reference to the fragment in
`onResumeFragments()`.
2016-04-23 00:02:15 +10:00
Peter Serwylo
e56d604d6f Only cleanup receivers, don't reset the UI when in onDestroy().
When an Activity is destroyed, the next time it is created should
reinitialize all of the UI stuff again. Thus, there is no point to
clearing up the UI state before leaving. More importantly, this was
causing a problem when navigating back and forth through activities
via the downloader service notifications:

```
E  java.lang.RuntimeException: Unable to destroy activity {org.fdroid.fdroid/org.fdroid.fdroid.AppDetails}: java.lang.IllegalStateException: activity is already destroyed
...
E  Caused by: java.lang.IllegalStateException: activity is already destroyed
E      at android.nfc.NfcActivityManager$NfcActivityState.<init>(NfcActivityManager.java:126)
E      at android.nfc.NfcActivityManager.getActivityState(NfcActivityManager.java:176)
E      at android.nfc.NfcActivityManager.setNdefPushContentUri(NfcActivityManager.java:252)
E      at android.nfc.NfcAdapter.setBeamPushUris(NfcAdapter.java:830)
E      at org.fdroid.fdroid.NfcHelper.disableAndroidBeam(NfcHelper.java:68)
E      at org.fdroid.fdroid.AppDetails$AppDetailsHeaderFragment.updateViews(AppDetails.java:1507)
E      at org.fdroid.fdroid.AppDetails$AppDetailsHeaderFragment.updateViews(AppDetails.java:1490)
E      at org.fdroid.fdroid.AppDetails$AppDetailsHeaderFragment.removeProgress(AppDetails.java:1473)
E      at org.fdroid.fdroid.AppDetails.cleanUpFinishedDownload(AppDetails.java:442)
E      at org.fdroid.fdroid.AppDetails.onDestroy(AppDetails.java:567)
E      at android.app.Activity.performDestroy(Activity.java:6169)
E      at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1141)
E      at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3726)
E      ... 10 more
```

This is related to `onDestroy` calling a method which ends up calling
UI related stuff that assumes the `Activity` is around to interact with.
2016-04-23 00:02:15 +10:00
Peter Serwylo
8794611b26 DownloadCompleteService uses same notification code as DownloadService.
Both classes required the same type of notification intent to be
created, so they now both use the same static function to create
the relevant intent.
2016-04-23 00:02:14 +10:00
Peter Serwylo
0163d6efa6 Add PendingIntent for notification in DownloaderService.
Fixes #625, as devices pre 4.0 require such `PendingIntent`s to
be passed to the notificaitons `setContentIntent` method. As the
`DownloaderService` handles both apks and repo updates, the pending
intent will either point to the relevant `AppDetails` screen for
an apk download - or the main F-Droid activity if it is any other
sort of download (i.e. a repo update download).
2016-04-23 00:02:11 +10:00
Daniel Martí
a826d1101d Remove unused app_list_item_click
As per #fdroid-dev:

    +mvdan | paresh: look at what lint says
    +mvdan | src/main/res/transition-v21/app_list_item_click.xml:2: The resource R.transition.app_list_item_click appears to be unused
    +mvdan | are you aware of this?
    paresh | mvdan, oh yes
    paresh | it is useless
    paresh | I think I planned on adding some transition
    paresh | you can remove it safely
2016-04-21 11:05:36 +01:00
Daniel Martí
ebbb5f3863 Run tools/remove-unused-trans.py 2016-04-21 10:40:58 +01:00
F-Droid Translatebot
560a620a6c Pull translation updates from Weblate
Translators:

Danial Behzadi            Persian
ezjerry liao              Traditional Chinese
Mohamad Hasan Al Banna    Indonesian
Olexandr Nesterenko       Ukrainian
Osoitz                    Basque
Paresh Chouhan            Hindi
Verdulo                   Esperanto
2016-04-21 10:40:25 +01:00
Peter Serwylo
3f9881a6f5 Fix if condition which was always true.
I suspect this is the expected behaviour, seeing as this service
handles downloads for both Apks and repo indices.
2016-04-21 13:26:03 +10:00
Peter Serwylo
8ce4cad7ef Merge branch 'dup-strings' into 'master'
Removed duplicate string resource for string ("Swap apps")

Removed duplicate string resource for string ("Swap apps")

See merge request !264
2016-04-20 22:58:35 +00:00
Paresh Chouhan
45313c6234 Removed duplicate string resource for string ("Swap apps") 2016-04-21 00:55:23 +05:30
Daniel Martí
b7a5c6d201 Get rid of the last java vercode name
Last of its series. Closes #37.
2016-04-19 22:44:22 +01:00
Daniel Martí
865d537745 Rename Repo's pubkey to signingCertificate
Updates #37.
2016-04-19 22:44:22 +01:00
Daniel Martí
0ec9689a6c Rename App's suggestedVersion to suggestedVersionName 2016-04-19 22:44:22 +01:00
Daniel Martí
550f04cc8b Rename App's upstream vars to VersionCode/Name
Updates #37.
2016-04-19 22:44:22 +01:00
Daniel Martí
cde57efb98 Rename App.suggestedVercode to App.suggestedVersionCode
Updates #37.
2016-04-19 22:44:22 +01:00
Daniel Martí
4d8e410176 Rename Apk.version to Apk.versionName
Updates #37.
2016-04-19 22:44:22 +01:00
Daniel Martí
1abbedc4ab Rename Apk.vercode to Apk.versionCode
Updates #37.
2016-04-19 22:44:22 +01:00
Daniel Martí
ac22cc5266 Bump to 0.100-alpha4 2016-04-17 11:02:40 +01:00
F-Droid Translatebot
ca3e13ebf6 Pull translation updates from Weblate
Translators:

Adrià García-Alzórriz    Catalan
ageru                    French
Alberto Moshpirit        Spanish
Allan Nordhøy            Norwegian Bokmål
Enol P                   Asturian
ezjerry liao             Traditional Chinese
Green Lunar              Hebrew
Kristoffer Grundström    Swedish
Ldm Public               French
Marcelo Santana          Portuguese (Brazil)
Mladen Pejaković         Serbian
naofum                   Japanese
Pander                   Dutch
Sérgio Marques           Portuguese (Portugal)
Tobias Bannert           German
Verdulo                  Esperanto
Verdulo                  Polish
Yaron Shahrabani         Hebrew
YFdyh000                 Simplified Chinese
2016-04-17 11:00:38 +01:00
Peter Serwylo
6d603ada0d Show progress bar in download notification.
By providing the same notification id, the existing one is updated.
2016-04-17 09:10:22 +10:00
Daniel Martí
132519590f Bump accesspoint library to 0.2.0
This release allows for Android 6+ support, but we'll need to ask for
permissions at runtime too. This commit simply does one half of the work
needed to support Android 6 with all things wi-fi.

See the issue and example app commit for reference:

https://github.com/mvdan/accesspoint/issues/6
6284f0376b
2016-04-14 15:31:47 +01:00
Daniel Martí
27c9a21764 Gradle: Bump android plugin to 2.0.0
Also add useProgard true, since minifyEnabled now refers to the new
experimental code shrinker.

I'm not removing proguard yet as we depend on it for the samsung
workaround. I also do not know how to port the rest of the config
options to the new shrinker.
2016-04-14 15:31:47 +01:00
Daniel Martí
127c65b78d Bump support libs to 23.3.0
Also bump the CI image to include the updated support lib maven repo.
2016-04-14 15:31:47 +01:00
Daniel Martí
db798afb67 PMD: Do all java files like checkstyle
Not just the org.fdroid.* classes. No changes needed.
2016-04-14 15:31:47 +01:00
Daniel Martí
158668f378 Merge branch 'new-downloader-service' into 'master'
New DownloaderService

This merge request is too big, but I have all this work complete, so I'm submitting it now for review.  If there are bigger issues with parts, I can rebase it down to the uncontroversial bits to get things merged.

This replaces `ApkDownloader`, `AsyncDownload`, and `AsyncDownloadWrapper`, and puts the whole APK download procedure into a custom `Service` that is based on the source code for `IntentService`.  It can't be a subclass of `IntentService` because it needs to be cancelable.  This does not yet add back a notification for the downloading, e.g. #592.  That was handled before by the Android DownloadManager stuff, and was not replaced since that was disabled.

My current implementation does not filter out duplicate requests like discussed in #601.  While its possible to do, I think it'll complicate the code a lot, and I really think that should be handled elsewhere.  The UI should prevent the possibility of the user being able to submit duplicate install requests.  If not, even if `DownloaderService` filtered them out, it would still be a buggy UX since the user would be clicking install again or something like that even though the install was in progress.

This also moves the APK verification logic to the `Installer` side.  The downloading side can check the file size to see if the whole thing is downloaded.  And to be extra safe, it should not be possible to submit an APK for installation without it going through the verification procedure.  So the only method for installing APKs, `Installer.install()`, is where the verification now happens.   Also, the installer now always copies the APK to be installed into the safe location RE: the Cure53 audit issue.  This way, the APK download and cache dirs can be merged into one, making resumable downloads and cache management easy.

ping @mvdan @pserwylo @dschuermann 
more comments in the commit messages

See merge request !248
2016-04-14 14:00:06 +00:00