Merge branch '1127-notification-channels' into 'maintenance-0.16'

Beta: Use channels for all notifications

See merge request !647
This commit is contained in:
akwizgran
2017-12-05 17:03:37 +00:00
6 changed files with 112 additions and 64 deletions

View File

@@ -1,11 +1,14 @@
package org.briarproject.briar.android; package org.briarproject.briar.android;
import android.annotation.TargetApi;
import android.app.Application; import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.StringRes;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import android.support.v4.app.TaskStackBuilder; import android.support.v4.app.TaskStackBuilder;
@@ -44,6 +47,7 @@ import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@@ -57,8 +61,10 @@ import javax.inject.Inject;
import static android.app.Notification.DEFAULT_LIGHTS; import static android.app.Notification.DEFAULT_LIGHTS;
import static android.app.Notification.DEFAULT_SOUND; import static android.app.Notification.DEFAULT_SOUND;
import static android.app.Notification.DEFAULT_VIBRATE; import static android.app.Notification.DEFAULT_VIBRATE;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.content.Context.NOTIFICATION_SERVICE; import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.os.Build.VERSION.SDK_INT;
import static android.support.v4.app.NotificationCompat.CATEGORY_MESSAGE; 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.CATEGORY_SOCIAL;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
@@ -83,6 +89,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
private static final int BLOG_POST_NOTIFICATION_ID = 6; private static final int BLOG_POST_NOTIFICATION_ID = 6;
private static final int INTRODUCTION_SUCCESS_NOTIFICATION_ID = 7; 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 long SOUND_DELAY = TimeUnit.SECONDS.toMillis(2);
private static final Logger LOG = private static final Logger LOG =
@@ -91,8 +103,9 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
private final Executor dbExecutor; private final Executor dbExecutor;
private final SettingsManager settingsManager; private final SettingsManager settingsManager;
private final AndroidExecutor androidExecutor; private final AndroidExecutor androidExecutor;
private final Context appContext;
private final Clock clock; private final Clock clock;
private final Context appContext;
private final NotificationManager notificationManager;
private final AtomicBoolean used = new AtomicBoolean(false); private final AtomicBoolean used = new AtomicBoolean(false);
// The following must only be accessed on the main UI thread // The following must only be accessed on the main UI thread
@@ -121,6 +134,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
this.androidExecutor = androidExecutor; this.androidExecutor = androidExecutor;
this.clock = clock; this.clock = clock;
appContext = app.getApplicationContext(); appContext = app.getApplicationContext();
notificationManager = (NotificationManager)
appContext.getSystemService(NOTIFICATION_SERVICE);
} }
@Override @Override
@@ -132,6 +147,33 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} catch (DbException e) { } catch (DbException e) {
throw new ServiceException(e); throw new ServiceException(e);
} }
if (SDK_INT >= 26) {
// Create notification channels
Callable<Void> task = () -> {
createNotificationChannel(CONTACT_CHANNEL_ID,
R.string.contact_list_button);
createNotificationChannel(GROUP_CHANNEL_ID,
R.string.groups_button);
createNotificationChannel(FORUM_CHANNEL_ID,
R.string.forums_button);
createNotificationChannel(BLOG_CHANNEL_ID,
R.string.blogs_button);
return null;
};
try {
androidExecutor.runOnUiThread(task).get();
} catch (InterruptedException | ExecutionException e) {
throw new ServiceException(e);
}
}
}
@TargetApi(26)
private void createNotificationChannel(String channelId,
@StringRes int name) {
notificationManager.createNotificationChannel(
new NotificationChannel(channelId, appContext.getString(name),
IMPORTANCE_DEFAULT));
} }
@Override @Override
@@ -156,44 +198,34 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
private void clearContactNotification() { private void clearContactNotification() {
contactCounts.clear(); contactCounts.clear();
contactTotal = 0; contactTotal = 0;
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(PRIVATE_MESSAGE_NOTIFICATION_ID);
NotificationManager nm = (NotificationManager) o;
nm.cancel(PRIVATE_MESSAGE_NOTIFICATION_ID);
} }
@UiThread @UiThread
private void clearGroupMessageNotification() { private void clearGroupMessageNotification() {
groupCounts.clear(); groupCounts.clear();
groupTotal = 0; groupTotal = 0;
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(GROUP_MESSAGE_NOTIFICATION_ID);
NotificationManager nm = (NotificationManager) o;
nm.cancel(GROUP_MESSAGE_NOTIFICATION_ID);
} }
@UiThread @UiThread
private void clearForumPostNotification() { private void clearForumPostNotification() {
forumCounts.clear(); forumCounts.clear();
forumTotal = 0; forumTotal = 0;
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(FORUM_POST_NOTIFICATION_ID);
NotificationManager nm = (NotificationManager) o;
nm.cancel(FORUM_POST_NOTIFICATION_ID);
} }
@UiThread @UiThread
private void clearBlogPostNotification() { private void clearBlogPostNotification() {
blogCounts.clear(); blogCounts.clear();
blogTotal = 0; blogTotal = 0;
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(BLOG_POST_NOTIFICATION_ID);
NotificationManager nm = (NotificationManager) o;
nm.cancel(BLOG_POST_NOTIFICATION_ID);
} }
@UiThread @UiThread
private void clearIntroductionSuccessNotification() { private void clearIntroductionSuccessNotification() {
introductionTotal = 0; introductionTotal = 0;
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(INTRODUCTION_SUCCESS_NOTIFICATION_ID);
NotificationManager nm = (NotificationManager) o;
nm.cancel(INTRODUCTION_SUCCESS_NOTIFICATION_ID);
} }
@Override @Override
@@ -269,8 +301,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
if (contactTotal == 0) { if (contactTotal == 0) {
clearContactNotification(); clearContactNotification();
} else if (settings.getBoolean(PREF_NOTIFY_PRIVATE, true)) { } else if (settings.getBoolean(PREF_NOTIFY_PRIVATE, true)) {
BriarNotificationBuilder b = BriarNotificationBuilder b = new BriarNotificationBuilder(
new BriarNotificationBuilder(appContext); appContext, CONTACT_CHANNEL_ID);
b.setSmallIcon(R.drawable.notification_private_message); b.setSmallIcon(R.drawable.notification_private_message);
b.setColorRes(R.color.briar_primary); b.setColorRes(R.color.briar_primary);
b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentTitle(appContext.getText(R.string.app_name));
@@ -305,9 +337,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
t.addNextIntent(i); t.addNextIntent(i);
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
} }
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(PRIVATE_MESSAGE_NOTIFICATION_ID,
NotificationManager nm = (NotificationManager) o; b.build());
nm.notify(PRIVATE_MESSAGE_NOTIFICATION_ID, b.build());
} }
} }
@@ -378,7 +409,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
clearGroupMessageNotification(); clearGroupMessageNotification();
} else if (settings.getBoolean(PREF_NOTIFY_GROUP, true)) { } else if (settings.getBoolean(PREF_NOTIFY_GROUP, true)) {
BriarNotificationBuilder b = BriarNotificationBuilder b =
new BriarNotificationBuilder(appContext); new BriarNotificationBuilder(appContext, GROUP_CHANNEL_ID);
b.setSmallIcon(R.drawable.notification_private_group); b.setSmallIcon(R.drawable.notification_private_group);
b.setColorRes(R.color.briar_primary); b.setColorRes(R.color.briar_primary);
b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentTitle(appContext.getText(R.string.app_name));
@@ -414,9 +445,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
t.addNextIntent(i); t.addNextIntent(i);
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
} }
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(GROUP_MESSAGE_NOTIFICATION_ID,
NotificationManager nm = (NotificationManager) o; b.build());
nm.notify(GROUP_MESSAGE_NOTIFICATION_ID, b.build());
} }
} }
@@ -455,7 +485,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
clearForumPostNotification(); clearForumPostNotification();
} else if (settings.getBoolean(PREF_NOTIFY_FORUM, true)) { } else if (settings.getBoolean(PREF_NOTIFY_FORUM, true)) {
BriarNotificationBuilder b = BriarNotificationBuilder b =
new BriarNotificationBuilder(appContext); new BriarNotificationBuilder(appContext, FORUM_CHANNEL_ID);
b.setSmallIcon(R.drawable.notification_forum); b.setSmallIcon(R.drawable.notification_forum);
b.setColorRes(R.color.briar_primary); b.setColorRes(R.color.briar_primary);
b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentTitle(appContext.getText(R.string.app_name));
@@ -491,9 +521,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
t.addNextIntent(i); t.addNextIntent(i);
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
} }
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(FORUM_POST_NOTIFICATION_ID, b.build());
NotificationManager nm = (NotificationManager) o;
nm.notify(FORUM_POST_NOTIFICATION_ID, b.build());
} }
} }
@@ -532,7 +560,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
clearBlogPostNotification(); clearBlogPostNotification();
} else if (settings.getBoolean(PREF_NOTIFY_BLOG, true)) { } else if (settings.getBoolean(PREF_NOTIFY_BLOG, true)) {
BriarNotificationBuilder b = BriarNotificationBuilder b =
new BriarNotificationBuilder(appContext); new BriarNotificationBuilder(appContext, BLOG_CHANNEL_ID);
b.setSmallIcon(R.drawable.notification_blog); b.setSmallIcon(R.drawable.notification_blog);
b.setColorRes(R.color.briar_primary); b.setColorRes(R.color.briar_primary);
b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentTitle(appContext.getText(R.string.app_name));
@@ -555,9 +583,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
t.addNextIntent(i); t.addNextIntent(i);
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(BLOG_POST_NOTIFICATION_ID, b.build());
NotificationManager nm = (NotificationManager) o;
nm.notify(BLOG_POST_NOTIFICATION_ID, b.build());
} }
} }
@@ -577,7 +603,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
@UiThread @UiThread
private void updateIntroductionNotification() { private void updateIntroductionNotification() {
BriarNotificationBuilder b = new BriarNotificationBuilder(appContext); BriarNotificationBuilder b =
new BriarNotificationBuilder(appContext, CONTACT_CHANNEL_ID);
b.setSmallIcon(R.drawable.notification_introduction); b.setSmallIcon(R.drawable.notification_introduction);
b.setColorRes(R.color.briar_primary); b.setColorRes(R.color.briar_primary);
b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentTitle(appContext.getText(R.string.app_name));
@@ -599,9 +626,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
t.addNextIntent(i); t.addNextIntent(i);
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(INTRODUCTION_SUCCESS_NOTIFICATION_ID,
NotificationManager nm = (NotificationManager) o; b.build());
nm.notify(INTRODUCTION_SUCCESS_NOTIFICATION_ID, b.build());
} }
@Override @Override

