mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Minimal Sign-in reminder
This commit is contained in:
@@ -85,13 +85,6 @@ import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_
|
||||
class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
Service, EventListener {
|
||||
|
||||
// Notification IDs
|
||||
private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3;
|
||||
private static final int GROUP_MESSAGE_NOTIFICATION_ID = 4;
|
||||
private static final int FORUM_POST_NOTIFICATION_ID = 5;
|
||||
private static final int BLOG_POST_NOTIFICATION_ID = 6;
|
||||
private static final int INTRODUCTION_SUCCESS_NOTIFICATION_ID = 7;
|
||||
|
||||
private static final long SOUND_DELAY = TimeUnit.SECONDS.toMillis(2);
|
||||
|
||||
private static final Logger LOG =
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.briarproject.briar.android;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||
|
||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.content.Context.NOTIFICATION_SERVICE;
|
||||
import static android.content.Intent.ACTION_BOOT_COMPLETED;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.support.v4.app.NotificationCompat.PRIORITY_LOW;
|
||||
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_CHANNEL_ID;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_NOTIFICATION_ID;
|
||||
|
||||
public class BootReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context ctx, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action != null && action.equals(ACTION_BOOT_COMPLETED)) {
|
||||
showSignInNotification(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private void showSignInNotification(Context ctx) {
|
||||
NotificationManager nm = (NotificationManager)
|
||||
ctx.getSystemService(NOTIFICATION_SERVICE);
|
||||
if (nm == null) return;
|
||||
|
||||
if (SDK_INT >= 26) {
|
||||
NotificationChannel channel =
|
||||
new NotificationChannel(REMINDER_CHANNEL_ID, ctx.getString(
|
||||
R.string.reminder_notification_channel_title),
|
||||
IMPORTANCE_LOW);
|
||||
channel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||
nm.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(ctx, REMINDER_CHANNEL_ID);
|
||||
b.setSmallIcon(R.drawable.notification_reminder);
|
||||
b.setColor(ContextCompat.getColor(ctx, R.color.briar_primary));
|
||||
b.setContentTitle(ctx.getText(R.string.reminder_notification_title));
|
||||
b.setContentText(ctx.getText(R.string.reminder_notification_text));
|
||||
b.setAutoCancel(true);
|
||||
b.setWhen(0); // Don't show the time
|
||||
b.setPriority(PRIORITY_LOW);
|
||||
|
||||
Intent i = new Intent(ctx, NavDrawerActivity.class);
|
||||
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
|
||||
b.setContentIntent(PendingIntent.getActivity(ctx, 0, i, 0));
|
||||
|
||||
nm.notify(REMINDER_NOTIFICATION_ID, b.build());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,6 +50,11 @@ import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.ALREADY_RUNNING;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.SUCCESS;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_NOTIFICATION_ID;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_NOTIFICATION_ID;
|
||||
|
||||
public class BriarService extends Service {
|
||||
|
||||
@@ -60,14 +65,6 @@ public class BriarService extends Service {
|
||||
public static String EXTRA_STARTUP_FAILED =
|
||||
"org.briarproject.briar.STARTUP_FAILED";
|
||||
|
||||
private static final int ONGOING_NOTIFICATION_ID = 1;
|
||||
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 =
|
||||
Logger.getLogger(BriarService.class.getName());
|
||||
|
||||
@@ -106,9 +103,9 @@ public class BriarService extends Service {
|
||||
}
|
||||
|
||||
// Create notification channels
|
||||
NotificationManager nm = (NotificationManager)
|
||||
getSystemService(NOTIFICATION_SERVICE);
|
||||
if (SDK_INT >= 26) {
|
||||
NotificationManager nm = (NotificationManager)
|
||||
getSystemService(NOTIFICATION_SERVICE);
|
||||
NotificationChannel ongoingChannel = new NotificationChannel(
|
||||
ONGOING_CHANNEL_ID,
|
||||
getString(R.string.ongoing_notification_title),
|
||||
@@ -140,6 +137,8 @@ public class BriarService extends Service {
|
||||
}
|
||||
b.setPriority(PRIORITY_MIN);
|
||||
startForeground(ONGOING_NOTIFICATION_ID, b.build());
|
||||
// Remove sign-in reminder notification
|
||||
nm.cancel(REMINDER_NOTIFICATION_ID);
|
||||
// Start the services in a background thread
|
||||
new Thread(() -> {
|
||||
String nickname = databaseConfig.getLocalAuthorName();
|
||||
|
||||
@@ -21,11 +21,26 @@ public interface AndroidNotificationManager {
|
||||
String PREF_NOTIFY_VIBRATION = "notifyVibration";
|
||||
String PREF_NOTIFY_LOCK_SCREEN = "notifyLockScreen";
|
||||
|
||||
// Notification IDs
|
||||
int ONGOING_NOTIFICATION_ID = 1;
|
||||
int FAILURE_NOTIFICATION_ID = 2;
|
||||
int REMINDER_NOTIFICATION_ID = 3;
|
||||
int PRIVATE_MESSAGE_NOTIFICATION_ID = 4;
|
||||
int GROUP_MESSAGE_NOTIFICATION_ID = 5;
|
||||
int FORUM_POST_NOTIFICATION_ID = 6;
|
||||
int BLOG_POST_NOTIFICATION_ID = 7;
|
||||
int INTRODUCTION_SUCCESS_NOTIFICATION_ID = 8;
|
||||
|
||||
// Channel IDs
|
||||
String CONTACT_CHANNEL_ID = "contacts";
|
||||
String GROUP_CHANNEL_ID = "groups";
|
||||
String FORUM_CHANNEL_ID = "forums";
|
||||
String BLOG_CHANNEL_ID = "blogs";
|
||||
// Channels are sorted by channel ID in the Settings app, so use IDs
|
||||
// that will sort below the main channels such as contacts
|
||||
String ONGOING_CHANNEL_ID = "zForegroundService";
|
||||
String FAILURE_CHANNEL_ID = "zStartupFailure";
|
||||
String REMINDER_CHANNEL_ID = "zSignInReminder";
|
||||
|
||||
// Content URIs for pending intents
|
||||
String CONTACT_URI = "content://org.briarproject.briar/contact";
|
||||
|
||||
Reference in New Issue
Block a user