2016-11-09 09:37:40 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Open Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
import android.Manifest;
|
2021-07-20 13:08:52 -03:00
|
|
|
import android.annotation.SuppressLint;
|
2020-04-23 16:20:59 -03:00
|
|
|
import android.app.PictureInPictureParams;
|
2020-12-02 13:43:05 -05:00
|
|
|
import android.content.Context;
|
2016-11-09 09:37:40 -08:00
|
|
|
import android.content.Intent;
|
2021-07-23 13:48:09 -03:00
|
|
|
import android.content.pm.ActivityInfo;
|
2020-04-23 16:20:59 -03:00
|
|
|
import android.content.pm.PackageManager;
|
2016-11-09 09:37:40 -08:00
|
|
|
import android.content.res.Configuration;
|
2021-07-23 13:48:09 -03:00
|
|
|
import android.graphics.Rect;
|
2016-11-09 09:37:40 -08:00
|
|
|
import android.media.AudioManager;
|
2020-04-23 16:20:59 -03:00
|
|
|
import android.os.Build;
|
2016-11-09 09:37:40 -08:00
|
|
|
import android.os.Bundle;
|
2020-04-23 16:20:59 -03:00
|
|
|
import android.util.Rational;
|
2016-11-09 09:37:40 -08:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
2021-08-24 10:18:39 -04:00
|
|
|
import android.widget.Toast;
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2020-12-02 13:43:05 -05:00
|
|
|
import androidx.appcompat.app.AppCompatDelegate;
|
2020-04-23 16:20:59 -03:00
|
|
|
import androidx.core.content.ContextCompat;
|
2021-07-23 13:48:09 -03:00
|
|
|
import androidx.core.util.Consumer;
|
2020-04-23 16:20:59 -03:00
|
|
|
import androidx.lifecycle.ViewModelProviders;
|
2021-07-23 13:48:09 -03:00
|
|
|
import androidx.window.DisplayFeature;
|
|
|
|
import androidx.window.FoldingFeature;
|
|
|
|
import androidx.window.WindowLayoutInfo;
|
2020-04-23 16:20:59 -03:00
|
|
|
|
2017-02-17 20:27:11 -08:00
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
2021-07-23 13:48:09 -03:00
|
|
|
import org.signal.core.util.concurrent.SignalExecutors;
|
2020-12-04 18:31:58 -05:00
|
|
|
import org.signal.core.util.logging.Log;
|
2022-03-24 13:23:23 -04:00
|
|
|
import org.signal.libsignal.protocol.IdentityKey;
|
2020-04-23 16:20:59 -03:00
|
|
|
import org.thoughtcrime.securesms.components.TooltipPopup;
|
2021-03-31 14:30:30 -04:00
|
|
|
import org.thoughtcrime.securesms.components.sensors.DeviceOrientationMonitor;
|
2020-12-04 15:41:29 -04:00
|
|
|
import org.thoughtcrime.securesms.components.webrtc.CallParticipantsListUpdatePopupWindow;
|
2020-09-10 16:59:47 -04:00
|
|
|
import org.thoughtcrime.securesms.components.webrtc.CallParticipantsState;
|
2021-05-25 12:15:07 -04:00
|
|
|
import org.thoughtcrime.securesms.components.webrtc.CallToastPopupWindow;
|
2020-12-04 15:24:18 -05:00
|
|
|
import org.thoughtcrime.securesms.components.webrtc.GroupCallSafetyNumberChangeNotificationUtil;
|
2020-04-23 16:20:59 -03:00
|
|
|
import org.thoughtcrime.securesms.components.webrtc.WebRtcAudioOutput;
|
|
|
|
import org.thoughtcrime.securesms.components.webrtc.WebRtcCallView;
|
|
|
|
import org.thoughtcrime.securesms.components.webrtc.WebRtcCallViewModel;
|
2021-07-23 13:48:09 -03:00
|
|
|
import org.thoughtcrime.securesms.components.webrtc.WebRtcControls;
|
2020-09-18 15:51:17 -04:00
|
|
|
import org.thoughtcrime.securesms.components.webrtc.participantslist.CallParticipantsListDialog;
|
2020-08-27 16:34:26 -04:00
|
|
|
import org.thoughtcrime.securesms.conversation.ui.error.SafetyNumberChangeDialog;
|
2021-03-31 14:30:30 -04:00
|
|
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
2017-02-02 18:34:51 -08:00
|
|
|
import org.thoughtcrime.securesms.events.WebRtcViewModel;
|
2020-07-06 16:27:03 -04:00
|
|
|
import org.thoughtcrime.securesms.messagerequests.CalleeMustAcceptMessageRequestActivity;
|
2017-11-24 22:00:30 -08:00
|
|
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
2016-11-09 09:37:40 -08:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2020-12-04 15:24:18 -05:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
2021-03-31 14:30:30 -04:00
|
|
|
import org.thoughtcrime.securesms.service.webrtc.SignalCallManager;
|
2020-09-10 16:59:47 -04:00
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
2020-04-23 16:20:59 -03:00
|
|
|
import org.thoughtcrime.securesms.util.EllapsedTimeFormatter;
|
2021-08-24 10:18:39 -04:00
|
|
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
2021-01-08 10:47:04 -04:00
|
|
|
import org.thoughtcrime.securesms.util.FullscreenHelper;
|
2016-11-09 09:37:40 -08:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2021-08-13 09:28:43 -04:00
|
|
|
import org.thoughtcrime.securesms.util.ThrottledDebouncer;
|
2020-12-04 15:24:18 -05:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2022-03-25 12:37:47 -04:00
|
|
|
import org.thoughtcrime.securesms.util.VibrateUtil;
|
2021-05-25 12:15:07 -04:00
|
|
|
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
2021-08-02 09:55:58 -03:00
|
|
|
import org.thoughtcrime.securesms.webrtc.CallParticipantsViewState;
|
2021-09-27 11:23:10 -04:00
|
|
|
import org.thoughtcrime.securesms.webrtc.audio.SignalAudioManager;
|
2020-05-08 14:39:32 -03:00
|
|
|
import org.whispersystems.signalservice.api.messages.calls.HangupMessage;
|
2017-05-19 18:01:40 -07:00
|
|
|
|
2020-12-04 15:24:18 -05:00
|
|
|
import java.util.List;
|
2021-07-23 13:48:09 -03:00
|
|
|
import java.util.Optional;
|
2021-08-13 09:28:43 -04:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2020-12-04 15:24:18 -05:00
|
|
|
|
2021-09-27 11:23:10 -04:00
|
|
|
import static org.thoughtcrime.securesms.components.sensors.Orientation.PORTRAIT_BOTTOM_EDGE;
|
|
|
|
|
2020-12-15 12:34:34 -04:00
|
|
|
public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChangeDialog.Callback {
|
2020-04-23 16:20:59 -03:00
|
|
|
|
2020-12-15 12:34:34 -04:00
|
|
|
private static final String TAG = Log.tag(WebRtcCallActivity.class);
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-12-04 15:24:18 -05:00
|
|
|
private static final int STANDARD_DELAY_FINISH = 1000;
|
2022-03-25 12:37:47 -04:00
|
|
|
private static final int VIBRATE_DURATION = 50;
|
2016-11-09 09:37:40 -08:00
|
|
|
|
|
|
|
public static final String ANSWER_ACTION = WebRtcCallActivity.class.getCanonicalName() + ".ANSWER_ACTION";
|
|
|
|
public static final String DENY_ACTION = WebRtcCallActivity.class.getCanonicalName() + ".DENY_ACTION";
|
|
|
|
public static final String END_CALL_ACTION = WebRtcCallActivity.class.getCanonicalName() + ".END_CALL_ACTION";
|
|
|
|
|
2019-12-03 16:26:05 -04:00
|
|
|
public static final String EXTRA_ENABLE_VIDEO_IF_AVAILABLE = WebRtcCallActivity.class.getCanonicalName() + ".ENABLE_VIDEO_IF_AVAILABLE";
|
|
|
|
|
2020-12-04 15:41:29 -04:00
|
|
|
private CallParticipantsListUpdatePopupWindow participantUpdateWindow;
|
2021-01-29 16:22:01 -04:00
|
|
|
private DeviceOrientationMonitor deviceOrientationMonitor;
|
2020-12-04 15:41:29 -04:00
|
|
|
|
2021-07-23 13:48:09 -03:00
|
|
|
private FullscreenHelper fullscreenHelper;
|
|
|
|
private WebRtcCallView callScreen;
|
|
|
|
private TooltipPopup videoTooltip;
|
|
|
|
private WebRtcCallViewModel viewModel;
|
|
|
|
private boolean enableVideoIfAvailable;
|
|
|
|
private androidx.window.WindowManager windowManager;
|
|
|
|
private WindowLayoutInfoConsumer windowLayoutInfoConsumer;
|
2021-08-13 09:28:43 -04:00
|
|
|
private ThrottledDebouncer requestNewSizesThrottle;
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-12-02 13:43:05 -05:00
|
|
|
@Override
|
|
|
|
protected void attachBaseContext(@NonNull Context newBase) {
|
|
|
|
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
|
|
|
super.attachBaseContext(newBase);
|
|
|
|
}
|
|
|
|
|
2021-07-23 13:48:09 -03:00
|
|
|
@SuppressLint("SourceLockedOrientationActivity")
|
2016-11-09 09:37:40 -08:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "onCreate()");
|
2016-11-09 09:37:40 -08:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
2017-02-02 19:02:26 -08:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
2016-11-09 09:37:40 -08:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2021-08-02 09:55:58 -03:00
|
|
|
boolean isLandscapeEnabled = getResources().getConfiguration().smallestScreenWidthDp >= 480;
|
2021-07-23 13:48:09 -03:00
|
|
|
if (!isLandscapeEnabled) {
|
|
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
|
|
}
|
|
|
|
|
2016-11-09 09:37:40 -08:00
|
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
|
setContentView(R.layout.webrtc_call_activity);
|
2021-01-08 10:47:04 -04:00
|
|
|
|
2021-01-30 11:28:54 -05:00
|
|
|
fullscreenHelper = new FullscreenHelper(this);
|
2016-11-09 09:37:40 -08:00
|
|
|
|
|
|
|
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
|
|
|
|
|
|
|
|
initializeResources();
|
2021-07-23 13:48:09 -03:00
|
|
|
initializeViewModel(isLandscapeEnabled);
|
2019-06-27 15:17:14 -04:00
|
|
|
|
|
|
|
processIntent(getIntent());
|
2019-12-03 16:26:05 -04:00
|
|
|
|
|
|
|
enableVideoIfAvailable = getIntent().getBooleanExtra(EXTRA_ENABLE_VIDEO_IF_AVAILABLE, false);
|
|
|
|
getIntent().removeExtra(EXTRA_ENABLE_VIDEO_IF_AVAILABLE);
|
2021-07-23 13:48:09 -03:00
|
|
|
|
|
|
|
windowManager = new androidx.window.WindowManager(this);
|
2021-08-02 09:55:58 -03:00
|
|
|
windowLayoutInfoConsumer = new WindowLayoutInfoConsumer();
|
2021-07-23 13:48:09 -03:00
|
|
|
|
|
|
|
windowManager.registerLayoutChangeCallback(SignalExecutors.BOUNDED, windowLayoutInfoConsumer);
|
2021-08-13 09:28:43 -04:00
|
|
|
|
|
|
|
requestNewSizesThrottle = new ThrottledDebouncer(TimeUnit.SECONDS.toMillis(1));
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "onResume()");
|
2016-11-09 09:37:40 -08:00
|
|
|
super.onResume();
|
|
|
|
initializeScreenshotSecurity();
|
2020-04-23 16:20:59 -03:00
|
|
|
|
|
|
|
if (!EventBus.getDefault().isRegistered(this)) {
|
|
|
|
EventBus.getDefault().register(this);
|
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-12-15 12:34:34 -04:00
|
|
|
public void onNewIntent(Intent intent) {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "onNewIntent");
|
2020-04-23 16:20:59 -03:00
|
|
|
super.onNewIntent(intent);
|
2019-06-27 15:17:14 -04:00
|
|
|
processIntent(intent);
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "onPause");
|
2016-11-09 09:37:40 -08:00
|
|
|
super.onPause();
|
2020-04-23 16:20:59 -03:00
|
|
|
|
2021-04-01 11:10:08 -04:00
|
|
|
if (!isInPipMode() || isFinishing()) {
|
2020-04-23 16:20:59 -03:00
|
|
|
EventBus.getDefault().unregister(this);
|
|
|
|
}
|
2020-09-25 13:39:30 -04:00
|
|
|
|
2021-01-06 15:15:50 -05:00
|
|
|
if (!viewModel.isCallStarting()) {
|
2020-12-04 15:24:18 -05:00
|
|
|
CallParticipantsState state = viewModel.getCallParticipantsState().getValue();
|
2021-01-06 15:15:50 -05:00
|
|
|
if (state != null && state.getCallState().isPreJoinOrNetworkUnavailable()) {
|
2020-12-04 15:24:18 -05:00
|
|
|
finish();
|
|
|
|
}
|
2020-09-25 13:39:30 -04:00
|
|
|
}
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
Log.i(TAG, "onStop");
|
|
|
|
super.onStop();
|
|
|
|
|
2021-04-01 11:10:08 -04:00
|
|
|
if (!isInPipMode() || isFinishing()) {
|
|
|
|
EventBus.getDefault().unregister(this);
|
2021-08-13 09:28:43 -04:00
|
|
|
requestNewSizesThrottle.clear();
|
2021-04-01 11:10:08 -04:00
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2021-01-06 15:15:50 -05:00
|
|
|
if (!viewModel.isCallStarting()) {
|
2020-12-04 15:24:18 -05:00
|
|
|
CallParticipantsState state = viewModel.getCallParticipantsState().getValue();
|
2021-01-06 15:15:50 -05:00
|
|
|
if (state != null && state.getCallState().isPreJoinOrNetworkUnavailable()) {
|
2021-03-31 14:30:30 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().cancelPreJoin();
|
2020-12-04 15:24:18 -05:00
|
|
|
}
|
2020-09-18 15:51:17 -04:00
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2021-04-01 11:10:08 -04:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
2021-07-23 13:48:09 -03:00
|
|
|
windowManager.unregisterLayoutChangeCallback(windowLayoutInfoConsumer);
|
2021-04-01 11:10:08 -04:00
|
|
|
EventBus.getDefault().unregister(this);
|
|
|
|
}
|
|
|
|
|
2021-07-20 13:08:52 -03:00
|
|
|
@SuppressLint("MissingSuperCall")
|
2017-11-24 22:00:30 -08:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
|
|
|
}
|
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
@Override
|
|
|
|
protected void onUserLeaveHint() {
|
2020-07-08 10:21:16 -04:00
|
|
|
enterPipModeIfPossible();
|
|
|
|
}
|
2020-04-23 16:20:59 -03:00
|
|
|
|
2020-07-08 10:21:16 -04:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (!enterPipModeIfPossible()) {
|
|
|
|
super.onBackPressed();
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
|
|
|
|
viewModel.setIsInPipMode(isInPictureInPictureMode);
|
2020-12-07 17:45:13 -04:00
|
|
|
participantUpdateWindow.setEnabled(!isInPictureInPictureMode);
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
|
|
|
|
2020-07-08 10:21:16 -04:00
|
|
|
private boolean enterPipModeIfPossible() {
|
2020-09-10 16:59:47 -04:00
|
|
|
if (viewModel.canEnterPipMode() && isSystemPipEnabledAndAvailable()) {
|
2020-07-08 10:21:16 -04:00
|
|
|
PictureInPictureParams params = new PictureInPictureParams.Builder()
|
2021-07-23 13:48:09 -03:00
|
|
|
.setAspectRatio(new Rational(9, 16))
|
|
|
|
.build();
|
2020-07-08 10:21:16 -04:00
|
|
|
enterPictureInPictureMode(params);
|
2020-12-07 14:50:11 -04:00
|
|
|
CallParticipantsListDialog.dismiss(getSupportFragmentManager());
|
2020-12-07 17:45:13 -04:00
|
|
|
|
2020-07-08 10:21:16 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
private boolean isInPipMode() {
|
2020-07-08 10:21:16 -04:00
|
|
|
return isSystemPipEnabledAndAvailable() && isInPictureInPictureMode();
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
|
|
|
|
2019-06-27 15:17:14 -04:00
|
|
|
private void processIntent(@NonNull Intent intent) {
|
|
|
|
if (ANSWER_ACTION.equals(intent.getAction())) {
|
2020-04-23 16:20:59 -03:00
|
|
|
handleAnswerWithAudio();
|
2019-06-27 15:17:14 -04:00
|
|
|
} else if (DENY_ACTION.equals(intent.getAction())) {
|
|
|
|
handleDenyCall();
|
|
|
|
} else if (END_CALL_ACTION.equals(intent.getAction())) {
|
|
|
|
handleEndCall();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 09:37:40 -08:00
|
|
|
private void initializeScreenshotSecurity() {
|
2019-03-20 15:09:27 -07:00
|
|
|
if (TextSecurePreferences.isScreenSecurityEnabled(this)) {
|
2016-11-09 09:37:40 -08:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
} else {
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeResources() {
|
2020-09-18 15:51:17 -04:00
|
|
|
callScreen = findViewById(R.id.callScreen);
|
2020-04-23 16:20:59 -03:00
|
|
|
callScreen.setControlsListener(new ControlsListener());
|
2020-12-04 15:41:29 -04:00
|
|
|
|
|
|
|
participantUpdateWindow = new CallParticipantsListUpdatePopupWindow(callScreen);
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
|
|
|
|
2021-07-23 13:48:09 -03:00
|
|
|
private void initializeViewModel(boolean isLandscapeEnabled) {
|
2021-01-29 16:22:01 -04:00
|
|
|
deviceOrientationMonitor = new DeviceOrientationMonitor(this);
|
|
|
|
getLifecycle().addObserver(deviceOrientationMonitor);
|
|
|
|
|
|
|
|
WebRtcCallViewModel.Factory factory = new WebRtcCallViewModel.Factory(deviceOrientationMonitor);
|
|
|
|
|
|
|
|
viewModel = ViewModelProviders.of(this, factory).get(WebRtcCallViewModel.class);
|
2021-07-23 13:48:09 -03:00
|
|
|
viewModel.setIsLandscapeEnabled(isLandscapeEnabled);
|
2020-04-23 16:20:59 -03:00
|
|
|
viewModel.setIsInPipMode(isInPipMode());
|
|
|
|
viewModel.getMicrophoneEnabled().observe(this, callScreen::setMicEnabled);
|
|
|
|
viewModel.getWebRtcControls().observe(this, callScreen::setWebRtcControls);
|
|
|
|
viewModel.getEvents().observe(this, this::handleViewModelEvent);
|
|
|
|
viewModel.getCallTime().observe(this, this::handleCallTime);
|
2021-08-24 10:18:39 -04:00
|
|
|
|
2021-08-02 09:55:58 -03:00
|
|
|
LiveDataUtil.combineLatest(viewModel.getCallParticipantsState(),
|
|
|
|
viewModel.getOrientationAndLandscapeEnabled(),
|
|
|
|
(s, o) -> new CallParticipantsViewState(s, o.first == PORTRAIT_BOTTOM_EDGE, o.second))
|
|
|
|
.observe(this, p -> callScreen.updateCallParticipants(p));
|
2020-12-04 15:41:29 -04:00
|
|
|
viewModel.getCallParticipantListUpdate().observe(this, participantUpdateWindow::addCallParticipantListUpdate);
|
2020-12-04 15:24:18 -05:00
|
|
|
viewModel.getSafetyNumberChangeEvent().observe(this, this::handleSafetyNumberChangeEvent);
|
2021-08-24 10:18:39 -04:00
|
|
|
viewModel.getGroupMembersChanged().observe(this, unused -> updateGroupMembersForGroupCall());
|
|
|
|
viewModel.getGroupMemberCount().observe(this, this::handleGroupMemberCountChange);
|
2020-12-08 17:18:22 -05:00
|
|
|
viewModel.shouldShowSpeakerHint().observe(this, this::updateSpeakerHint);
|
2020-11-20 15:42:46 -05:00
|
|
|
|
|
|
|
callScreen.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
|
|
|
|
CallParticipantsState state = viewModel.getCallParticipantsState().getValue();
|
|
|
|
if (state != null) {
|
|
|
|
if (state.needsNewRequestSizes()) {
|
2021-08-13 09:28:43 -04:00
|
|
|
requestNewSizesThrottle.publish(() -> ApplicationDependencies.getSignalCallManager().updateRenderedResolutions());
|
2020-11-20 15:42:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-01-29 16:22:01 -04:00
|
|
|
|
2021-07-23 13:48:09 -03:00
|
|
|
viewModel.getOrientationAndLandscapeEnabled().observe(this, pair -> ApplicationDependencies.getSignalCallManager().orientationChanged(pair.second, pair.first.getDegrees()));
|
|
|
|
viewModel.getControlsRotation().observe(this, callScreen::rotateControls);
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleViewModelEvent(@NonNull WebRtcCallViewModel.Event event) {
|
2020-12-04 15:24:18 -05:00
|
|
|
if (event instanceof WebRtcCallViewModel.Event.StartCall) {
|
2021-07-23 13:48:09 -03:00
|
|
|
startCall(((WebRtcCallViewModel.Event.StartCall) event).isVideoCall());
|
2020-12-04 15:24:18 -05:00
|
|
|
return;
|
|
|
|
} else if (event instanceof WebRtcCallViewModel.Event.ShowGroupCallSafetyNumberChange) {
|
|
|
|
SafetyNumberChangeDialog.showForGroupCall(getSupportFragmentManager(), ((WebRtcCallViewModel.Event.ShowGroupCallSafetyNumberChange) event).getIdentityRecords());
|
|
|
|
return;
|
2021-05-25 12:15:07 -04:00
|
|
|
} else if (event instanceof WebRtcCallViewModel.Event.SwitchToSpeaker) {
|
|
|
|
callScreen.switchToSpeakerView();
|
|
|
|
return;
|
|
|
|
} else if (event instanceof WebRtcCallViewModel.Event.ShowSwipeToSpeakerHint) {
|
|
|
|
CallToastPopupWindow.show(callScreen);
|
|
|
|
return;
|
2020-12-04 15:24:18 -05:00
|
|
|
}
|
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
if (isInPipMode()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-04 15:24:18 -05:00
|
|
|
if (event instanceof WebRtcCallViewModel.Event.ShowVideoTooltip) {
|
|
|
|
if (videoTooltip == null) {
|
|
|
|
videoTooltip = TooltipPopup.forTarget(callScreen.getVideoTooltipTarget())
|
|
|
|
.setBackgroundTint(ContextCompat.getColor(this, R.color.core_ultramarine))
|
|
|
|
.setTextColor(ContextCompat.getColor(this, R.color.core_white))
|
|
|
|
.setText(R.string.WebRtcCallActivity__tap_here_to_turn_on_your_video)
|
|
|
|
.setOnDismissListener(() -> viewModel.onDismissedVideoTooltip())
|
|
|
|
.show(TooltipPopup.POSITION_ABOVE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (event instanceof WebRtcCallViewModel.Event.DismissVideoTooltip) {
|
|
|
|
if (videoTooltip != null) {
|
|
|
|
videoTooltip.dismiss();
|
|
|
|
videoTooltip = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new IllegalArgumentException("Unknown event: " + event);
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleCallTime(long callTime) {
|
|
|
|
EllapsedTimeFormatter ellapsedTimeFormatter = EllapsedTimeFormatter.fromDurationMillis(callTime);
|
|
|
|
|
|
|
|
if (ellapsedTimeFormatter == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callScreen.setStatus(getString(R.string.WebRtcCallActivity__signal_s, ellapsedTimeFormatter.toString()));
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2020-05-21 16:57:21 -03:00
|
|
|
private void handleSetAudioHandset() {
|
2021-09-27 11:23:10 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().selectAudioDevice(SignalAudioManager.AudioDevice.EARPIECE);
|
2019-12-18 13:57:33 -04:00
|
|
|
}
|
|
|
|
|
2020-05-21 16:57:21 -03:00
|
|
|
private void handleSetAudioSpeaker() {
|
2021-09-27 11:23:10 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().selectAudioDevice(SignalAudioManager.AudioDevice.SPEAKER_PHONE);
|
2020-05-21 16:57:21 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleSetAudioBluetooth() {
|
2021-09-27 11:23:10 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().selectAudioDevice(SignalAudioManager.AudioDevice.BLUETOOTH);
|
2019-12-18 13:57:33 -04:00
|
|
|
}
|
|
|
|
|
2016-11-09 09:37:40 -08:00
|
|
|
private void handleSetMuteAudio(boolean enabled) {
|
2021-03-31 14:30:30 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().setMuteAudio(enabled);
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleSetMuteVideo(boolean muted) {
|
2020-04-23 16:20:59 -03:00
|
|
|
Recipient recipient = viewModel.getRecipient().get();
|
|
|
|
|
|
|
|
if (!recipient.equals(Recipient.UNKNOWN)) {
|
|
|
|
String recipientDisplayName = recipient.getDisplayName(this);
|
|
|
|
|
|
|
|
Permissions.with(this)
|
|
|
|
.request(Manifest.permission.CAMERA)
|
|
|
|
.ifNecessary()
|
|
|
|
.withRationaleDialog(getString(R.string.WebRtcCallActivity__to_call_s_signal_needs_access_to_your_camera, recipientDisplayName), R.drawable.ic_video_solid_24_tinted)
|
|
|
|
.withPermanentDenialDialog(getString(R.string.WebRtcCallActivity__to_call_s_signal_needs_access_to_your_camera, recipientDisplayName))
|
2021-03-31 14:30:30 -04:00
|
|
|
.onAllGranted(() -> ApplicationDependencies.getSignalCallManager().setMuteVideo(!muted))
|
2020-04-23 16:20:59 -03:00
|
|
|
.execute();
|
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2018-04-25 11:00:03 -07:00
|
|
|
private void handleFlipCamera() {
|
2021-03-31 14:30:30 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().flipCamera();
|
2018-03-23 20:31:03 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
private void handleAnswerWithAudio() {
|
2021-12-17 10:36:07 -05:00
|
|
|
Permissions.with(this)
|
|
|
|
.request(Manifest.permission.RECORD_AUDIO)
|
|
|
|
.ifNecessary()
|
|
|
|
.withRationaleDialog(getString(R.string.WebRtcCallActivity_to_answer_the_call_give_signal_access_to_your_microphone),
|
|
|
|
R.drawable.ic_mic_solid_24)
|
|
|
|
.withPermanentDenialDialog(getString(R.string.WebRtcCallActivity_signal_requires_microphone_and_camera_permissions_in_order_to_make_or_receive_calls))
|
|
|
|
.onAllGranted(() -> {
|
|
|
|
callScreen.setStatus(getString(R.string.RedPhone_answering));
|
|
|
|
|
|
|
|
ApplicationDependencies.getSignalCallManager().acceptCall(false);
|
|
|
|
})
|
|
|
|
.onAnyDenied(this::handleDenyCall)
|
|
|
|
.execute();
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleAnswerWithVideo() {
|
|
|
|
Recipient recipient = viewModel.getRecipient().get();
|
|
|
|
|
|
|
|
if (!recipient.equals(Recipient.UNKNOWN)) {
|
2017-11-24 22:00:30 -08:00
|
|
|
Permissions.with(this)
|
|
|
|
.request(Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA)
|
|
|
|
.ifNecessary()
|
2020-04-23 16:20:59 -03:00
|
|
|
.withRationaleDialog(getString(R.string.WebRtcCallActivity_to_answer_the_call_from_s_give_signal_access_to_your_microphone, recipient.getDisplayName(this)),
|
2021-07-23 13:48:09 -03:00
|
|
|
R.drawable.ic_mic_solid_24, R.drawable.ic_video_solid_24_tinted)
|
2017-11-24 22:00:30 -08:00
|
|
|
.withPermanentDenialDialog(getString(R.string.WebRtcCallActivity_signal_requires_microphone_and_camera_permissions_in_order_to_make_or_receive_calls))
|
|
|
|
.onAllGranted(() -> {
|
2020-04-23 16:20:59 -03:00
|
|
|
callScreen.setRecipient(recipient);
|
|
|
|
callScreen.setStatus(getString(R.string.RedPhone_answering));
|
2017-11-24 22:00:30 -08:00
|
|
|
|
2021-03-31 14:30:30 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().acceptCall(true);
|
2020-04-23 16:20:59 -03:00
|
|
|
|
|
|
|
handleSetMuteVideo(false);
|
2017-11-24 22:00:30 -08:00
|
|
|
})
|
|
|
|
.onAnyDenied(this::handleDenyCall)
|
|
|
|
.execute();
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleDenyCall() {
|
2020-04-23 16:20:59 -03:00
|
|
|
Recipient recipient = viewModel.getRecipient().get();
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
if (!recipient.equals(Recipient.UNKNOWN)) {
|
2021-03-31 14:30:30 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().denyCall();
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
callScreen.setRecipient(recipient);
|
|
|
|
callScreen.setStatus(getString(R.string.RedPhone_ending_call));
|
2016-11-09 09:37:40 -08:00
|
|
|
delayedFinish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleEndCall() {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "Hangup pressed, handling termination now...");
|
2021-03-31 14:30:30 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().localHangup();
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2020-11-11 15:11:03 -05:00
|
|
|
private void handleOutgoingCall(@NonNull WebRtcViewModel event) {
|
|
|
|
if (event.getGroupState().isNotIdle()) {
|
|
|
|
callScreen.setStatusFromGroupCallState(event.getGroupState());
|
|
|
|
} else {
|
|
|
|
callScreen.setStatus(getString(R.string.WebRtcCallActivity__calling));
|
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2020-05-08 14:39:32 -03:00
|
|
|
private void handleTerminate(@NonNull Recipient recipient, @NonNull HangupMessage.Type hangupType) {
|
|
|
|
Log.i(TAG, "handleTerminate called: " + hangupType.name());
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-05-08 14:39:32 -03:00
|
|
|
callScreen.setStatusFromHangupType(hangupType);
|
|
|
|
|
2017-02-02 18:34:51 -08:00
|
|
|
EventBus.getDefault().removeStickyEvent(WebRtcViewModel.class);
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-07-06 16:27:03 -04:00
|
|
|
if (hangupType == HangupMessage.Type.NEED_PERMISSION) {
|
|
|
|
startActivity(CalleeMustAcceptMessageRequestActivity.createIntent(this, recipient.getId()));
|
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
delayedFinish();
|
|
|
|
}
|
|
|
|
|
2021-11-03 13:07:16 -04:00
|
|
|
private void handleGlare(@NonNull Recipient recipient) {
|
|
|
|
Log.i(TAG, "handleGlare: " + recipient.getId());
|
|
|
|
|
|
|
|
callScreen.setStatus("");
|
|
|
|
}
|
|
|
|
|
2020-09-18 15:51:17 -04:00
|
|
|
private void handleCallRinging() {
|
2020-04-23 16:20:59 -03:00
|
|
|
callScreen.setStatus(getString(R.string.RedPhone_ringing));
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2020-09-18 15:51:17 -04:00
|
|
|
private void handleCallBusy() {
|
2020-02-11 19:56:16 -08:00
|
|
|
EventBus.getDefault().removeStickyEvent(WebRtcViewModel.class);
|
2020-04-23 16:20:59 -03:00
|
|
|
callScreen.setStatus(getString(R.string.RedPhone_busy));
|
2021-03-31 14:30:30 -04:00
|
|
|
delayedFinish(SignalCallManager.BUSY_TONE_LENGTH);
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2020-11-11 15:11:03 -05:00
|
|
|
private void handleCallConnected(@NonNull WebRtcViewModel event) {
|
2016-11-09 09:37:40 -08:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES);
|
2020-11-11 15:11:03 -05:00
|
|
|
if (event.getGroupState().isNotIdleOrConnected()) {
|
|
|
|
callScreen.setStatusFromGroupCallState(event.getGroupState());
|
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2022-03-22 21:12:40 -04:00
|
|
|
private void handleCallReconnecting() {
|
|
|
|
callScreen.setStatus(getString(R.string.WebRtcCallActivity__reconnecting));
|
2022-03-25 12:37:47 -04:00
|
|
|
VibrateUtil.vibrate(this, VIBRATE_DURATION);
|
2022-03-22 21:12:40 -04:00
|
|
|
}
|
|
|
|
|
2020-09-18 15:51:17 -04:00
|
|
|
private void handleRecipientUnavailable() {
|
2020-02-11 19:56:16 -08:00
|
|
|
EventBus.getDefault().removeStickyEvent(WebRtcViewModel.class);
|
2020-04-23 16:20:59 -03:00
|
|
|
callScreen.setStatus(getString(R.string.RedPhone_recipient_unavailable));
|
2016-11-09 09:37:40 -08:00
|
|
|
delayedFinish();
|
|
|
|
}
|
|
|
|
|
2020-09-18 15:51:17 -04:00
|
|
|
private void handleServerFailure() {
|
2020-02-11 19:56:16 -08:00
|
|
|
EventBus.getDefault().removeStickyEvent(WebRtcViewModel.class);
|
2020-04-23 16:20:59 -03:00
|
|
|
callScreen.setStatus(getString(R.string.RedPhone_network_failed));
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2017-02-02 18:34:51 -08:00
|
|
|
private void handleNoSuchUser(final @NonNull WebRtcViewModel event) {
|
2016-11-09 09:37:40 -08:00
|
|
|
if (isFinishing()) return; // XXX Stuart added this check above, not sure why, so I'm repeating in ignorance. - moxie
|
2020-09-18 15:51:17 -04:00
|
|
|
new AlertDialog.Builder(this)
|
2021-07-23 13:48:09 -03:00
|
|
|
.setTitle(R.string.RedPhone_number_not_registered)
|
|
|
|
.setIcon(R.drawable.ic_warning)
|
|
|
|
.setMessage(R.string.RedPhone_the_number_you_dialed_does_not_support_secure_voice)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setPositiveButton(R.string.RedPhone_got_it, (d, w) -> handleTerminate(event.getRecipient(), HangupMessage.Type.NORMAL))
|
|
|
|
.setOnCancelListener(d -> handleTerminate(event.getRecipient(), HangupMessage.Type.NORMAL))
|
|
|
|
.show();
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2017-02-02 18:34:51 -08:00
|
|
|
private void handleUntrustedIdentity(@NonNull WebRtcViewModel event) {
|
2020-09-10 16:59:47 -04:00
|
|
|
final IdentityKey theirKey = event.getRemoteParticipants().get(0).getIdentityKey();
|
|
|
|
final Recipient recipient = event.getRemoteParticipants().get(0).getRecipient();
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
if (theirKey == null) {
|
2021-02-17 10:26:45 -05:00
|
|
|
Log.w(TAG, "Untrusted identity without an identity key, terminating call.");
|
2020-05-08 14:39:32 -03:00
|
|
|
handleTerminate(recipient, HangupMessage.Type.NORMAL);
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-08-27 16:34:26 -04:00
|
|
|
SafetyNumberChangeDialog.showForCall(getSupportFragmentManager(), recipient.getId());
|
|
|
|
}
|
|
|
|
|
2020-12-04 15:24:18 -05:00
|
|
|
public void handleSafetyNumberChangeEvent(@NonNull WebRtcCallViewModel.SafetyNumberChangeEvent safetyNumberChangeEvent) {
|
|
|
|
if (Util.hasItems(safetyNumberChangeEvent.getRecipientIds())) {
|
|
|
|
if (safetyNumberChangeEvent.isInPipMode()) {
|
|
|
|
GroupCallSafetyNumberChangeNotificationUtil.showNotification(this, viewModel.getRecipient().get());
|
|
|
|
} else {
|
|
|
|
GroupCallSafetyNumberChangeNotificationUtil.cancelNotification(this, viewModel.getRecipient().get());
|
|
|
|
SafetyNumberChangeDialog.showForDuringGroupCall(getSupportFragmentManager(), safetyNumberChangeEvent.getRecipientIds());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-27 16:34:26 -04:00
|
|
|
|
2020-12-05 20:55:52 -05:00
|
|
|
private void updateGroupMembersForGroupCall() {
|
2021-03-31 14:30:30 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().requestUpdateGroupMembers();
|
2020-12-05 20:55:52 -05:00
|
|
|
}
|
|
|
|
|
2021-08-24 10:18:39 -04:00
|
|
|
public void handleGroupMemberCountChange(int count) {
|
|
|
|
boolean canRing = count <= FeatureFlags.maxGroupCallRingSize() && FeatureFlags.groupCallRinging();
|
|
|
|
callScreen.enableRingGroup(canRing);
|
|
|
|
ApplicationDependencies.getSignalCallManager().setRingGroup(canRing);
|
|
|
|
}
|
|
|
|
|
2020-12-08 17:18:22 -05:00
|
|
|
private void updateSpeakerHint(boolean showSpeakerHint) {
|
|
|
|
if (showSpeakerHint) {
|
|
|
|
callScreen.showSpeakerViewHint();
|
|
|
|
} else {
|
|
|
|
callScreen.hideSpeakerViewHint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 15:24:18 -05:00
|
|
|
@Override
|
|
|
|
public void onSendAnywayAfterSafetyNumberChange(@NonNull List<RecipientId> changedRecipients) {
|
|
|
|
CallParticipantsState state = viewModel.getCallParticipantsState().getValue();
|
2021-03-31 14:30:30 -04:00
|
|
|
|
|
|
|
if (state == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-04 15:24:18 -05:00
|
|
|
if (state.getGroupCallState().isConnected()) {
|
2021-03-31 14:30:30 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().groupApproveSafetyChange(changedRecipients);
|
2020-12-04 15:24:18 -05:00
|
|
|
} else {
|
2021-01-06 15:15:50 -05:00
|
|
|
viewModel.startCall(state.getLocalParticipant().isVideoEnabled());
|
2020-12-04 15:24:18 -05:00
|
|
|
}
|
2020-08-27 16:34:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMessageResentAfterSafetyNumberChange() { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
2020-12-04 15:24:18 -05:00
|
|
|
CallParticipantsState state = viewModel.getCallParticipantsState().getValue();
|
|
|
|
if (state != null && state.getGroupCallState().isNotIdle()) {
|
2021-01-06 15:15:50 -05:00
|
|
|
if (state.getCallState().isPreJoinOrNetworkUnavailable()) {
|
2021-03-31 14:30:30 -04:00
|
|
|
ApplicationDependencies.getSignalCallManager().cancelPreJoin();
|
2020-12-04 15:24:18 -05:00
|
|
|
finish();
|
|
|
|
} else {
|
|
|
|
handleEndCall();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
handleTerminate(viewModel.getRecipient().get(), HangupMessage.Type.NORMAL);
|
|
|
|
}
|
2020-04-23 16:20:59 -03:00
|
|
|
}
|
|
|
|
|
2020-07-08 10:21:16 -04:00
|
|
|
private boolean isSystemPipEnabledAndAvailable() {
|
2020-04-23 16:20:59 -03:00
|
|
|
return Build.VERSION.SDK_INT >= 26 &&
|
|
|
|
getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void delayedFinish() {
|
|
|
|
delayedFinish(STANDARD_DELAY_FINISH);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void delayedFinish(int delayMillis) {
|
2020-04-23 16:20:59 -03:00
|
|
|
callScreen.postDelayed(WebRtcCallActivity.this::finish, delayMillis);
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2017-02-17 20:27:11 -08:00
|
|
|
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
|
2020-09-10 16:59:47 -04:00
|
|
|
public void onEventMainThread(@NonNull WebRtcViewModel event) {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "Got message from service: " + event);
|
2016-11-09 09:37:40 -08:00
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
viewModel.setRecipient(event.getRecipient());
|
2020-09-10 16:59:47 -04:00
|
|
|
callScreen.setRecipient(event.getRecipient());
|
2020-04-23 16:20:59 -03:00
|
|
|
|
2017-02-02 18:34:51 -08:00
|
|
|
switch (event.getState()) {
|
2021-07-23 13:48:09 -03:00
|
|
|
case CALL_PRE_JOIN:
|
|
|
|
handleCallPreJoin(event); break;
|
|
|
|
case CALL_CONNECTED:
|
|
|
|
handleCallConnected(event); break;
|
2022-03-22 21:12:40 -04:00
|
|
|
case CALL_RECONNECTING:
|
|
|
|
handleCallReconnecting(); break;
|
2021-07-23 13:48:09 -03:00
|
|
|
case NETWORK_FAILURE:
|
|
|
|
handleServerFailure(); break;
|
|
|
|
case CALL_RINGING:
|
|
|
|
handleCallRinging(); break;
|
|
|
|
case CALL_DISCONNECTED:
|
|
|
|
handleTerminate(event.getRecipient(), HangupMessage.Type.NORMAL); break;
|
2021-11-03 13:07:16 -04:00
|
|
|
case CALL_DISCONNECTED_GLARE:
|
|
|
|
handleGlare(event.getRecipient()); break;
|
2021-07-23 13:48:09 -03:00
|
|
|
case CALL_ACCEPTED_ELSEWHERE:
|
|
|
|
handleTerminate(event.getRecipient(), HangupMessage.Type.ACCEPTED); break;
|
|
|
|
case CALL_DECLINED_ELSEWHERE:
|
|
|
|
handleTerminate(event.getRecipient(), HangupMessage.Type.DECLINED); break;
|
|
|
|
case CALL_ONGOING_ELSEWHERE:
|
|
|
|
handleTerminate(event.getRecipient(), HangupMessage.Type.BUSY); break;
|
|
|
|
case CALL_NEEDS_PERMISSION:
|
|
|
|
handleTerminate(event.getRecipient(), HangupMessage.Type.NEED_PERMISSION); break;
|
|
|
|
case NO_SUCH_USER:
|
|
|
|
handleNoSuchUser(event); break;
|
|
|
|
case RECIPIENT_UNAVAILABLE:
|
|
|
|
handleRecipientUnavailable(); break;
|
|
|
|
case CALL_OUTGOING:
|
|
|
|
handleOutgoingCall(event); break;
|
|
|
|
case CALL_BUSY:
|
|
|
|
handleCallBusy(); break;
|
|
|
|
case UNTRUSTED_IDENTITY:
|
|
|
|
handleUntrustedIdentity(event); break;
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
2017-02-02 18:34:51 -08:00
|
|
|
|
2020-09-10 16:59:47 -04:00
|
|
|
boolean enableVideo = event.getLocalParticipant().getCameraState().getCameraCount() > 0 && enableVideoIfAvailable;
|
2019-12-03 16:26:05 -04:00
|
|
|
|
2020-06-12 09:38:26 -04:00
|
|
|
viewModel.updateFromWebRtcViewModel(event, enableVideo);
|
|
|
|
|
|
|
|
if (enableVideo) {
|
2019-12-03 16:26:05 -04:00
|
|
|
enableVideoIfAvailable = false;
|
|
|
|
handleSetMuteVideo(false);
|
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2020-11-11 15:11:03 -05:00
|
|
|
private void handleCallPreJoin(@NonNull WebRtcViewModel event) {
|
|
|
|
if (event.getGroupState().isNotIdle()) {
|
|
|
|
callScreen.setStatusFromGroupCallState(event.getGroupState());
|
2021-08-24 10:18:39 -04:00
|
|
|
callScreen.setRingGroup(event.shouldRingGroup());
|
|
|
|
|
|
|
|
if (event.shouldRingGroup() && event.areRemoteDevicesInCall()) {
|
|
|
|
ApplicationDependencies.getSignalCallManager().setRingGroup(false);
|
|
|
|
}
|
2020-11-11 15:11:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 15:24:18 -05:00
|
|
|
private void startCall(boolean isVideoCall) {
|
|
|
|
enableVideoIfAvailable = isVideoCall;
|
|
|
|
|
2021-03-31 14:30:30 -04:00
|
|
|
if (isVideoCall) {
|
|
|
|
ApplicationDependencies.getSignalCallManager().startOutgoingVideoCall(viewModel.getRecipient().get());
|
|
|
|
} else {
|
|
|
|
ApplicationDependencies.getSignalCallManager().startOutgoingAudioCall(viewModel.getRecipient().get());
|
|
|
|
}
|
2020-12-04 15:24:18 -05:00
|
|
|
|
|
|
|
MessageSender.onMessageSent();
|
|
|
|
}
|
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
private final class ControlsListener implements WebRtcCallView.ControlsListener {
|
|
|
|
|
2020-09-10 16:59:47 -04:00
|
|
|
@Override
|
2020-09-18 15:51:17 -04:00
|
|
|
public void onStartCall(boolean isVideoCall) {
|
2020-12-04 15:24:18 -05:00
|
|
|
viewModel.startCall(isVideoCall);
|
2020-09-10 16:59:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancelStartCall() {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
2020-04-23 16:20:59 -03:00
|
|
|
@Override
|
|
|
|
public void onControlsFadeOut() {
|
|
|
|
if (videoTooltip != null) {
|
|
|
|
videoTooltip.dismiss();
|
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2021-01-08 10:47:04 -04:00
|
|
|
@Override
|
|
|
|
public void showSystemUI() {
|
|
|
|
fullscreenHelper.showSystemUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void hideSystemUI() {
|
|
|
|
fullscreenHelper.hideSystemUI();
|
|
|
|
}
|
|
|
|
|
2016-11-09 09:37:40 -08:00
|
|
|
@Override
|
2020-04-23 16:20:59 -03:00
|
|
|
public void onAudioOutputChanged(@NonNull WebRtcAudioOutput audioOutput) {
|
|
|
|
switch (audioOutput) {
|
|
|
|
case HANDSET:
|
2020-05-21 16:57:21 -03:00
|
|
|
handleSetAudioHandset();
|
2020-04-23 16:20:59 -03:00
|
|
|
break;
|
|
|
|
case HEADSET:
|
2020-05-21 16:57:21 -03:00
|
|
|
handleSetAudioBluetooth();
|
2020-04-23 16:20:59 -03:00
|
|
|
break;
|
|
|
|
case SPEAKER:
|
2020-05-21 16:57:21 -03:00
|
|
|
handleSetAudioSpeaker();
|
2020-04-23 16:20:59 -03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new IllegalStateException("Unknown output: " + audioOutput);
|
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-23 16:20:59 -03:00
|
|
|
public void onVideoChanged(boolean isVideoEnabled) {
|
|
|
|
handleSetMuteVideo(!isVideoEnabled);
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
2018-03-23 20:31:03 +01:00
|
|
|
@Override
|
2020-04-23 16:20:59 -03:00
|
|
|
public void onMicChanged(boolean isMicEnabled) {
|
|
|
|
handleSetMuteAudio(!isMicEnabled);
|
2018-04-25 11:00:03 -07:00
|
|
|
}
|
2018-03-23 20:31:03 +01:00
|
|
|
|
2017-03-04 15:48:10 -08:00
|
|
|
@Override
|
2020-04-23 16:20:59 -03:00
|
|
|
public void onCameraDirectionChanged() {
|
|
|
|
handleFlipCamera();
|
2017-03-04 15:48:10 -08:00
|
|
|
}
|
2017-02-03 12:00:00 -08:00
|
|
|
|
2016-11-09 09:37:40 -08:00
|
|
|
@Override
|
2020-04-23 16:20:59 -03:00
|
|
|
public void onEndCallPressed() {
|
|
|
|
handleEndCall();
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-23 16:20:59 -03:00
|
|
|
public void onDenyCallPressed() {
|
|
|
|
handleDenyCall();
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-23 16:20:59 -03:00
|
|
|
public void onAcceptCallWithVoiceOnlyPressed() {
|
|
|
|
handleAnswerWithAudio();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAcceptCallPressed() {
|
|
|
|
if (viewModel.isAnswerWithVideoAvailable()) {
|
|
|
|
handleAnswerWithVideo();
|
|
|
|
} else {
|
|
|
|
handleAnswerWithAudio();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-09-10 16:59:47 -04:00
|
|
|
public void onShowParticipantsList() {
|
|
|
|
CallParticipantsListDialog.show(getSupportFragmentManager());
|
|
|
|
}
|
2020-04-23 16:20:59 -03:00
|
|
|
|
2020-09-10 16:59:47 -04:00
|
|
|
@Override
|
|
|
|
public void onPageChanged(@NonNull CallParticipantsState.SelectedPage page) {
|
|
|
|
viewModel.setIsViewingFocusedParticipant(page);
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
2021-01-13 11:33:41 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLocalPictureInPictureClicked() {
|
|
|
|
viewModel.onLocalPictureInPictureClicked();
|
|
|
|
}
|
2021-08-24 10:18:39 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRingGroupChanged(boolean ringGroup, boolean ringingAllowed) {
|
|
|
|
if (ringingAllowed) {
|
|
|
|
ApplicationDependencies.getSignalCallManager().setRingGroup(ringGroup);
|
|
|
|
} else {
|
|
|
|
ApplicationDependencies.getSignalCallManager().setRingGroup(false);
|
|
|
|
Toast.makeText(WebRtcCallActivity.this, R.string.WebRtcCallActivity__group_is_too_large_to_ring_the_participants, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
2016-11-09 09:37:40 -08:00
|
|
|
}
|
2021-07-23 13:48:09 -03:00
|
|
|
|
|
|
|
private class WindowLayoutInfoConsumer implements Consumer<WindowLayoutInfo> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void accept(WindowLayoutInfo windowLayoutInfo) {
|
|
|
|
Log.d(TAG, "On WindowLayoutInfo accepted: " + windowLayoutInfo.toString());
|
|
|
|
|
|
|
|
Optional<DisplayFeature> feature = windowLayoutInfo.getDisplayFeatures().stream().filter(f -> f instanceof FoldingFeature).findFirst();
|
2021-08-02 09:55:58 -03:00
|
|
|
viewModel.setIsLandscapeEnabled(feature.isPresent());
|
|
|
|
setRequestedOrientation(feature.isPresent() ? ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
2021-07-23 13:48:09 -03:00
|
|
|
if (feature.isPresent()) {
|
|
|
|
FoldingFeature foldingFeature = (FoldingFeature) feature.get();
|
2021-08-09 11:56:06 -04:00
|
|
|
Rect bounds = foldingFeature.getBounds();
|
2021-07-23 13:48:09 -03:00
|
|
|
if (foldingFeature.getState() == FoldingFeature.State.HALF_OPENED && bounds.top == bounds.bottom) {
|
|
|
|
Log.d(TAG, "OnWindowLayoutInfo accepted: ensure call view is in table-top display mode");
|
|
|
|
viewModel.setFoldableState(WebRtcControls.FoldableState.folded(bounds.top));
|
|
|
|
} else {
|
|
|
|
Log.d(TAG, "OnWindowLayoutInfo accepted: ensure call view is in flat display mode");
|
|
|
|
viewModel.setFoldableState(WebRtcControls.FoldableState.flat());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-11 19:56:16 -08:00
|
|
|
}
|