OpenDelta: Check if already installed more reliably
In case the user opened the app too soon after boot
This commit is contained in:
parent
9aa25d9150
commit
900a97d116
|
@ -48,7 +48,7 @@ class ABUpdate {
|
|||
private final ProgressListener mProgressListener;
|
||||
|
||||
private final UpdateService mUpdateService;
|
||||
|
||||
private final UpdateEngine mUpdateEngine;
|
||||
private boolean mBound;
|
||||
|
||||
private final UpdateEngineCallback mUpdateEngineCallback = new UpdateEngineCallback() {
|
||||
|
@ -129,22 +129,23 @@ class ABUpdate {
|
|||
.putBoolean(PREFS_IS_INSTALLING_UPDATE, installing).commit();
|
||||
}
|
||||
|
||||
static synchronized void pokeStatus(String zipPath, UpdateService us) {
|
||||
ABUpdate installer = new ABUpdate(zipPath, null, us);
|
||||
installer.bindCallbacks();
|
||||
}
|
||||
|
||||
private ABUpdate(String zipPath, ProgressListener listener,
|
||||
UpdateService us) {
|
||||
UpdateService us) {
|
||||
this.zipPath = zipPath;
|
||||
this.mProgressListener = listener;
|
||||
this.mUpdateService = us;
|
||||
this.enableABPerfMode = mUpdateService.getConfig().getABPerfModeCurrent();
|
||||
this.mUpdateEngine = new UpdateEngine();
|
||||
}
|
||||
|
||||
private boolean bindCallbacks() {
|
||||
UpdateEngine updateEngine = new UpdateEngine();
|
||||
return bindCallbacks(updateEngine);
|
||||
}
|
||||
|
||||
private boolean bindCallbacks(UpdateEngine updateEngine) {
|
||||
if (mBound) return true;
|
||||
mBound = updateEngine.bind(mUpdateEngineCallback);
|
||||
mBound = mUpdateEngine.bind(mUpdateEngineCallback);
|
||||
if (!mBound) {
|
||||
Log.e(TAG, "Could not bind UpdateEngineCallback");
|
||||
return false;
|
||||
|
@ -181,11 +182,10 @@ class ABUpdate {
|
|||
return false;
|
||||
}
|
||||
|
||||
UpdateEngine updateEngine = new UpdateEngine();
|
||||
updateEngine.setPerformanceMode(enableABPerfMode);
|
||||
if (!bindCallbacks(updateEngine)) return false;
|
||||
mUpdateEngine.setPerformanceMode(enableABPerfMode);
|
||||
if (!bindCallbacks()) return false;
|
||||
String zipFileUri = "file://" + file.getAbsolutePath();
|
||||
updateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs);
|
||||
mUpdateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,11 +24,15 @@ package eu.chainfire.opendelta;
|
|||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.UserManager;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class BootCompleteReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.edit().remove(UpdateService.PREF_PENDING_REBOOT).commit();
|
||||
UserManager um = UserManager.get(context);
|
||||
if (um.isAdminUser()) {
|
||||
UpdateService.startClearRunningInstall(context);
|
||||
|
|
|
@ -190,7 +190,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
|||
// we only snooze until a new build
|
||||
private static final String PREF_SNOOZE_UPDATE_NAME = "last_snooze_update";
|
||||
|
||||
private static final String PREF_PENDING_REBOOT = "pending_reboot";
|
||||
public static final String PREF_PENDING_REBOOT = "pending_reboot";
|
||||
|
||||
private static final String PREF_CURRENT_AB_FILENAME_NAME = "current_ab_filename";
|
||||
public static final String PREF_CURRENT_FILENAME_NAME = "current_filename";
|
||||
|
@ -376,7 +376,6 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
|||
} else if (ACTION_UPDATE.equals(intent.getAction())) {
|
||||
autoState(true, PREF_AUTO_DOWNLOAD_CHECK, false);
|
||||
} else if (ACTION_CLEAR_INSTALL_RUNNING.equals(intent.getAction())) {
|
||||
prefs.edit().putBoolean(PREF_PENDING_REBOOT, false).commit();
|
||||
ABUpdate.setInstallingUpdate(false, this);
|
||||
} else if (ACTION_FLASH_FILE.equals(intent.getAction())) {
|
||||
if (intent.hasExtra(EXTRA_FILENAME)) {
|
||||
|
@ -519,9 +518,9 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
|||
|
||||
// Check if a previous update was done already
|
||||
if (prefs.getBoolean(PREF_PENDING_REBOOT, false)) {
|
||||
filename = prefs.getString(PREF_CURRENT_AB_FILENAME_NAME, null);
|
||||
startABRebootNotification(filename);
|
||||
updateState(STATE_ACTION_AB_FINISHED, null, null, null, null, null);
|
||||
final String lastFilename = prefs.getString(PREF_CURRENT_AB_FILENAME_NAME, null);
|
||||
prefs.edit().putBoolean(PREF_PENDING_REBOOT, false).commit();
|
||||
ABUpdate.pokeStatus(lastFilename, this);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue