Introduce NotificationChannelManager
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.service;
|
||||
|
||||
|
||||
import android.Manifest;
|
||||
import android.accounts.Account;
|
||||
import android.app.PendingIntent;
|
||||
@@ -38,6 +39,7 @@ import android.support.v4.content.ContextCompat;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.KeychainApplication;
|
||||
import org.sufficientlysecure.keychain.NotificationChannelManager;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.SettingsActivity;
|
||||
import org.sufficientlysecure.keychain.util.ContactHelper;
|
||||
@@ -73,6 +75,8 @@ public class ContactSyncAdapterService extends Service {
|
||||
// deactivate sync
|
||||
ContentResolver.setSyncAutomatically(account, authority, false);
|
||||
|
||||
NotificationChannelManager.getInstance(getContext()).createNotificationChannelsIfNecessary();
|
||||
|
||||
// show notification linking to sync settings
|
||||
Intent resultIntent = new Intent(ContactSyncAdapterService.this, SettingsActivity.class);
|
||||
resultIntent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
|
||||
@@ -85,7 +89,7 @@ public class ContactSyncAdapterService extends Service {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
);
|
||||
NotificationCompat.Builder mBuilder =
|
||||
new NotificationCompat.Builder(ContactSyncAdapterService.this)
|
||||
new NotificationCompat.Builder(ContactSyncAdapterService.this, NotificationChannelManager.PERMISSION_REQUESTS)
|
||||
.setAutoCancel(true)
|
||||
.setSmallIcon(R.drawable.ic_stat_notify_24dp)
|
||||
.setColor(getResources().getColor(R.color.primary))
|
||||
|
||||
@@ -22,8 +22,6 @@ import java.util.Date;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -31,7 +29,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
@@ -45,11 +42,11 @@ import android.support.v4.app.NotificationCompat.InboxStyle;
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.Constants.NotificationChannels;
|
||||
import org.sufficientlysecure.keychain.Constants.NotificationIds;
|
||||
import org.sufficientlysecure.keychain.NotificationChannelManager;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
import org.sufficientlysecure.keychain.daos.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import timber.log.Timber;
|
||||
@@ -494,7 +491,6 @@ public class PassphraseCacheService extends Service {
|
||||
|
||||
private void updateService() {
|
||||
if (mPassphraseCache.size() > 0) {
|
||||
createNotificationChannelsIfNecessary();
|
||||
startForeground(NotificationIds.PASSPHRASE_CACHE, getNotification());
|
||||
} else {
|
||||
// stop whole service if no cached passphrases remaining
|
||||
@@ -505,7 +501,9 @@ public class PassphraseCacheService extends Service {
|
||||
}
|
||||
|
||||
private Notification getNotification() {
|
||||
Builder builder = new Builder(this, NotificationChannels.PASSPHRASE_CACHE);
|
||||
NotificationChannelManager.getInstance(this).createNotificationChannelsIfNecessary();
|
||||
|
||||
Builder builder = new Builder(this, NotificationChannelManager.PASSPHRASE_CACHE);
|
||||
builder.setSmallIcon(R.drawable.ic_stat_notify_24dp)
|
||||
.setColor(getResources().getColor(R.color.primary))
|
||||
.setContentTitle(getResources().getQuantityString(R.plurals.passp_cache_notif_n_keys,
|
||||
@@ -547,22 +545,6 @@ public class PassphraseCacheService extends Service {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private void createNotificationChannelsIfNecessary() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
return;
|
||||
}
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (notificationManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
CharSequence name = getString(R.string.notify_channel_passcache);
|
||||
NotificationChannel channel = new NotificationChannel(
|
||||
NotificationChannels.PASSPHRASE_CACHE, name, NotificationManager.IMPORTANCE_LOW);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
Reference in New Issue
Block a user