Updater: Allow to suspend A/B updates
Change-Id: I0387fd491a07a2214e4331a2cfe25988e0016a61
This commit is contained in:
committed by
Rashed Abdel-Tawab
parent
6a012ef541
commit
50d0fd5291
@@ -54,6 +54,9 @@ public class UpdaterService extends Service {
|
||||
public static final String ACTION_INSTALL_UPDATE = "action_install_update";
|
||||
public static final String ACTION_INSTALL_STOP = "action_install_stop";
|
||||
|
||||
public static final String ACTION_INSTALL_SUSPEND = "action_install_suspend";
|
||||
public static final String ACTION_INSTALL_RESUME = "action_install_resume";
|
||||
|
||||
private static final String ONGOING_NOTIFICATION_CHANNEL =
|
||||
"ongoing_notification_channel";
|
||||
|
||||
@@ -212,6 +215,20 @@ public class UpdaterService extends Service {
|
||||
installer.reconnect();
|
||||
installer.cancel();
|
||||
}
|
||||
} else if (ACTION_INSTALL_SUSPEND.equals(intent.getAction())) {
|
||||
if (ABUpdateInstaller.isInstallingUpdate(this)) {
|
||||
ABUpdateInstaller installer = ABUpdateInstaller.getInstance(this,
|
||||
mUpdaterController);
|
||||
installer.reconnect();
|
||||
installer.suspend();
|
||||
}
|
||||
} else if (ACTION_INSTALL_RESUME.equals(intent.getAction())) {
|
||||
if (ABUpdateInstaller.isInstallingUpdateSuspended(this)) {
|
||||
ABUpdateInstaller installer = ABUpdateInstaller.getInstance(this,
|
||||
mUpdaterController);
|
||||
installer.reconnect();
|
||||
installer.resume();
|
||||
}
|
||||
}
|
||||
return ABUpdateInstaller.isInstallingUpdate(this) ? START_STICKY : START_NOT_STICKY;
|
||||
}
|
||||
@@ -355,6 +372,11 @@ public class UpdaterService extends Service {
|
||||
getString(R.string.dialog_prepare_zip_message) :
|
||||
getString(R.string.installing_update);
|
||||
mNotificationStyle.bigText(text);
|
||||
if (ABUpdateInstaller.isInstallingUpdate(this)) {
|
||||
mNotificationBuilder.addAction(android.R.drawable.ic_media_pause,
|
||||
getString(R.string.suspend_button),
|
||||
getSuspendInstallationPendingIntent());
|
||||
}
|
||||
mNotificationBuilder.setTicker(text);
|
||||
mNotificationBuilder.setOngoing(true);
|
||||
mNotificationBuilder.setAutoCancel(false);
|
||||
@@ -364,6 +386,7 @@ public class UpdaterService extends Service {
|
||||
}
|
||||
case INSTALLED: {
|
||||
stopForeground(STOP_FOREGROUND_DETACH);
|
||||
mNotificationBuilder.mActions.clear();
|
||||
mNotificationBuilder.setStyle(null);
|
||||
mNotificationBuilder.setSmallIcon(R.drawable.ic_system_update);
|
||||
mNotificationBuilder.setProgress(0, 0, false);
|
||||
@@ -398,6 +421,25 @@ public class UpdaterService extends Service {
|
||||
tryStopSelf();
|
||||
break;
|
||||
}
|
||||
case INSTALLATION_SUSPENDED: {
|
||||
stopForeground(STOP_FOREGROUND_DETACH);
|
||||
// In case we pause before the first progress update
|
||||
mNotificationBuilder.setProgress(100, update.getProgress(), false);
|
||||
mNotificationBuilder.mActions.clear();
|
||||
String text = getString(R.string.installation_suspended_notification);
|
||||
mNotificationStyle.bigText(text);
|
||||
mNotificationBuilder.setStyle(mNotificationStyle);
|
||||
mNotificationBuilder.setSmallIcon(R.drawable.ic_pause);
|
||||
mNotificationBuilder.addAction(android.R.drawable.ic_media_play,
|
||||
getString(R.string.resume_button),
|
||||
getResumeInstallationPendingIntent());
|
||||
mNotificationBuilder.setTicker(text);
|
||||
mNotificationBuilder.setOngoing(true);
|
||||
mNotificationBuilder.setAutoCancel(false);
|
||||
mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build());
|
||||
tryStopSelf();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,4 +505,17 @@ public class UpdaterService extends Service {
|
||||
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
private PendingIntent getSuspendInstallationPendingIntent() {
|
||||
final Intent intent = new Intent(this, UpdaterService.class);
|
||||
intent.setAction(ACTION_INSTALL_SUSPEND);
|
||||
return PendingIntent.getService(this, 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
private PendingIntent getResumeInstallationPendingIntent() {
|
||||
final Intent intent = new Intent(this, UpdaterService.class);
|
||||
intent.setAction(ACTION_INSTALL_RESUME);
|
||||
return PendingIntent.getService(this, 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user