Wait for the UPDATED_NEED_REBOOT status
Consider an update as installed only when update engine reports that the device needs to be rebooted. This change also move the entire logic in onStatusUpdate(), which reports all we need to properly track the progress of the installation. Change-Id: Ic8db00cccdd19fd62ba4dee31fd1dccc9037193d
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
package org.lineageos.updater.controller;
|
package org.lineageos.updater.controller;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.UpdateEngine;
|
import android.os.UpdateEngine;
|
||||||
import android.os.UpdateEngineCallback;
|
import android.os.UpdateEngineCallback;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
@@ -47,7 +48,6 @@ class ABUpdateInstaller {
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
private final UpdateEngineCallback mUpdateEngineCallback = new UpdateEngineCallback() {
|
private final UpdateEngineCallback mUpdateEngineCallback = new UpdateEngineCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusUpdate(int status, float percent) {
|
public void onStatusUpdate(int status, float percent) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
@@ -60,41 +60,34 @@ class ABUpdateInstaller {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case UpdateEngine.UpdateStatusConstants.REPORTING_ERROR_EVENT: {
|
case UpdateEngine.UpdateStatusConstants.REPORTING_ERROR_EVENT: {
|
||||||
|
sDownloadId = null;
|
||||||
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
||||||
update.setInstallProgress(0);
|
update.setInstallProgress(0);
|
||||||
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
||||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT: {
|
||||||
|
sDownloadId = null;
|
||||||
|
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
||||||
|
update.setInstallProgress(0);
|
||||||
|
update.setStatus(UpdateStatus.INSTALLED);
|
||||||
|
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||||
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(
|
||||||
|
mContext);
|
||||||
|
boolean deleteUpdate = pref.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK,
|
||||||
|
false);
|
||||||
|
if (deleteUpdate) {
|
||||||
|
mUpdaterController.deleteUpdate(mDownloadId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPayloadApplicationComplete(int errorCode) {
|
public void onPayloadApplicationComplete(int errorCode) {
|
||||||
sDownloadId = null;
|
|
||||||
switch (errorCode) {
|
|
||||||
case UpdateEngine.ErrorCodeConstants.SUCCESS: {
|
|
||||||
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
|
||||||
update.setInstallProgress(0);
|
|
||||||
update.setStatus(UpdateStatus.INSTALLED);
|
|
||||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: {
|
|
||||||
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
|
||||||
update.setInstallProgress(0);
|
|
||||||
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
|
||||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean deleteUpdate = PreferenceManager.getDefaultSharedPreferences(mContext)
|
|
||||||
.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, false);
|
|
||||||
if (deleteUpdate) {
|
|
||||||
mUpdaterController.deleteUpdate(mDownloadId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user