Don't register multiple UpdateEngine callbacks

We are loosely tied to UpdateEngine and have no way to know whether
we are bound or not without keeping track of the connection manually.
Since UpdaterService is for both A/B and legacy updates, turn
ABUpdateInstaller into a singleton to keep the code simple while
ensuring that a single callback is registered.

Change-Id: Ib4e9ad1413ba96bf5ed59cc3383741b5c9bac427
This commit is contained in:
Gabriele M
2018-03-24 16:17:19 +01:00
parent c92f44b66e
commit dd712cfdbe
2 changed files with 44 additions and 23 deletions

View File

@@ -155,7 +155,7 @@ public class UpdaterService extends Service {
if ((intent == null || intent.getAction() == null) &&
ABUpdateInstaller.isInstallingUpdate(this)) {
// The service is being restarted.
ABUpdateInstaller installer = new ABUpdateInstaller(this, mUpdaterController);
ABUpdateInstaller installer = ABUpdateInstaller.getInstance(this, mUpdaterController);
if (installer.reconnect()) {
return START_STICKY;
}
@@ -177,7 +177,8 @@ public class UpdaterService extends Service {
}
try {
if (Utils.isABUpdate(update.getFile())) {
ABUpdateInstaller installer = new ABUpdateInstaller(this, mUpdaterController);
ABUpdateInstaller installer = ABUpdateInstaller.getInstance(this,
mUpdaterController);
if (installer.install(downloadId)) {
return START_STICKY;
}
@@ -196,7 +197,8 @@ public class UpdaterService extends Service {
UpdateInstaller installer = new UpdateInstaller(this, mUpdaterController);
installer.cancel();
} else if (ABUpdateInstaller.isInstallingUpdate(this)) {
ABUpdateInstaller installer = new ABUpdateInstaller(this, mUpdaterController);
ABUpdateInstaller installer = ABUpdateInstaller.getInstance(this,
mUpdaterController);
installer.reconnect();
installer.cancel();
}