initial work toward api 26+
* introduce notification channels * always use foreground service on 26+
This commit is contained in:
parent
d5b50d1076
commit
676d31f606
|
@ -60,13 +60,13 @@ ext {
|
|||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
compileSdkVersion 28
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 25
|
||||
targetSdkVersion 28
|
||||
versionCode 283
|
||||
versionName "2.2.9"
|
||||
versionName "2.3.0-alpha"
|
||||
archivesBaseName += "-$versionName"
|
||||
applicationId "eu.siacs.conversations"
|
||||
resValue "string", "applicationId", applicationId
|
||||
|
|
|
@ -13,4 +13,3 @@
|
|||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
org.gradle.jvmargs=-Xmx2048M
|
||||
org.gradle.configureondemand=false
|
||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.location"
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.os.CancellationSignal;
|
|||
import android.os.IBinder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
@ -162,7 +163,6 @@ public class BarcodeProvider extends ContentProvider implements ServiceConnectio
|
|||
synchronized (this) {
|
||||
if (mXmppConnectionService == null && !mBindingInProcess) {
|
||||
Log.d(Config.LOGTAG, "calling to bind service");
|
||||
context.startService(intent);
|
||||
context.bindService(intent, this, Context.BIND_AUTO_CREATE);
|
||||
this.mBindingInProcess = true;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.os.Bundle;
|
|||
import android.os.IBinder;
|
||||
import android.service.chooser.ChooserTarget;
|
||||
import android.service.chooser.ChooserTargetService;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -32,7 +33,6 @@ public class ContactChooserTargetService extends ChooserTargetService implements
|
|||
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
|
||||
Intent intent = new Intent(this, XmppConnectionService.class);
|
||||
intent.setAction("contact_chooser");
|
||||
startService(intent);
|
||||
bindService(intent, this, Context.BIND_AUTO_CREATE);
|
||||
ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
|
||||
try {
|
||||
|
|
|
@ -3,38 +3,37 @@ package eu.siacs.conversations.services;
|
|||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.persistance.DatabaseBackend;
|
||||
|
||||
public class EventReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String SETTING_ENABLED_ACCOUNTS = "enabled_accounts";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Intent mIntentForService = new Intent(context, XmppConnectionService.class);
|
||||
if (intent.getAction() != null) {
|
||||
mIntentForService.setAction(intent.getAction());
|
||||
public void onReceive(final Context context, final Intent originalIntent) {
|
||||
final Intent intentForService = new Intent(context, XmppConnectionService.class);
|
||||
if (originalIntent.getAction() != null) {
|
||||
intentForService.setAction(originalIntent.getAction());
|
||||
} else {
|
||||
mIntentForService.setAction("other");
|
||||
intentForService.setAction("other");
|
||||
}
|
||||
final String action = intent.getAction();
|
||||
final String action = originalIntent.getAction();
|
||||
if (action.equals("ui") || hasEnabledAccounts(context)) {
|
||||
try {
|
||||
context.startService(mIntentForService);
|
||||
ContextCompat.startForegroundService(context, intentForService);
|
||||
} catch (RuntimeException e) {
|
||||
Log.d(Config.LOGTAG,"EventReceiver was unable to start service");
|
||||
}
|
||||
} else {
|
||||
Log.d(Config.LOGTAG,"EventReceiver ignored action "+mIntentForService.getAction());
|
||||
Log.d(Config.LOGTAG,"EventReceiver ignored action "+intentForService.getAction());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasEnabledAccounts(Context context) {
|
||||
public static boolean hasEnabledAccounts(final Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTING_ENABLED_ACCOUNTS,true);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,14 +42,11 @@ public class ExportLogsService extends Service {
|
|||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (running.compareAndSet(false, true)) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Thread(() -> {
|
||||
export();
|
||||
stopForeground(true);
|
||||
running.set(false);
|
||||
stopSelf();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
return START_NOT_STICKY;
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
package eu.siacs.conversations.services;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Typeface;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationCompat.BigPictureStyle;
|
||||
import android.support.v4.app.NotificationCompat.Builder;
|
||||
|
@ -25,7 +32,6 @@ import android.util.Log;
|
|||
import android.util.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
@ -49,6 +55,7 @@ import eu.siacs.conversations.persistance.FileBackend;
|
|||
import eu.siacs.conversations.ui.ConversationsActivity;
|
||||
import eu.siacs.conversations.ui.ManageAccountActivity;
|
||||
import eu.siacs.conversations.ui.TimePreference;
|
||||
import eu.siacs.conversations.utils.Compatibility;
|
||||
import eu.siacs.conversations.utils.GeoHelper;
|
||||
import eu.siacs.conversations.utils.UIHelper;
|
||||
import eu.siacs.conversations.xmpp.XmppConnection;
|
||||
|
@ -58,26 +65,88 @@ public class NotificationService {
|
|||
public static final Object CATCHUP_LOCK = new Object();
|
||||
|
||||
private static final String CONVERSATIONS_GROUP = "eu.siacs.conversations";
|
||||
private final XmppConnectionService mXmppConnectionService;
|
||||
|
||||
private final LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<>();
|
||||
|
||||
private static final int NOTIFICATION_ID_MULTIPLIER = 1024 * 1024;
|
||||
|
||||
public static final int NOTIFICATION_ID = 2 * NOTIFICATION_ID_MULTIPLIER;
|
||||
private static final int NOTIFICATION_ID = 2 * NOTIFICATION_ID_MULTIPLIER;
|
||||
public static final int FOREGROUND_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 4;
|
||||
public static final int ERROR_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 6;
|
||||
|
||||
private static final int ERROR_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 6;
|
||||
private final XmppConnectionService mXmppConnectionService;
|
||||
private final LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<>();
|
||||
private final HashMap<Conversation, AtomicInteger> mBacklogMessageCounter = new HashMap<>();
|
||||
private Conversation mOpenConversation;
|
||||
private boolean mIsInForeground;
|
||||
private long mLastNotification;
|
||||
|
||||
private final HashMap<Conversation, AtomicInteger> mBacklogMessageCounter = new HashMap<>();
|
||||
|
||||
public NotificationService(final XmppConnectionService service) {
|
||||
NotificationService(final XmppConnectionService service) {
|
||||
this.mXmppConnectionService = service;
|
||||
}
|
||||
|
||||
private static boolean displaySnoozeAction(List<Message> messages) {
|
||||
int numberOfMessagesWithoutReply = 0;
|
||||
for (Message message : messages) {
|
||||
if (message.getStatus() == Message.STATUS_RECEIVED) {
|
||||
++numberOfMessagesWithoutReply;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return numberOfMessagesWithoutReply >= 3;
|
||||
}
|
||||
|
||||
public static Pattern generateNickHighlightPattern(final String nick) {
|
||||
return Pattern.compile("(?<=(^|\\s))" + Pattern.quote(nick) + "\\b");
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public void initializeChannels() {
|
||||
final Context c = mXmppConnectionService;
|
||||
NotificationManager notificationManager = c.getSystemService(NotificationManager.class);
|
||||
if (notificationManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("status", c.getString(R.string.notification_group_status_information)));
|
||||
notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("chats", c.getString(R.string.notification_group_messages)));
|
||||
final NotificationChannel foregroundServiceChannel = new NotificationChannel("foreground",
|
||||
c.getString(R.string.foreground_service_channel_name),
|
||||
NotificationManager.IMPORTANCE_MIN);
|
||||
foregroundServiceChannel.setDescription(c.getString(R.string.foreground_service_channel_description));
|
||||
foregroundServiceChannel.setShowBadge(false);
|
||||
foregroundServiceChannel.setGroup("status");
|
||||
notificationManager.createNotificationChannel(foregroundServiceChannel);
|
||||
final NotificationChannel errorChannel = new NotificationChannel("error",
|
||||
c.getString(R.string.error_channel_name),
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
errorChannel.setDescription(c.getString(R.string.error_channel_description));
|
||||
errorChannel.setShowBadge(false);
|
||||
errorChannel.setGroup("status");
|
||||
notificationManager.createNotificationChannel(errorChannel);
|
||||
final NotificationChannel messagesChannel = new NotificationChannel("messages",
|
||||
c.getString(R.string.messages_channel_name),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
messagesChannel.setShowBadge(true);
|
||||
messagesChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), new AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
|
||||
.build());
|
||||
messagesChannel.setLightColor(0xff00ff00);
|
||||
final int dat = 70;
|
||||
final long[] pattern = {0, 3 * dat, dat, dat};
|
||||
messagesChannel.setVibrationPattern(pattern);
|
||||
messagesChannel.enableVibration(true);
|
||||
messagesChannel.enableLights(true);
|
||||
messagesChannel.setGroup("chats");
|
||||
notificationManager.createNotificationChannel(messagesChannel);
|
||||
final NotificationChannel silentMessagesChannel = new NotificationChannel("silent_messages",
|
||||
c.getString(R.string.silent_messages_channel_name),
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
silentMessagesChannel.setDescription(c.getString(R.string.silent_messages_channel_description));
|
||||
silentMessagesChannel.setShowBadge(true);
|
||||
silentMessagesChannel.setLightColor(0xff00ff00);
|
||||
silentMessagesChannel.enableLights(true);
|
||||
silentMessagesChannel.setGroup("chats");
|
||||
notificationManager.createNotificationChannel(silentMessagesChannel);
|
||||
}
|
||||
|
||||
public boolean notify(final Message message) {
|
||||
final Conversation conversation = (Conversation) message.getConversation();
|
||||
return message.getStatus() == Message.STATUS_RECEIVED
|
||||
|
@ -88,7 +157,7 @@ public class NotificationService {
|
|||
;
|
||||
}
|
||||
|
||||
public boolean notificationsEnabled() {
|
||||
private boolean notificationsEnabled() {
|
||||
return mXmppConnectionService.getBooleanPreference("show_notification", R.bool.show_notification);
|
||||
}
|
||||
|
||||
|
@ -96,7 +165,7 @@ public class NotificationService {
|
|||
return mXmppConnectionService.getBooleanPreference("notifications_from_strangers", R.bool.notifications_from_strangers);
|
||||
}
|
||||
|
||||
public boolean isQuietHours() {
|
||||
private boolean isQuietHours() {
|
||||
if (!mXmppConnectionService.getBooleanPreference("enable_quiet_hours", R.bool.enable_quiet_hours)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -257,7 +326,7 @@ public class NotificationService {
|
|||
updateNotification(notify, false);
|
||||
}
|
||||
|
||||
public void updateNotification(final boolean notify, boolean summaryOnly) {
|
||||
private void updateNotification(final boolean notify, boolean summaryOnly) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService);
|
||||
|
||||
if (notifications.size() == 0) {
|
||||
|
@ -268,15 +337,16 @@ public class NotificationService {
|
|||
}
|
||||
final Builder mBuilder;
|
||||
if (notifications.size() == 1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||
mBuilder = buildSingleConversations(notifications.values().iterator().next());
|
||||
mBuilder = buildSingleConversations(notifications.values().iterator().next(), notify);
|
||||
modifyForSoundVibrationAndLight(mBuilder, notify, preferences);
|
||||
notify(NOTIFICATION_ID, mBuilder.build());
|
||||
} else {
|
||||
mBuilder = buildMultipleConversation();
|
||||
mBuilder = buildMultipleConversation(notify);
|
||||
mBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
|
||||
modifyForSoundVibrationAndLight(mBuilder, notify, preferences);
|
||||
if (!summaryOnly) {
|
||||
for (Map.Entry<String, ArrayList<Message>> entry : notifications.entrySet()) {
|
||||
Builder singleBuilder = buildSingleConversations(entry.getValue());
|
||||
Builder singleBuilder = buildSingleConversations(entry.getValue(), notify);
|
||||
singleBuilder.setGroup(CONVERSATIONS_GROUP);
|
||||
setNotificationColor(singleBuilder);
|
||||
notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build());
|
||||
|
@ -287,7 +357,6 @@ public class NotificationService {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void modifyForSoundVibrationAndLight(Builder mBuilder, boolean notify, SharedPreferences preferences) {
|
||||
final Resources resources = mXmppConnectionService.getResources();
|
||||
final String ringtone = preferences.getString("notification_ringtone", resources.getString(R.string.notification_ringtone));
|
||||
|
@ -328,9 +397,8 @@ public class NotificationService {
|
|||
}
|
||||
}
|
||||
|
||||
private Builder buildMultipleConversation() {
|
||||
final Builder mBuilder = new NotificationCompat.Builder(
|
||||
mXmppConnectionService);
|
||||
private Builder buildMultipleConversation(final boolean notify) {
|
||||
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService, notify ? "messages" : "silent_messages");
|
||||
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
||||
style.setBigContentTitle(notifications.size()
|
||||
+ " "
|
||||
|
@ -376,8 +444,8 @@ public class NotificationService {
|
|||
return mBuilder;
|
||||
}
|
||||
|
||||
private Builder buildSingleConversations(final ArrayList<Message> messages) {
|
||||
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
||||
private Builder buildSingleConversations(final ArrayList<Message> messages, final boolean notify) {
|
||||
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService, notify ? "messages" : "silent_messages");
|
||||
if (messages.size() >= 1) {
|
||||
final Conversation conversation = (Conversation) messages.get(0).getConversation();
|
||||
final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName().toString());
|
||||
|
@ -471,18 +539,6 @@ public class NotificationService {
|
|||
return mBuilder;
|
||||
}
|
||||
|
||||
private static boolean displaySnoozeAction(List<Message> messages) {
|
||||
int numberOfMessagesWithoutReply = 0;
|
||||
for (Message message : messages) {
|
||||
if (message.getStatus() == Message.STATUS_RECEIVED) {
|
||||
++numberOfMessagesWithoutReply;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return numberOfMessagesWithoutReply >= 3;
|
||||
}
|
||||
|
||||
private void modifyForImage(final Builder builder, final UnreadConversation.Builder uBuilder,
|
||||
final Message message, final ArrayList<Message> messages) {
|
||||
try {
|
||||
|
@ -674,7 +730,7 @@ public class NotificationService {
|
|||
return PendingIntent.getService(mXmppConnectionService, generateRequestCode(conversation, 16), intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
public PendingIntent createSnoozeIntent(Conversation conversation) {
|
||||
private PendingIntent createSnoozeIntent(Conversation conversation) {
|
||||
final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
|
||||
intent.setAction(XmppConnectionService.ACTION_SNOOZE);
|
||||
intent.putExtra("uuid", conversation.getUuid());
|
||||
|
@ -709,10 +765,6 @@ public class NotificationService {
|
|||
}
|
||||
}
|
||||
|
||||
public static Pattern generateNickHighlightPattern(final String nick) {
|
||||
return Pattern.compile("(?<=(^|\\s))" + Pattern.quote(nick) + "\\b");
|
||||
}
|
||||
|
||||
public void setOpenConversation(final Conversation conversation) {
|
||||
this.mOpenConversation = conversation;
|
||||
}
|
||||
|
@ -738,10 +790,9 @@ public class NotificationService {
|
|||
}
|
||||
|
||||
public Notification createForegroundNotification() {
|
||||
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
||||
|
||||
final Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService);
|
||||
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service));
|
||||
if (Config.SHOW_CONNECTED_ACCOUNTS) {
|
||||
if (Compatibility.twentySix() || Config.SHOW_CONNECTED_ACCOUNTS) {
|
||||
List<Account> accounts = mXmppConnectionService.getAccounts();
|
||||
int enabled = 0;
|
||||
int connected = 0;
|
||||
|
@ -759,8 +810,14 @@ public class NotificationService {
|
|||
}
|
||||
mBuilder.setContentIntent(createOpenConversationsIntent());
|
||||
mBuilder.setWhen(0);
|
||||
mBuilder.setPriority(Config.SHOW_CONNECTED_ACCOUNTS ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_MIN);
|
||||
mBuilder.setPriority(Notification.PRIORITY_LOW);
|
||||
mBuilder.setSmallIcon(R.drawable.ic_link_white_24dp);
|
||||
|
||||
if (Compatibility.twentySix()) {
|
||||
mBuilder.setChannelId("foreground");
|
||||
}
|
||||
|
||||
|
||||
return mBuilder.build();
|
||||
}
|
||||
|
||||
|
@ -779,10 +836,10 @@ public class NotificationService {
|
|||
errors.add(account);
|
||||
}
|
||||
}
|
||||
if (mXmppConnectionService.keepForegroundService()) {
|
||||
if (Compatibility.keepForegroundService(mXmppConnectionService)) {
|
||||
notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification());
|
||||
}
|
||||
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
||||
final Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService);
|
||||
if (errors.size() == 0) {
|
||||
cancel(ERROR_NOTIFICATION_ID);
|
||||
return;
|
||||
|
@ -797,30 +854,37 @@ public class NotificationService {
|
|||
mXmppConnectionService.getString(R.string.try_again),
|
||||
createTryAgainIntent());
|
||||
mBuilder.setDeleteIntent(createDismissErrorIntent());
|
||||
mBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
mBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
|
||||
mBuilder.setSmallIcon(R.drawable.ic_warning_white_24dp);
|
||||
} else {
|
||||
mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
|
||||
mBuilder.setLocalOnly(true);
|
||||
mBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
|
||||
}
|
||||
mBuilder.setPriority(Notification.PRIORITY_LOW);
|
||||
mBuilder.setContentIntent(PendingIntent.getActivity(mXmppConnectionService,
|
||||
145,
|
||||
new Intent(mXmppConnectionService, ManageAccountActivity.class),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT));
|
||||
if (Compatibility.twentySix()) {
|
||||
mBuilder.setChannelId("error");
|
||||
}
|
||||
notify(ERROR_NOTIFICATION_ID, mBuilder.build());
|
||||
}
|
||||
|
||||
public Notification updateFileAddingNotification(int current, Message message) {
|
||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
||||
public void updateFileAddingNotification(int current, Message message) {
|
||||
Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService);
|
||||
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.transcoding_video));
|
||||
mBuilder.setProgress(100, current, false);
|
||||
mBuilder.setSmallIcon(R.drawable.ic_hourglass_empty_white_24dp);
|
||||
mBuilder.setContentIntent(createContentIntent(message.getConversation()));
|
||||
if (Compatibility.twentySix()) {
|
||||
mBuilder.setChannelId("foreground");
|
||||
}
|
||||
Notification notification = mBuilder.build();
|
||||
notify(FOREGROUND_NOTIFICATION_ID, notification);
|
||||
return notification;
|
||||
}
|
||||
|
||||
private void notify(String tag, int id, Notification notification) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.siacs.conversations.services;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlarmManager;
|
||||
|
@ -104,6 +105,7 @@ import eu.siacs.conversations.ui.SettingsActivity;
|
|||
import eu.siacs.conversations.ui.UiCallback;
|
||||
import eu.siacs.conversations.ui.interfaces.OnAvatarPublication;
|
||||
import eu.siacs.conversations.ui.interfaces.OnSearchResultsAvailable;
|
||||
import eu.siacs.conversations.utils.Compatibility;
|
||||
import eu.siacs.conversations.utils.ConversationsFileObserver;
|
||||
import eu.siacs.conversations.utils.CryptoHelper;
|
||||
import eu.siacs.conversations.utils.ExceptionHelper;
|
||||
|
@ -157,7 +159,6 @@ public class XmppConnectionService extends Service {
|
|||
public static final String ACTION_IDLE_PING = "idle_ping";
|
||||
public static final String ACTION_FCM_TOKEN_REFRESH = "fcm_token_refresh";
|
||||
public static final String ACTION_FCM_MESSAGE_RECEIVED = "fcm_message_received";
|
||||
private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
|
||||
|
||||
private static final String SETTING_LAST_ACTIVITY_TS = "last_activity_timestamp";
|
||||
|
||||
|
@ -193,10 +194,9 @@ public class XmppConnectionService extends Service {
|
|||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
Intent intent = new Intent(getApplicationContext(),
|
||||
XmppConnectionService.class);
|
||||
intent.setAction(ACTION_MERGE_PHONE_CONTACTS);
|
||||
startService(intent);
|
||||
if (restoredFromDatabaseLatch.getCount() == 0) {
|
||||
loadPhoneContacts();
|
||||
}
|
||||
}
|
||||
};
|
||||
private FileBackend fileBackend = new FileBackend(this);
|
||||
|
@ -240,6 +240,7 @@ public class XmppConnectionService extends Service {
|
|||
) {
|
||||
@Override
|
||||
public void onEvent(int event, String path) {
|
||||
Log.d(Config.LOGTAG,"event "+event+" path="+path);
|
||||
markFileDeleted(path);
|
||||
}
|
||||
};
|
||||
|
@ -569,11 +570,6 @@ public class XmppConnectionService extends Service {
|
|||
resetAllAttemptCounts(true, false);
|
||||
}
|
||||
break;
|
||||
case ACTION_MERGE_PHONE_CONTACTS:
|
||||
if (restoredFromDatabaseLatch.getCount() == 0) {
|
||||
loadPhoneContacts();
|
||||
}
|
||||
return START_STICKY;
|
||||
case Intent.ACTION_SHUTDOWN:
|
||||
logoutAndSave(true);
|
||||
return START_NOT_STICKY;
|
||||
|
@ -958,6 +954,9 @@ public class XmppConnectionService extends Service {
|
|||
Resolver.init(this);
|
||||
this.mRandom = new SecureRandom();
|
||||
updateMemorizingTrustmanager();
|
||||
if (Compatibility.twentySix()) {
|
||||
mNotificationService.initializeChannels();
|
||||
}
|
||||
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
|
||||
final int cacheSize = maxMemory / 8;
|
||||
this.mBitmapCache = new LruCache<String, Bitmap>(cacheSize) {
|
||||
|
@ -984,7 +983,10 @@ public class XmppConnectionService extends Service {
|
|||
|
||||
restoreFromDatabase();
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
||||
//TODO get this restarted if users gives permission
|
||||
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.d(Config.LOGTAG, "starting file observer");
|
||||
new Thread(fileObserver::startWatching).start();
|
||||
|
@ -1062,7 +1064,7 @@ public class XmppConnectionService extends Service {
|
|||
}
|
||||
|
||||
public void toggleForegroundService() {
|
||||
if (mForceForegroundService.get() || (keepForegroundService() && hasEnabledAccounts())) {
|
||||
if (mForceForegroundService.get() || (Compatibility.keepForegroundService(this) && hasEnabledAccounts())) {
|
||||
startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification());
|
||||
Log.d(Config.LOGTAG, "started foreground service");
|
||||
} else {
|
||||
|
@ -1071,14 +1073,11 @@ public class XmppConnectionService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean keepForegroundService() {
|
||||
return getBooleanPreference(SettingsActivity.KEEP_FOREGROUND_SERVICE, R.bool.enable_foreground_service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskRemoved(final Intent rootIntent) {
|
||||
super.onTaskRemoved(rootIntent);
|
||||
if (keepForegroundService() || mForceForegroundService.get()) {
|
||||
//TODO check for accounts enabled
|
||||
if ((Compatibility.keepForegroundService(this) && hasEnabledAccounts()) || mForceForegroundService.get()) {
|
||||
Log.d(Config.LOGTAG, "ignoring onTaskRemoved because foreground service is activated");
|
||||
} else {
|
||||
this.logoutAndSave(false);
|
||||
|
@ -1951,6 +1950,7 @@ public class XmppConnectionService extends Service {
|
|||
updateAccountUi();
|
||||
getNotificationService().updateErrorNotification();
|
||||
syncEnabledAccountSetting();
|
||||
toggleForegroundService();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.siacs.conversations.ui;
|
|||
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -406,7 +407,7 @@ public class SettingsActivity extends XmppActivity implements
|
|||
}
|
||||
|
||||
private void startExport() {
|
||||
startService(new Intent(getApplicationContext(), ExportLogsService.class));
|
||||
ContextCompat.startForegroundService(this, new Intent(this, ExportLogsService.class));
|
||||
}
|
||||
|
||||
private void displayToast(final String msg) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.widget.ListView;
|
|||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.utils.Compatibility;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragment {
|
||||
|
||||
|
@ -32,6 +33,7 @@ public class SettingsFragment extends PreferenceFragment {
|
|||
mCategory.removePreference(cleanPrivateStorage);
|
||||
}
|
||||
}
|
||||
Compatibility.removeUnusedPreferences(this);
|
||||
|
||||
if (!TextUtils.isEmpty(page)) {
|
||||
openPreferenceScreen(page);
|
||||
|
|
|
@ -536,7 +536,11 @@ public abstract class XmppActivity extends ActionBarActivity {
|
|||
intent.setAction(Intent.ACTION_SEND);
|
||||
intent.setData(uri);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
try {
|
||||
startService(intent);
|
||||
} catch (Exception e) {
|
||||
Log.e(Config.LOGTAG,"unable to delegate uri permission",e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void inviteToConversation(Conversation conversation) {
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package eu.siacs.conversations.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.BoolRes;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.ui.SettingsActivity;
|
||||
import eu.siacs.conversations.ui.SettingsFragment;
|
||||
|
||||
public class Compatibility {
|
||||
|
||||
private static final List<String> UNUSED_SETTINGS_POST_TWENTYSIX = Arrays.asList(
|
||||
SettingsActivity.KEEP_FOREGROUND_SERVICE,
|
||||
"led",
|
||||
"notification_ringtone",
|
||||
"notification_headsup",
|
||||
"vibrate_on_notification");
|
||||
private static final List<String> UNUESD_SETTINGS_PRE_TWENTYSIX = Collections.singletonList("more_notification_settings");
|
||||
|
||||
|
||||
public static boolean twentySix() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
|
||||
}
|
||||
|
||||
private static boolean getBooleanPreference(Context context, String name, @BoolRes int res) {
|
||||
return getPreferences(context).getBoolean(name, context.getResources().getBoolean(res));
|
||||
}
|
||||
|
||||
private static SharedPreferences getPreferences(final Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
public static boolean keepForegroundService(Context context) {
|
||||
return twentySix() || getBooleanPreference(context, SettingsActivity.KEEP_FOREGROUND_SERVICE, R.bool.enable_foreground_service);
|
||||
}
|
||||
|
||||
public static void removeUnusedPreferences(SettingsFragment settingsFragment) {
|
||||
List<PreferenceCategory> categories = Arrays.asList(
|
||||
(PreferenceCategory) settingsFragment.findPreference("notification_category"),
|
||||
(PreferenceCategory) settingsFragment.findPreference("other_expert_category"));
|
||||
for (String key : (twentySix() ? UNUSED_SETTINGS_POST_TWENTYSIX : UNUESD_SETTINGS_PRE_TWENTYSIX)) {
|
||||
Preference preference = settingsFragment.findPreference(key);
|
||||
if (preference != null) {
|
||||
for (PreferenceCategory category : categories) {
|
||||
if (category != null) {
|
||||
category.removePreference(preference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,12 +2,15 @@ package eu.siacs.conversations.utils;
|
|||
|
||||
|
||||
import android.os.FileObserver;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import eu.siacs.conversations.Config;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2012 Bartek Przybylski
|
||||
* Copyright (C) 2015 ownCloud Inc.
|
||||
|
@ -19,7 +22,7 @@ public abstract class ConversationsFileObserver {
|
|||
private final String path;
|
||||
private final List<SingleFileObserver> mObservers = new ArrayList<>();
|
||||
|
||||
public ConversationsFileObserver(String path) {
|
||||
protected ConversationsFileObserver(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
|
@ -83,13 +86,17 @@ public abstract class ConversationsFileObserver {
|
|||
private class SingleFileObserver extends FileObserver {
|
||||
private final String path;
|
||||
|
||||
public SingleFileObserver(String path, int mask) {
|
||||
SingleFileObserver(String path, int mask) {
|
||||
super(path, mask);
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int event, String filename) {
|
||||
if (filename == null) {
|
||||
Log.d(Config.LOGTAG,"ignored file event with NULL filename (event="+event+")");
|
||||
return;
|
||||
}
|
||||
ConversationsFileObserver.this.onEvent(event, path+'/'+filename);
|
||||
}
|
||||
|
||||
|
|
|
@ -727,4 +727,15 @@
|
|||
<string name="conference_destroyed">This group chat has been destroyed</string>
|
||||
<string name="phone_book">Address book</string>
|
||||
<string name="unable_to_save_recording">Unable to save recording</string>
|
||||
<string name="foreground_service_channel_name">Foreground service</string>
|
||||
<string name="foreground_service_channel_description">This notification category is used to display a permanent notification indicating that Conversations is running.</string>
|
||||
<string name="notification_group_status_information">Status Information</string>
|
||||
<string name="error_channel_name">Connectivity Problems</string>
|
||||
<string name="error_channel_description">This notification category is used to display a notification in case there is a problem connecting to an account.</string>
|
||||
<string name="notification_group_messages">Messages</string>
|
||||
<string name="messages_channel_name">Messages</string>
|
||||
<string name="silent_messages_channel_name">Silent messages</string>
|
||||
<string name="silent_messages_channel_description">This notification group is used to display notifications that should not trigger any sound. For example when being active on another device (Grace Period).</string>
|
||||
<string name="pref_more_notification_settings">Notification Settings</string>
|
||||
<string name="pref_more_notification_settings_summary">Importance, Sound, Vibrate</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="?attr/color_background_secondary"
|
||||
android:key="main_screen">
|
||||
|
||||
|
@ -10,8 +9,7 @@
|
|||
<PreferenceScreen
|
||||
android:key="huawei"
|
||||
android:summary="@string/huawei_protected_apps_summary"
|
||||
android:title="@string/huawei_protected_apps"
|
||||
>
|
||||
android:title="@string/huawei_protected_apps">
|
||||
<intent
|
||||
android:targetClass="com.huawei.systemmanager.optimize.process.ProtectActivity"
|
||||
android:targetPackage="com.huawei.systemmanager" />
|
||||
|
@ -24,8 +22,7 @@
|
|||
android:entryValues="@array/omemo_setting_entry_values"
|
||||
android:key="omemo"
|
||||
android:summary="@string/pref_omemo_setting_summary_default_on"
|
||||
android:title="@string/pref_omemo_setting"
|
||||
/>
|
||||
android:title="@string/pref_omemo_setting" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@bool/confirm_messages"
|
||||
android:key="confirm_messages"
|
||||
|
@ -43,7 +40,9 @@
|
|||
android:summary="@string/pref_broadcast_last_activity_summary"
|
||||
android:title="@string/pref_broadcast_last_activity" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_notification_settings">
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_notification_settings"
|
||||
android:key="notification_category">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@bool/show_notification"
|
||||
android:key="show_notification"
|
||||
|
@ -55,6 +54,20 @@
|
|||
android:key="notifications_from_strangers"
|
||||
android:summary="@string/pref_notifications_from_strangers_summary"
|
||||
android:title="@string/pref_notifications_from_strangers" />
|
||||
<PreferenceScreen
|
||||
android:key="more_notification_settings"
|
||||
android:dependency="show_notification"
|
||||
android:summary="@string/pref_more_notification_settings_summary"
|
||||
android:title="@string/pref_more_notification_settings">
|
||||
<intent android:action="android.settings.CHANNEL_NOTIFICATION_SETTINGS">
|
||||
<extra
|
||||
android:name="android.provider.extra.APP_PACKAGE"
|
||||
android:value="@string/applicationId" />
|
||||
<extra
|
||||
android:name="android.provider.extra.CHANNEL_ID"
|
||||
android:value="messages" />
|
||||
</intent>
|
||||
</PreferenceScreen>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@bool/headsup_notifications"
|
||||
android:dependency="show_notification"
|
||||
|
@ -118,8 +131,7 @@
|
|||
android:entryValues="@array/grace_periods_values"
|
||||
android:key="grace_period_length"
|
||||
android:summary="@string/pref_notification_grace_period_summary"
|
||||
android:title="@string/pref_notification_grace_period"
|
||||
/>
|
||||
android:title="@string/pref_notification_grace_period" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="attachments"
|
||||
|
@ -310,13 +322,14 @@
|
|||
android:summary="@string/pref_treat_vibrate_as_dnd_summary"
|
||||
android:title="@string/pref_treat_vibrate_as_silent" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_expert_options_other">
|
||||
<PreferenceCategory
|
||||
android:key="other_expert_category"
|
||||
android:title="@string/pref_expert_options_other">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@bool/autojoin"
|
||||
android:key="autojoin"
|
||||
android:summary="@string/pref_autojoin_summary"
|
||||
android:title="@string/pref_autojoin"
|
||||
/>
|
||||
android:title="@string/pref_autojoin" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@bool/indicate_received"
|
||||
android:key="indicate_received"
|
||||
|
|
Loading…
Reference in a new issue