1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-25 01:06:04 +00:00

Check DND for speak/sound

This commit is contained in:
M66B 2022-07-30 23:02:17 +02:00
parent 2939a50bd2
commit 867de1e813
3 changed files with 18 additions and 3 deletions

View file

@ -906,7 +906,7 @@ public class EntityRule {
@Override
public void run() {
try {
if (MediaPlayerHelper.isInCall(context))
if (MediaPlayerHelper.isInCall(context) || MediaPlayerHelper.isDnd(context))
return;
speak(context, EntityRule.this, message);
} catch (Throwable ex) {

View file

@ -2688,6 +2688,10 @@ public class Log {
Helper.getInterruptionFilter(filter),
(filter == NotificationManager.INTERRUPTION_FILTER_ALL ? "" : "!!!")));
size += write(os, String.format("InCall=%b DND=%b\r\n\r\n",
MediaPlayerHelper.isInCall(context),
MediaPlayerHelper.isDnd(context)));
for (NotificationChannel channel : nm.getNotificationChannels())
try {
JSONObject jchannel = NotificationHelper.channelToJSON(channel);

View file

@ -1,5 +1,6 @@
package eu.faircode.email;
import android.app.NotificationManager;
import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
@ -38,8 +39,9 @@ public class MediaPlayerHelper {
@Override
public void run() {
try {
if (!isInCall(context))
play(context, uri, alarm, duration);
if (isInCall(context) || isDnd(context))
return;
play(context, uri, alarm, duration);
} catch (Throwable ex) {
Log.e(ex);
}
@ -146,6 +148,15 @@ public class MediaPlayerHelper {
}
}
static boolean isDnd(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return false;
NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
int filter = nm.getCurrentInterruptionFilter();
// All: no notifications are suppressed
return (filter != NotificationManager.INTERRUPTION_FILTER_ALL);
}
static boolean isInCall(int mode) {
return (mode == AudioManager.MODE_RINGTONE ||
mode == AudioManager.MODE_IN_CALL ||