Commit Graph

47 Commits

Author SHA1 Message Date
Gabriele M
8d0471effc Make updates world readable
This should allow update_engine to access the file without
granting the dac_override capability.

Change-Id: I5d0c8792fd47e5571dbaf802b2725f99ee2dc150
2018-04-05 16:37:49 +02:00
Gabriele M
0e79b791f0 Add support for duplicate links
Support duplicate links [1] to handle better temporarily unavailable
mirrors.

[1] https://tools.ietf.org/html/rfc6249

Change-Id: If78fb4a90da68ef221294eed2c59063a14cf1f43
2018-01-23 22:41:40 +01:00
Gabriele M
e02b8a0b00 Copy the updates for uncrypt using a Service
Same as change I488018d01c0baf74660362a384e53bfe5d85de2b
("Use a service to export the updates"). While at it, move the code
out of UpdaterService to better separate the code that deal with AB
updates and regular updates.

Change-Id: I2bc3e78e80f5e63c57303cbbcdc0353dbab0f67f
2018-01-23 22:41:40 +01:00
Gabriele M
f3d9b3f1b2 Allow service restarts while installing AB updates
The update engine service is independent and once started doesn't need
our service to install updates. Therefore we can't assume that our
service will stay up as long as the installation is being performed.
If the service gets terminated while an update is being installed, we
simply lose our connection to the update engine service and stop
receiving notifications, the installation itself won't stop. Keep
track of ongoing installations using a shared preference and use a
sticky service when installing updates. The service will try to
re-connect to the update engine service and determine if the
installation is still ongoing.

Change-Id: Id2fc11cab51610d04bf41a0927824bb8c0c94d71
2018-01-23 22:41:40 +01:00
Gabriele M
9dc1349c1a Implement DownloadClient using HttpURLConnection
The version of OkHttp used in AOSP doesn't handle dynamic table size
updates [1] properly [2]. Instead of fixing OkHttp or importing a
prebuilt updated version, implement a new download client only using
HttpURLConnection, which seems to work properly.

[1] https://tools.ietf.org/html/rfc7541#section-6.3
[2] https://trac.nginx.org/nginx/ticket/1397

Change-Id: I3eedf7326f2017812c4a12d41f9ea028d255f7a8
2017-11-12 16:10:17 +01:00
Gabriele M
87202371de Don't change status when cancelled downloads fail
It takes a bit of time to actually pause (i.e. cancel) a download. If
we change the update status once the download is actually cancelled,
we might override any status change that happened between the user
request and its completion. For example, the following can happen when
the user deletes an ongoing downloads:

 - pauseDownload(): DOWNLOADING -> PAUSED
 - deleteUpdate(): PAUSED -> DELETED
 - onFailure(): DELETED -> PAUSED

Don't change the status of cancelled downloads from the onFailure()
callback not to have an incorrect final status.

Change-Id: Iee90482d82df984672c59d7c508ad834fa08061f
2017-08-18 14:31:54 +02:00
Gabriele M
09968f1b25 Rename cancelDownload() to deleteUpdate()
The method can be used to delete any update, incomplete or not.
2017-07-21 17:05:53 +02:00
Gabriele M
1e2f353b55 Rename UpdateDownload and Update classes 2017-07-21 17:04:12 +02:00
Gabriele M
28b8774db6 Define interfaces with only getters for the updates
This also changes the code to use the new interfaces wherever the
update is not supposed to change.
2017-07-21 16:52:24 +02:00
Gabriele M
11f82cfb87 Reorder includes directives
These went out of order moving some stuff around. Reorder them so
that there won't be unnecessary line changes in future.
2017-07-21 01:17:19 +02:00
Gabriele M
821efd8219 Rename UpdaterControllerInt to Controller 2017-07-18 22:26:51 +02:00
Gabriele M
341eec0b28 Fix a couple of typos 2017-07-18 22:17:29 +02:00
Gabriele M
af1e9c4478 Create model package 2017-07-18 22:15:13 +02:00
Gabriele M
f496f0d0e7 Don't set status of download to unknown when download fail
The controller should report the actual status of the downloads, let
the clients handle the special cases. Also, don't try to resume
downloads whose destination doesn't exist.

This partially reverts 7369e9cea9
("Set the status of paused downloads to unknown if no file exists").
2017-07-17 12:27:15 +02:00
Gabriele M
1af40da839 Send the notification and then start the download
In this way if the download fails immediately, it will fail after the
notification.
2017-07-17 12:26:08 +02:00
Gabriele M
f94846674f Allow to check if an AB update is being installed 2017-07-16 21:24:07 +02:00
Gabriele M
601823dfc7 Allow to check if an update is being verified 2017-07-16 21:24:07 +02:00
Gabriele M
7369e9cea9 Set the status of paused downloads to unknown if no file exists
This is useful in case the download is stopped before it could start.
2017-07-16 21:24:06 +02:00
Gabriele M
40f15b1fb3 Reset speed and ETA when pausing downloads 2017-07-15 02:10:34 +02:00
Gabriele M
d30ba00a7b Update download size only if it was unknown
The returned content-length depends on the requested range, therefore
when resuming download the reported size is smaller than the actual
file size and we should not update it.
2017-07-15 02:10:31 +02:00
Gabriele M
e34334a1d7 Pass the destination File to the callback
The current argument is unused and it should have been removed
with commit 81229329f1
("Generate download clients using a builder class"). Instead of
removing it completely, use it to pass the File of the download.
2017-07-10 01:31:35 +02:00
Gabriele M
79b44602e0 Allow to have different updates using the same filename 2017-07-08 22:18:15 +02:00
Gabriele M
4979c4d78d Increase number of veryfing updates immediately
Or we might notify the listeners too early.
2017-07-08 22:11:01 +02:00
Gabriele M
1c1bac67b4 Protect the data of UpdaterController
Create copies of the objects not to allow other classes change them,
excluding those of controller package.
2017-07-08 22:10:59 +02:00
Gabriele M
a2919a8947 Don't modify the objects of the controller directly
Add a method to the controller that allows to set a list of
downloads as not available online.
2017-07-08 22:10:58 +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
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
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
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
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
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
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
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
520105284c Rename some constants 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