Commit 4a410c70 authored by Greyson Parrelli's avatar Greyson Parrelli Committed by Bastien Le Querrec
Browse files

Add notification channel support.

Bucket our notifications into channels. Required to target API 26.

Upstream commit: https://github.com/WhisperSystems/Signal-Android/commit/dbd42c4af2a95feb9a1bc45ca352e4c122157d0f

Fixes #489
parent 9f044d71
......@@ -387,6 +387,12 @@
</intent-filter>
</receiver>
<receiver android:name=".notifications.LocaleChangedReceiver">
<intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED"/>
</intent-filter>
</receiver>
<receiver android:name=".notifications.MessageNotifier$ReminderReceiver">
<intent-filter>
<action android:name="org.smssecure.smssecure.MessageNotifier.REMINDER_ACTION"/>
......
......@@ -440,6 +440,12 @@
<string name="MessageNotifier_message_received">Message received by %s.</string>
<string name="MessageNotifier_reply">Reply</string>
<!-- Notification Channels -->
<string name="NotificationChannel_messages">Messages</string>
<string name="NotificationChannel_failures">Failures</string>
<string name="NotificationChannel_locked_status">Locked status</string>
<string name="NotificationChannel_other">Other</string>
<!-- QuickResponseService -->
<string name="QuickResponseService_quick_response_unavailable_when_Silence_is_locked">Quick response unavailable when Silence is locked!</string>
<string name="QuickResponseService_problem_sending_message">Problem sending message!</string>
......
......@@ -17,14 +17,19 @@
package org.smssecure.smssecure;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.support.v4.app.NotificationManagerCompat;
import org.smssecure.smssecure.crypto.PRNGFixes;
import org.smssecure.smssecure.dependencies.InjectableType;
import org.smssecure.smssecure.jobs.persistence.EncryptingJobSerializer;
import org.smssecure.smssecure.jobs.requirements.MasterSecretRequirementProvider;
import org.smssecure.smssecure.jobs.requirements.MediaNetworkRequirementProvider;
import org.smssecure.smssecure.jobs.requirements.ServiceRequirementProvider;
import org.smssecure.smssecure.notifications.NotificationChannels;
import org.smssecure.smssecure.util.SilencePreferences;
import org.whispersystems.jobqueue.JobManager;
import org.whispersystems.jobqueue.dependencies.DependencyInjector;
......@@ -61,6 +66,7 @@ public class ApplicationContext extends Application implements DependencyInjecto
initializeRandomNumberFix();
initializeLogging();
initializeJobManager();
NotificationChannels.create(this);
}
@Override
......
......@@ -13,6 +13,7 @@ import android.support.annotation.NonNull;
import android.support.v4.app.NotificationCompat;
import org.smssecure.smssecure.BaseActionBarActivity;
import org.smssecure.smssecure.notifications.NotificationChannels;
import org.smssecure.smssecure.R;
import org.smssecure.smssecure.permissions.Permissions;
import org.smssecure.smssecure.util.ServiceUtil;
......@@ -103,7 +104,7 @@ public class WelcomeActivity extends BaseActionBarActivity {
private static void displayPermissionsNotification(Context context) {
Intent targetIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
Notification notification = new NotificationCompat.Builder(context)
Notification notification = new NotificationCompat.Builder(context, NotificationChannels.OTHER)
.setPriority(Notification.PRIORITY_MAX)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.icon_notification)
......
......@@ -29,6 +29,8 @@ public abstract class AbstractNotificationBuilder extends NotificationCompat.Bui
this.context = context;
this.privacy = privacy;
setChannelId(NotificationChannels.MESSAGES);
}
protected CharSequence getStyledMessage(@NonNull Recipient recipient, @Nullable CharSequence message) {
......
......@@ -24,6 +24,7 @@ public class FailedNotificationBuilder extends AbstractNotificationBuilder {
setAutoCancel(true);
setAudibleAlarms(null, RecipientPreferenceDatabase.VibrateState.DEFAULT);
setVisualAlarms();
setChannelId(NotificationChannels.FAILURES);
}
......
package org.smssecure.smssecure.notifications;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class LocaleChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationChannels.create(context);
}
}
package org.smssecure.smssecure.notifications;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import org.smssecure.smssecure.BuildConfig;
import org.smssecure.smssecure.R;
import java.util.Arrays;
public class NotificationChannels {
public static String MESSAGES = "messages";
public static String FAILURES = "failures";
public static String LOCKED_STATUS = "locked_status";
public static String OTHER = "other";
/**
* Ensures all of the notification channels are created. No harm in repeat calls. Call is safely
* ignored for API < 26.
*/
public static void create(@NonNull Context context) {
if (Build.VERSION.SDK_INT < 26) {
return;
}
NotificationChannel messages = new NotificationChannel(MESSAGES, context.getString(R.string.NotificationChannel_messages), NotificationManager.IMPORTANCE_HIGH);
NotificationChannel failures = new NotificationChannel(FAILURES, context.getString(R.string.NotificationChannel_failures), NotificationManager.IMPORTANCE_HIGH);
NotificationChannel lockedStatus = new NotificationChannel(LOCKED_STATUS, context.getString(R.string.NotificationChannel_locked_status), NotificationManager.IMPORTANCE_LOW);
NotificationChannel other = new NotificationChannel(OTHER, context.getString(R.string.NotificationChannel_other), NotificationManager.IMPORTANCE_LOW);
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannels(Arrays.asList(messages, failures, lockedStatus, other));
}
}
......@@ -22,6 +22,7 @@ import org.smssecure.smssecure.R;
import org.smssecure.smssecure.crypto.MasterSecret;
import org.smssecure.smssecure.database.SmsMigrator;
import org.smssecure.smssecure.database.SmsMigrator.ProgressDescription;
import org.smssecure.smssecure.notifications.NotificationChannels;
import java.lang.ref.WeakReference;
import java.util.concurrent.Executor;
......@@ -126,7 +127,7 @@ public class ApplicationMigrationService extends Service
}
private NotificationCompat.Builder initializeBackgroundNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationChannels.OTHER);
builder.setSmallIcon(R.drawable.icon_notification);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon_notification));
......@@ -186,7 +187,7 @@ public class ApplicationMigrationService extends Service
private static class CompletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationChannels.OTHER);
builder.setSmallIcon(R.drawable.icon_notification);
builder.setContentTitle(context.getString(R.string.ApplicationMigrationService_import_complete));
builder.setContentText(context.getString(R.string.ApplicationMigrationService_system_database_import_is_complete));
......
......@@ -41,6 +41,7 @@ import org.smssecure.smssecure.crypto.InvalidPassphraseException;
import org.smssecure.smssecure.crypto.MasterSecret;
import org.smssecure.smssecure.crypto.MasterSecretUtil;
import org.smssecure.smssecure.notifications.MessageNotifier;
import org.smssecure.smssecure.notifications.NotificationChannels;
import org.smssecure.smssecure.util.DynamicLanguage;
import org.smssecure.smssecure.util.ParcelUtil;
import org.smssecure.smssecure.util.SilencePreferences;
......@@ -234,7 +235,7 @@ public class KeyCachingService extends Service {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void foregroundServiceModern() {
Log.w("KeyCachingService", "foregrounding KCS");
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationChannels.LOCKED_STATUS);
builder.setContentTitle(getString(R.string.KeyCachingService_passphrase_cached));
builder.setContentText(getString(R.string.KeyCachingService_silence_passphrase_cached));
......@@ -250,7 +251,7 @@ public class KeyCachingService extends Service {
}
private void foregroundServiceICS() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationChannels.LOCKED_STATUS);
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.key_caching_notification);
remoteViews.setOnClickPendingIntent(R.id.lock_cache_icon, buildLockIntent());
......@@ -264,7 +265,7 @@ public class KeyCachingService extends Service {
}
private void foregroundServiceLegacy() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationChannels.LOCKED_STATUS);
builder.setSmallIcon(R.drawable.icon_cached);
builder.setWhen(System.currentTimeMillis());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment