OpenDelta: delete previous created but never flashed images
if a new ready-to-flash image has been created check if a previous one is still available that is not the current one and delete that first for debugging purposes scan and log all images found Change-Id: Iceb50fe9d0512c03e6c1dc81df3a46c73312e51d
This commit is contained in:
parent
5fe11bb467
commit
b4a2e9375b
|
@ -187,7 +187,7 @@ public class SettingsActivity extends PreferenceActivity implements
|
||||||
int numDeletedFiles = cleanFiles();
|
int numDeletedFiles = cleanFiles();
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = PreferenceManager
|
||||||
.getDefaultSharedPreferences(this);
|
.getDefaultSharedPreferences(this);
|
||||||
UpdateService.clearState(prefs);
|
clearState(prefs);
|
||||||
prefs.edit().putBoolean(PREF_START_HINT_SHOWN, false).commit();
|
prefs.edit().putBoolean(PREF_START_HINT_SHOWN, false).commit();
|
||||||
Toast.makeText(this, String.format(getString(R.string.clean_files_feedback), numDeletedFiles), Toast.LENGTH_LONG).show();
|
Toast.makeText(this, String.format(getString(R.string.clean_files_feedback), numDeletedFiles), Toast.LENGTH_LONG).show();
|
||||||
return true;
|
return true;
|
||||||
|
@ -335,4 +335,13 @@ public class SettingsActivity extends PreferenceActivity implements
|
||||||
weekDayList.addAll(Arrays.asList(dfs.getWeekdays()).subList(1, dfs.getWeekdays().length));
|
weekDayList.addAll(Arrays.asList(dfs.getWeekdays()).subList(1, dfs.getWeekdays().length));
|
||||||
return weekDayList.toArray(new String[weekDayList.size()]);
|
return weekDayList.toArray(new String[weekDayList.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clearState(SharedPreferences prefs) {
|
||||||
|
prefs.edit().putString(UpdateService.PREF_LATEST_FULL_NAME, UpdateService.PREF_READY_FILENAME_DEFAULT).commit();
|
||||||
|
prefs.edit().putString(UpdateService.PREF_LATEST_DELTA_NAME, UpdateService.PREF_READY_FILENAME_DEFAULT).commit();
|
||||||
|
prefs.edit().putString(UpdateService.PREF_READY_FILENAME_NAME, UpdateService.PREF_READY_FILENAME_DEFAULT).commit();
|
||||||
|
prefs.edit().putLong(UpdateService.PREF_DOWNLOAD_SIZE, -1).commit();
|
||||||
|
prefs.edit().putBoolean(UpdateService.PREF_DELTA_SIGNATURE, false).commit();
|
||||||
|
prefs.edit().putString(UpdateService.PREF_INITIAL_FILE, UpdateService.PREF_READY_FILENAME_DEFAULT).commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,6 +214,7 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
private boolean updateRunning;
|
private boolean updateRunning;
|
||||||
private int failedUpdateCount;
|
private int failedUpdateCount;
|
||||||
private SharedPreferences prefs = null;
|
private SharedPreferences prefs = null;
|
||||||
|
private String oldFlashFilename;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Using reflection voodoo instead calling the hidden class directly, to
|
* Using reflection voodoo instead calling the hidden class directly, to
|
||||||
|
@ -307,10 +308,12 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
if (ACTION_CHECK.equals(intent.getAction())) {
|
if (ACTION_CHECK.equals(intent.getAction())) {
|
||||||
if (checkPermissions()) {
|
if (checkPermissions()) {
|
||||||
checkForUpdates(true, PREF_AUTO_DOWNLOAD_CHECK);
|
checkForUpdates(true, PREF_AUTO_DOWNLOAD_CHECK);
|
||||||
|
scanImageFiles();
|
||||||
}
|
}
|
||||||
} else if (ACTION_FLASH.equals(intent.getAction())) {
|
} else if (ACTION_FLASH.equals(intent.getAction())) {
|
||||||
if (checkPermissions()) {
|
if (checkPermissions()) {
|
||||||
flashUpdate();
|
flashUpdate();
|
||||||
|
scanImageFiles();
|
||||||
}
|
}
|
||||||
} else if (ACTION_ALARM.equals(intent.getAction())) {
|
} else if (ACTION_ALARM.equals(intent.getAction())) {
|
||||||
scheduler.alarm(intent.getIntExtra(EXTRA_ALARM_ID, -1));
|
scheduler.alarm(intent.getIntExtra(EXTRA_ALARM_ID, -1));
|
||||||
|
@ -326,6 +329,7 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
} else if (ACTION_BUILD.equals(intent.getAction())) {
|
} else if (ACTION_BUILD.equals(intent.getAction())) {
|
||||||
if (checkPermissions()) {
|
if (checkPermissions()) {
|
||||||
checkForUpdates(true, PREF_AUTO_DOWNLOAD_FULL);
|
checkForUpdates(true, PREF_AUTO_DOWNLOAD_FULL);
|
||||||
|
scanImageFiles();
|
||||||
}
|
}
|
||||||
} else if (ACTION_UPDATE.equals(intent.getAction())) {
|
} else if (ACTION_UPDATE.equals(intent.getAction())) {
|
||||||
autoState(true, PREF_AUTO_DOWNLOAD_CHECK, false);
|
autoState(true, PREF_AUTO_DOWNLOAD_CHECK, false);
|
||||||
|
@ -426,7 +430,7 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
String filename = prefs.getString(PREF_READY_FILENAME_NAME,
|
String filename = prefs.getString(PREF_READY_FILENAME_NAME,
|
||||||
PREF_READY_FILENAME_DEFAULT);
|
PREF_READY_FILENAME_DEFAULT);
|
||||||
|
|
||||||
if (filename != null) {
|
if (filename != PREF_READY_FILENAME_DEFAULT) {
|
||||||
if (!(new File(filename)).exists()) {
|
if (!(new File(filename)).exists()) {
|
||||||
filename = null;
|
filename = null;
|
||||||
}
|
}
|
||||||
|
@ -1360,6 +1364,7 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
if (downloadUrlFileUnknownSize(url, f, md5Sum)) {
|
if (downloadUrlFileUnknownSize(url, f, md5Sum)) {
|
||||||
Logger.d("success");
|
Logger.d("success");
|
||||||
|
deleteOldFlashFile(fn);
|
||||||
prefs.edit().putString(PREF_READY_FILENAME_NAME, fn).commit();
|
prefs.edit().putString(PREF_READY_FILENAME_NAME, fn).commit();
|
||||||
} else {
|
} else {
|
||||||
f.delete();
|
f.delete();
|
||||||
|
@ -1493,11 +1498,12 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
String flashFilename = prefs.getString(PREF_READY_FILENAME_NAME, PREF_READY_FILENAME_DEFAULT);
|
String flashFilename = prefs.getString(PREF_READY_FILENAME_NAME, PREF_READY_FILENAME_DEFAULT);
|
||||||
String intialFile = prefs.getString(PREF_INITIAL_FILE, PREF_READY_FILENAME_DEFAULT);
|
String intialFile = prefs.getString(PREF_INITIAL_FILE, PREF_READY_FILENAME_DEFAULT);
|
||||||
|
|
||||||
clearState(prefs);
|
clearState();
|
||||||
|
|
||||||
if ((flashFilename == null)
|
if (flashFilename == PREF_READY_FILENAME_DEFAULT
|
||||||
|| !flashFilename.startsWith(config.getPathBase())) {
|
|| !flashFilename.startsWith(config.getPathBase())
|
||||||
Logger.d("flashUpdate - no valid file to flash found");
|
|| !new File(flashFilename).exists()) {
|
||||||
|
Logger.d("flashUpdate - no valid file to flash found " + flashFilename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// now delete the initial file
|
// now delete the initial file
|
||||||
|
@ -1781,9 +1787,10 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
return timeSnooze;
|
return timeSnooze;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearState(SharedPreferences prefs) {
|
private void clearState() {
|
||||||
prefs.edit().putString(PREF_LATEST_FULL_NAME, PREF_READY_FILENAME_DEFAULT).commit();
|
prefs.edit().putString(PREF_LATEST_FULL_NAME, PREF_READY_FILENAME_DEFAULT).commit();
|
||||||
prefs.edit().putString(PREF_LATEST_DELTA_NAME, PREF_READY_FILENAME_DEFAULT).commit();
|
prefs.edit().putString(PREF_LATEST_DELTA_NAME, PREF_READY_FILENAME_DEFAULT).commit();
|
||||||
|
oldFlashFilename = prefs.getString(PREF_READY_FILENAME_NAME, PREF_READY_FILENAME_DEFAULT);
|
||||||
prefs.edit().putString(PREF_READY_FILENAME_NAME, PREF_READY_FILENAME_DEFAULT).commit();
|
prefs.edit().putString(PREF_READY_FILENAME_NAME, PREF_READY_FILENAME_DEFAULT).commit();
|
||||||
prefs.edit().putLong(PREF_DOWNLOAD_SIZE, -1).commit();
|
prefs.edit().putLong(PREF_DOWNLOAD_SIZE, -1).commit();
|
||||||
prefs.edit().putBoolean(PREF_DELTA_SIGNATURE, false).commit();
|
prefs.edit().putBoolean(PREF_DELTA_SIGNATURE, false).commit();
|
||||||
|
@ -1839,7 +1846,7 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
(new File(config.getPathBase())).mkdir();
|
(new File(config.getPathBase())).mkdir();
|
||||||
(new File(config.getPathFlashAfterUpdate())).mkdir();
|
(new File(config.getPathFlashAfterUpdate())).mkdir();
|
||||||
|
|
||||||
clearState(prefs);
|
clearState();
|
||||||
|
|
||||||
String latestFullBuild = getNewestFullBuild();
|
String latestFullBuild = getNewestFullBuild();
|
||||||
// if we dont even find a build on dl no sense to continue
|
// if we dont even find a build on dl no sense to continue
|
||||||
|
@ -2045,6 +2052,7 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
if (new File(fn).exists()) {
|
if (new File(fn).exists()) {
|
||||||
if (checkFullBuildMd5Sum(latestFullFetch, fn)) {
|
if (checkFullBuildMd5Sum(latestFullFetch, fn)) {
|
||||||
Logger.d("match found (full): " + fn);
|
Logger.d("match found (full): " + fn);
|
||||||
|
deleteOldFlashFile(fn);
|
||||||
prefs.edit().putString(PREF_READY_FILENAME_NAME, fn).commit();
|
prefs.edit().putString(PREF_READY_FILENAME_NAME, fn).commit();
|
||||||
downloadFullBuild = false;
|
downloadFullBuild = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2116,6 +2124,7 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prefs.edit().putBoolean(PREF_DELTA_SIGNATURE, true).commit();
|
prefs.edit().putBoolean(PREF_DELTA_SIGNATURE, true).commit();
|
||||||
|
deleteOldFlashFile(flashFilename);
|
||||||
prefs.edit().putString(PREF_READY_FILENAME_NAME, flashFilename).commit();
|
prefs.edit().putString(PREF_READY_FILENAME_NAME, flashFilename).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2139,7 +2148,7 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
if (isErrorState(state)) {
|
if (isErrorState(state)) {
|
||||||
failedUpdateCount++;
|
failedUpdateCount++;
|
||||||
clearState(prefs);
|
clearState();
|
||||||
if (!userInitiated) {
|
if (!userInitiated) {
|
||||||
shouldShowErrorNotification();
|
shouldShowErrorNotification();
|
||||||
}
|
}
|
||||||
|
@ -2162,4 +2171,28 @@ OnWantUpdateCheckListener, OnSharedPreferenceChangeListener {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteOldFlashFile(String newFlashFilename) {
|
||||||
|
if (oldFlashFilename != PREF_READY_FILENAME_DEFAULT && !oldFlashFilename.equals(newFlashFilename)
|
||||||
|
&& oldFlashFilename.startsWith(config.getPathBase())) {
|
||||||
|
File file = new File(oldFlashFilename);
|
||||||
|
if (file.exists() && file.getName().startsWith(config.getFileBaseNamePrefix())) {
|
||||||
|
Logger.d("delete oldFlashFilename " + oldFlashFilename);
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scanImageFiles() {
|
||||||
|
// for debugging purposes
|
||||||
|
String dataFolder = config.getPathBase();
|
||||||
|
File[] contents = new File(dataFolder).listFiles();
|
||||||
|
if (contents != null) {
|
||||||
|
for (File file : contents) {
|
||||||
|
if (file.isFile() && file.getName().startsWith(config.getFileBaseNamePrefix())) {
|
||||||
|
Logger.d("image file: " + file.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue