From 900a97d1163bcee808030f330b7aab98198e08ea Mon Sep 17 00:00:00 2001 From: Ido Ben-Hur Date: Thu, 13 Jan 2022 05:38:55 +0200 Subject: [PATCH] OpenDelta: Check if already installed more reliably In case the user opened the app too soon after boot --- src/eu/chainfire/opendelta/ABUpdate.java | 24 +++++++++---------- .../opendelta/BootCompleteReceiver.java | 4 ++++ src/eu/chainfire/opendelta/UpdateService.java | 9 ++++--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/eu/chainfire/opendelta/ABUpdate.java b/src/eu/chainfire/opendelta/ABUpdate.java index 0baf583..fb3c8ce 100644 --- a/src/eu/chainfire/opendelta/ABUpdate.java +++ b/src/eu/chainfire/opendelta/ABUpdate.java @@ -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; } diff --git a/src/eu/chainfire/opendelta/BootCompleteReceiver.java b/src/eu/chainfire/opendelta/BootCompleteReceiver.java index f6e33da..6df76d3 100644 --- a/src/eu/chainfire/opendelta/BootCompleteReceiver.java +++ b/src/eu/chainfire/opendelta/BootCompleteReceiver.java @@ -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); diff --git a/src/eu/chainfire/opendelta/UpdateService.java b/src/eu/chainfire/opendelta/UpdateService.java index 0534011..cbfebbd 100644 --- a/src/eu/chainfire/opendelta/UpdateService.java +++ b/src/eu/chainfire/opendelta/UpdateService.java @@ -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; }