Commit Graph

158 Commits

Author SHA1 Message Date
Gabriele M
b4f0abd97d Cancel partial downloads if the server doesn't fulfil them
If the server doesn't fulfil a partial content request, bail out.
While at it, fix a typo.
2017-07-08 17:43:56 +02:00
Gabriele M
81229329f1 Generate download clients using a builder class
This change allows to define a proper interface for the download
client and keep its implementation completely separate. It also
allows to create clients without starting the download right away,
which could be useful when defining callbacks that require a
reference to the client.

Note that this change also drops the unused methods of DownloadClient.
2017-07-08 17:43:56 +02:00
Gabriele M
5b0e37ea22 Don't use a static object as download tag
Otherwise all the downloads will use the same tag and cancelling a
download will actually cancel all the downloads.
2017-07-08 17:20:47 +02:00
Gabriele M
efa829358d Remove unknwon files that are in the downloads dir
The files are supposed to be downloaded in a privileged location
that the user can't access. If the user wipes the data of the
application, the updates downloaded are not removed. Perform a
one-time cleanup so that our downloads dir doesn't grow without
control.
2017-07-08 14:07:05 +02:00
Gabriele M
6534932b20 Show "verify" for complete INCOMPLETE updates
INCOMPLETE is used for any update that isn't verified, even if the
file has been completed. This change is mostly needed to support
imported downloads, which we take as complete, but unverified.
2017-07-08 14:05:36 +02:00
Gabriele M
26f149bef1 Import updates downloaded with CMUpdater 2017-07-08 14:05:19 +02:00
Gabriele M
b8a769eeab Remove "update name" column from the database
It's useless since it's just the name of the file and we also stores
the full path.
2017-07-07 23:23:19 +02:00
Gabriele M
cb089aa445 Don't save the URL of the update in the database
Each update must now be in updates.json to be downloaded. Since this
file already stores the URL of each update and that the URL is not
needed after the download, the URL entry can be removed from the
database.
2017-07-07 22:57:54 +02:00
Gabriele M
e6a061c090 Use a single config to define the download path
There's no point in using a bool, just define the path.
2017-07-07 22:05:23 +02:00
Gabriele M
89cb51e3dd Replace error message with debug message
Trying to add an already added download is not error and it's
actually a way to mark an update as available online.
2017-07-07 22:05:23 +02:00
Gabriele M
c90700d3d2 Remove no longer available updates when refreshing the list 2017-07-07 22:05:23 +02:00
Gabriele M
d327d61cc6 Send an event when update are canceled
This allows to properly update the status of the application.
In particular, when an update is deleted:
 - Cancel the associated notification, if any.
 - Remove the entry from the controller if the update is no longer
   available online.
 - Disable the resume button if download is partially downloaded
   and is no longer available online.
2017-07-07 22:05:22 +02:00
Gabriele M
08a7dfade9 Track "online updates" rather than "local updates"
This is a preparation commit with no actual changes.
2017-07-07 22:05:22 +02:00
Gabriele M
ab9ac395f0 Use deleteUpdateAsync() even if we know the file doesn't exist
deleteUpdateAsync() is safe and it makes the code more readable at
the expense of an extra File.exists() call.
2017-07-07 22:05:22 +02:00
Gabriele M
805e672148 Use correct progress value when installing updates 2017-07-07 22:05:22 +02:00
Gabriele M
8a559103a9 Update progressbar only if it's not indeterminate
Otherwise it can show the wrong value when it goes back to the
non-indeterminate mode (e.g. after a verification failure).
2017-07-06 23:50:09 +02:00
Gabriele M
f23bc5e967 Close response body when download is complete
Response.body().source() requires an explicit close() call.
2017-07-06 22:10:33 +02:00
Gabriele M
47f48cff3f Fix first updates list load 2017-07-06 22:07:36 +02:00
Gabriele M
718c877687 Provide some feedback when refreshing the list
Add a progress dialog to inform the user about the ongoing operation
and show a snackbar with the result of the operation.
2017-07-05 23:35:14 +02:00
Gabriele M
7819587a22 Add a toolbar menu with back and refresh buttons
Change theme just to make the refresh button visible without
changing its color.
2017-07-05 23:35:14 +02:00
Gabriele M
eaba161d43 Replace current json only if new one is valid 2017-07-05 23:35:14 +02:00
Gabriele M
3e36596127 Create Constants class 2017-07-05 23:35:14 +02:00
Gabriele M
5aa2c62296 Remove unused layout file 2017-07-05 23:35:14 +02:00
Gabriele M
217f84b57e Simplify handling of intentional download failures 2017-07-05 23:35:14 +02:00
Gabriele M
1795bd8b11 Report if a failure is following a download abort 2017-07-05 23:35:14 +02:00
Gabriele M
3de555ea06 Replace AsyncTask with Thread in DownloadClient 2017-07-05 23:35:14 +02:00
Gabriele M
e245631b46 Add support for A/B (Seamless) System Updates
Loosely based on:
0465cb691d
2017-07-04 19:36:32 +02:00
Gabriele M
311b2f7cfd Replace DB entries on conflict
In this way we could add previously unknown info such as the size.
2017-07-04 19:05:04 +02:00
Gabriele M
320112dae4 Allow to choose the conflict algorithm when adding DB entries 2017-07-04 19:05:04 +02:00
Gabriele M
1e89ff8f8d Don't assume we always know the final size of the files 2017-07-04 19:05:04 +02:00
Gabriele M
bb2f2c1005 Disable indeterminate progressbar in case of download error
Similar to the 'paused' case, but take into account that the error
can happen when the progress is 0, in which case we just hide the
progress bar.
2017-07-04 19:05:04 +02:00
Gabriele M
02f504a1fb Disable buttons while verifying updates 2017-07-04 19:05:04 +02:00
Gabriele M
653b577d61 Keep track of the number of updates being verified 2017-07-04 19:05:04 +02:00
Gabriele M
e7923a3d56 Keep track of the number of active downloads 2017-07-04 19:05:04 +02:00
Gabriele M
f0940dafca Verify package when resuming a completed download
It's possible to resume already completed downloads. When this
happens, starts verifying the package. Otherwise we won't be
able to resume the download since the server will likely reply
with 416.
2017-07-04 19:05:04 +02:00
Gabriele M
fe3d8be858 Download file only if the server replies with success code 2017-07-04 19:05:04 +02:00
Gabriele M
c4c5a72c75 Perform some database operations in separate threads
These operations shouldn't be frequent enough to require explicit
synchronization.
2017-07-04 19:05:04 +02:00
Gabriele M
fe18add111 Verify downloads in a separate thread 2017-07-04 19:05:04 +02:00
Gabriele M
c13d79b39c Use a Thread instead of an AsyncTask to delete downloads 2017-07-04 19:05:04 +02:00
Gabriele M
4dcf4199f1 Minor code refactoring 2017-07-04 19:05:04 +02:00
Gabriele M
520105284c Rename some constants 2017-07-04 19:05:04 +02:00
Gabriele M
437d4b1913 Don't make UpdaterService sticky
We are using it as non-sticky service, so just declare it as such.
2017-07-04 19:05:04 +02:00
Gabriele M
db3f14832a Replace 'Download' prefix with 'Updater'
These classes do more than controlling the download of the updates.
2017-07-04 19:05:04 +02:00
Gabriele M
21cc96f300 Add missing RECOVERY and REBOOT permissions
And sort alphabetically the list of permissions.
2017-07-04 19:05:04 +02:00
Gabriele M
945e50aad1 Don't crash when requesting non-existing updates 2017-07-03 17:41:34 +02:00
Gabriele M
9b3deda9fa Protect DownloadController instantiation
Enforce the use of DownloadService to create new DownloadController
instaces, but give access to the existing instances to anyone.
2017-07-03 17:41:33 +02:00
Gabriele M
dcbcc759d2 Handle installation requests from DownloadService
This is needed to protect the instantiation of DownloadController,
which will be done with a follow-up change.
2017-07-03 16:08:33 +02:00
Gabriele M
dc95edbf80 Start service to pause/resume downloads from notification
These operations require the service, so it's better to let
DownloadService handle them. This also ensures we always fulfil
the requests, even when sent while the service is not running.
2017-07-03 16:08:33 +02:00
Gabriele M
789dc7d737 Rename DownloadController's newInstance() to getInstance()
Also, make both the instance getters synchronized.
2017-07-03 16:08:32 +02:00
Gabriele M
bda4d2b9b4 Load the updates stored in the database from DownloadController
Also, hide the distinction between local and non-local updates.
Local updates should be handled only by DownloadController.
2017-07-03 16:08:31 +02:00