Check DND for speak/sound

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

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

@ -2688,6 +2688,10 @@ public class Log {
Helper.getInterruptionFilter(filter), Helper.getInterruptionFilter(filter),
(filter == NotificationManager.INTERRUPTION_FILTER_ALL ? "" : "!!!"))); (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()) for (NotificationChannel channel : nm.getNotificationChannels())
try { try {
JSONObject jchannel = NotificationHelper.channelToJSON(channel); JSONObject jchannel = NotificationHelper.channelToJSON(channel);

@ -1,5 +1,6 @@
package eu.faircode.email; package eu.faircode.email;
import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.media.AudioAttributes; import android.media.AudioAttributes;
import android.media.AudioManager; import android.media.AudioManager;
@ -38,8 +39,9 @@ public class MediaPlayerHelper {
@Override @Override
public void run() { public void run() {
try { try {
if (!isInCall(context)) if (isInCall(context) || isDnd(context))
play(context, uri, alarm, duration); return;
play(context, uri, alarm, duration);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(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) { static boolean isInCall(int mode) {
return (mode == AudioManager.MODE_RINGTONE || return (mode == AudioManager.MODE_RINGTONE ||
mode == AudioManager.MODE_IN_CALL || mode == AudioManager.MODE_IN_CALL ||

Loading…
Cancel
Save