Add option to delete updates when installed
This is mostly useful on encrypted devices since it allows to not copy the update before installing it.
This commit is contained in:
@@ -12,4 +12,9 @@
|
|||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:title="@string/menu_auto_updates_check"
|
android:title="@string/menu_auto_updates_check"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_auto_delete_updates"
|
||||||
|
android:checkable="true"
|
||||||
|
android:title="@string/menu_auto_delete_updates"
|
||||||
|
app:showAsAction="never" />
|
||||||
</menu>
|
</menu>
|
||||||
|
@@ -55,6 +55,7 @@
|
|||||||
|
|
||||||
<string name="menu_refresh">Refresh</string>
|
<string name="menu_refresh">Refresh</string>
|
||||||
<string name="menu_auto_updates_check">Auto updates check</string>
|
<string name="menu_auto_updates_check">Auto updates check</string>
|
||||||
|
<string name="menu_auto_delete_updates">Delete updates when installed</string>
|
||||||
<string name="menu_delete_update">Delete</string>
|
<string name="menu_delete_update">Delete</string>
|
||||||
<string name="menu_copy_url">Copy URL</string>
|
<string name="menu_copy_url">Copy URL</string>
|
||||||
<string name="menu_export_update">Export update</string>
|
<string name="menu_export_update">Export update</string>
|
||||||
|
@@ -180,10 +180,11 @@ public class UpdatesActivity extends UpdatesListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_refresh:
|
case R.id.menu_refresh: {
|
||||||
downloadUpdatesList(true);
|
downloadUpdatesList(true);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_auto_updates_check:
|
}
|
||||||
|
case R.id.menu_auto_updates_check: {
|
||||||
boolean enable = !item.isChecked();
|
boolean enable = !item.isChecked();
|
||||||
item.setChecked(enable);
|
item.setChecked(enable);
|
||||||
PreferenceManager.getDefaultSharedPreferences(UpdatesActivity.this)
|
PreferenceManager.getDefaultSharedPreferences(UpdatesActivity.this)
|
||||||
@@ -198,6 +199,16 @@ public class UpdatesActivity extends UpdatesListActivity {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case R.id.menu_auto_delete_updates: {
|
||||||
|
boolean enable = !item.isChecked();
|
||||||
|
item.setChecked(enable);
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(UpdatesActivity.this)
|
||||||
|
.edit()
|
||||||
|
.putBoolean(Constants.PREF_AUTO_DELETE_UPDATES, enable)
|
||||||
|
.apply();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,8 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.lineageos.updater.controller;
|
package org.lineageos.updater.controller;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.os.UpdateEngine;
|
import android.os.UpdateEngine;
|
||||||
import android.os.UpdateEngineCallback;
|
import android.os.UpdateEngineCallback;
|
||||||
|
import android.support.v7.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.lineageos.updater.misc.Constants;
|
import org.lineageos.updater.misc.Constants;
|
||||||
@@ -42,6 +44,7 @@ class ABUpdateInstaller {
|
|||||||
|
|
||||||
private final UpdaterController mUpdaterController;
|
private final UpdaterController mUpdaterController;
|
||||||
private final String mDownloadId;
|
private final String mDownloadId;
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
private final UpdateEngineCallback mUpdateEngineCallback = new UpdateEngineCallback() {
|
private final UpdateEngineCallback mUpdateEngineCallback = new UpdateEngineCallback() {
|
||||||
|
|
||||||
@@ -86,15 +89,21 @@ class ABUpdateInstaller {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean deleteUpdate = PreferenceManager.getDefaultSharedPreferences(mContext)
|
||||||
|
.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, false);
|
||||||
|
if (deleteUpdate) {
|
||||||
|
mUpdaterController.deleteUpdate(mDownloadId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static synchronized boolean start(UpdaterController updaterController,
|
static synchronized boolean start(Context context, UpdaterController updaterController,
|
||||||
String downloadId) {
|
String downloadId) {
|
||||||
if (sDownloadId != null) {
|
if (sDownloadId != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ABUpdateInstaller installer = new ABUpdateInstaller(updaterController, downloadId);
|
ABUpdateInstaller installer = new ABUpdateInstaller(context, updaterController, downloadId);
|
||||||
if (installer.startUpdate()) {
|
if (installer.startUpdate()) {
|
||||||
sDownloadId = downloadId;
|
sDownloadId = downloadId;
|
||||||
return true;
|
return true;
|
||||||
@@ -110,9 +119,11 @@ class ABUpdateInstaller {
|
|||||||
return sDownloadId != null && sDownloadId.equals(downloadId);
|
return sDownloadId != null && sDownloadId.equals(downloadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ABUpdateInstaller(UpdaterController updaterController, String downloadId) {
|
private ABUpdateInstaller(Context context, UpdaterController updaterController,
|
||||||
|
String downloadId) {
|
||||||
mUpdaterController = updaterController;
|
mUpdaterController = updaterController;
|
||||||
mDownloadId = downloadId;
|
mDownloadId = downloadId;
|
||||||
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean startUpdate() {
|
private boolean startUpdate() {
|
||||||
|
@@ -27,6 +27,7 @@ import android.os.Bundle;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.app.NotificationCompat;
|
import android.support.v7.app.NotificationCompat;
|
||||||
|
import android.support.v7.preference.PreferenceManager;
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -170,9 +171,17 @@ public class UpdaterService extends Service {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (Utils.isABUpdate(update.getFile())) {
|
if (Utils.isABUpdate(update.getFile())) {
|
||||||
ABUpdateInstaller.start(mUpdaterController, downloadId);
|
ABUpdateInstaller.start(this, mUpdaterController, downloadId);
|
||||||
} else {
|
} else {
|
||||||
if (update.getFile().getAbsolutePath().startsWith("/data/") &&
|
boolean deleteUpdate = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, false);
|
||||||
|
if (deleteUpdate) {
|
||||||
|
// Renaming the file is enough to have it deleted automatically
|
||||||
|
File uncrytpFile = new File(
|
||||||
|
update.getFile().getAbsolutePath() + Constants.UNCRYPT_FILE_EXT);
|
||||||
|
update.getFile().renameTo(uncrytpFile);
|
||||||
|
installPackage(uncrytpFile);
|
||||||
|
} else if (update.getFile().getAbsolutePath().startsWith("/data/") &&
|
||||||
Utils.isDeviceEncrypted(this)) {
|
Utils.isDeviceEncrypted(this)) {
|
||||||
// uncrypt rewrites the file so that it can be read without mounting
|
// uncrypt rewrites the file so that it can be read without mounting
|
||||||
// the filesystem, so create a copy of it.
|
// the filesystem, so create a copy of it.
|
||||||
|
@@ -25,6 +25,7 @@ public final class Constants {
|
|||||||
|
|
||||||
public static final String PREF_LAST_UPDATE_CHECK = "last_update_check";
|
public static final String PREF_LAST_UPDATE_CHECK = "last_update_check";
|
||||||
public static final String PREF_AUTO_UPDATES_CHECK = "auto_updates_check";
|
public static final String PREF_AUTO_UPDATES_CHECK = "auto_updates_check";
|
||||||
|
public static final String PREF_AUTO_DELETE_UPDATES = "auto_delete_updates";
|
||||||
|
|
||||||
public static final String UNCRYPT_FILE_EXT = ".uncrypt";
|
public static final String UNCRYPT_FILE_EXT = ".uncrypt";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user