mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 16:49:40 +01:00
Fix state exception by always starting call service in foreground.
This commit is contained in:
@@ -97,7 +97,12 @@ public class ActiveCallActionProcessorDelegate extends WebRtcActionProcessor {
|
||||
|
||||
@Override
|
||||
protected @NonNull WebRtcServiceState handleLocalHangup(@NonNull WebRtcServiceState currentState) {
|
||||
Log.i(tag, "handleLocalHangup(): call_id: " + currentState.getCallInfoState().requireActivePeer().getCallId());
|
||||
RemotePeer remotePeer = currentState.getCallInfoState().getActivePeer();
|
||||
if (remotePeer == null) {
|
||||
Log.i(tag, "handleLocalHangup(): no active peer");
|
||||
} else {
|
||||
Log.i(tag, "handleLocalHangup(): call_id: " + remotePeer.getCallId());
|
||||
}
|
||||
|
||||
ApplicationDependencies.getSignalServiceAccountManager().cancelInFlightRequests();
|
||||
ApplicationDependencies.getSignalServiceMessageSender().cancelInFlightRequests();
|
||||
@@ -112,7 +117,7 @@ public class ActiveCallActionProcessorDelegate extends WebRtcActionProcessor {
|
||||
|
||||
webRtcInteractor.postStateUpdate(currentState);
|
||||
|
||||
return terminate(currentState, currentState.getCallInfoState().getActivePeer());
|
||||
return terminate(currentState, remotePeer);
|
||||
} catch (CallException e) {
|
||||
return callFailure(currentState, "hangup() failed: ", e);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ public class CallSetupActionProcessorDelegate extends WebRtcActionProcessor {
|
||||
|
||||
ApplicationDependencies.getAppForegroundObserver().removeListener(webRtcInteractor.getForegroundListener());
|
||||
webRtcInteractor.startAudioCommunication(activePeer.getState() == CallState.REMOTE_RINGING);
|
||||
webRtcInteractor.setWantsBluetoothConnection(true);
|
||||
|
||||
activePeer.connected();
|
||||
|
||||
@@ -57,8 +56,9 @@ public class CallSetupActionProcessorDelegate extends WebRtcActionProcessor {
|
||||
.callConnectedTime(System.currentTimeMillis())
|
||||
.build();
|
||||
|
||||
webRtcInteractor.unregisterPowerButtonReceiver();
|
||||
webRtcInteractor.setCallInProgressNotification(TYPE_ESTABLISHED, activePeer);
|
||||
webRtcInteractor.unregisterPowerButtonReceiver();
|
||||
webRtcInteractor.setWantsBluetoothConnection(true);
|
||||
|
||||
try {
|
||||
CallManager callManager = webRtcInteractor.getCallManager();
|
||||
|
||||
@@ -329,10 +329,10 @@ public class GroupActionProcessor extends DeviceAwareActionProcessor {
|
||||
|
||||
public synchronized @NonNull WebRtcServiceState terminateGroupCall(@NonNull WebRtcServiceState currentState, boolean terminateVideo) {
|
||||
webRtcInteractor.updatePhoneState(LockManager.PhoneState.PROCESSING);
|
||||
webRtcInteractor.stopForegroundService();
|
||||
boolean playDisconnectSound = currentState.getCallInfoState().getCallState() == WebRtcViewModel.State.CALL_DISCONNECTED;
|
||||
webRtcInteractor.stopAudio(playDisconnectSound);
|
||||
webRtcInteractor.setWantsBluetoothConnection(false);
|
||||
webRtcInteractor.stopForegroundService();
|
||||
|
||||
webRtcInteractor.updatePhoneState(LockManager.PhoneState.IDLE);
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ public class GroupJoiningActionProcessor extends GroupActionProcessor {
|
||||
if (device.getJoinState() == GroupCall.JoinState.JOINED) {
|
||||
|
||||
webRtcInteractor.startAudioCommunication(true);
|
||||
webRtcInteractor.setWantsBluetoothConnection(true);
|
||||
|
||||
if (currentState.getLocalDeviceState().getCameraState().isEnabled()) {
|
||||
webRtcInteractor.updatePhoneState(LockManager.PhoneState.IN_VIDEO);
|
||||
@@ -71,6 +70,7 @@ public class GroupJoiningActionProcessor extends GroupActionProcessor {
|
||||
}
|
||||
|
||||
webRtcInteractor.setCallInProgressNotification(TYPE_ESTABLISHED, currentState.getCallInfoState().getCallRecipient());
|
||||
webRtcInteractor.setWantsBluetoothConnection(true);
|
||||
|
||||
try {
|
||||
groupCall.setOutgoingVideoMuted(!currentState.getLocalDeviceState().getCameraState().isEnabled());
|
||||
|
||||
@@ -145,8 +145,8 @@ public class GroupPreJoinActionProcessor extends GroupActionProcessor {
|
||||
|
||||
webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context));
|
||||
webRtcInteractor.initializeAudioForCall();
|
||||
webRtcInteractor.setWantsBluetoothConnection(true);
|
||||
webRtcInteractor.setCallInProgressNotification(TYPE_OUTGOING_RINGING, currentState.getCallInfoState().getCallRecipient());
|
||||
webRtcInteractor.setWantsBluetoothConnection(true);
|
||||
|
||||
try {
|
||||
groupCall.setOutgoingVideoSource(currentState.getVideoState().requireLocalSink(), currentState.getVideoState().requireCamera());
|
||||
|
||||
@@ -176,8 +176,8 @@ public class IncomingCallActionProcessor extends DeviceAwareActionProcessor {
|
||||
webRtcInteractor.startIncomingRinger(ringtone, vibrateState == RecipientDatabase.VibrateState.ENABLED || (vibrateState == RecipientDatabase.VibrateState.DEFAULT && TextSecurePreferences.isCallNotificationVibrateEnabled(context)));
|
||||
}
|
||||
|
||||
webRtcInteractor.registerPowerButtonReceiver();
|
||||
webRtcInteractor.setCallInProgressNotification(TYPE_INCOMING_RINGING, activePeer);
|
||||
webRtcInteractor.registerPowerButtonReceiver();
|
||||
|
||||
return currentState.builder()
|
||||
.changeCallInfoState()
|
||||
|
||||
@@ -72,9 +72,9 @@ public class OutgoingCallActionProcessor extends DeviceAwareActionProcessor {
|
||||
webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context));
|
||||
webRtcInteractor.initializeAudioForCall();
|
||||
webRtcInteractor.startOutgoingRinger();
|
||||
webRtcInteractor.setWantsBluetoothConnection(true);
|
||||
|
||||
webRtcInteractor.setCallInProgressNotification(TYPE_OUTGOING_RINGING, remotePeer);
|
||||
webRtcInteractor.setWantsBluetoothConnection(true);
|
||||
|
||||
DatabaseFactory.getSmsDatabase(context).insertOutgoingCall(remotePeer.getId(), currentState.getCallSetupState().isEnableVideoOnCreate());
|
||||
|
||||
|
||||
@@ -532,15 +532,15 @@ public abstract class WebRtcActionProcessor {
|
||||
ApplicationDependencies.getAppForegroundObserver().removeListener(webRtcInteractor.getForegroundListener());
|
||||
|
||||
webRtcInteractor.updatePhoneState(LockManager.PhoneState.PROCESSING);
|
||||
webRtcInteractor.stopForegroundService();
|
||||
boolean playDisconnectSound = (activePeer.getState() == CallState.DIALING) ||
|
||||
(activePeer.getState() == CallState.REMOTE_RINGING) ||
|
||||
(activePeer.getState() == CallState.RECEIVED_BUSY) ||
|
||||
(activePeer.getState() == CallState.CONNECTED);
|
||||
webRtcInteractor.stopAudio(playDisconnectSound);
|
||||
webRtcInteractor.setWantsBluetoothConnection(false);
|
||||
|
||||
webRtcInteractor.setWantsBluetoothConnection(false);
|
||||
webRtcInteractor.updatePhoneState(LockManager.PhoneState.IDLE);
|
||||
webRtcInteractor.stopForegroundService();
|
||||
|
||||
return WebRtcVideoUtil.deinitializeVideo(currentState)
|
||||
.builder()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.thoughtcrime.securesms.service.webrtc;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -48,6 +49,8 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
|
||||
private static final String EXTRA_RECIPIENT_ID = "RECIPIENT_ID";
|
||||
private static final String EXTRA_ENABLED = "ENABLED";
|
||||
|
||||
private static final int INVALID_NOTIFICATION_ID = -1;
|
||||
|
||||
private SignalCallManager callManager;
|
||||
|
||||
private WiredHeadsetStateReceiver wiredHeadsetStateReceiver;
|
||||
@@ -56,6 +59,8 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
|
||||
private UncaughtExceptionHandlerManager uncaughtExceptionHandlerManager;
|
||||
private PhoneStateListener hangUpRtcOnDeviceCallAnswered;
|
||||
private BluetoothStateManager bluetoothStateManager;
|
||||
private int lastNotificationId;
|
||||
private Notification lastNotification;
|
||||
|
||||
public static void update(@NonNull Context context, int type, @NonNull RecipientId recipientId) {
|
||||
Intent intent = new Intent(context, WebRtcCallService.class);
|
||||
@@ -70,7 +75,7 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
|
||||
Intent intent = new Intent(context, WebRtcCallService.class);
|
||||
intent.setAction(ACTION_STOP);
|
||||
|
||||
context.startService(intent);
|
||||
ContextCompat.startForegroundService(context, intent);
|
||||
}
|
||||
|
||||
public static @NonNull Intent denyCallIntent(@NonNull Context context) {
|
||||
@@ -86,7 +91,7 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
|
||||
intent.setAction(ACTION_WANTS_BLUETOOTH)
|
||||
.putExtra(EXTRA_ENABLED, enabled);
|
||||
|
||||
context.startService(intent);
|
||||
ContextCompat.startForegroundService(context, intent);
|
||||
}
|
||||
|
||||
public static void changePowerButtonReceiver(@NonNull Context context, boolean register) {
|
||||
@@ -94,7 +99,7 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
|
||||
intent.setAction(ACTION_CHANGE_POWER_BUTTON)
|
||||
.putExtra(EXTRA_ENABLED, register);
|
||||
|
||||
context.startService(intent);
|
||||
ContextCompat.startForegroundService(context, intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,6 +109,7 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
|
||||
this.callManager = ApplicationDependencies.getSignalCallManager();
|
||||
this.bluetoothStateManager = new BluetoothStateManager(this, this);
|
||||
this.hangUpRtcOnDeviceCallAnswered = new HangUpRtcOnPstnCallAnsweredListener();
|
||||
this.lastNotificationId = INVALID_NOTIFICATION_ID;
|
||||
|
||||
registerUncaughtExceptionHandler();
|
||||
registerWiredHeadsetStateReceiver();
|
||||
@@ -151,11 +157,13 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
|
||||
Objects.requireNonNull(intent.getParcelableExtra(EXTRA_RECIPIENT_ID)));
|
||||
return START_STICKY;
|
||||
case ACTION_WANTS_BLUETOOTH:
|
||||
setCallNotification();
|
||||
if (bluetoothStateManager != null) {
|
||||
bluetoothStateManager.setWantsConnection(intent.getBooleanExtra(EXTRA_ENABLED, false));
|
||||
}
|
||||
return START_STICKY;
|
||||
case ACTION_CHANGE_POWER_BUTTON:
|
||||
setCallNotification();
|
||||
if (intent.getBooleanExtra(EXTRA_ENABLED, false)) {
|
||||
registerPowerButtonReceiver();
|
||||
} else {
|
||||
@@ -163,13 +171,15 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
|
||||
}
|
||||
return START_STICKY;
|
||||
case ACTION_STOP:
|
||||
stopSelf();
|
||||
stopForeground(true);
|
||||
setCallNotification();
|
||||
stop();
|
||||
return START_NOT_STICKY;
|
||||
case ACTION_DENY_CALL:
|
||||
setCallNotification();
|
||||
callManager.denyCall();
|
||||
return START_NOT_STICKY;
|
||||
case ACTION_LOCAL_HANGUP:
|
||||
setCallNotification();
|
||||
callManager.localHangup();
|
||||
return START_NOT_STICKY;
|
||||
default:
|
||||
@@ -177,9 +187,26 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
|
||||
}
|
||||
}
|
||||
|
||||
private void setCallNotification() {
|
||||
if (lastNotificationId != INVALID_NOTIFICATION_ID) {
|
||||
startForeground(lastNotificationId, lastNotification);
|
||||
} else {
|
||||
Log.w(TAG, "Service running without having called start first, show temp notification and terminate service.");
|
||||
startForeground(CallNotificationBuilder.getStoppingNotificationId(), CallNotificationBuilder.getStoppingNotification(this));
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCallInProgressNotification(int type, @NonNull RecipientId id) {
|
||||
startForeground(CallNotificationBuilder.getNotificationId(type),
|
||||
CallNotificationBuilder.getCallInProgressNotification(this, type, Recipient.resolved(id)));
|
||||
lastNotificationId = CallNotificationBuilder.getNotificationId(type);
|
||||
lastNotification = CallNotificationBuilder.getCallInProgressNotification(this, type, Recipient.resolved(id));
|
||||
|
||||
startForeground(lastNotificationId, lastNotification);
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
stopForeground(true);
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
private void registerUncaughtExceptionHandler() {
|
||||
|
||||
Reference in New Issue
Block a user