Allow to install updates from the notification
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M17 1.01L7 1c-1.1 0-2 .9-2 2v18c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2V3c0-1.1-.9-1.99-2-1.99zM17 19H7V5h10v14zm-1-6h-3V8h-2v5H8l4 4 4-4z" />
|
||||
</vector>
|
||||
@@ -220,6 +220,9 @@ public class DownloadService extends Service {
|
||||
String text = getString(R.string.download_completed_notification);
|
||||
NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle()
|
||||
.setBigContentTitle(text).bigText(update.getName());
|
||||
mNotificationBuilder.addAction(R.drawable.ic_tab_install,
|
||||
getString(R.string.install_button),
|
||||
getResumePendingIntent(update.getDownloadId()));
|
||||
mNotificationBuilder.setStyle(style);
|
||||
mNotificationBuilder.setContentTitle(text);
|
||||
mNotificationBuilder.setTicker(text);
|
||||
@@ -263,4 +266,12 @@ public class DownloadService extends Service {
|
||||
return PendingIntent.getBroadcast(this, 0, intent,
|
||||
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
private PendingIntent getInstallPendingIntent(String downloadId) {
|
||||
final Intent intent = new Intent(this, UpdaterBroadcastReceiver.class);
|
||||
intent.setAction(UpdaterBroadcastReceiver.ACTION_INSTALL_UPDATE);
|
||||
intent.putExtra(UpdaterBroadcastReceiver.EXTRA_DOWNLOAD_ID, downloadId);
|
||||
return PendingIntent.getBroadcast(this, 0, intent,
|
||||
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import org.lineageos.updater.misc.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UpdaterBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String ACTION_DOWNLOAD =
|
||||
@@ -28,6 +32,8 @@ public class UpdaterBroadcastReceiver extends BroadcastReceiver {
|
||||
"org.lineageos.updater.extra.DOWNLOAD_ID";
|
||||
public static final String EXTRA_DOWNLOAD_ACTION =
|
||||
"org.lineageos.updater.extra.DOWNLOAD_CHANGE";
|
||||
public static final String ACTION_INSTALL_UPDATE =
|
||||
"org.lineageos.updater.action.INSTALL_UPDATE";
|
||||
|
||||
public static final int PAUSE = 0;
|
||||
public static final int RESUME = 1;
|
||||
@@ -38,13 +44,17 @@ public class UpdaterBroadcastReceiver extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (ACTION_DOWNLOAD.equals(action)) {
|
||||
if (intent.hasExtra(EXTRA_DOWNLOAD_ACTION) && intent.hasExtra(EXTRA_DOWNLOAD_ID)) {
|
||||
DownloadController downloadController = DownloadController.getInstance();
|
||||
if (downloadController == null) {
|
||||
Log.e(TAG, "No download controller instance found");
|
||||
return;
|
||||
}
|
||||
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
|
||||
if (!intent.hasExtra(EXTRA_DOWNLOAD_ID)) {
|
||||
Log.e(TAG, "Missing download ID");
|
||||
return;
|
||||
}
|
||||
DownloadController downloadController = DownloadController.getInstance();
|
||||
if (downloadController == null) {
|
||||
Log.e(TAG, "No download controller instance found");
|
||||
return;
|
||||
}
|
||||
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
|
||||
if (intent.hasExtra(EXTRA_DOWNLOAD_ACTION)) {
|
||||
int requestedAction = intent.getIntExtra(EXTRA_DOWNLOAD_ACTION, -1);
|
||||
if (requestedAction == PAUSE) {
|
||||
downloadController.pauseDownload(downloadId);
|
||||
@@ -56,6 +66,24 @@ public class UpdaterBroadcastReceiver extends BroadcastReceiver {
|
||||
} else {
|
||||
Log.e(TAG, "Missing extra data");
|
||||
}
|
||||
} else if (ACTION_INSTALL_UPDATE.equals(action)) {
|
||||
if (!intent.hasExtra(EXTRA_DOWNLOAD_ID)) {
|
||||
Log.e(TAG, "Missing download ID");
|
||||
return;
|
||||
}
|
||||
DownloadController downloadController = DownloadController.getInstance();
|
||||
if (downloadController == null) {
|
||||
Log.e(TAG, "No download controller instance found");
|
||||
return;
|
||||
}
|
||||
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
|
||||
UpdateDownload update = downloadController.getUpdate(downloadId);
|
||||
try {
|
||||
Utils.triggerUpdate(context, update);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Could not trigger update");
|
||||
// TODO: show error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user