mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-31 06:08:31 +02:00
Check DND for speak/sound
This commit is contained in:
@@ -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 ||
|
||||
|
||||
Reference in New Issue
Block a user