diff options
-rw-r--r-- | res/values-ar/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-ast-rES/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-cy/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-de/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-el/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-en-rAU/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-en-rIN/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-et/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-it/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-ro/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-ru/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-sl/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-tr/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values-zh-rCN/cm_strings.xml | 2 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 3 | ||||
-rw-r--r-- | src/com/android/messaging/datamodel/BugleNotifications.java | 31 | ||||
-rw-r--r-- | src/com/android/messaging/datamodel/action/ActionServiceImpl.java | 32 | ||||
-rw-r--r-- | src/com/android/messaging/datamodel/action/BackgroundWorkerService.java | 27 | ||||
-rw-r--r-- | src/org/lineageos/messaging/util/NotifUtils.java | 45 |
19 files changed, 101 insertions, 65 deletions
diff --git a/res/values-ar/cm_strings.xml b/res/values-ar/cm_strings.xml index a90ecd3..54c539a 100644 --- a/res/values-ar/cm_strings.xml +++ b/res/values-ar/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">تاشير كمقروء</string> <!-- Notification channel --> - <string name="notification_channel_title">الرسائل</string> + <string name="notification_channel_messages_title">الرسائل</string> <string name="background_worker_notif">يتم فحص الرسائل</string> </resources> diff --git a/res/values-ast-rES/cm_strings.xml b/res/values-ast-rES/cm_strings.xml index 789bb41..1881b7e 100644 --- a/res/values-ast-rES/cm_strings.xml +++ b/res/values-ast-rES/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Marcar como lleíu</string> <!-- Notification channel --> - <string name="notification_channel_title">Mensaxes</string> + <string name="notification_channel_messages_title">Mensaxes</string> <string name="background_worker_notif">Verificando mensaxes\u2026</string> </resources> diff --git a/res/values-cy/cm_strings.xml b/res/values-cy/cm_strings.xml index 37dc4bb..50d6381 100644 --- a/res/values-cy/cm_strings.xml +++ b/res/values-cy/cm_strings.xml @@ -29,6 +29,6 @@ <string name="mediapicker_audio_list_item_unselected_content_description">Tara i ddewis</string> <!-- Mark message as read --> <!-- Notification channel --> - <string name="notification_channel_title">Negeseuon</string> + <string name="notification_channel_messages_title">Negeseuon</string> <string name="background_worker_notif">Yn gwirio negeseuon\u2026</string> </resources> diff --git a/res/values-de/cm_strings.xml b/res/values-de/cm_strings.xml index 9ec9f1e..536d2dc 100644 --- a/res/values-de/cm_strings.xml +++ b/res/values-de/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Als gelesen markieren</string> <!-- Notification channel --> - <string name="notification_channel_title">Nachrichten</string> + <string name="notification_channel_messages_title">Nachrichten</string> <string name="background_worker_notif">Prüfe auf Nachrichten\u2026</string> </resources> diff --git a/res/values-el/cm_strings.xml b/res/values-el/cm_strings.xml index 8e56051..abb8876 100644 --- a/res/values-el/cm_strings.xml +++ b/res/values-el/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Σήμανση ως αναγνωσμένο</string> <!-- Notification channel --> - <string name="notification_channel_title">Μηνύματα</string> + <string name="notification_channel_messages_title">Μηνύματα</string> <string name="background_worker_notif">Έλεγχος μηνυμάτων\u2026</string> </resources> diff --git a/res/values-en-rAU/cm_strings.xml b/res/values-en-rAU/cm_strings.xml index 7e957f5..893862c 100644 --- a/res/values-en-rAU/cm_strings.xml +++ b/res/values-en-rAU/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Mark as read</string> <!-- Notification channel --> - <string name="notification_channel_title">Messages</string> + <string name="notification_channel_messages_title">Messages</string> <string name="background_worker_notif">Checking messages\u2026</string> </resources> diff --git a/res/values-en-rIN/cm_strings.xml b/res/values-en-rIN/cm_strings.xml index 7e957f5..893862c 100644 --- a/res/values-en-rIN/cm_strings.xml +++ b/res/values-en-rIN/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Mark as read</string> <!-- Notification channel --> - <string name="notification_channel_title">Messages</string> + <string name="notification_channel_messages_title">Messages</string> <string name="background_worker_notif">Checking messages\u2026</string> </resources> diff --git a/res/values-et/cm_strings.xml b/res/values-et/cm_strings.xml index 155b9b7..54950a2 100644 --- a/res/values-et/cm_strings.xml +++ b/res/values-et/cm_strings.xml @@ -22,6 +22,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Märgi loetuks</string> <!-- Notification channel --> - <string name="notification_channel_title">Sõnumid</string> + <string name="notification_channel_messages_title">Sõnumid</string> <string name="background_worker_notif">Sõnumite kontrollimine\u2026</string> </resources> diff --git a/res/values-it/cm_strings.xml b/res/values-it/cm_strings.xml index 015dfff..b4592df 100644 --- a/res/values-it/cm_strings.xml +++ b/res/values-it/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Segna come letto</string> <!-- Notification channel --> - <string name="notification_channel_title">Messaggi</string> + <string name="notification_channel_messages_title">Messaggi</string> <string name="background_worker_notif">Controllo messaggi\u2026</string> </resources> diff --git a/res/values-ro/cm_strings.xml b/res/values-ro/cm_strings.xml index 03c05b2..4f310c0 100644 --- a/res/values-ro/cm_strings.xml +++ b/res/values-ro/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Marchează ca citit</string> <!-- Notification channel --> - <string name="notification_channel_title">Mesaje</string> + <string name="notification_channel_messages_title">Mesaje</string> <string name="background_worker_notif">Verificarea mesajelor\u2026</string> </resources> diff --git a/res/values-ru/cm_strings.xml b/res/values-ru/cm_strings.xml index c1ea343..0a9c4f3 100644 --- a/res/values-ru/cm_strings.xml +++ b/res/values-ru/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Прочитано</string> <!-- Notification channel --> - <string name="notification_channel_title">Сообщения</string> + <string name="notification_channel_messages_title">Сообщения</string> <string name="background_worker_notif">Проверка сообщений\u2026</string> </resources> diff --git a/res/values-sl/cm_strings.xml b/res/values-sl/cm_strings.xml index 287b4e8..a1c49e0 100644 --- a/res/values-sl/cm_strings.xml +++ b/res/values-sl/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Označi kot prebrano</string> <!-- Notification channel --> - <string name="notification_channel_title">Sporočila</string> + <string name="notification_channel_messages_title">Sporočila</string> <string name="background_worker_notif">Preverjanje sporočil \u2026</string> </resources> diff --git a/res/values-tr/cm_strings.xml b/res/values-tr/cm_strings.xml index ced88d2..c700d70 100644 --- a/res/values-tr/cm_strings.xml +++ b/res/values-tr/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">Okundu olarak işaretle</string> <!-- Notification channel --> - <string name="notification_channel_title">Mesajlar</string> + <string name="notification_channel_messages_title">Mesajlar</string> <string name="background_worker_notif">Mesaj gönderiliyor\u2026</string> </resources> diff --git a/res/values-zh-rCN/cm_strings.xml b/res/values-zh-rCN/cm_strings.xml index 47d2923..415fc3c 100644 --- a/res/values-zh-rCN/cm_strings.xml +++ b/res/values-zh-rCN/cm_strings.xml @@ -33,6 +33,6 @@ <!-- Mark message as read --> <string name="notification_mark_as_read">标记为已读</string> <!-- Notification channel --> - <string name="notification_channel_title">短信</string> + <string name="notification_channel_messages_title">短信</string> <string name="background_worker_notif">正在检查信息\u2026</string> </resources> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 1c902a7..8fbcbc6 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -36,6 +36,7 @@ <string name="notification_mark_as_read">Mark as read</string> <!-- Notification channel --> - <string name="notification_channel_title">Messages</string> + <string name="notification_channel_messages_title">Messages</string> + <string name="notification_channel_processing_title">Background operations</string> <string name="background_worker_notif">Checking messages\u2026</string> </resources> diff --git a/src/com/android/messaging/datamodel/BugleNotifications.java b/src/com/android/messaging/datamodel/BugleNotifications.java index 2127d81..52f81b4 100644 --- a/src/com/android/messaging/datamodel/BugleNotifications.java +++ b/src/com/android/messaging/datamodel/BugleNotifications.java @@ -17,7 +17,6 @@ package com.android.messaging.datamodel; import android.app.Notification; -import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; @@ -83,6 +82,8 @@ import com.android.messaging.util.RingtoneUtil; import com.android.messaging.util.ThreadUtil; import com.android.messaging.util.UriUtil; +import org.lineageos.messaging.util.NotifUtils; + import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -1003,8 +1004,11 @@ public class BugleNotifications { notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; - createChannel(); - + Context context = Factory.get().getApplicationContext(); + NotifUtils.createNotificationChannel(context, + CHANNEL_ID, + R.string.notification_channel_messages_title, + NotificationManager.IMPORTANCE_DEFAULT); notificationManager.notify(notificationTag, type, notification); LogUtil.i(TAG, "Notifying for conversation " + conversationId + "; " @@ -1244,25 +1248,14 @@ public class BugleNotifications { .setSound(UriUtil.getUriForResourceId(context, R.raw.message_failure)); final String tag = context.getPackageName() + ":emergency_sms_error"; - createChannel(); + + NotifUtils.createNotificationChannel(context, + CHANNEL_ID, + R.string.notification_channel_messages_title, + NotificationManager.IMPORTANCE_DEFAULT); NotificationManagerCompat.from(context).notify( tag, PendingIntentConstants.MSG_SEND_ERROR, builder.build()); } - - private static void createChannel() { - Context context = Factory.get().getApplicationContext(); - NotificationManager manager = context.getSystemService(NotificationManager.class); - - NotificationChannel existing = manager.getNotificationChannel(CHANNEL_ID); - if (existing != null) { - return; - } - - String title = context.getString(R.string.notification_channel_title); - NotificationChannel newChannel = new NotificationChannel(CHANNEL_ID, - title, NotificationManager.IMPORTANCE_DEFAULT); - manager.createNotificationChannel(newChannel); - } } diff --git a/src/com/android/messaging/datamodel/action/ActionServiceImpl.java b/src/com/android/messaging/datamodel/action/ActionServiceImpl.java index b410bf7..ee8b130 100644 --- a/src/com/android/messaging/datamodel/action/ActionServiceImpl.java +++ b/src/com/android/messaging/datamodel/action/ActionServiceImpl.java @@ -19,7 +19,6 @@ package com.android.messaging.datamodel.action; import android.app.AlarmManager; import android.app.IntentService; import android.app.Notification; -import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; @@ -38,12 +37,17 @@ import com.android.messaging.util.LoggingTimer; import com.android.messaging.util.WakeLockHelper; import com.google.common.annotations.VisibleForTesting; +import org.lineageos.messaging.util.NotifUtils; + +import com.android.messaging.R; + /** * ActionService used to perform background processing for data model */ public class ActionServiceImpl extends IntentService { private static final String TAG = LogUtil.BUGLE_DATAMODEL_TAG; private static final boolean VERBOSE = false; + private static final String CHANNEL_ID = "processing_channel"; public ActionServiceImpl() { super("ActionService"); @@ -213,18 +217,22 @@ public class ActionServiceImpl extends IntentService { super.onCreate(); mBackgroundWorker = DataModel.get().getBackgroundWorkerForActionService(); DataModel.get().getConnectivityUtil().registerForSignalStrength(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - String CHANNEL_ID = "my_channel_01"; - NotificationChannel channel = new NotificationChannel(CHANNEL_ID, - "Channel human readable title 1", - NotificationManager.IMPORTANCE_DEFAULT); - ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel); - Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID) - .setContentTitle("") - .setContentText("").build(); - int NOTIFICATION_ID = (int) (System.currentTimeMillis()%10000); - startForeground(NOTIFICATION_ID, notification); + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + return; } + + Context context = Factory.get().getApplicationContext(); + NotifUtils.createNotificationChannel(context, + CHANNEL_ID, + R.string.notification_channel_processing_title, + NotificationManager.IMPORTANCE_MIN); + Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID) + .setContentTitle(context.getString(R.string.background_worker_notif)) + .setSmallIcon(R.drawable.ic_sms_light) + .build(); + int notificationId = (int) (System.currentTimeMillis() % 10000); + startForeground(notificationId, notification); } @Override diff --git a/src/com/android/messaging/datamodel/action/BackgroundWorkerService.java b/src/com/android/messaging/datamodel/action/BackgroundWorkerService.java index 4107ae8..a84a783 100644 --- a/src/com/android/messaging/datamodel/action/BackgroundWorkerService.java +++ b/src/com/android/messaging/datamodel/action/BackgroundWorkerService.java @@ -19,7 +19,6 @@ package com.android.messaging.datamodel.action; import android.app.IntentService; import android.app.IntentService; import android.app.Notification; -import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; @@ -37,6 +36,8 @@ import com.android.messaging.util.LoggingTimer; import com.android.messaging.util.WakeLockHelper; import com.google.common.annotations.VisibleForTesting; +import org.lineageos.messaging.util.NotifUtils; + import java.util.List; import com.android.messaging.R; @@ -49,7 +50,7 @@ import com.android.messaging.R; public class BackgroundWorkerService extends IntentService { private static final String TAG = LogUtil.BUGLE_DATAMODEL_TAG; private static final boolean VERBOSE = false; - private static final String CHANNEL_ID = "messaging_channel"; + private static final String CHANNEL_ID = "processing_channel"; private static final String WAKELOCK_ID = "bugle_background_worker_wakelock"; @VisibleForTesting @@ -117,14 +118,17 @@ public class BackgroundWorkerService extends IntentService { return; } - createChannel(); Context context = Factory.get().getApplicationContext(); + NotifUtils.createNotificationChannel(context, + CHANNEL_ID, + R.string.notification_channel_processing_title, + NotificationManager.IMPORTANCE_MIN); Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle(context.getString(R.string.background_worker_notif)) + .setSmallIcon(R.drawable.ic_sms_light) .build(); int notifId = (int) System.currentTimeMillis() % 10000; startForeground(notifId, notification); - } @Override @@ -195,19 +199,4 @@ public class BackgroundWorkerService extends IntentService { } } } - - private void createChannel() { - NotificationManager manager = getSystemService(NotificationManager.class); - - NotificationChannel existing = manager.getNotificationChannel(CHANNEL_ID); - if (existing != null) { - return; - } - - Context context = Factory.get().getApplicationContext(); - String title = context.getString(R.string.notification_channel_title); - NotificationChannel newChannel = new NotificationChannel(CHANNEL_ID, - title, NotificationManager.IMPORTANCE_DEFAULT); - manager.createNotificationChannel(newChannel); - } } diff --git a/src/org/lineageos/messaging/util/NotifUtils.java b/src/org/lineageos/messaging/util/NotifUtils.java new file mode 100644 index 0000000..87890c0 --- /dev/null +++ b/src/org/lineageos/messaging/util/NotifUtils.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2019 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.messaging.util; + +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.os.Build; + +public final class NotifUtils { + + private NotifUtils() { + } + + public static void createNotificationChannel(Context context, String id, + int titleResId, int priority) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + return; + } + + NotificationManager manager = context.getSystemService(NotificationManager.class); + NotificationChannel existing = manager.getNotificationChannel(id); + if (existing != null) { + return; + } + + String title = context.getString(titleResId); + NotificationChannel newChannel = new NotificationChannel(id, title, priority); + manager.createNotificationChannel(newChannel); + } +} |