зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1051654 - Delete APK after update. r=snorp
This commit is contained in:
Родитель
fd0f97fa14
Коммит
8f19e4e615
|
@ -107,6 +107,11 @@ public class UpdateService extends IntentService {
|
|||
} else if (UpdateServiceHelper.ACTION_CANCEL_DOWNLOAD.equals(intent.getAction())) {
|
||||
mCancelDownload = true;
|
||||
} else {
|
||||
if (!UpdateServiceHelper.ACTION_APPLY_UPDATE.equals(intent.getAction())) {
|
||||
// Delete the update package used to install the current version.
|
||||
deleteUpdatePackage(getLastFileName());
|
||||
}
|
||||
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
|
@ -412,8 +417,26 @@ public class UpdateService extends IntentService {
|
|||
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
||||
}
|
||||
|
||||
private boolean deleteUpdatePackage(String path) {
|
||||
if (path == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
File pkg = new File(path);
|
||||
if (!pkg.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pkg.delete();
|
||||
Log.i(LOGTAG, "deleted update package: " + path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private File downloadUpdatePackage(UpdateInfo info, boolean overwriteExisting) {
|
||||
File downloadFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), new File(info.url.getFile()).getName());
|
||||
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||
String fileName = new File(info.url.getFile()).getName();
|
||||
File downloadFile = new File(path, fileName);
|
||||
|
||||
if (!overwriteExisting && info.buildID.equals(getLastBuildID()) && downloadFile.exists()) {
|
||||
// The last saved buildID is the same as the one for the current update. We also have a file
|
||||
|
@ -533,7 +556,7 @@ public class UpdateService extends IntentService {
|
|||
|
||||
private void applyUpdate(String updatePath) {
|
||||
if (updatePath == null) {
|
||||
updatePath = mPrefs.getString(KEY_LAST_FILE_NAME, null);
|
||||
updatePath = getLastFileName();
|
||||
}
|
||||
applyUpdate(new File(updatePath));
|
||||
}
|
||||
|
@ -569,6 +592,10 @@ public class UpdateService extends IntentService {
|
|||
return mPrefs.getString(KEY_LAST_HASH_VALUE, null);
|
||||
}
|
||||
|
||||
private String getLastFileName() {
|
||||
return mPrefs.getString(KEY_LAST_FILE_NAME, null);
|
||||
}
|
||||
|
||||
private Calendar getLastAttemptDate() {
|
||||
long lastAttempt = mPrefs.getLong(KEY_LAST_ATTEMPT_DATE, -1);
|
||||
if (lastAttempt < 0)
|
||||
|
|
Загрузка…
Ссылка в новой задаче