Updater: Allow to suspend A/B updates
Change-Id: I0387fd491a07a2214e4331a2cfe25988e0016a61
This commit is contained in:
committed by
Rashed Abdel-Tawab
parent
6a012ef541
commit
50d0fd5291
@@ -43,6 +43,7 @@ class ABUpdateInstaller {
|
||||
private static final String TAG = "ABUpdateInstaller";
|
||||
|
||||
private static final String PREF_INSTALLING_AB_ID = "installing_ab_id";
|
||||
private static final String PREF_INSTALLING_SUSPENDED_AB_ID = "installing_suspended_ab_id";
|
||||
|
||||
private static ABUpdateInstaller sInstance = null;
|
||||
|
||||
@@ -53,6 +54,9 @@ class ABUpdateInstaller {
|
||||
private UpdateEngine mUpdateEngine;
|
||||
private boolean mBound;
|
||||
|
||||
private boolean mFinalizing;
|
||||
private int mProgress;
|
||||
|
||||
private final UpdateEngineCallback mUpdateEngineCallback = new UpdateEngineCallback() {
|
||||
|
||||
@Override
|
||||
@@ -71,10 +75,10 @@ class ABUpdateInstaller {
|
||||
update.setStatus(UpdateStatus.INSTALLING);
|
||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||
}
|
||||
int progress = Math.round(percent * 100);
|
||||
mUpdaterController.getActualUpdate(mDownloadId).setInstallProgress(progress);
|
||||
boolean finalizing = status == UpdateEngine.UpdateStatusConstants.FINALIZING;
|
||||
mUpdaterController.getActualUpdate(mDownloadId).setFinalizing(finalizing);
|
||||
mProgress = Math.round(percent * 100);
|
||||
mUpdaterController.getActualUpdate(mDownloadId).setInstallProgress(mProgress);
|
||||
mFinalizing = status == UpdateEngine.UpdateStatusConstants.FINALIZING;
|
||||
mUpdaterController.getActualUpdate(mDownloadId).setFinalizing(mFinalizing);
|
||||
mUpdaterController.notifyInstallProgress(mDownloadId);
|
||||
}
|
||||
break;
|
||||
@@ -127,6 +131,16 @@ class ABUpdateInstaller {
|
||||
TextUtils.equals(pref.getString(Constants.PREF_NEEDS_REBOOT_ID, null), downloadId);
|
||||
}
|
||||
|
||||
static synchronized boolean isInstallingUpdateSuspended(Context context) {
|
||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return pref.getString(ABUpdateInstaller.PREF_INSTALLING_SUSPENDED_AB_ID, null) != null;
|
||||
}
|
||||
|
||||
static synchronized boolean isInstallingUpdateSuspended(Context context, String downloadId) {
|
||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return downloadId.equals(pref.getString(ABUpdateInstaller.PREF_INSTALLING_SUSPENDED_AB_ID, null));
|
||||
}
|
||||
|
||||
static synchronized boolean isWaitingForReboot(Context context, String downloadId) {
|
||||
String waitingId = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(Constants.PREF_NEEDS_REBOOT_ID, null);
|
||||
@@ -273,4 +287,54 @@ class ABUpdateInstaller {
|
||||
public void setPerformanceMode(boolean enable) {
|
||||
mUpdateEngine.setPerformanceMode(enable);
|
||||
}
|
||||
|
||||
public boolean suspend() {
|
||||
if (!isInstallingUpdate(mContext)) {
|
||||
Log.e(TAG, "cancel: Not installing any update");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mBound) {
|
||||
Log.e(TAG, "Not connected to update engine");
|
||||
return false;
|
||||
}
|
||||
|
||||
mUpdateEngine.suspend();
|
||||
|
||||
mUpdaterController.getActualUpdate(mDownloadId)
|
||||
.setStatus(UpdateStatus.INSTALLATION_SUSPENDED);
|
||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
|
||||
.putString(PREF_INSTALLING_SUSPENDED_AB_ID, mDownloadId)
|
||||
.apply();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean resume() {
|
||||
if (!isInstallingUpdateSuspended(mContext)) {
|
||||
Log.e(TAG, "cancel: No update is suspended");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mBound) {
|
||||
Log.e(TAG, "Not connected to update engine");
|
||||
return false;
|
||||
}
|
||||
|
||||
mUpdateEngine.resume();
|
||||
|
||||
mUpdaterController.getActualUpdate(mDownloadId).setStatus(UpdateStatus.INSTALLING);
|
||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||
mUpdaterController.getActualUpdate(mDownloadId).setInstallProgress(mProgress);
|
||||
mUpdaterController.getActualUpdate(mDownloadId).setFinalizing(mFinalizing);
|
||||
mUpdaterController.notifyInstallProgress(mDownloadId);
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
|
||||
.remove(PREF_INSTALLING_SUSPENDED_AB_ID)
|
||||
.apply();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user