diff --git a/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java
index 698809cac..a9a9a6522 100644
--- a/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java
+++ b/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java
@@ -62,6 +62,7 @@ import javax.inject.Inject;
import static android.app.Notification.DEFAULT_LIGHTS;
import static android.app.Notification.DEFAULT_SOUND;
import static android.app.Notification.DEFAULT_VIBRATE;
+import static android.app.Notification.VISIBILITY_SECRET;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
@@ -90,12 +91,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
private static final int BLOG_POST_NOTIFICATION_ID = 6;
private static final int INTRODUCTION_SUCCESS_NOTIFICATION_ID = 7;
- // Channel IDs
- private static final String CONTACT_CHANNEL_ID = "contacts";
- private static final String GROUP_CHANNEL_ID = "groups";
- private static final String FORUM_CHANNEL_ID = "forums";
- private static final String BLOG_CHANNEL_ID = "blogs";
-
private static final long SOUND_DELAY = TimeUnit.SECONDS.toMillis(2);
private static final Logger LOG =
@@ -174,6 +169,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
NotificationChannel nc =
new NotificationChannel(channelId, appContext.getString(name),
IMPORTANCE_DEFAULT);
+ nc.setLockscreenVisibility(VISIBILITY_SECRET);
+ nc.enableVibration(true);
nc.enableLights(true);
nc.setLightColor(
ContextCompat.getColor(appContext, R.color.briar_green_light));
diff --git a/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java
index dd049fbca..1efca2346 100644
--- a/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java
+++ b/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java
@@ -1,12 +1,13 @@
package org.briarproject.briar.android.settings;
+import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
-import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
@@ -44,6 +45,10 @@ import static android.media.RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT;
import static android.media.RingtoneManager.EXTRA_RINGTONE_TITLE;
import static android.media.RingtoneManager.EXTRA_RINGTONE_TYPE;
import static android.media.RingtoneManager.TYPE_NOTIFICATION;
+import static android.os.Build.VERSION.SDK_INT;
+import static android.provider.Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS;
+import static android.provider.Settings.EXTRA_APP_PACKAGE;
+import static android.provider.Settings.EXTRA_CHANNEL_ID;
import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.INFO;
@@ -53,6 +58,10 @@ import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_ALWAYS;
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
+import static org.briarproject.briar.api.android.AndroidNotificationManager.BLOG_CHANNEL_ID;
+import static org.briarproject.briar.api.android.AndroidNotificationManager.CONTACT_CHANNEL_ID;
+import static org.briarproject.briar.api.android.AndroidNotificationManager.FORUM_CHANNEL_ID;
+import static org.briarproject.briar.api.android.AndroidNotificationManager.GROUP_CHANNEL_ID;
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_BLOG;
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_FORUM;
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_GROUP;
@@ -132,33 +141,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
enableBluetooth.setOnPreferenceChangeListener(this);
torNetwork.setOnPreferenceChangeListener(this);
- notifyPrivateMessages.setOnPreferenceChangeListener(this);
- notifyGroupMessages.setOnPreferenceChangeListener(this);
- notifyForumPosts.setOnPreferenceChangeListener(this);
- notifyBlogPosts.setOnPreferenceChangeListener(this);
- notifyVibration.setOnPreferenceChangeListener(this);
- if (Build.VERSION.SDK_INT >= 21) {
+ if (SDK_INT >= 21) {
notifyLockscreen.setVisible(true);
notifyLockscreen.setOnPreferenceChangeListener(this);
}
- notifySound.setOnPreferenceClickListener(preference -> {
- String title = getString(R.string.choose_ringtone_title);
- Intent i = new Intent(ACTION_RINGTONE_PICKER);
- i.putExtra(EXTRA_RINGTONE_TYPE, TYPE_NOTIFICATION);
- i.putExtra(EXTRA_RINGTONE_TITLE, title);
- i.putExtra(EXTRA_RINGTONE_DEFAULT_URI, DEFAULT_NOTIFICATION_URI);
- i.putExtra(EXTRA_RINGTONE_SHOW_SILENT, true);
- if (settings.getBoolean(PREF_NOTIFY_SOUND, true)) {
- Uri uri;
- String ringtoneUri = settings.get(PREF_NOTIFY_RINGTONE_URI);
- if (StringUtils.isNullOrEmpty(ringtoneUri))
- uri = DEFAULT_NOTIFICATION_URI;
- else uri = Uri.parse(ringtoneUri);
- i.putExtra(EXTRA_RINGTONE_EXISTING_URI, uri);
- }
- startActivityForResult(i, REQUEST_RINGTONE);
- return true;
- });
findPreference("pref_key_send_feedback").setOnPreferenceClickListener(
preference -> {
@@ -220,36 +206,54 @@ public class SettingsFragment extends PreferenceFragmentCompat
enableBluetooth.setValue(Boolean.toString(btSetting));
torNetwork.setValue(Integer.toString(torSetting));
- notifyPrivateMessages.setChecked(settings.getBoolean(
- PREF_NOTIFY_PRIVATE, true));
-
- notifyGroupMessages.setChecked(settings.getBoolean(
- PREF_NOTIFY_GROUP, true));
-
- notifyForumPosts.setChecked(settings.getBoolean(
- PREF_NOTIFY_FORUM, true));
-
- notifyBlogPosts.setChecked(settings.getBoolean(
- PREF_NOTIFY_BLOG, true));
-
- notifyVibration.setChecked(settings.getBoolean(
- PREF_NOTIFY_VIBRATION, true));
-
- notifyLockscreen.setChecked(settings.getBoolean(
- PREF_NOTIFY_LOCK_SCREEN, false));
-
- String text;
- if (settings.getBoolean(PREF_NOTIFY_SOUND, true)) {
- String ringtoneName = settings.get(PREF_NOTIFY_RINGTONE_NAME);
- if (StringUtils.isNullOrEmpty(ringtoneName)) {
- text = getString(R.string.notify_sound_setting_default);
+ if (SDK_INT < 26) {
+ notifyPrivateMessages.setChecked(settings.getBoolean(
+ PREF_NOTIFY_PRIVATE, true));
+ notifyGroupMessages.setChecked(settings.getBoolean(
+ PREF_NOTIFY_GROUP, true));
+ notifyForumPosts.setChecked(settings.getBoolean(
+ PREF_NOTIFY_FORUM, true));
+ notifyBlogPosts.setChecked(settings.getBoolean(
+ PREF_NOTIFY_BLOG, true));
+ notifyVibration.setChecked(settings.getBoolean(
+ PREF_NOTIFY_VIBRATION, true));
+ notifyPrivateMessages.setOnPreferenceChangeListener(this);
+ notifyGroupMessages.setOnPreferenceChangeListener(this);
+ notifyForumPosts.setOnPreferenceChangeListener(this);
+ notifyBlogPosts.setOnPreferenceChangeListener(this);
+ notifyVibration.setOnPreferenceChangeListener(this);
+ notifyLockscreen.setChecked(settings.getBoolean(
+ PREF_NOTIFY_LOCK_SCREEN, false));
+ notifySound.setOnPreferenceClickListener(
+ pref -> onNotificationSoundClicked());
+ String text;
+ if (settings.getBoolean(PREF_NOTIFY_SOUND, true)) {
+ String ringtoneName =
+ settings.get(PREF_NOTIFY_RINGTONE_NAME);
+ if (StringUtils.isNullOrEmpty(ringtoneName)) {
+ text = getString(R.string.notify_sound_setting_default);
+ } else {
+ text = ringtoneName;
+ }
} else {
- text = ringtoneName;
+ text = getString(R.string.notify_sound_setting_disabled);
}
+ notifySound.setSummary(text);
} else {
- text = getString(R.string.notify_sound_setting_disabled);
+ setupNotificationPreference(notifyPrivateMessages,
+ CONTACT_CHANNEL_ID,
+ R.string.notify_private_messages_setting_summary_26);
+ setupNotificationPreference(notifyGroupMessages,
+ GROUP_CHANNEL_ID,
+ R.string.notify_group_messages_setting_summary_26);
+ setupNotificationPreference(notifyForumPosts, FORUM_CHANNEL_ID,
+ R.string.notify_forum_posts_setting_summary_26);
+ setupNotificationPreference(notifyBlogPosts, BLOG_CHANNEL_ID,
+ R.string.notify_blog_posts_setting_summary_26);
+ notifyVibration.setVisible(false);
+ notifyLockscreen.setVisible(false);
+ notifySound.setVisible(false);
}
- notifySound.setSummary(text);
setSettingsEnabled(true);
});
}
@@ -266,6 +270,41 @@ public class SettingsFragment extends PreferenceFragmentCompat
notifySound.setEnabled(enabled);
}
+ @TargetApi(26)
+ private void setupNotificationPreference(CheckBoxPreference pref,
+ String channelId, @StringRes int summary) {
+ pref.setWidgetLayoutResource(0);
+ pref.setSummary(summary);
+ pref.setOnPreferenceClickListener(clickedPref -> {
+ Intent intent = new Intent(ACTION_CHANNEL_NOTIFICATION_SETTINGS)
+ .putExtra(EXTRA_APP_PACKAGE, getContext().getPackageName())
+ .putExtra(EXTRA_CHANNEL_ID, channelId);
+ startActivity(intent);
+ return true;
+ });
+ }
+
+ private boolean onNotificationSoundClicked() {
+ String title = getString(R.string.choose_ringtone_title);
+ Intent i = new Intent(ACTION_RINGTONE_PICKER);
+ i.putExtra(EXTRA_RINGTONE_TYPE, TYPE_NOTIFICATION);
+ i.putExtra(EXTRA_RINGTONE_TITLE, title);
+ i.putExtra(EXTRA_RINGTONE_DEFAULT_URI,
+ DEFAULT_NOTIFICATION_URI);
+ i.putExtra(EXTRA_RINGTONE_SHOW_SILENT, true);
+ if (settings.getBoolean(PREF_NOTIFY_SOUND, true)) {
+ Uri uri;
+ String ringtoneUri =
+ settings.get(PREF_NOTIFY_RINGTONE_URI);
+ if (StringUtils.isNullOrEmpty(ringtoneUri))
+ uri = DEFAULT_NOTIFICATION_URI;
+ else uri = Uri.parse(ringtoneUri);
+ i.putExtra(EXTRA_RINGTONE_EXISTING_URI, uri);
+ }
+ startActivityForResult(i, REQUEST_RINGTONE);
+ return true;
+ }
+
private void triggerFeedback() {
androidExecutor.runOnBackgroundThread(() -> ACRA.getErrorReporter()
.handleException(new UserFeedback(), false));
diff --git a/briar-android/src/main/java/org/briarproject/briar/api/android/AndroidNotificationManager.java b/briar-android/src/main/java/org/briarproject/briar/api/android/AndroidNotificationManager.java
index d95d258da..0579dc873 100644
--- a/briar-android/src/main/java/org/briarproject/briar/api/android/AndroidNotificationManager.java
+++ b/briar-android/src/main/java/org/briarproject/briar/api/android/AndroidNotificationManager.java
@@ -21,6 +21,12 @@ public interface AndroidNotificationManager {
String PREF_NOTIFY_VIBRATION = "notifyVibration";
String PREF_NOTIFY_LOCK_SCREEN = "notifyLockScreen";
+ // Channel IDs
+ String CONTACT_CHANNEL_ID = "contacts";
+ String GROUP_CHANNEL_ID = "groups";
+ String FORUM_CHANNEL_ID = "forums";
+ String BLOG_CHANNEL_ID = "blogs";
+
// Content URIs for pending intents
String CONTACT_URI = "content://org.briarproject.briar/contact";
String GROUP_URI = "content://org.briarproject.briar/group";
diff --git a/briar-android/src/main/res/values/strings.xml b/briar-android/src/main/res/values/strings.xml
index d55418460..1a1ffc0b6 100644
--- a/briar-android/src/main/res/values/strings.xml
+++ b/briar-android/src/main/res/values/strings.xml
@@ -355,12 +355,16 @@
Notifications
Private messages
Show alerts for private messages
+ Configure alerts for private messages
Group messages
Show alerts for group messages
+ Configure alerts for group messages
Forum posts
Show alerts for forum posts
+ Configure alerts for forum posts
Blog posts
Show alerts for blog posts
+ Configure alerts for blog posts
Vibrate
Lock Screen
Show notifications on the lock screen