turn proximity wake lock and/off depending on speaker configuration

This commit is contained in:
Daniel Gultsch 2020-04-13 14:55:07 +02:00
parent 9bc264bd73
commit ef22071bd1
2 changed files with 14 additions and 2 deletions

View File

@ -135,12 +135,20 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
private void releaseProximityWakeLock() { private void releaseProximityWakeLock() {
if (this.mProximityWakeLock != null && mProximityWakeLock.isHeld()) { 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.release();
this.mProximityWakeLock = null; this.mProximityWakeLock = null;
} }
} }
private void putProximityWakeLockInProperState() {
if (requireRtpConnection().getAudioManager().getSelectedAudioDevice() == AppRTCAudioManager.AudioDevice.EARPIECE) {
acquireProximityWakeLock();
} else {
releaseProximityWakeLock();
}
}
@Override @Override
protected void refreshUiReal() { protected void refreshUiReal() {
@ -200,6 +208,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
private void proposeJingleRtpSession(final Account account, final Jid with) { private void proposeJingleRtpSession(final Account account, final Jid with) {
xmppConnectionService.getJingleConnectionManager().proposeJingleRtpSession(account, with); xmppConnectionService.getJingleConnectionManager().proposeJingleRtpSession(account, with);
//TODO maybe we dont want to acquire a wake lock just yet and wait for audio manager to discover what speaker we are using
putScreenInCallMode(); putScreenInCallMode();
} }
@ -506,6 +515,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
requireRtpConnection().isMicrophoneEnabled() requireRtpConnection().isMicrophoneEnabled()
); );
} }
putProximityWakeLockInProperState();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.d(Config.LOGTAG, "RTP connection was not available when audio device changed"); Log.d(Config.LOGTAG, "RTP connection was not available when audio device changed");
} }

View File

@ -145,7 +145,8 @@ public class WebRTCWrapper {
); );
mainHandler.post(() -> { mainHandler.post(() -> {
appRTCAudioManager = AppRTCAudioManager.create(context, AppRTCAudioManager.SpeakerPhonePreference.EARPIECE); 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); peerConnection.setAudioRecording(true);
this.peerConnection = peerConnection; this.peerConnection = peerConnection;
} }
public void close() { public void close() {
final PeerConnection peerConnection = this.peerConnection; final PeerConnection peerConnection = this.peerConnection;
if (peerConnection != null) { if (peerConnection != null) {