Detect update failures

This allows to delete the update only if the installation succeeded
and to notify the user in case the installation failed.

Since we now need the file in case of failure, create a copy for
uncrypt even if the user chose to delete installed updates.

Change-Id: I80b0f499663bbf50bcbca5f643c01ffdb4cd3957
This commit is contained in:
Gabriele M
2018-04-05 21:54:44 +02:00
parent af9b4adbe0
commit d5f4c1bcec
5 changed files with 99 additions and 10 deletions

View File

@@ -264,11 +264,26 @@ public class Utils {
*/
public static void cleanupDownloadsDir(Context context) {
File downloadPath = getDownloadPath(context);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
removeUncryptFiles(downloadPath);
long buildTimestamp = SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0);
long prevTimestamp = preferences.getLong(Constants.PREF_INSTALL_OLD_TIMESTAMP, 0);
String lastUpdatePath = preferences.getString(Constants.PREF_INSTALL_PACKAGE_PATH, null);
boolean reinstalling = preferences.getBoolean(Constants.PREF_INSTALL_AGAIN, false);
boolean deleteUpdates = preferences.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, false);
if ((buildTimestamp != prevTimestamp || reinstalling) && deleteUpdates &&
lastUpdatePath != null) {
File lastUpdate = new File(lastUpdatePath);
if (lastUpdate.exists()) {
lastUpdate.delete();
// Remove the pref not to delete the file if re-downloaded
preferences.edit().remove(Constants.PREF_INSTALL_PACKAGE_PATH).apply();
}
}
final String DOWNLOADS_CLEANUP_DONE = "cleanup_done";
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences.getBoolean(DOWNLOADS_CLEANUP_DONE, false)) {
return;
}