mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
More intelligent default behavior with speakerphone and wired headset
When video is enabled, speakerphone is now enabled unless there's a wired headset. If speakerphone is enabled and a wired headset gets plugged in, speakerphone is disabled. If video is enabled and a wired headset is removed, speakerphone is enabled. Fixes #6153 // FREEBIE
This commit is contained in:
parent
5cfd7477ab
commit
d92cbfe305
@ -1,6 +1,7 @@
|
|||||||
package org.thoughtcrime.redphone.util;
|
package org.thoughtcrime.redphone.util;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -62,4 +63,12 @@ public class AudioUtils {
|
|||||||
return AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED;
|
return AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getWiredHeadsetUpdateAction() {
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
return AudioManager.ACTION_HEADSET_PLUG;
|
||||||
|
} else {
|
||||||
|
return Intent.ACTION_HEADSET_PLUG;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
|
|||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.service.MessageRetrievalService;
|
import org.thoughtcrime.securesms.service.MessageRetrievalService;
|
||||||
import org.thoughtcrime.securesms.service.WebRtcCallService;
|
import org.thoughtcrime.securesms.service.WebRtcCallService;
|
||||||
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
import org.whispersystems.libsignal.IdentityKey;
|
import org.whispersystems.libsignal.IdentityKey;
|
||||||
@ -91,7 +92,9 @@ public class WebRtcCallActivity extends Activity {
|
|||||||
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStarted(this);
|
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStarted(this);
|
||||||
initializeScreenshotSecurity();
|
initializeScreenshotSecurity();
|
||||||
EventBus.getDefault().registerSticky(this);
|
EventBus.getDefault().registerSticky(this);
|
||||||
|
|
||||||
registerBluetoothReceiver();
|
registerBluetoothReceiver();
|
||||||
|
registerWiredHeadsetReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -113,6 +116,7 @@ public class WebRtcCallActivity extends Activity {
|
|||||||
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this);
|
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this);
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
unregisterReceiver(bluetoothStateReceiver);
|
unregisterReceiver(bluetoothStateReceiver);
|
||||||
|
unregisterReceiver(wiredHeadsetStateReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -149,7 +153,12 @@ public class WebRtcCallActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleSetMuteVideo(boolean muted) {
|
private void handleSetMuteVideo(boolean muted) {
|
||||||
// callScreen.setLocalVideoEnabled(!muted);
|
AudioManager audioManager = ServiceUtil.getAudioManager(this);
|
||||||
|
|
||||||
|
if (!muted && !audioManager.isWiredHeadsetOn() && !audioManager.isBluetoothScoOn()) {
|
||||||
|
AudioUtils.enableSpeakerphoneRouting(WebRtcCallActivity.this);
|
||||||
|
callScreen.notifyAudioRoutingChange();
|
||||||
|
}
|
||||||
|
|
||||||
Intent intent = new Intent(this, WebRtcCallService.class);
|
Intent intent = new Intent(this, WebRtcCallService.class);
|
||||||
intent.setAction(WebRtcCallService.ACTION_SET_MUTE_VIDEO);
|
intent.setAction(WebRtcCallService.ACTION_SET_MUTE_VIDEO);
|
||||||
@ -352,6 +361,27 @@ public class WebRtcCallActivity extends Activity {
|
|||||||
callScreen.notifyBluetoothChange();
|
callScreen.notifyBluetoothChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerWiredHeadsetReceiver() {
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(AudioUtils.getWiredHeadsetUpdateAction());
|
||||||
|
wiredHeadsetStateReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
int state = intent.getIntExtra("state", -1);
|
||||||
|
|
||||||
|
if (state == 0 && callScreen.isVideoEnabled()) {
|
||||||
|
AudioUtils.enableSpeakerphoneRouting(WebRtcCallActivity.this);
|
||||||
|
callScreen.notifyAudioRoutingChange();
|
||||||
|
} else if (state == 1) {
|
||||||
|
AudioUtils.enableDefaultRouting(WebRtcCallActivity.this);
|
||||||
|
callScreen.notifyAudioRoutingChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
registerReceiver(wiredHeadsetStateReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
private class AudioButtonListener implements WebRtcCallControls.AudioButtonListener {
|
private class AudioButtonListener implements WebRtcCallControls.AudioButtonListener {
|
||||||
@Override
|
@Override
|
||||||
public void onAudioChange(AudioUtils.AudioMode mode) {
|
public void onAudioChange(AudioUtils.AudioMode mode) {
|
||||||
|
@ -99,14 +99,14 @@ public class WebRtcCallControls extends LinearLayout {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVideoMuted() {
|
|
||||||
return !videoMuteButton.isChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAudioButtonListener(final AudioButtonListener listener) {
|
public void setAudioButtonListener(final AudioButtonListener listener) {
|
||||||
audioButton.setListener(listener);
|
audioButton.setListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isVideoEnabled() {
|
||||||
|
return videoMuteButton.isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
updateAudioButton();
|
updateAudioButton();
|
||||||
audioMuteButton.setChecked(false);
|
audioMuteButton.setChecked(false);
|
||||||
|
@ -179,6 +179,10 @@ public class WebRtcCallScreen extends FrameLayout implements Recipient.Recipient
|
|||||||
this.controls.updateAudioButton();
|
this.controls.updateAudioButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void notifyAudioRoutingChange() {
|
||||||
|
this.controls.updateAudioButton();
|
||||||
|
}
|
||||||
|
|
||||||
public void setLocalVideoEnabled(boolean enabled) {
|
public void setLocalVideoEnabled(boolean enabled) {
|
||||||
if (enabled && this.localRenderLayout.isHidden()) {
|
if (enabled && this.localRenderLayout.isHidden()) {
|
||||||
this.localRenderLayout.setHidden(false);
|
this.localRenderLayout.setHidden(false);
|
||||||
@ -199,6 +203,10 @@ public class WebRtcCallScreen extends FrameLayout implements Recipient.Recipient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isVideoEnabled() {
|
||||||
|
return controls.isVideoEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
inflater.inflate(R.layout.webrtc_call_screen, this, true);
|
inflater.inflate(R.layout.webrtc_call_screen, this, true);
|
||||||
|
Loading…
Reference in New Issue
Block a user