mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-01 14:46:31 +02:00
Check if in-call via audio manager
This commit is contained in:
@@ -822,6 +822,9 @@ public class EntityRule {
|
||||
private boolean onActionTts(Context context, EntityMessage message, JSONObject jargs) {
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
if (message.ui_seen)
|
||||
return false;
|
||||
|
||||
if (!message.content) {
|
||||
EntityOperation.queue(context, message, EntityOperation.BODY);
|
||||
EntityOperation.queue(context, message, EntityOperation.RULE, this.id);
|
||||
@@ -832,6 +835,8 @@ public class EntityRule {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (MediaPlayerHelper.isInCall(context))
|
||||
return;
|
||||
speak(context, EntityRule.this, message);
|
||||
} catch (Throwable ex) {
|
||||
db.message().setMessageError(message.id, Log.formatThrowable(ex));
|
||||
@@ -974,6 +979,8 @@ public class EntityRule {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (MediaPlayerHelper.isInCall(context))
|
||||
return;
|
||||
MediaPlayerHelper.play(context, uri, alarm, duration);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
|
||||
@@ -49,4 +50,18 @@ public class MediaPlayerHelper {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isInCall(Context context) {
|
||||
AudioManager am =
|
||||
(AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
if (am == null)
|
||||
return false;
|
||||
|
||||
// This doesn't require READ_PHONE_STATE permission
|
||||
int mode = am.getMode();
|
||||
EntityLog.log(context, "Audio mode=" + mode);
|
||||
return (mode == AudioManager.MODE_RINGTONE ||
|
||||
mode == AudioManager.MODE_IN_CALL ||
|
||||
mode == AudioManager.MODE_IN_COMMUNICATION);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user