From 4de14a5dc1d12bd057760faa6874ea826a6c0596 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Fri, 15 Dec 2017 09:45:00 -0800 Subject: [PATCH] Only use startForegroundService for initial service construction --- .../securesms/jobs/PushDecryptJob.java | 12 +-- .../securesms/service/WebRtcCallService.java | 87 ++++++++++--------- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 8d0e7d9fee..60bbbf8924 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -256,8 +256,7 @@ public class PushDecryptJob extends ContextJob { intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, envelope.getSource())); intent.putExtra(WebRtcCallService.EXTRA_REMOTE_DESCRIPTION, message.getDescription()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) context.startForegroundService(intent); - else context.startService(intent); + context.startService(intent); } private void handleCallIceUpdateMessage(@NonNull SignalServiceEnvelope envelope, @@ -273,8 +272,7 @@ public class PushDecryptJob extends ContextJob { intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_MID, message.getSdpMid()); intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_LINE_INDEX, message.getSdpMLineIndex()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) context.startForegroundService(intent); - else context.startService(intent); + context.startService(intent); } } @@ -291,8 +289,7 @@ public class PushDecryptJob extends ContextJob { intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, envelope.getSource())); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) context.startForegroundService(intent); - else context.startService(intent); + context.startService(intent); } } @@ -304,8 +301,7 @@ public class PushDecryptJob extends ContextJob { intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, envelope.getSource())); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) context.startForegroundService(intent); - else context.startService(intent); + context.startService(intent); } private void handleEndSessionMessage(@NonNull MasterSecretUnion masterSecret, diff --git a/src/org/thoughtcrime/securesms/service/WebRtcCallService.java b/src/org/thoughtcrime/securesms/service/WebRtcCallService.java index b91e3b32be..c5d4545d4a 100644 --- a/src/org/thoughtcrime/securesms/service/WebRtcCallService.java +++ b/src/org/thoughtcrime/securesms/service/WebRtcCallService.java @@ -194,31 +194,28 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo Log.w(TAG, "onStartCommand..."); if (intent == null || intent.getAction() == null) return START_NOT_STICKY; - serviceExecutor.execute(new Runnable() { - @Override - public void run() { - if (intent.getAction().equals(ACTION_INCOMING_CALL) && isBusy()) handleBusyCall(intent); - else if (intent.getAction().equals(ACTION_REMOTE_BUSY)) handleBusyMessage(intent); - else if (intent.getAction().equals(ACTION_INCOMING_CALL)) handleIncomingCall(intent); - else if (intent.getAction().equals(ACTION_OUTGOING_CALL) && isIdle()) handleOutgoingCall(intent); - else if (intent.getAction().equals(ACTION_ANSWER_CALL)) handleAnswerCall(intent); - else if (intent.getAction().equals(ACTION_DENY_CALL)) handleDenyCall(intent); - else if (intent.getAction().equals(ACTION_LOCAL_HANGUP)) handleLocalHangup(intent); - else if (intent.getAction().equals(ACTION_REMOTE_HANGUP)) handleRemoteHangup(intent); - else if (intent.getAction().equals(ACTION_SET_MUTE_AUDIO)) handleSetMuteAudio(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_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_RESPONSE_MESSAGE)) handleResponseMessage(intent); - else if (intent.getAction().equals(ACTION_ICE_MESSAGE)) handleRemoteIceCandidate(intent); - else if (intent.getAction().equals(ACTION_ICE_CANDIDATE)) handleLocalIceCandidate(intent); - else if (intent.getAction().equals(ACTION_ICE_CONNECTED)) handleIceConnected(intent); - else if (intent.getAction().equals(ACTION_CALL_CONNECTED)) handleCallConnected(intent); - else if (intent.getAction().equals(ACTION_CHECK_TIMEOUT)) handleCheckTimeout(intent); - else if (intent.getAction().equals(ACTION_IS_IN_CALL_QUERY)) handleIsInCallQuery(intent); - } + serviceExecutor.execute(() -> { + if (intent.getAction().equals(ACTION_INCOMING_CALL) && isBusy()) handleBusyCall(intent); + else if (intent.getAction().equals(ACTION_REMOTE_BUSY)) handleBusyMessage(intent); + else if (intent.getAction().equals(ACTION_INCOMING_CALL)) handleIncomingCall(intent); + else if (intent.getAction().equals(ACTION_OUTGOING_CALL) && isIdle()) handleOutgoingCall(intent); + else if (intent.getAction().equals(ACTION_ANSWER_CALL)) handleAnswerCall(intent); + else if (intent.getAction().equals(ACTION_DENY_CALL)) handleDenyCall(intent); + else if (intent.getAction().equals(ACTION_LOCAL_HANGUP)) handleLocalHangup(intent); + else if (intent.getAction().equals(ACTION_REMOTE_HANGUP)) handleRemoteHangup(intent); + else if (intent.getAction().equals(ACTION_SET_MUTE_AUDIO)) handleSetMuteAudio(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_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_RESPONSE_MESSAGE)) handleResponseMessage(intent); + else if (intent.getAction().equals(ACTION_ICE_MESSAGE)) handleRemoteIceCandidate(intent); + else if (intent.getAction().equals(ACTION_ICE_CANDIDATE)) handleLocalIceCandidate(intent); + else if (intent.getAction().equals(ACTION_ICE_CONNECTED)) handleIceConnected(intent); + else if (intent.getAction().equals(ACTION_CALL_CONNECTED)) handleCallConnected(intent); + else if (intent.getAction().equals(ACTION_CHECK_TIMEOUT)) handleCheckTimeout(intent); + else if (intent.getAction().equals(ACTION_IS_IN_CALL_QUERY)) handleIsInCallQuery(intent); }); return START_NOT_STICKY; @@ -601,6 +598,17 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo Recipient recipient = getRemoteRecipient(intent); long callId = getCallId(intent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + switch (callState) { + case STATE_DIALING: + case STATE_REMOTE_RINGING: setCallInProgressNotification(TYPE_OUTGOING_RINGING, this.recipient); break; + case STATE_ANSWERING: setCallInProgressNotification(TYPE_INCOMING_CONNECTING, this.recipient); break; + case STATE_LOCAL_RINGING: setCallInProgressNotification(TYPE_INCOMING_RINGING, this.recipient); break; + case STATE_CONNECTED: setCallInProgressNotification(TYPE_ESTABLISHED, this.recipient); break; + default: throw new AssertionError(); + } + } + sendMessage(recipient, SignalServiceCallMessage.forBusy(new BusyMessage(callId))); insertMissedCall(getRemoteRecipient(intent), false); } @@ -1109,28 +1117,25 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo } private ListenableFutureTask> retrieveTurnServers() { - Callable> callable = new Callable>() { - @Override - public List call() { - LinkedList results = new LinkedList<>(); + Callable> callable = () -> { + LinkedList results = new LinkedList<>(); - try { - TurnServerInfo turnServerInfo = accountManager.getTurnServerInfo(); + try { + TurnServerInfo turnServerInfo = accountManager.getTurnServerInfo(); - for (String url : turnServerInfo.getUrls()) { - if (url.startsWith("turn")) { - results.add(new PeerConnection.IceServer(url, turnServerInfo.getUsername(), turnServerInfo.getPassword())); - } else { - results.add(new PeerConnection.IceServer(url)); - } + for (String url : turnServerInfo.getUrls()) { + if (url.startsWith("turn")) { + results.add(new PeerConnection.IceServer(url, turnServerInfo.getUsername(), turnServerInfo.getPassword())); + } else { + results.add(new PeerConnection.IceServer(url)); } - - } catch (IOException e) { - Log.w(TAG, e); } - return results; + } catch (IOException e) { + Log.w(TAG, e); } + + return results; }; ListenableFutureTask> futureTask = new ListenableFutureTask<>(callable, null, serviceExecutor);