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

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