Updater: Add notification channels

Change-Id: I2f538fb47fe90e1008bf286739d33c829123353a
This commit is contained in:
Harry Youd
2017-09-27 22:33:00 +01:00
committed by LuK1337
parent 0e79b791f0
commit ff53035537
4 changed files with 39 additions and 5 deletions

View File

@@ -127,4 +127,8 @@
<string name="blocked_update_dialog_title">Update blocked</string> <string name="blocked_update_dialog_title">Update blocked</string>
<string name="blocked_update_dialog_message">This update cannot be installed using the updater app. Please read <xliff:g id="info_url">%1$s</xliff:g> for more information.</string> <string name="blocked_update_dialog_message">This update cannot be installed using the updater app. Please read <xliff:g id="info_url">%1$s</xliff:g> for more information.</string>
<string name="blocked_update_info_url" translatable="false">http://wiki.lineageos.org/upgrading.html</string> <string name="blocked_update_info_url" translatable="false">http://wiki.lineageos.org/upgrading.html</string>
<string name="export_channel_title">Export completion</string>
<string name="new_updates_channel_title">New updates</string>
<string name="ongoing_channel_title">Ongoing downloads</string>
</resources> </resources>

View File

@@ -15,6 +15,7 @@
*/ */
package org.lineageos.updater; package org.lineageos.updater;
import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
@@ -43,6 +44,9 @@ public class ExportUpdateService extends Service {
public static final String EXTRA_SOURCE_FILE = "source_file"; public static final String EXTRA_SOURCE_FILE = "source_file";
public static final String EXTRA_DEST_FILE = "dest_file"; public static final String EXTRA_DEST_FILE = "dest_file";
private static final String EXPORT_NOTIFICATION_CHANNEL =
"export_notification_channel";
private volatile boolean mIsExporting = false; private volatile boolean mIsExporting = false;
private Thread mExportThread; private Thread mExportThread;
@@ -133,8 +137,14 @@ public class ExportUpdateService extends Service {
private void startExporting(File source, File destination) { private void startExporting(File source, File destination) {
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE); (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationChannel notificationChannel = new NotificationChannel(
EXPORT_NOTIFICATION_CHANNEL,
getString(R.string.export_channel_title),
NotificationManager.IMPORTANCE_LOW);
notificationManager.createNotificationChannel(notificationChannel);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,
EXPORT_NOTIFICATION_CHANNEL);
NotificationCompat.BigTextStyle notificationStyle = new NotificationCompat.BigTextStyle(); NotificationCompat.BigTextStyle notificationStyle = new NotificationCompat.BigTextStyle();
notificationBuilder.setContentTitle(getString(R.string.dialog_export_title)); notificationBuilder.setContentTitle(getString(R.string.dialog_export_title));
notificationStyle.setBigContentTitle(getString(R.string.dialog_export_title)); notificationStyle.setBigContentTitle(getString(R.string.dialog_export_title));

View File

@@ -16,6 +16,7 @@
package org.lineageos.updater; package org.lineageos.updater;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@@ -24,7 +25,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.SystemClock; import android.os.SystemClock;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import org.json.JSONException; import org.json.JSONException;
@@ -46,6 +47,9 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
private static final String DAILY_CHECK_ACTION = "daily_check_action"; private static final String DAILY_CHECK_ACTION = "daily_check_action";
private static final String ONESHOT_CHECK_ACTION = "oneshot_check_action"; private static final String ONESHOT_CHECK_ACTION = "oneshot_check_action";
private static final String NEW_UPDATES_NOTIFICATION_CHANNEL =
"new_updates_notification_channel";
@Override @Override
public void onReceive(final Context context, Intent intent) { public void onReceive(final Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
@@ -121,7 +125,12 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
private static void showNotification(Context context) { private static void showNotification(Context context) {
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); NotificationChannel notificationChannel = new NotificationChannel(
NEW_UPDATES_NOTIFICATION_CHANNEL,
context.getString(R.string.new_updates_channel_title),
NotificationManager.IMPORTANCE_LOW);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,
NEW_UPDATES_NOTIFICATION_CHANNEL);
notificationBuilder.setSmallIcon(R.drawable.ic_system_update); notificationBuilder.setSmallIcon(R.drawable.ic_system_update);
Intent notificationIntent = new Intent(context, UpdatesActivity.class); Intent notificationIntent = new Intent(context, UpdatesActivity.class);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
@@ -129,6 +138,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
notificationBuilder.setContentIntent(intent); notificationBuilder.setContentIntent(intent);
notificationBuilder.setContentTitle(context.getString(R.string.new_updates_found_title)); notificationBuilder.setContentTitle(context.getString(R.string.new_updates_found_title));
notificationBuilder.setAutoCancel(true); notificationBuilder.setAutoCancel(true);
notificationManager.createNotificationChannel(notificationChannel);
notificationManager.notify(0, notificationBuilder.build()); notificationManager.notify(0, notificationBuilder.build());
} }

View File

@@ -15,6 +15,7 @@
*/ */
package org.lineageos.updater.controller; package org.lineageos.updater.controller;
import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
@@ -25,8 +26,8 @@ import android.content.IntentFilter;
import android.os.Binder; import android.os.Binder;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.util.Log; import android.util.Log;
@@ -53,6 +54,9 @@ public class UpdaterService extends Service {
public static final String ACTION_INSTALL_UPDATE = "action_install_update"; public static final String ACTION_INSTALL_UPDATE = "action_install_update";
public static final String ACTION_INSTALL_STOP = "action_install_stop"; public static final String ACTION_INSTALL_STOP = "action_install_stop";
private static final String ONGOING_NOTIFICATION_CHANNEL =
"ongoing_notification_channel";
public static final int DOWNLOAD_RESUME = 0; public static final int DOWNLOAD_RESUME = 0;
public static final int DOWNLOAD_PAUSE = 1; public static final int DOWNLOAD_PAUSE = 1;
@@ -75,7 +79,13 @@ public class UpdaterService extends Service {
mUpdaterController = UpdaterController.getInstance(this); mUpdaterController = UpdaterController.getInstance(this);
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationBuilder = new NotificationCompat.Builder(this); NotificationChannel notificationChannel = new NotificationChannel(
ONGOING_NOTIFICATION_CHANNEL,
getString(R.string.ongoing_channel_title),
NotificationManager.IMPORTANCE_LOW);
mNotificationManager.createNotificationChannel(notificationChannel);
mNotificationBuilder = new NotificationCompat.Builder(this,
ONGOING_NOTIFICATION_CHANNEL);
mNotificationBuilder.setSmallIcon(R.drawable.ic_system_update); mNotificationBuilder.setSmallIcon(R.drawable.ic_system_update);
mNotificationBuilder.setShowWhen(false); mNotificationBuilder.setShowWhen(false);
mNotificationStyle = new NotificationCompat.BigTextStyle(); mNotificationStyle = new NotificationCompat.BigTextStyle();