View File

@@ -8,7 +8,6 @@ import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.Binder; import android.os.Binder;
import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@@ -26,9 +25,12 @@ import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.os.Build.VERSION.SDK_INT;
import static android.support.v4.app.NotificationCompat.CATEGORY_SERVICE; import static android.support.v4.app.NotificationCompat.CATEGORY_SERVICE;
import static android.support.v4.app.NotificationCompat.PRIORITY_MIN; import static android.support.v4.app.NotificationCompat.PRIORITY_MIN;
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET; import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
@@ -38,9 +40,21 @@ import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResul
public class BriarService extends Service { public class BriarService extends Service {
public static String EXTRA_START_RESULT =
"org.briarproject.briar.START_RESULT";
public static String EXTRA_NOTIFICATION_ID =
"org.briarproject.briar.FAILURE_NOTIFICATION_ID";
public static String EXTRA_STARTUP_FAILED =
"org.briarproject.briar.STARTUP_FAILED";
private static final int ONGOING_NOTIFICATION_ID = 1; private static final int ONGOING_NOTIFICATION_ID = 1;
private static final int FAILURE_NOTIFICATION_ID = 2; private static final int FAILURE_NOTIFICATION_ID = 2;
// Channels are sorted by channel ID in the Settings app, so use IDs
// that will sort below the main channels such as contacts
private static final String ONGOING_CHANNEL_ID = "zForegroundService";
private static final String FAILURE_CHANNEL_ID = "zStartupFailure";
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(BriarService.class.getName()); Logger.getLogger(BriarService.class.getName());
@@ -74,20 +88,26 @@ public class BriarService extends Service {
stopSelf(); stopSelf();
return; return;
} }
// Create mandatory notification channel // Create notification channels
String channelId = "foregroundService"; if (SDK_INT >= 26) {
if (Build.VERSION.SDK_INT >= 26) { NotificationManager nm = (NotificationManager)
NotificationChannel channel = new NotificationChannel(channelId, getSystemService(NOTIFICATION_SERVICE);
getString(R.string.app_name), NotificationChannel ongoingChannel = new NotificationChannel(
NotificationManager.IMPORTANCE_NONE); ONGOING_CHANNEL_ID,
channel.setLockscreenVisibility(VISIBILITY_SECRET); getString(R.string.ongoing_notification_title),
NotificationManager nm = IMPORTANCE_NONE);
(NotificationManager) getSystemService(NOTIFICATION_SERVICE); ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
nm.createNotificationChannel(channel); nm.createNotificationChannel(ongoingChannel);
NotificationChannel failureChannel = new NotificationChannel(
FAILURE_CHANNEL_ID,
getString(R.string.startup_failed_notification_title),
IMPORTANCE_DEFAULT);
failureChannel.setLockscreenVisibility(VISIBILITY_SECRET);
nm.createNotificationChannel(failureChannel);
} }
// Show an ongoing notification that the service is running // Show an ongoing notification that the service is running
NotificationCompat.Builder b = NotificationCompat.Builder b =
new NotificationCompat.Builder(this, channelId); new NotificationCompat.Builder(this, ONGOING_CHANNEL_ID);
b.setSmallIcon(R.drawable.notification_ongoing); b.setSmallIcon(R.drawable.notification_ongoing);
b.setColor(ContextCompat.getColor(this, R.color.briar_primary)); b.setColor(ContextCompat.getColor(this, R.color.briar_primary));
b.setContentTitle(getText(R.string.ongoing_notification_title)); b.setContentTitle(getText(R.string.ongoing_notification_title));
@@ -97,7 +117,7 @@ public class BriarService extends Service {
Intent i = new Intent(this, NavDrawerActivity.class); Intent i = new Intent(this, NavDrawerActivity.class);
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP); i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
b.setContentIntent(PendingIntent.getActivity(this, 0, i, 0)); b.setContentIntent(PendingIntent.getActivity(this, 0, i, 0));
if (Build.VERSION.SDK_INT >= 21) { if (SDK_INT >= 21) {
b.setCategory(CATEGORY_SERVICE); b.setCategory(CATEGORY_SERVICE);
b.setVisibility(VISIBILITY_SECRET); b.setVisibility(VISIBILITY_SECRET);
} }
@@ -126,8 +146,8 @@ public class BriarService extends Service {
private void showStartupFailureNotification(StartResult result) { private void showStartupFailureNotification(StartResult result) {
androidExecutor.runOnUiThread(() -> { androidExecutor.runOnUiThread(() -> {
NotificationCompat.Builder b = NotificationCompat.Builder b = new NotificationCompat.Builder(
new NotificationCompat.Builder(BriarService.this); BriarService.this, FAILURE_CHANNEL_ID);
b.setSmallIcon(android.R.drawable.stat_notify_error); b.setSmallIcon(android.R.drawable.stat_notify_error);
b.setContentTitle(getText( b.setContentTitle(getText(
R.string.startup_failed_notification_title)); R.string.startup_failed_notification_title));
@@ -136,9 +156,8 @@ public class BriarService extends Service {
Intent i = new Intent(BriarService.this, Intent i = new Intent(BriarService.this,
StartupFailureActivity.class); StartupFailureActivity.class);
i.setFlags(FLAG_ACTIVITY_NEW_TASK); i.setFlags(FLAG_ACTIVITY_NEW_TASK);
i.putExtra("briar.START_RESULT", result); i.putExtra(EXTRA_START_RESULT, result);
i.putExtra("briar.FAILURE_NOTIFICATION_ID", i.putExtra(EXTRA_NOTIFICATION_ID, FAILURE_NOTIFICATION_ID);
FAILURE_NOTIFICATION_ID);
b.setContentIntent(PendingIntent.getActivity(BriarService.this, b.setContentIntent(PendingIntent.getActivity(BriarService.this,
0, i, FLAG_UPDATE_CURRENT)); 0, i, FLAG_UPDATE_CURRENT));
Object o = getSystemService(NOTIFICATION_SERVICE); Object o = getSystemService(NOTIFICATION_SERVICE);
@@ -147,7 +166,7 @@ public class BriarService extends Service {
// Bring the dashboard to the front to clear the back stack // Bring the dashboard to the front to clear the back stack
i = new Intent(BriarService.this, NavDrawerActivity.class); i = new Intent(BriarService.this, NavDrawerActivity.class);
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP); i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
i.putExtra("briar.STARTUP_FAILED", true); i.putExtra(EXTRA_STARTUP_FAILED, true);
startActivity(i); startActivity(i);
}); });
} }

View File

@@ -10,6 +10,8 @@ import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BaseActivity; import org.briarproject.briar.android.activity.BaseActivity;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult; import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult;
import static org.briarproject.briar.android.BriarService.EXTRA_NOTIFICATION_ID;
import static org.briarproject.briar.android.BriarService.EXTRA_START_RESULT;
public class StartupFailureActivity extends BaseActivity { public class StartupFailureActivity extends BaseActivity {
@@ -27,8 +29,9 @@ public class StartupFailureActivity extends BaseActivity {
} }
private void handleIntent(Intent i) { private void handleIntent(Intent i) {
StartResult result = (StartResult) i.getSerializableExtra("briar.START_RESULT"); StartResult result =
int notificationId = i.getIntExtra("briar.FAILURE_NOTIFICATION_ID", -1); (StartResult) i.getSerializableExtra(EXTRA_START_RESULT);
int notificationId = i.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
// cancel notification // cancel notification
if (notificationId > -1) { if (notificationId > -1) {

View File

@@ -36,7 +36,6 @@ import static org.briarproject.briar.android.util.UiUtils.getDozeWhitelistingInt
@SuppressLint("Registered") @SuppressLint("Registered")
public abstract class BriarActivity extends BaseActivity { public abstract class BriarActivity extends BaseActivity {
public static final String KEY_STARTUP_FAILED = "briar.STARTUP_FAILED";
public static final String GROUP_ID = "briar.GROUP_ID"; public static final String GROUP_ID = "briar.GROUP_ID";
public static final String GROUP_NAME = "briar.GROUP_NAME"; public static final String GROUP_NAME = "briar.GROUP_NAME";
@@ -131,8 +130,8 @@ public abstract class BriarActivity extends BaseActivity {
b.setNegativeButton(R.string.cancel, b.setNegativeButton(R.string.cancel,
(dialog, which) -> dialog.dismiss()); (dialog, which) -> dialog.dismiss());
b.setOnDismissListener(dialog -> { b.setOnDismissListener(dialog -> {
CheckBox checkBox = (CheckBox) ((AlertDialog) dialog) CheckBox checkBox =
.findViewById(R.id.checkbox); ((AlertDialog) dialog).findViewById(R.id.checkbox);
if (checkBox.isChecked()) if (checkBox.isChecked())
briarController.doNotAskAgainForDozeWhiteListing(); briarController.doNotAskAgainForDozeWhiteListing();
}); });

View File

@@ -51,6 +51,7 @@ import static android.support.v4.view.GravityCompat.START;
import static android.support.v4.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED; import static android.support.v4.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static org.briarproject.briar.android.BriarService.EXTRA_STARTUP_FAILED;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD; import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
import static org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning.NO; import static org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning.NO;
import static org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning.UPDATE; import static org.briarproject.briar.android.navdrawer.NavDrawerController.ExpiryWarning.UPDATE;
@@ -167,7 +168,7 @@ public class NavDrawerActivity extends BriarActivity implements
} }
private void exitIfStartupFailed(Intent intent) { private void exitIfStartupFailed(Intent intent) {
if (intent.getBooleanExtra(KEY_STARTUP_FAILED, false)) { if (intent.getBooleanExtra(EXTRA_STARTUP_FAILED, false)) {
finish(); finish();
LOG.info("Exiting"); LOG.info("Exiting");
System.exit(0); System.exit(0);

View File

@@ -12,8 +12,8 @@ import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
public class BriarNotificationBuilder extends NotificationCompat.Builder { public class BriarNotificationBuilder extends NotificationCompat.Builder {
public BriarNotificationBuilder(Context context) { public BriarNotificationBuilder(Context context, String channelId) {
super(context); super(context, channelId);
// Auto-cancel does not fire the delete intent, see // Auto-cancel does not fire the delete intent, see
// https://issuetracker.google.com/issues/36961721 // https://issuetracker.google.com/issues/36961721
setAutoCancel(true); setAutoCancel(true);