mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Silence incoming ringer when power button is pressed
// FREEBIE
This commit is contained in:
parent
cd28cd172f
commit
bdcfabf1ee
@ -133,6 +133,7 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
public static final String ACTION_SET_MUTE_VIDEO = "SET_MUTE_VIDEO";
|
public static final String ACTION_SET_MUTE_VIDEO = "SET_MUTE_VIDEO";
|
||||||
public static final String ACTION_BLUETOOTH_CHANGE = "BLUETOOTH_CHANGE";
|
public static final String ACTION_BLUETOOTH_CHANGE = "BLUETOOTH_CHANGE";
|
||||||
public static final String ACTION_WIRED_HEADSET_CHANGE = "WIRED_HEADSET_CHANGE";
|
public static final String ACTION_WIRED_HEADSET_CHANGE = "WIRED_HEADSET_CHANGE";
|
||||||
|
public static final String ACTION_SCREEN_OFF = "SCREEN_OFF";
|
||||||
public static final String ACTION_CHECK_TIMEOUT = "CHECK_TIMEOUT";
|
public static final String ACTION_CHECK_TIMEOUT = "CHECK_TIMEOUT";
|
||||||
public static final String ACTION_IS_IN_CALL_QUERY = "IS_IN_CALL";
|
public static final String ACTION_IS_IN_CALL_QUERY = "IS_IN_CALL";
|
||||||
|
|
||||||
@ -160,6 +161,7 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
private SignalAudioManager audioManager;
|
private SignalAudioManager audioManager;
|
||||||
private BluetoothStateManager bluetoothStateManager;
|
private BluetoothStateManager bluetoothStateManager;
|
||||||
private WiredHeadsetStateReceiver wiredHeadsetStateReceiver;
|
private WiredHeadsetStateReceiver wiredHeadsetStateReceiver;
|
||||||
|
private PowerButtonReceiver powerButtonReceiver;
|
||||||
private LockManager lockManager;
|
private LockManager lockManager;
|
||||||
|
|
||||||
private IncomingPstnCallReceiver callReceiver;
|
private IncomingPstnCallReceiver callReceiver;
|
||||||
@ -210,6 +212,7 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
else if (intent.getAction().equals(ACTION_SET_MUTE_VIDEO)) handleSetMuteVideo(intent);
|
else if (intent.getAction().equals(ACTION_SET_MUTE_VIDEO)) handleSetMuteVideo(intent);
|
||||||
else if (intent.getAction().equals(ACTION_BLUETOOTH_CHANGE)) handleBluetoothChange(intent);
|
else if (intent.getAction().equals(ACTION_BLUETOOTH_CHANGE)) handleBluetoothChange(intent);
|
||||||
else if (intent.getAction().equals(ACTION_WIRED_HEADSET_CHANGE)) handleWiredHeadsetChange(intent);
|
else if (intent.getAction().equals(ACTION_WIRED_HEADSET_CHANGE)) handleWiredHeadsetChange(intent);
|
||||||
|
else if (intent.getAction().equals((ACTION_SCREEN_OFF))) handleScreenOffChange(intent);
|
||||||
else if (intent.getAction().equals(ACTION_REMOTE_VIDEO_MUTE)) handleRemoteVideoMute(intent);
|
else if (intent.getAction().equals(ACTION_REMOTE_VIDEO_MUTE)) handleRemoteVideoMute(intent);
|
||||||
else if (intent.getAction().equals(ACTION_RESPONSE_MESSAGE)) handleResponseMessage(intent);
|
else if (intent.getAction().equals(ACTION_RESPONSE_MESSAGE)) handleResponseMessage(intent);
|
||||||
else if (intent.getAction().equals(ACTION_ICE_MESSAGE)) handleRemoteIceCandidate(intent);
|
else if (intent.getAction().equals(ACTION_ICE_MESSAGE)) handleRemoteIceCandidate(intent);
|
||||||
@ -242,6 +245,12 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
|
|
||||||
if (wiredHeadsetStateReceiver != null) {
|
if (wiredHeadsetStateReceiver != null) {
|
||||||
unregisterReceiver(wiredHeadsetStateReceiver);
|
unregisterReceiver(wiredHeadsetStateReceiver);
|
||||||
|
wiredHeadsetStateReceiver = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (powerButtonReceiver != null) {
|
||||||
|
unregisterReceiver(powerButtonReceiver);
|
||||||
|
powerButtonReceiver = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,6 +304,22 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
registerReceiver(wiredHeadsetStateReceiver, new IntentFilter(action));
|
registerReceiver(wiredHeadsetStateReceiver, new IntentFilter(action));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerPowerButtonReceiver() {
|
||||||
|
if (powerButtonReceiver == null) {
|
||||||
|
powerButtonReceiver = new PowerButtonReceiver();
|
||||||
|
|
||||||
|
registerReceiver(powerButtonReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unregisterPowerButtonReceiver() {
|
||||||
|
if (powerButtonReceiver != null) {
|
||||||
|
unregisterReceiver(powerButtonReceiver);
|
||||||
|
|
||||||
|
powerButtonReceiver = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
|
|
||||||
private void handleIncomingCall(final Intent intent) {
|
private void handleIncomingCall(final Intent intent) {
|
||||||
@ -505,6 +530,8 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
audioManager.initializeAudioForCall();
|
audioManager.initializeAudioForCall();
|
||||||
audioManager.startIncomingRinger();
|
audioManager.startIncomingRinger();
|
||||||
|
|
||||||
|
registerPowerButtonReceiver();
|
||||||
|
|
||||||
setCallInProgressNotification(TYPE_INCOMING_RINGING, recipient);
|
setCallInProgressNotification(TYPE_INCOMING_RINGING, recipient);
|
||||||
} else if (callState == CallState.STATE_DIALING) {
|
} else if (callState == CallState.STATE_DIALING) {
|
||||||
if (this.recipient == null) throw new AssertionError("assert");
|
if (this.recipient == null) throw new AssertionError("assert");
|
||||||
@ -541,6 +568,8 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
|
|
||||||
sendMessage(WebRtcViewModel.State.CALL_CONNECTED, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
sendMessage(WebRtcViewModel.State.CALL_CONNECTED, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
||||||
|
|
||||||
|
unregisterPowerButtonReceiver();
|
||||||
|
|
||||||
setCallInProgressNotification(TYPE_ESTABLISHED, recipient);
|
setCallInProgressNotification(TYPE_ESTABLISHED, recipient);
|
||||||
|
|
||||||
this.peerConnection.setAudioEnabled(microphoneEnabled);
|
this.peerConnection.setAudioEnabled(microphoneEnabled);
|
||||||
@ -753,6 +782,15 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleScreenOffChange(Intent intent) {
|
||||||
|
if (callState == CallState.STATE_ANSWERING ||
|
||||||
|
callState == CallState.STATE_LOCAL_RINGING)
|
||||||
|
{
|
||||||
|
Log.w(TAG, "Silencing incoming ringer...");
|
||||||
|
audioManager.silenceIncomingRinger();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleRemoteVideoMute(Intent intent) {
|
private void handleRemoteVideoMute(Intent intent) {
|
||||||
boolean muted = intent.getBooleanExtra(EXTRA_MUTE, false);
|
boolean muted = intent.getBooleanExtra(EXTRA_MUTE, false);
|
||||||
long callId = intent.getLongExtra(EXTRA_CALL_ID, -1);
|
long callId = intent.getLongExtra(EXTRA_CALL_ID, -1);
|
||||||
@ -1110,6 +1148,17 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class PowerButtonReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
|
||||||
|
Intent serviceIntent = new Intent(context, WebRtcCallService.class);
|
||||||
|
serviceIntent.setAction(WebRtcCallService.ACTION_SCREEN_OFF);
|
||||||
|
context.startService(serviceIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class TimeoutRunnable implements Runnable {
|
private class TimeoutRunnable implements Runnable {
|
||||||
|
|
||||||
private final long callId;
|
private final long callId;
|
||||||
|
@ -75,6 +75,10 @@ public class SignalAudioManager {
|
|||||||
outgoingRinger.start(type);
|
outgoingRinger.start(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void silenceIncomingRinger() {
|
||||||
|
incomingRinger.stop();
|
||||||
|
}
|
||||||
|
|
||||||
public void startCommunication(boolean preserveSpeakerphone) {
|
public void startCommunication(boolean preserveSpeakerphone) {
|
||||||
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user