From ef22071bd16d6a9fd6d48f5d6d2df21f317d43b9 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 13 Apr 2020 14:55:07 +0200 Subject: [PATCH] turn proximity wake lock and/off depending on speaker configuration --- .../siacs/conversations/ui/RtpSessionActivity.java | 12 +++++++++++- .../conversations/xmpp/jingle/WebRTCWrapper.java | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 1d9c19a4a..2d31274cb 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -135,12 +135,20 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe private void releaseProximityWakeLock() { if (this.mProximityWakeLock != null && mProximityWakeLock.isHeld()) { - Log.d(Config.LOGTAG, "releasing wake lock"); + Log.d(Config.LOGTAG, "releasing proximity wake lock"); this.mProximityWakeLock.release(); this.mProximityWakeLock = null; } } + private void putProximityWakeLockInProperState() { + if (requireRtpConnection().getAudioManager().getSelectedAudioDevice() == AppRTCAudioManager.AudioDevice.EARPIECE) { + acquireProximityWakeLock(); + } else { + releaseProximityWakeLock(); + } + } + @Override protected void refreshUiReal() { @@ -200,6 +208,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe private void proposeJingleRtpSession(final Account account, final Jid with) { xmppConnectionService.getJingleConnectionManager().proposeJingleRtpSession(account, with); + //TODO maybe we don’t want to acquire a wake lock just yet and wait for audio manager to discover what speaker we are using putScreenInCallMode(); } @@ -506,6 +515,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe requireRtpConnection().isMicrophoneEnabled() ); } + putProximityWakeLockInProperState(); } catch (IllegalStateException e) { Log.d(Config.LOGTAG, "RTP connection was not available when audio device changed"); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java index e21a65f19..d723e96e5 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java @@ -145,7 +145,8 @@ public class WebRTCWrapper { ); mainHandler.post(() -> { appRTCAudioManager = AppRTCAudioManager.create(context, AppRTCAudioManager.SpeakerPhonePreference.EARPIECE); - appRTCAudioManager.start(audioManagerEvents); + appRTCAudioManager.start(audioManagerEvents); + eventCallback.onAudioDeviceChanged(appRTCAudioManager.getSelectedAudioDevice(), appRTCAudioManager.getAudioDevices()); }); } @@ -218,6 +219,7 @@ public class WebRTCWrapper { peerConnection.setAudioRecording(true); this.peerConnection = peerConnection; } + public void close() { final PeerConnection peerConnection = this.peerConnection; if (peerConnection != null) {