diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b802ce4b..a5822169 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -28,7 +28,6 @@ - diff --git a/src/org/lineageos/updater/DownloadService.java b/src/org/lineageos/updater/DownloadService.java index 84fe144a..1cc1cd42 100644 --- a/src/org/lineageos/updater/DownloadService.java +++ b/src/org/lineageos/updater/DownloadService.java @@ -30,6 +30,9 @@ import android.text.format.DateUtils; import android.text.format.Formatter; import android.util.Log; +import org.lineageos.updater.misc.Utils; + +import java.io.IOException; import java.text.NumberFormat; public class DownloadService extends Service { @@ -39,6 +42,7 @@ public class DownloadService extends Service { public static final String ACTION_DOWNLOAD_CONTROL = "action_download_control"; public static final String EXTRA_DOWNLOAD_ID = "extra_download_id"; public static final String EXTRA_DOWNLOAD_CONTROL = "extra_download_control"; + public static final String ACTION_INSTALL_UPDATE = "action_install_update"; public static final int DOWNLOAD_RESUME = 0; public static final int DOWNLOAD_PAUSE = 1; @@ -152,6 +156,14 @@ public class DownloadService extends Service { } else { Log.e(TAG, "Unknown download action"); } + } else if (ACTION_INSTALL_UPDATE.equals(intent.getAction())) { + String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID); + try { + Utils.triggerUpdate(this, mDownloadController.getUpdate(downloadId)); + } catch (IOException e) { + Log.e(TAG, "Could not install update"); + // TODO: user facing message + } } Log.d(TAG, "Service started"); return START_STICKY; @@ -285,10 +297,10 @@ public class DownloadService extends Service { } 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, + final Intent intent = new Intent(this, DownloadService.class); + intent.setAction(ACTION_INSTALL_UPDATE); + intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId); + return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); } } diff --git a/src/org/lineageos/updater/UpdaterBroadcastReceiver.java b/src/org/lineageos/updater/UpdaterBroadcastReceiver.java deleted file mode 100644 index 2cfec876..00000000 --- a/src/org/lineageos/updater/UpdaterBroadcastReceiver.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2017 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.lineageos.updater; - -import android.content.BroadcastReceiver; -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 EXTRA_DOWNLOAD_ID = - "org.lineageos.updater.extra.DOWNLOAD_ID"; - public static final String ACTION_INSTALL_UPDATE = - "org.lineageos.updater.action.INSTALL_UPDATE"; - - private final static String TAG = "BroadcastReceiver"; - - @Override - public void onReceive(Context context, Intent intent) { - final String action = intent.getAction(); - if (ACTION_INSTALL_UPDATE.equals(action)) { - if (!intent.hasExtra(EXTRA_DOWNLOAD_ID)) { - Log.e(TAG, "Missing download ID"); - return; - } - DownloadController downloadController = DownloadController.getInstance(context); - 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 - } - } - } -}