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 003c77ee762786da489dc2ce6ce95696403e583e..7d774721af1dbf67022c9dcb0398a34a06108848 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 @@ -61,6 +61,7 @@ import static android.content.Context.NOTIFICATION_SERVICE; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import static android.support.v4.app.NotificationCompat.CATEGORY_MESSAGE; import static android.support.v4.app.NotificationCompat.CATEGORY_SOCIAL; +import static android.support.v4.app.NotificationCompat.VISIBILITY_PRIVATE; import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET; import static java.util.logging.Level.WARNING; import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID; @@ -327,7 +328,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } if (Build.VERSION.SDK_INT >= 21) { b.setCategory(CATEGORY_MESSAGE); - b.setVisibility(VISIBILITY_SECRET); + boolean showOnLockScreen = + settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false); + if (showOnLockScreen) + b.setVisibility(VISIBILITY_PRIVATE); + else + b.setVisibility(VISIBILITY_SECRET); } Object o = appContext.getSystemService(NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) o; @@ -347,17 +353,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, return defaults; } - @Override - public void clearAllContactNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - clearContactNotification(); - clearIntroductionSuccessNotification(); - } - }); - } - @UiThread private void showGroupMessageNotification(final GroupId g) { androidExecutor.runOnUiThread(new Runnable() { @@ -432,7 +427,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } if (Build.VERSION.SDK_INT >= 21) { b.setCategory(CATEGORY_SOCIAL); - b.setVisibility(VISIBILITY_SECRET); + boolean showOnLockScreen = + settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false); + if (showOnLockScreen) + b.setVisibility(VISIBILITY_PRIVATE); + else + b.setVisibility(VISIBILITY_SECRET); } Object o = appContext.getSystemService(NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) o; @@ -440,16 +440,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } } - @Override - public void clearAllGroupMessageNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - clearGroupMessageNotification(); - } - }); - } - @UiThread private void showForumPostNotification(final GroupId g) { androidExecutor.runOnUiThread(new Runnable() { @@ -524,7 +514,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } if (Build.VERSION.SDK_INT >= 21) { b.setCategory(CATEGORY_SOCIAL); - b.setVisibility(VISIBILITY_SECRET); + boolean showOnLockScreen = + settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false); + if (showOnLockScreen) + b.setVisibility(VISIBILITY_PRIVATE); + else + b.setVisibility(VISIBILITY_SECRET); } Object o = appContext.getSystemService(NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) o; @@ -532,16 +527,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } } - @Override - public void clearAllForumPostNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - clearForumPostNotification(); - } - }); - } - @UiThread private void showBlogPostNotification(final GroupId g) { androidExecutor.runOnUiThread(new Runnable() { @@ -602,7 +587,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); if (Build.VERSION.SDK_INT >= 21) { b.setCategory(CATEGORY_SOCIAL); - b.setVisibility(VISIBILITY_SECRET); + boolean showOnLockScreen = + settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false); + if (showOnLockScreen) + b.setVisibility(VISIBILITY_PRIVATE); + else + b.setVisibility(VISIBILITY_SECRET); } Object o = appContext.getSystemService(NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) o; @@ -610,16 +600,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } } - @Override - public void clearAllBlogPostNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - clearBlogPostNotification(); - } - }); - } - private void showIntroductionNotification() { androidExecutor.runOnUiThread(new Runnable() { @Override @@ -658,7 +638,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); if (Build.VERSION.SDK_INT >= 21) { b.setCategory(CATEGORY_MESSAGE); - b.setVisibility(VISIBILITY_SECRET); + boolean showOnLockScreen = + settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false); + if (showOnLockScreen) + b.setVisibility(VISIBILITY_PRIVATE); + else + b.setVisibility(VISIBILITY_SECRET); } Object o = appContext.getSystemService(NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) o; @@ -704,87 +689,4 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } }); } - - @Override - public void blockAllContactNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - blockContacts = true; - blockIntroductions = true; - } - }); - } - - @Override - public void unblockAllContactNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - blockContacts = false; - blockIntroductions = false; - } - }); - } - - @Override - public void blockAllGroupMessageNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - blockGroups = true; - } - }); - } - - @Override - public void unblockAllGroupMessageNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - blockGroups = false; - } - }); - } - - @Override - public void blockAllForumPostNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - blockForums = true; - } - }); - } - - @Override - public void unblockAllForumPostNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - blockForums = false; - } - }); - } - - @Override - public void blockAllBlogPostNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - blockBlogs = true; - } - }); - } - - @Override - public void unblockAllBlogPostNotifications() { - androidExecutor.runOnUiThread(new Runnable() { - @Override - public void run() { - blockBlogs = false; - } - }); - } - } diff --git a/briar-android/src/main/java/org/briarproject/briar/android/blog/FeedControllerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/blog/FeedControllerImpl.java index 1d02c8fdc197cd99c58cd6a3c3497c301202c0e4..84b3c07390421bd6171bd52781c193ed23733a6c 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/blog/FeedControllerImpl.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/blog/FeedControllerImpl.java @@ -53,14 +53,11 @@ class FeedControllerImpl extends BaseControllerImpl public void onStart() { super.onStart(); if (listener == null) throw new IllegalStateException(); - notificationManager.blockAllBlogPostNotifications(); - notificationManager.clearAllBlogPostNotifications(); } @Override public void onStop() { super.onStop(); - notificationManager.unblockAllBlogPostNotifications(); } @Override diff --git a/briar-android/src/main/java/org/briarproject/briar/android/contact/ContactListFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/contact/ContactListFragment.java index 3ce6e7f1fd124c85e0202c5e239a02e8d0ea7b9e..d52915fce9e1ea38572f5935c4e0c61e689afb19 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/contact/ContactListFragment.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/contact/ContactListFragment.java @@ -178,8 +178,6 @@ public class ContactListFragment extends BaseFragment implements EventListener { @Override public void onStart() { super.onStart(); - notificationManager.blockAllContactNotifications(); - notificationManager.clearAllContactNotifications(); eventBus.addListener(this); loadContacts(); list.startPeriodicUpdate(); @@ -189,7 +187,6 @@ public class ContactListFragment extends BaseFragment implements EventListener { public void onStop() { super.onStop(); eventBus.removeListener(this); - notificationManager.unblockAllContactNotifications(); adapter.clear(); list.showProgressBar(); list.stopPeriodicUpdate(); diff --git a/briar-android/src/main/java/org/briarproject/briar/android/forum/ForumListFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/forum/ForumListFragment.java index daf83ac123c17ff3933cf3f12d641f3068fd3bed..42f22288d5f7472a8a7d3496eae659bc1ece89b6 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/forum/ForumListFragment.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/forum/ForumListFragment.java @@ -119,8 +119,6 @@ public class ForumListFragment extends BaseEventFragment implements @Override public void onStart() { super.onStart(); - notificationManager.blockAllForumPostNotifications(); - notificationManager.clearAllForumPostNotifications(); loadForums(); loadAvailableForums(); list.startPeriodicUpdate(); @@ -129,7 +127,6 @@ public class ForumListFragment extends BaseEventFragment implements @Override public void onStop() { super.onStop(); - notificationManager.unblockAllForumPostNotifications(); adapter.clear(); list.showProgressBar(); list.stopPeriodicUpdate(); diff --git a/briar-android/src/main/java/org/briarproject/briar/android/privategroup/list/GroupListControllerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/privategroup/list/GroupListControllerImpl.java index 4c0febda6cba7bc10dd84e63a15e3828593c83ae..6cde4e9552a4a99320a6bc73c3a426a1f1b0bb59 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/privategroup/list/GroupListControllerImpl.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/privategroup/list/GroupListControllerImpl.java @@ -79,15 +79,12 @@ class GroupListControllerImpl extends DbControllerImpl throw new IllegalStateException( "GroupListListener needs to be attached"); eventBus.addListener(this); - notificationManager.blockAllGroupMessageNotifications(); - notificationManager.clearAllGroupMessageNotifications(); } @Override @CallSuper public void onStop() { eventBus.removeListener(this); - notificationManager.unblockAllGroupMessageNotifications(); } @Override 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 0f627bb40fe1792a85cf2d45425065f3ab0593cd..98afedd525a1f7ade64f9458805eb0ddf18c2300 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 @@ -6,6 +6,7 @@ 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.v7.preference.CheckBoxPreference; import android.support.v7.preference.ListPreference; @@ -54,6 +55,7 @@ import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGT 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; +import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_LOCK_SCREEN; import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_PRIVATE; import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_RINGTONE_NAME; import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_RINGTONE_URI; @@ -81,6 +83,8 @@ public class SettingsFragment extends PreferenceFragmentCompat private CheckBoxPreference notifyForumPosts; private CheckBoxPreference notifyBlogPosts; private CheckBoxPreference notifyVibration; + private CheckBoxPreference notifyLockscreen; + private Preference notifySound; // Fields that are accessed from background threads must be volatile @@ -114,6 +118,8 @@ public class SettingsFragment extends PreferenceFragmentCompat "pref_key_notify_blog_posts"); notifyVibration = (CheckBoxPreference) findPreference( "pref_key_notify_vibration"); + notifyLockscreen = (CheckBoxPreference) findPreference( + "pref_key_notify_lock_screen"); notifySound = findPreference("pref_key_notify_sound"); enableBluetooth.setOnPreferenceChangeListener(this); @@ -123,7 +129,10 @@ public class SettingsFragment extends PreferenceFragmentCompat notifyForumPosts.setOnPreferenceChangeListener(this); notifyBlogPosts.setOnPreferenceChangeListener(this); notifyVibration.setOnPreferenceChangeListener(this); - + if (Build.VERSION.SDK_INT >= 21) { + notifyLockscreen.setVisible(true); + notifyLockscreen.setOnPreferenceChangeListener(this); + } notifySound.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { @Override @@ -234,6 +243,9 @@ public class SettingsFragment extends PreferenceFragmentCompat 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 = @@ -290,6 +302,10 @@ public class SettingsFragment extends PreferenceFragmentCompat Settings s = new Settings(); s.putBoolean(PREF_NOTIFY_VIBRATION, (Boolean) o); storeSettings(s); + } else if (preference == notifyLockscreen) { + Settings s = new Settings(); + s.putBoolean(PREF_NOTIFY_LOCK_SCREEN, (Boolean) o); + storeSettings(s); } return true; } 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 869869c2efd0299c269b3c152634f38fba1f1c97..865e7d77f46bee3d5f961642c2d14e50bdf46b5d 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 @@ -18,23 +18,16 @@ public interface AndroidNotificationManager { String PREF_NOTIFY_RINGTONE_NAME = "notifyRingtoneName"; String PREF_NOTIFY_RINGTONE_URI = "notifyRingtoneUri"; String PREF_NOTIFY_VIBRATION = "notifyVibration"; + String PREF_NOTIFY_LOCK_SCREEN = "notifyLockScreen"; void clearContactNotification(ContactId c); - void clearAllContactNotifications(); - void clearGroupMessageNotification(GroupId g); - void clearAllGroupMessageNotifications(); - void clearForumPostNotification(GroupId g); - void clearAllForumPostNotifications(); - void clearBlogPostNotification(GroupId g); - void clearAllBlogPostNotifications(); - void blockContactNotification(ContactId c); void unblockContactNotification(ContactId c); @@ -42,20 +35,4 @@ public interface AndroidNotificationManager { void blockNotification(GroupId g); void unblockNotification(GroupId g); - - void blockAllContactNotifications(); - - void unblockAllContactNotifications(); - - void blockAllGroupMessageNotifications(); - - void unblockAllGroupMessageNotifications(); - - void blockAllForumPostNotifications(); - - void unblockAllForumPostNotifications(); - - void blockAllBlogPostNotifications(); - - void unblockAllBlogPostNotifications(); } diff --git a/briar-android/src/main/res/values/strings.xml b/briar-android/src/main/res/values/strings.xml index 8a652f477cca26c9e4a5fbf977ae505c1e7f52d9..bb1288d6f187477b9c4637c45b8a124e552e7137 100644 --- a/briar-android/src/main/res/values/strings.xml +++ b/briar-android/src/main/res/values/strings.xml @@ -348,6 +348,8 @@ <string name="notify_blog_posts_setting_title">Blog posts</string> <string name="notify_blog_posts_setting_summary">Show alerts for blog posts</string> <string name="notify_vibration_setting">Vibrate</string> + <string name="notify_lock_screen_setting_title">Lock Screen</string> + <string name="notify_lock_screen_setting_summary">Show notifications on the lock screen</string> <string name="notify_sound_setting">Sound</string> <string name="notify_sound_setting_default">Default ringtone</string> <string name="notify_sound_setting_disabled">None</string> diff --git a/briar-android/src/main/res/xml/settings.xml b/briar-android/src/main/res/xml/settings.xml index 07d47137b6fa3350d898b1556d812c304d461664..889161679485ef2afa91262812a45de1b1a9948d 100644 --- a/briar-android/src/main/res/xml/settings.xml +++ b/briar-android/src/main/res/xml/settings.xml @@ -85,6 +85,14 @@ android:title="@string/notify_blog_posts_setting_title" android:summary="@string/notify_blog_posts_setting_summary"/> + <CheckBoxPreference + android:defaultValue="false" + android:key="pref_key_notify_lock_screen" + android:persistent="false" + android:title="@string/notify_lock_screen_setting_title" + android:summary="@string/notify_lock_screen_setting_summary" + android:visibility="gone"/> + <CheckBoxPreference android:defaultValue="true" android:key="pref_key_notify_vibration"