Don't allow any operation if a reboot is needed
Change-Id: I175525071faa44f30b8f2bbf36da56a2e6f2dd1b
This commit is contained in:
@@ -42,6 +42,7 @@ class ABUpdateInstaller {
|
|||||||
private static final String TAG = "ABUpdateInstaller";
|
private static final String TAG = "ABUpdateInstaller";
|
||||||
|
|
||||||
private static final String PREF_INSTALLING_AB_ID = "installing_ab_id";
|
private static final String PREF_INSTALLING_AB_ID = "installing_ab_id";
|
||||||
|
private static final String PREF_NEEDS_REBOOT = "needs_reboot";
|
||||||
|
|
||||||
private final UpdaterController mUpdaterController;
|
private final UpdaterController mUpdaterController;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -57,7 +58,7 @@ class ABUpdateInstaller {
|
|||||||
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
||||||
if (update == null) {
|
if (update == null) {
|
||||||
// We read the id from a preference, the update could no longer exist
|
// We read the id from a preference, the update could no longer exist
|
||||||
installationDone();
|
installationDone(status == UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ class ABUpdateInstaller {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case UpdateEngine.UpdateStatusConstants.REPORTING_ERROR_EVENT: {
|
case UpdateEngine.UpdateStatusConstants.REPORTING_ERROR_EVENT: {
|
||||||
installationDone();
|
installationDone(false);
|
||||||
update.setInstallProgress(0);
|
update.setInstallProgress(0);
|
||||||
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
||||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||||
@@ -79,7 +80,7 @@ class ABUpdateInstaller {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT: {
|
case UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT: {
|
||||||
installationDone();
|
installationDone(true);
|
||||||
update.setInstallProgress(0);
|
update.setInstallProgress(0);
|
||||||
update.setStatus(UpdateStatus.INSTALLED);
|
update.setStatus(UpdateStatus.INSTALLED);
|
||||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||||
@@ -97,7 +98,7 @@ class ABUpdateInstaller {
|
|||||||
if (mReconnecting) {
|
if (mReconnecting) {
|
||||||
// The service was restarted because we thought we were installing an
|
// The service was restarted because we thought we were installing an
|
||||||
// update, but we aren't, so clear everything.
|
// update, but we aren't, so clear everything.
|
||||||
installationDone();
|
installationDone(false);
|
||||||
mReconnecting = false;
|
mReconnecting = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,13 +112,15 @@ class ABUpdateInstaller {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static synchronized boolean isInstallingUpdate(Context context) {
|
static synchronized boolean isInstallingUpdate(Context context) {
|
||||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null) != null;
|
return pref.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null) != null ||
|
||||||
|
pref.getBoolean(ABUpdateInstaller.PREF_NEEDS_REBOOT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static synchronized boolean isInstallingUpdate(Context context, String downloadId) {
|
static synchronized boolean isInstallingUpdate(Context context, String downloadId) {
|
||||||
return downloadId.equals(PreferenceManager.getDefaultSharedPreferences(context)
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null));
|
return downloadId.equals(pref.getString(ABUpdateInstaller.PREF_INSTALLING_AB_ID, null)) ||
|
||||||
|
pref.getBoolean(ABUpdateInstaller.PREF_NEEDS_REBOOT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ABUpdateInstaller(Context context, UpdaterController updaterController) {
|
ABUpdateInstaller(Context context, UpdaterController updaterController) {
|
||||||
@@ -200,8 +203,9 @@ class ABUpdateInstaller {
|
|||||||
return mUpdateEngine.bind(mUpdateEngineCallback);
|
return mUpdateEngine.bind(mUpdateEngineCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void installationDone() {
|
private void installationDone(boolean needsReboot) {
|
||||||
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
|
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
|
||||||
|
.putBoolean(PREF_NEEDS_REBOOT, needsReboot)
|
||||||
.remove(PREF_INSTALLING_AB_ID)
|
.remove(PREF_INSTALLING_AB_ID)
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
@@ -218,7 +222,7 @@ class ABUpdateInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mUpdateEngine.cancel();
|
mUpdateEngine.cancel();
|
||||||
installationDone();
|
installationDone(false);
|
||||||
|
|
||||||
mUpdaterController.getActualUpdate(mDownloadId)
|
mUpdaterController.getActualUpdate(mDownloadId)
|
||||||
.setStatus(UpdateStatus.INSTALLATION_CANCELLED);
|
.setStatus(UpdateStatus.INSTALLATION_CANCELLED);
|
||||||
|
|||||||
Reference in New Issue
Block a user