Check DND for speak/sound

pull/209/head
M66B 2 years ago
parent 2939a50bd2
commit 867de1e813

@ -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) {

@ -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);

@ -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 ||

Loading…
Cancel
Save