2020-04-07 09:36:28 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2021-08-24 12:40:12 +00:00
|
|
|
import static java.util.Arrays.asList;
|
|
|
|
import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
|
|
|
|
|
2020-04-09 17:45:21 +00:00
|
|
|
import android.Manifest;
|
2020-04-10 07:31:39 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2022-09-09 17:06:37 +00:00
|
|
|
import android.app.Activity;
|
2020-04-16 15:38:05 +00:00
|
|
|
import android.app.PictureInPictureParams;
|
2020-06-12 06:26:33 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2020-04-10 09:16:54 +00:00
|
|
|
import android.content.Context;
|
2020-04-07 11:15:24 +00:00
|
|
|
import android.content.Intent;
|
2020-04-23 10:14:45 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2020-04-10 09:16:54 +00:00
|
|
|
import android.os.Build;
|
2020-04-07 09:36:28 +00:00
|
|
|
import android.os.Bundle;
|
2020-05-09 09:14:39 +00:00
|
|
|
import android.os.Handler;
|
2020-04-10 09:16:54 +00:00
|
|
|
import android.os.PowerManager;
|
2020-04-18 15:51:21 +00:00
|
|
|
import android.os.SystemClock;
|
2020-04-07 11:15:24 +00:00
|
|
|
import android.util.Log;
|
2020-04-16 15:38:05 +00:00
|
|
|
import android.util.Rational;
|
2021-02-18 19:55:29 +00:00
|
|
|
import android.view.KeyEvent;
|
2020-06-12 06:26:33 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2020-04-07 09:36:28 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.WindowManager;
|
2020-04-09 17:45:21 +00:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2021-01-23 08:25:34 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2022-08-22 09:29:04 +00:00
|
|
|
import androidx.annotation.Nullable;
|
2021-01-23 08:25:34 +00:00
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
import androidx.annotation.StringRes;
|
|
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
|
2020-04-14 17:06:39 +00:00
|
|
|
import com.google.common.base.Optional;
|
2020-04-29 06:51:38 +00:00
|
|
|
import com.google.common.base.Preconditions;
|
2020-05-02 15:15:46 +00:00
|
|
|
import com.google.common.base.Throwables;
|
2020-04-09 17:45:21 +00:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2020-04-15 08:49:38 +00:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
2020-05-02 15:15:46 +00:00
|
|
|
import com.google.common.util.concurrent.FutureCallback;
|
|
|
|
import com.google.common.util.concurrent.Futures;
|
2020-04-07 09:36:28 +00:00
|
|
|
|
2021-05-09 06:56:07 +00:00
|
|
|
import org.webrtc.RendererCommon;
|
2020-04-14 17:06:39 +00:00
|
|
|
import org.webrtc.SurfaceViewRenderer;
|
|
|
|
import org.webrtc.VideoTrack;
|
|
|
|
|
2020-04-07 11:15:24 +00:00
|
|
|
import java.lang.ref.WeakReference;
|
2020-04-10 09:16:54 +00:00
|
|
|
import java.util.Arrays;
|
2020-04-29 06:51:38 +00:00
|
|
|
import java.util.Collections;
|
2020-04-15 16:47:15 +00:00
|
|
|
import java.util.List;
|
2020-04-13 10:02:34 +00:00
|
|
|
import java.util.Set;
|
2020-04-07 11:15:24 +00:00
|
|
|
|
|
|
|
import eu.siacs.conversations.Config;
|
2020-04-07 09:36:28 +00:00
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.databinding.ActivityRtpSessionBinding;
|
2020-04-07 11:15:24 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.entities.Contact;
|
2020-05-30 08:30:57 +00:00
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2020-04-13 10:02:34 +00:00
|
|
|
import eu.siacs.conversations.services.AppRTCAudioManager;
|
2020-04-07 11:15:24 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2020-04-20 11:41:50 +00:00
|
|
|
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
2020-05-02 15:15:46 +00:00
|
|
|
import eu.siacs.conversations.ui.util.MainThreadExecutor;
|
2021-08-24 12:40:12 +00:00
|
|
|
import eu.siacs.conversations.ui.util.Rationals;
|
2020-04-09 17:45:21 +00:00
|
|
|
import eu.siacs.conversations.utils.PermissionUtils;
|
2020-05-09 09:14:39 +00:00
|
|
|
import eu.siacs.conversations.utils.TimeFrameUtils;
|
2020-05-30 12:56:12 +00:00
|
|
|
import eu.siacs.conversations.xml.Namespace;
|
2021-01-23 08:25:34 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2020-04-07 11:15:24 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection;
|
2022-11-28 10:39:26 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.ContentAddition;
|
2020-06-11 19:17:13 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager;
|
2020-04-07 11:15:24 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.JingleRtpConnection;
|
2020-04-15 08:49:38 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.Media;
|
2020-04-07 11:15:24 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.RtpEndUserState;
|
2020-04-07 09:36:28 +00:00
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
public class RtpSessionActivity extends XmppActivity
|
|
|
|
implements XmppConnectionService.OnJingleRtpConnectionUpdate,
|
|
|
|
eu.siacs.conversations.ui.widget.SurfaceViewRenderer.OnAspectRatioChanged {
|
2020-04-07 09:36:28 +00:00
|
|
|
|
|
|
|
public static final String EXTRA_WITH = "with";
|
2020-04-07 11:15:24 +00:00
|
|
|
public static final String EXTRA_SESSION_ID = "session_id";
|
2020-04-09 15:37:21 +00:00
|
|
|
public static final String EXTRA_LAST_REPORTED_STATE = "last_reported_state";
|
2020-04-16 08:03:53 +00:00
|
|
|
public static final String EXTRA_LAST_ACTION = "last_action";
|
2020-04-08 07:42:06 +00:00
|
|
|
public static final String ACTION_ACCEPT_CALL = "action_accept_call";
|
|
|
|
public static final String ACTION_MAKE_VOICE_CALL = "action_make_voice_call";
|
|
|
|
public static final String ACTION_MAKE_VIDEO_CALL = "action_make_video_call";
|
2020-05-09 09:14:39 +00:00
|
|
|
|
|
|
|
private static final int CALL_DURATION_UPDATE_INTERVAL = 333;
|
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private static final List<RtpEndUserState> END_CARD =
|
|
|
|
Arrays.asList(
|
|
|
|
RtpEndUserState.APPLICATION_ERROR,
|
|
|
|
RtpEndUserState.SECURITY_ERROR,
|
|
|
|
RtpEndUserState.DECLINED_OR_BUSY,
|
|
|
|
RtpEndUserState.CONNECTIVITY_ERROR,
|
|
|
|
RtpEndUserState.CONNECTIVITY_LOST_ERROR,
|
|
|
|
RtpEndUserState.RETRACTED);
|
|
|
|
private static final List<RtpEndUserState> STATES_SHOWING_HELP_BUTTON =
|
|
|
|
Arrays.asList(
|
|
|
|
RtpEndUserState.APPLICATION_ERROR,
|
|
|
|
RtpEndUserState.CONNECTIVITY_ERROR,
|
|
|
|
RtpEndUserState.SECURITY_ERROR);
|
|
|
|
private static final List<RtpEndUserState> STATES_SHOWING_SWITCH_TO_CHAT =
|
|
|
|
Arrays.asList(
|
|
|
|
RtpEndUserState.CONNECTING,
|
|
|
|
RtpEndUserState.CONNECTED,
|
2022-11-28 10:39:26 +00:00
|
|
|
RtpEndUserState.RECONNECTING,
|
|
|
|
RtpEndUserState.INCOMING_CONTENT_ADD);
|
2022-02-23 14:57:29 +00:00
|
|
|
private static final List<RtpEndUserState> STATES_CONSIDERED_CONNECTED =
|
2022-11-28 10:39:26 +00:00
|
|
|
Arrays.asList(
|
|
|
|
RtpEndUserState.CONNECTED,
|
|
|
|
RtpEndUserState.RECONNECTING);
|
2022-02-23 14:57:29 +00:00
|
|
|
private static final List<RtpEndUserState> STATES_SHOWING_PIP_PLACEHOLDER =
|
|
|
|
Arrays.asList(
|
|
|
|
RtpEndUserState.ACCEPTING_CALL,
|
|
|
|
RtpEndUserState.CONNECTING,
|
|
|
|
RtpEndUserState.RECONNECTING);
|
2020-04-16 15:38:05 +00:00
|
|
|
private static final String PROXIMITY_WAKE_LOCK_TAG = "conversations:in-rtp-session";
|
|
|
|
private static final int REQUEST_ACCEPT_CALL = 0x1111;
|
2022-11-28 10:39:26 +00:00
|
|
|
private static final int REQUEST_ACCEPT_CONTENT = 0x1112;
|
|
|
|
private static final int REQUEST_ADD_CONTENT = 0x1113;
|
2020-04-07 11:15:24 +00:00
|
|
|
private WeakReference<JingleRtpConnection> rtpConnectionReference;
|
2020-04-07 09:36:28 +00:00
|
|
|
|
|
|
|
private ActivityRtpSessionBinding binding;
|
2020-04-10 09:16:54 +00:00
|
|
|
private PowerManager.WakeLock mProximityWakeLock;
|
2020-04-07 09:36:28 +00:00
|
|
|
|
2021-01-23 08:25:34 +00:00
|
|
|
private final Handler mHandler = new Handler();
|
2022-02-23 14:57:29 +00:00
|
|
|
private final Runnable mTickExecutor =
|
|
|
|
new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
updateCallDuration();
|
|
|
|
mHandler.postDelayed(mTickExecutor, CALL_DURATION_UPDATE_INTERVAL);
|
|
|
|
}
|
|
|
|
};
|
2020-05-09 09:14:39 +00:00
|
|
|
|
2020-04-16 15:38:05 +00:00
|
|
|
private static Set<Media> actionToMedia(final String action) {
|
|
|
|
if (ACTION_MAKE_VIDEO_CALL.equals(action)) {
|
|
|
|
return ImmutableSet.of(Media.AUDIO, Media.VIDEO);
|
|
|
|
} else {
|
|
|
|
return ImmutableSet.of(Media.AUDIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private static void addSink(
|
|
|
|
final VideoTrack videoTrack, final SurfaceViewRenderer surfaceViewRenderer) {
|
2020-05-30 08:30:57 +00:00
|
|
|
try {
|
|
|
|
videoTrack.addSink(surfaceViewRenderer);
|
|
|
|
} catch (final IllegalStateException e) {
|
2022-02-23 14:57:29 +00:00
|
|
|
Log.e(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"possible race condition on trying to display video track. ignoring",
|
|
|
|
e);
|
2020-05-30 08:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 14:17:29 +00:00
|
|
|
@Override
|
2020-04-07 09:36:28 +00:00
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2022-02-23 14:57:29 +00:00
|
|
|
getWindow()
|
|
|
|
.addFlags(
|
|
|
|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
|
|
|
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
|
|
|
|
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
|
|
|
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
2020-04-07 09:36:28 +00:00
|
|
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_rtp_session);
|
2020-04-14 17:35:26 +00:00
|
|
|
setSupportActionBar(binding.toolbar);
|
2020-04-07 12:22:12 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 06:26:33 +00:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.activity_rtp_session, menu);
|
|
|
|
final MenuItem help = menu.findItem(R.id.action_help);
|
2020-07-10 17:30:16 +00:00
|
|
|
final MenuItem gotoChat = menu.findItem(R.id.action_goto_chat);
|
2022-11-28 10:39:26 +00:00
|
|
|
final MenuItem switchToVideo = menu.findItem(R.id.action_switch_to_video);
|
2022-11-10 06:54:47 +00:00
|
|
|
help.setVisible(Config.HELP != null && isHelpButtonVisible());
|
2020-07-10 17:30:16 +00:00
|
|
|
gotoChat.setVisible(isSwitchToConversationVisible());
|
2022-11-28 10:39:26 +00:00
|
|
|
switchToVideo.setVisible(isSwitchToVideoVisible());
|
2020-06-12 06:26:33 +00:00
|
|
|
return super.onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
2021-02-18 19:55:29 +00:00
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
|
2021-03-06 08:45:42 +00:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
2021-02-18 19:55:29 +00:00
|
|
|
if (xmppConnectionService != null) {
|
2021-02-18 21:16:28 +00:00
|
|
|
if (xmppConnectionService.getNotificationService().stopSoundAndVibration()) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-18 19:55:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2020-06-12 06:26:33 +00:00
|
|
|
private boolean isHelpButtonVisible() {
|
|
|
|
try {
|
|
|
|
return STATES_SHOWING_HELP_BUTTON.contains(requireRtpConnection().getEndUserState());
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
final Intent intent = getIntent();
|
2022-02-23 14:57:29 +00:00
|
|
|
final String state =
|
|
|
|
intent != null ? intent.getStringExtra(EXTRA_LAST_REPORTED_STATE) : null;
|
2020-06-12 06:26:33 +00:00
|
|
|
if (state != null) {
|
|
|
|
return STATES_SHOWING_HELP_BUTTON.contains(RtpEndUserState.valueOf(state));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:30:16 +00:00
|
|
|
private boolean isSwitchToConversationVisible() {
|
2022-02-23 14:57:29 +00:00
|
|
|
final JingleRtpConnection connection =
|
|
|
|
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
|
|
|
return connection != null
|
|
|
|
&& STATES_SHOWING_SWITCH_TO_CHAT.contains(connection.getEndUserState());
|
2020-07-10 17:30:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 10:39:26 +00:00
|
|
|
private boolean isSwitchToVideoVisible() {
|
|
|
|
final JingleRtpConnection connection =
|
|
|
|
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
|
|
|
if (connection == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-12-12 09:15:10 +00:00
|
|
|
return connection.isSwitchToVideoAvailable();
|
2022-11-28 10:39:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 17:30:16 +00:00
|
|
|
private void switchToConversation() {
|
|
|
|
final Contact contact = getWith();
|
2022-02-23 14:57:29 +00:00
|
|
|
final Conversation conversation =
|
|
|
|
xmppConnectionService.findOrCreateConversation(
|
|
|
|
contact.getAccount(), contact.getJid(), false, true);
|
2020-07-10 17:30:16 +00:00
|
|
|
switchToConversation(conversation);
|
|
|
|
}
|
|
|
|
|
2020-06-12 06:26:33 +00:00
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
2020-07-10 17:30:16 +00:00
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_help:
|
|
|
|
launchHelpInBrowser();
|
2022-11-28 10:39:26 +00:00
|
|
|
return true;
|
2020-07-10 17:30:16 +00:00
|
|
|
case R.id.action_goto_chat:
|
|
|
|
switchToConversation();
|
2022-11-28 10:39:26 +00:00
|
|
|
return true;
|
|
|
|
case R.id.action_switch_to_video:
|
|
|
|
requestPermissionAndSwitchToVideo();
|
|
|
|
return true;
|
2020-06-12 06:26:33 +00:00
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void launchHelpInBrowser() {
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW, Config.HELP);
|
|
|
|
try {
|
|
|
|
startActivity(intent);
|
|
|
|
} catch (final ActivityNotFoundException e) {
|
2022-02-23 14:57:29 +00:00
|
|
|
Toast.makeText(this, R.string.no_application_found_to_open_link, Toast.LENGTH_LONG)
|
|
|
|
.show();
|
2020-06-12 06:26:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:22:12 +00:00
|
|
|
private void endCall(View view) {
|
2020-04-10 08:35:00 +00:00
|
|
|
endCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void endCall() {
|
2020-04-08 07:42:06 +00:00
|
|
|
if (this.rtpConnectionReference == null) {
|
2020-04-21 20:46:46 +00:00
|
|
|
retractSessionProposal();
|
2020-04-10 11:13:20 +00:00
|
|
|
finish();
|
2020-04-08 07:42:06 +00:00
|
|
|
} else {
|
|
|
|
requireRtpConnection().endCall();
|
|
|
|
}
|
2020-04-07 09:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 20:46:46 +00:00
|
|
|
private void retractSessionProposal() {
|
|
|
|
final Intent intent = getIntent();
|
2020-04-30 07:06:43 +00:00
|
|
|
final String action = intent.getAction();
|
2020-04-21 20:46:46 +00:00
|
|
|
final Account account = extractAccount(intent);
|
2020-05-17 08:24:46 +00:00
|
|
|
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
2020-04-30 07:06:43 +00:00
|
|
|
final String state = intent.getStringExtra(EXTRA_LAST_REPORTED_STATE);
|
2022-02-23 14:57:29 +00:00
|
|
|
if (!Intent.ACTION_VIEW.equals(action)
|
|
|
|
|| state == null
|
|
|
|
|| !END_CARD.contains(RtpEndUserState.valueOf(state))) {
|
|
|
|
resetIntent(
|
|
|
|
account, with, RtpEndUserState.RETRACTED, actionToMedia(intent.getAction()));
|
2020-04-30 07:06:43 +00:00
|
|
|
}
|
2022-02-23 14:57:29 +00:00
|
|
|
xmppConnectionService
|
|
|
|
.getJingleConnectionManager()
|
|
|
|
.retractSessionProposal(account, with.asBareJid());
|
2020-04-21 20:46:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 09:36:28 +00:00
|
|
|
private void rejectCall(View view) {
|
2020-04-07 11:15:24 +00:00
|
|
|
requireRtpConnection().rejectCall();
|
2020-04-10 11:13:20 +00:00
|
|
|
finish();
|
2020-04-07 09:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void acceptCall(View view) {
|
2020-04-09 17:45:21 +00:00
|
|
|
requestPermissionsAndAcceptCall();
|
|
|
|
}
|
|
|
|
|
2022-11-28 10:39:26 +00:00
|
|
|
private void acceptContentAdd() {
|
|
|
|
try {
|
|
|
|
requireRtpConnection()
|
|
|
|
.acceptContentAdd(requireRtpConnection().getPendingContentAddition().summary);
|
|
|
|
} catch (final IllegalStateException e) {
|
|
|
|
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void requestPermissionAndSwitchToVideo() {
|
|
|
|
final List<String> permissions = permissions(ImmutableSet.of(Media.VIDEO, Media.AUDIO));
|
|
|
|
if (PermissionUtils.hasPermission(this, permissions, REQUEST_ADD_CONTENT)) {
|
|
|
|
switchToVideo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void switchToVideo() {
|
|
|
|
try {
|
|
|
|
requireRtpConnection().addMedia(Media.VIDEO);
|
|
|
|
} catch (final IllegalStateException e) {
|
|
|
|
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void acceptContentAdd(final ContentAddition contentAddition) {
|
|
|
|
if (contentAddition == null || contentAddition.direction != ContentAddition.Direction.INCOMING) {
|
|
|
|
Log.d(Config.LOGTAG,"ignore press on content-accept button");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
requestPermissionAndAcceptContentAdd(contentAddition);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void requestPermissionAndAcceptContentAdd(final ContentAddition contentAddition) {
|
|
|
|
final List<String> permissions = permissions(contentAddition.media());
|
|
|
|
if (PermissionUtils.hasPermission(this, permissions, REQUEST_ACCEPT_CONTENT)) {
|
|
|
|
requireRtpConnection().acceptContentAdd(contentAddition.summary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void rejectContentAdd(final View view) {
|
|
|
|
requireRtpConnection().rejectContentAdd();
|
|
|
|
}
|
|
|
|
|
2020-04-09 17:45:21 +00:00
|
|
|
private void requestPermissionsAndAcceptCall() {
|
2022-11-28 10:39:26 +00:00
|
|
|
final List<String> permissions = permissions(getMedia());
|
|
|
|
if (PermissionUtils.hasPermission(this, permissions, REQUEST_ACCEPT_CALL)) {
|
|
|
|
putScreenInCallMode();
|
|
|
|
checkRecorderAndAcceptCall();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<String> permissions(final Set<Media> media) {
|
2022-08-08 19:08:28 +00:00
|
|
|
final ImmutableList.Builder<String> permissions = ImmutableList.builder();
|
2022-11-28 10:39:26 +00:00
|
|
|
if (media.contains(Media.VIDEO)) {
|
2022-08-08 19:08:28 +00:00
|
|
|
permissions.add(Manifest.permission.CAMERA).add(Manifest.permission.RECORD_AUDIO);
|
2020-04-15 16:47:15 +00:00
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
permissions.add(Manifest.permission.RECORD_AUDIO);
|
2020-04-15 16:47:15 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
|
|
permissions.add(Manifest.permission.BLUETOOTH_CONNECT);
|
|
|
|
}
|
2022-11-28 10:39:26 +00:00
|
|
|
return permissions.build();
|
2020-04-18 15:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void checkRecorderAndAcceptCall() {
|
2022-02-23 14:57:29 +00:00
|
|
|
checkMicrophoneAvailabilityAsync();
|
2020-05-05 07:37:24 +00:00
|
|
|
try {
|
|
|
|
requireRtpConnection().acceptCall();
|
|
|
|
} catch (final IllegalStateException e) {
|
|
|
|
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2020-04-19 06:49:08 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private void checkMicrophoneAvailabilityAsync() {
|
2022-09-09 17:06:37 +00:00
|
|
|
new Thread(new MicrophoneAvailabilityCheck(this)).start();
|
2022-02-23 14:57:29 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 17:06:37 +00:00
|
|
|
private static class MicrophoneAvailabilityCheck implements Runnable {
|
|
|
|
|
|
|
|
private final WeakReference<Activity> activityReference;
|
|
|
|
|
|
|
|
private MicrophoneAvailabilityCheck(final Activity activity) {
|
|
|
|
this.activityReference = new WeakReference<>(activity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
final long start = SystemClock.elapsedRealtime();
|
|
|
|
final boolean isMicrophoneAvailable = AppRTCAudioManager.isMicrophoneAvailable();
|
|
|
|
final long stop = SystemClock.elapsedRealtime();
|
|
|
|
Log.d(Config.LOGTAG, "checking microphone availability took " + (stop - start) + "ms");
|
|
|
|
if (isMicrophoneAvailable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Activity activity = activityReference.get();
|
|
|
|
if (activity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
activity.runOnUiThread(
|
|
|
|
() ->
|
|
|
|
Toast.makeText(
|
|
|
|
activity,
|
|
|
|
R.string.microphone_unavailable,
|
|
|
|
Toast.LENGTH_LONG)
|
|
|
|
.show());
|
2020-04-09 17:45:21 +00:00
|
|
|
}
|
2020-04-07 09:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 09:16:54 +00:00
|
|
|
private void putScreenInCallMode() {
|
2020-04-15 20:40:37 +00:00
|
|
|
putScreenInCallMode(requireRtpConnection().getMedia());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void putScreenInCallMode(final Set<Media> media) {
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
if (!media.contains(Media.VIDEO)) {
|
2022-02-23 14:57:29 +00:00
|
|
|
final JingleRtpConnection rtpConnection =
|
|
|
|
rtpConnectionReference != null ? rtpConnectionReference.get() : null;
|
|
|
|
final AppRTCAudioManager audioManager =
|
|
|
|
rtpConnection == null ? null : rtpConnection.getAudioManager();
|
|
|
|
if (audioManager == null
|
|
|
|
|| audioManager.getSelectedAudioDevice()
|
|
|
|
== AppRTCAudioManager.AudioDevice.EARPIECE) {
|
2020-04-15 20:40:37 +00:00
|
|
|
acquireProximityWakeLock();
|
|
|
|
}
|
2020-04-13 12:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-15 20:40:37 +00:00
|
|
|
@SuppressLint("WakelockTimeout")
|
2020-04-13 12:24:32 +00:00
|
|
|
private void acquireProximityWakeLock() {
|
2020-04-10 09:16:54 +00:00
|
|
|
final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
|
if (powerManager == null) {
|
|
|
|
Log.e(Config.LOGTAG, "power manager not available");
|
|
|
|
return;
|
|
|
|
}
|
2022-02-23 14:57:29 +00:00
|
|
|
if (isFinishing()) {
|
|
|
|
Log.e(Config.LOGTAG, "do not acquire wakelock. activity is finishing");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.mProximityWakeLock == null) {
|
|
|
|
this.mProximityWakeLock =
|
|
|
|
powerManager.newWakeLock(
|
|
|
|
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, PROXIMITY_WAKE_LOCK_TAG);
|
|
|
|
}
|
|
|
|
if (!this.mProximityWakeLock.isHeld()) {
|
|
|
|
Log.d(Config.LOGTAG, "acquiring proximity wake lock");
|
|
|
|
this.mProximityWakeLock.acquire();
|
2020-04-10 09:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 12:24:32 +00:00
|
|
|
private void releaseProximityWakeLock() {
|
2020-04-10 09:16:54 +00:00
|
|
|
if (this.mProximityWakeLock != null && mProximityWakeLock.isHeld()) {
|
2020-04-13 12:55:07 +00:00
|
|
|
Log.d(Config.LOGTAG, "releasing proximity wake lock");
|
2022-02-23 14:57:29 +00:00
|
|
|
this.mProximityWakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
|
2020-04-10 09:16:54 +00:00
|
|
|
this.mProximityWakeLock = null;
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 13:37:22 +00:00
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private void putProximityWakeLockInProperState(
|
|
|
|
final AppRTCAudioManager.AudioDevice audioDevice) {
|
2020-06-14 14:22:53 +00:00
|
|
|
if (audioDevice == AppRTCAudioManager.AudioDevice.EARPIECE) {
|
2020-04-13 12:55:07 +00:00
|
|
|
acquireProximityWakeLock();
|
|
|
|
} else {
|
|
|
|
releaseProximityWakeLock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 09:36:28 +00:00
|
|
|
@Override
|
2022-02-23 14:57:29 +00:00
|
|
|
protected void refreshUiReal() {}
|
2020-04-07 09:36:28 +00:00
|
|
|
|
2020-04-07 19:26:51 +00:00
|
|
|
@Override
|
|
|
|
public void onNewIntent(final Intent intent) {
|
2020-04-19 08:12:33 +00:00
|
|
|
Log.d(Config.LOGTAG, this.getClass().getName() + ".onNewIntent()");
|
2020-04-07 19:26:51 +00:00
|
|
|
super.onNewIntent(intent);
|
2020-04-11 18:51:37 +00:00
|
|
|
setIntent(intent);
|
|
|
|
if (xmppConnectionService == null) {
|
2022-02-23 14:57:29 +00:00
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"RtpSessionActivity: background service wasn't bound in onNewIntent()");
|
2020-04-11 18:51:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-10 07:31:39 +00:00
|
|
|
final Account account = extractAccount(intent);
|
2020-07-10 14:10:40 +00:00
|
|
|
final String action = intent.getAction();
|
2020-05-17 08:24:46 +00:00
|
|
|
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
2020-04-10 07:31:39 +00:00
|
|
|
final String sessionId = intent.getStringExtra(EXTRA_SESSION_ID);
|
|
|
|
if (sessionId != null) {
|
|
|
|
Log.d(Config.LOGTAG, "reinitializing from onNewIntent()");
|
2020-04-23 10:52:02 +00:00
|
|
|
if (initializeActivityWithRunningRtpSession(account, with, sessionId)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-10 07:31:39 +00:00
|
|
|
if (ACTION_ACCEPT_CALL.equals(intent.getAction())) {
|
|
|
|
Log.d(Config.LOGTAG, "accepting call from onNewIntent()");
|
|
|
|
requestPermissionsAndAcceptCall();
|
2020-04-10 11:13:20 +00:00
|
|
|
resetIntent(intent.getExtras());
|
2020-04-10 07:31:39 +00:00
|
|
|
}
|
2020-07-10 14:10:40 +00:00
|
|
|
} else if (asList(ACTION_MAKE_VIDEO_CALL, ACTION_MAKE_VOICE_CALL).contains(action)) {
|
|
|
|
proposeJingleRtpSession(account, with, actionToMedia(action));
|
2022-03-10 17:40:30 +00:00
|
|
|
setWith(account.getRoster().getContact(with), null);
|
2020-04-10 07:31:39 +00:00
|
|
|
} else {
|
|
|
|
throw new IllegalStateException("received onNewIntent without sessionId");
|
2020-04-07 19:26:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 09:36:28 +00:00
|
|
|
@Override
|
|
|
|
void onBackendConnected() {
|
2020-04-07 11:15:24 +00:00
|
|
|
final Intent intent = getIntent();
|
2020-04-15 14:26:53 +00:00
|
|
|
final String action = intent.getAction();
|
2020-04-07 11:15:24 +00:00
|
|
|
final Account account = extractAccount(intent);
|
2020-05-17 08:24:46 +00:00
|
|
|
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
2020-04-07 11:15:24 +00:00
|
|
|
final String sessionId = intent.getStringExtra(EXTRA_SESSION_ID);
|
2020-04-08 07:42:06 +00:00
|
|
|
if (sessionId != null) {
|
2020-04-23 10:52:02 +00:00
|
|
|
if (initializeActivityWithRunningRtpSession(account, with, sessionId)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-08 07:42:06 +00:00
|
|
|
if (ACTION_ACCEPT_CALL.equals(intent.getAction())) {
|
|
|
|
Log.d(Config.LOGTAG, "intent action was accept");
|
2020-04-09 17:45:21 +00:00
|
|
|
requestPermissionsAndAcceptCall();
|
2020-04-10 11:13:20 +00:00
|
|
|
resetIntent(intent.getExtras());
|
2020-04-07 16:50:39 +00:00
|
|
|
}
|
2020-04-15 14:26:53 +00:00
|
|
|
} else if (asList(ACTION_MAKE_VIDEO_CALL, ACTION_MAKE_VOICE_CALL).contains(action)) {
|
2020-04-15 19:08:49 +00:00
|
|
|
proposeJingleRtpSession(account, with, actionToMedia(action));
|
2022-03-10 17:40:30 +00:00
|
|
|
setWith(account.getRoster().getContact(with), null);
|
2020-04-15 14:26:53 +00:00
|
|
|
} else if (Intent.ACTION_VIEW.equals(action)) {
|
2020-04-09 15:37:21 +00:00
|
|
|
final String extraLastState = intent.getStringExtra(EXTRA_LAST_REPORTED_STATE);
|
2022-02-23 14:57:29 +00:00
|
|
|
final RtpEndUserState state =
|
|
|
|
extraLastState == null ? null : RtpEndUserState.valueOf(extraLastState);
|
2020-08-01 07:50:51 +00:00
|
|
|
if (state != null) {
|
2020-04-09 15:37:21 +00:00
|
|
|
Log.d(Config.LOGTAG, "restored last state from intent extra");
|
|
|
|
updateButtonConfiguration(state);
|
2021-03-03 08:41:05 +00:00
|
|
|
updateVerifiedShield(false);
|
2020-04-09 15:37:21 +00:00
|
|
|
updateStateDisplay(state);
|
2022-03-07 12:10:57 +00:00
|
|
|
updateIncomingCallScreen(state);
|
2020-06-12 06:26:33 +00:00
|
|
|
invalidateOptionsMenu();
|
2020-04-09 15:37:21 +00:00
|
|
|
}
|
2022-03-10 17:40:30 +00:00
|
|
|
setWith(account.getRoster().getContact(with), state);
|
2022-02-23 14:57:29 +00:00
|
|
|
if (xmppConnectionService
|
|
|
|
.getJingleConnectionManager()
|
|
|
|
.fireJingleRtpConnectionStateUpdates()) {
|
2020-08-01 07:50:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-02-23 14:57:29 +00:00
|
|
|
if (END_CARD.contains(state)
|
|
|
|
|| xmppConnectionService
|
|
|
|
.getJingleConnectionManager()
|
|
|
|
.hasMatchingProposal(account, with)) {
|
2020-08-01 07:50:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Log.d(Config.LOGTAG, "restored state (" + state + ") was not an end card. finishing");
|
|
|
|
finish();
|
2020-04-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-10 17:40:30 +00:00
|
|
|
private void setWidth(final RtpEndUserState state) {
|
|
|
|
setWith(getWith(), state);
|
2022-03-07 11:43:55 +00:00
|
|
|
}
|
|
|
|
|
2022-03-10 17:40:30 +00:00
|
|
|
private void setWith(final Contact contact, final RtpEndUserState state) {
|
2022-03-07 11:43:55 +00:00
|
|
|
binding.with.setText(contact.getDisplayName());
|
2022-03-10 17:40:30 +00:00
|
|
|
if (Arrays.asList(RtpEndUserState.INCOMING_CALL, RtpEndUserState.ACCEPTING_CALL)
|
|
|
|
.contains(state)) {
|
|
|
|
binding.withJid.setText(contact.getJid().asBareJid().toEscapedString());
|
|
|
|
binding.withJid.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
binding.withJid.setVisibility(View.GONE);
|
|
|
|
}
|
2022-03-07 11:43:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private void proposeJingleRtpSession(
|
|
|
|
final Account account, final Jid with, final Set<Media> media) {
|
|
|
|
checkMicrophoneAvailabilityAsync();
|
2020-05-30 12:56:12 +00:00
|
|
|
if (with.isBareJid()) {
|
2022-02-23 14:57:29 +00:00
|
|
|
xmppConnectionService
|
|
|
|
.getJingleConnectionManager()
|
|
|
|
.proposeJingleRtpSession(account, with, media);
|
2020-05-30 12:56:12 +00:00
|
|
|
} else {
|
2022-02-23 14:57:29 +00:00
|
|
|
final String sessionId =
|
|
|
|
xmppConnectionService
|
|
|
|
.getJingleConnectionManager()
|
|
|
|
.initializeRtpSession(account, with, media);
|
2020-05-30 12:56:12 +00:00
|
|
|
initializeActivityWithRunningRtpSession(account, with, sessionId);
|
|
|
|
resetIntent(account, with, sessionId);
|
|
|
|
}
|
2020-04-15 20:40:37 +00:00
|
|
|
putScreenInCallMode(media);
|
2020-04-10 09:16:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:45:21 +00:00
|
|
|
@Override
|
2022-02-23 14:57:29 +00:00
|
|
|
public void onRequestPermissionsResult(
|
|
|
|
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
2020-04-09 17:45:21 +00:00
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
2022-08-08 19:08:28 +00:00
|
|
|
final PermissionUtils.PermissionResult permissionResult =
|
|
|
|
PermissionUtils.removeBluetoothConnect(permissions, grantResults);
|
|
|
|
if (PermissionUtils.allGranted(permissionResult.grantResults)) {
|
2020-04-09 17:45:21 +00:00
|
|
|
if (requestCode == REQUEST_ACCEPT_CALL) {
|
2020-04-18 15:51:21 +00:00
|
|
|
checkRecorderAndAcceptCall();
|
2022-11-28 10:39:26 +00:00
|
|
|
} else if (requestCode == REQUEST_ACCEPT_CONTENT) {
|
|
|
|
acceptContentAdd();
|
|
|
|
} else if (requestCode == REQUEST_ADD_CONTENT) {
|
|
|
|
switchToVideo();
|
2020-04-09 17:45:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
@StringRes int res;
|
2022-08-08 19:08:28 +00:00
|
|
|
final String firstDenied =
|
|
|
|
getFirstDenied(permissionResult.grantResults, permissionResult.permissions);
|
2022-10-01 07:26:07 +00:00
|
|
|
if (firstDenied == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-09 17:45:21 +00:00
|
|
|
if (Manifest.permission.RECORD_AUDIO.equals(firstDenied)) {
|
|
|
|
res = R.string.no_microphone_permission;
|
|
|
|
} else if (Manifest.permission.CAMERA.equals(firstDenied)) {
|
|
|
|
res = R.string.no_camera_permission;
|
|
|
|
} else {
|
|
|
|
throw new IllegalStateException("Invalid permission result request");
|
|
|
|
}
|
2022-02-23 14:57:29 +00:00
|
|
|
Toast.makeText(this, getString(res, getString(R.string.app_name)), Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
2020-04-09 17:45:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-09 09:14:39 +00:00
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
mHandler.postDelayed(mTickExecutor, CALL_DURATION_UPDATE_INTERVAL);
|
2021-08-24 12:40:12 +00:00
|
|
|
this.binding.remoteVideo.setOnAspectRatioChanged(this);
|
2020-05-09 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 11:13:20 +00:00
|
|
|
@Override
|
|
|
|
public void onStop() {
|
2020-05-09 09:14:39 +00:00
|
|
|
mHandler.removeCallbacks(mTickExecutor);
|
2020-04-14 19:06:26 +00:00
|
|
|
binding.remoteVideo.release();
|
2021-08-24 12:40:12 +00:00
|
|
|
binding.remoteVideo.setOnAspectRatioChanged(null);
|
2020-04-14 19:06:26 +00:00
|
|
|
binding.localVideo.release();
|
2020-04-17 12:33:56 +00:00
|
|
|
final WeakReference<JingleRtpConnection> weakReference = this.rtpConnectionReference;
|
2022-02-23 14:57:29 +00:00
|
|
|
final JingleRtpConnection jingleRtpConnection =
|
|
|
|
weakReference == null ? null : weakReference.get();
|
2020-04-17 12:33:56 +00:00
|
|
|
if (jingleRtpConnection != null) {
|
|
|
|
releaseVideoTracks(jingleRtpConnection);
|
|
|
|
}
|
2020-04-13 12:24:32 +00:00
|
|
|
releaseProximityWakeLock();
|
2020-04-10 11:13:20 +00:00
|
|
|
super.onStop();
|
|
|
|
}
|
|
|
|
|
2020-04-17 12:33:56 +00:00
|
|
|
private void releaseVideoTracks(final JingleRtpConnection jingleRtpConnection) {
|
|
|
|
final Optional<VideoTrack> remoteVideo = jingleRtpConnection.getRemoteVideoTrack();
|
|
|
|
if (remoteVideo.isPresent()) {
|
|
|
|
remoteVideo.get().removeSink(binding.remoteVideo);
|
|
|
|
}
|
2020-04-29 06:51:38 +00:00
|
|
|
final Optional<VideoTrack> localVideo = jingleRtpConnection.getLocalVideoTrack();
|
2020-04-17 12:33:56 +00:00
|
|
|
if (localVideo.isPresent()) {
|
|
|
|
localVideo.get().removeSink(binding.localVideo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 08:35:00 +00:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2021-01-23 17:42:34 +00:00
|
|
|
if (isConnected()) {
|
|
|
|
if (switchToPictureInPicture()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
endCall();
|
|
|
|
}
|
2020-04-10 08:35:00 +00:00
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:38:05 +00:00
|
|
|
@Override
|
|
|
|
public void onUserLeaveHint() {
|
2020-06-22 13:37:22 +00:00
|
|
|
super.onUserLeaveHint();
|
2021-01-23 17:42:34 +00:00
|
|
|
if (switchToPictureInPicture()) {
|
|
|
|
return;
|
2020-04-16 15:38:05 +00:00
|
|
|
}
|
2022-02-23 14:57:29 +00:00
|
|
|
// TODO apparently this method is not getting called on Android 10 when using the task
|
|
|
|
// switcher
|
2021-03-06 08:45:42 +00:00
|
|
|
if (emptyReference(rtpConnectionReference) && xmppConnectionService != null) {
|
2020-07-10 14:10:40 +00:00
|
|
|
retractSessionProposal();
|
|
|
|
}
|
2020-04-23 10:14:45 +00:00
|
|
|
}
|
2020-04-16 15:38:05 +00:00
|
|
|
|
2021-01-23 17:42:34 +00:00
|
|
|
private boolean isConnected() {
|
2022-02-23 14:57:29 +00:00
|
|
|
final JingleRtpConnection connection =
|
|
|
|
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
2022-11-28 10:39:26 +00:00
|
|
|
final RtpEndUserState endUserState = connection == null ? null : connection.getEndUserState();
|
|
|
|
return STATES_CONSIDERED_CONNECTED.contains(endUserState) || endUserState == RtpEndUserState.INCOMING_CONTENT_ADD;
|
2021-01-23 17:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean switchToPictureInPicture() {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && deviceSupportsPictureInPicture()) {
|
|
|
|
if (shouldBePictureInPicture()) {
|
|
|
|
startPictureInPicture();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-24 08:37:46 +00:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
|
private void startPictureInPicture() {
|
|
|
|
try {
|
2021-08-24 12:40:12 +00:00
|
|
|
final Rational rational = this.binding.remoteVideo.getAspectRatio();
|
|
|
|
final Rational clippedRational = Rationals.clip(rational);
|
2022-02-23 14:57:29 +00:00
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"suggested rational " + rational + ". clipped to " + clippedRational);
|
2020-04-24 08:37:46 +00:00
|
|
|
enterPictureInPictureMode(
|
2022-02-23 14:57:29 +00:00
|
|
|
new PictureInPictureParams.Builder().setAspectRatio(clippedRational).build());
|
2020-06-22 13:37:22 +00:00
|
|
|
} catch (final IllegalStateException e) {
|
2022-02-23 14:57:29 +00:00
|
|
|
// this sometimes happens on Samsung phones (possibly when Knox is enabled)
|
2020-04-24 08:37:46 +00:00
|
|
|
Log.w(Config.LOGTAG, "unable to enter picture in picture mode", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 12:40:12 +00:00
|
|
|
@Override
|
|
|
|
public void onAspectRatioChanged(final Rational rational) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isPictureInPicture()) {
|
|
|
|
final Rational clippedRational = Rationals.clip(rational);
|
2022-02-23 14:57:29 +00:00
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"suggested rational after aspect ratio change "
|
|
|
|
+ rational
|
|
|
|
+ ". clipped to "
|
|
|
|
+ clippedRational);
|
|
|
|
setPictureInPictureParams(
|
|
|
|
new PictureInPictureParams.Builder().setAspectRatio(clippedRational).build());
|
2021-08-24 12:40:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 10:14:45 +00:00
|
|
|
private boolean deviceSupportsPictureInPicture() {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-16 15:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean shouldBePictureInPicture() {
|
|
|
|
try {
|
|
|
|
final JingleRtpConnection rtpConnection = requireRtpConnection();
|
2022-02-23 14:57:29 +00:00
|
|
|
return rtpConnection.getMedia().contains(Media.VIDEO)
|
|
|
|
&& Arrays.asList(
|
|
|
|
RtpEndUserState.ACCEPTING_CALL,
|
|
|
|
RtpEndUserState.CONNECTING,
|
|
|
|
RtpEndUserState.CONNECTED)
|
|
|
|
.contains(rtpConnection.getEndUserState());
|
2020-06-22 13:37:22 +00:00
|
|
|
} catch (final IllegalStateException e) {
|
2020-04-16 15:38:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-04-08 07:42:06 +00:00
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private boolean initializeActivityWithRunningRtpSession(
|
|
|
|
final Account account, Jid with, String sessionId) {
|
|
|
|
final WeakReference<JingleRtpConnection> reference =
|
|
|
|
xmppConnectionService
|
|
|
|
.getJingleConnectionManager()
|
|
|
|
.findJingleRtpConnection(account, with, sessionId);
|
2020-04-08 07:42:06 +00:00
|
|
|
if (reference == null || reference.get() == null) {
|
2022-02-23 14:57:29 +00:00
|
|
|
final JingleConnectionManager.TerminatedRtpSession terminatedRtpSession =
|
|
|
|
xmppConnectionService
|
|
|
|
.getJingleConnectionManager()
|
|
|
|
.getTerminalSessionState(with, sessionId);
|
2020-06-11 19:17:13 +00:00
|
|
|
if (terminatedRtpSession == null) {
|
2022-02-23 14:57:29 +00:00
|
|
|
throw new IllegalStateException(
|
|
|
|
"failed to initialize activity with running rtp session. session not found");
|
2020-06-11 19:17:13 +00:00
|
|
|
}
|
|
|
|
initializeWithTerminatedSessionState(account, with, terminatedRtpSession);
|
|
|
|
return true;
|
2020-04-08 07:42:06 +00:00
|
|
|
}
|
|
|
|
this.rtpConnectionReference = reference;
|
|
|
|
final RtpEndUserState currentState = requireRtpConnection().getEndUserState();
|
2021-03-03 08:41:05 +00:00
|
|
|
final boolean verified = requireRtpConnection().isVerified();
|
2020-04-08 07:42:06 +00:00
|
|
|
if (currentState == RtpEndUserState.ENDED) {
|
2020-04-10 11:13:20 +00:00
|
|
|
finish();
|
2020-04-23 10:52:02 +00:00
|
|
|
return true;
|
2020-04-08 07:42:06 +00:00
|
|
|
}
|
2020-04-29 06:51:38 +00:00
|
|
|
final Set<Media> media = getMedia();
|
2022-11-28 10:39:26 +00:00
|
|
|
final ContentAddition contentAddition = getPendingContentAddition();
|
2020-04-11 18:51:37 +00:00
|
|
|
if (currentState == RtpEndUserState.INCOMING_CALL) {
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
}
|
2022-02-23 14:57:29 +00:00
|
|
|
if (JingleRtpConnection.STATES_SHOWING_ONGOING_CALL.contains(
|
|
|
|
requireRtpConnection().getState())) {
|
2020-04-10 13:19:56 +00:00
|
|
|
putScreenInCallMode();
|
|
|
|
}
|
2022-03-10 17:40:30 +00:00
|
|
|
setWidth(currentState);
|
2020-04-15 22:08:58 +00:00
|
|
|
updateVideoViews(currentState);
|
2022-11-28 10:39:26 +00:00
|
|
|
updateStateDisplay(currentState, media, contentAddition);
|
2021-03-03 08:41:05 +00:00
|
|
|
updateVerifiedShield(verified && STATES_SHOWING_SWITCH_TO_CHAT.contains(currentState));
|
2022-11-28 10:39:26 +00:00
|
|
|
updateButtonConfiguration(currentState, media, contentAddition);
|
2022-03-07 12:10:57 +00:00
|
|
|
updateIncomingCallScreen(currentState);
|
2020-06-12 06:26:33 +00:00
|
|
|
invalidateOptionsMenu();
|
2020-04-23 10:52:02 +00:00
|
|
|
return false;
|
2020-04-08 07:42:06 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private void initializeWithTerminatedSessionState(
|
|
|
|
final Account account,
|
|
|
|
final Jid with,
|
|
|
|
final JingleConnectionManager.TerminatedRtpSession terminatedRtpSession) {
|
2020-06-12 06:26:33 +00:00
|
|
|
Log.d(Config.LOGTAG, "initializeWithTerminatedSessionState()");
|
2020-06-11 19:17:13 +00:00
|
|
|
if (terminatedRtpSession.state == RtpEndUserState.ENDED) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2022-03-10 17:40:30 +00:00
|
|
|
final RtpEndUserState state = terminatedRtpSession.state;
|
2020-06-11 19:17:13 +00:00
|
|
|
resetIntent(account, with, terminatedRtpSession.state, terminatedRtpSession.media);
|
|
|
|
updateButtonConfiguration(state);
|
|
|
|
updateStateDisplay(state);
|
2022-03-07 12:10:57 +00:00
|
|
|
updateIncomingCallScreen(state);
|
2020-06-12 06:26:33 +00:00
|
|
|
updateCallDuration();
|
2021-03-03 08:41:05 +00:00
|
|
|
updateVerifiedShield(false);
|
2020-06-12 06:26:33 +00:00
|
|
|
invalidateOptionsMenu();
|
2022-03-10 17:40:30 +00:00
|
|
|
setWith(account.getRoster().getContact(with), state);
|
2020-06-11 19:17:13 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private void reInitializeActivityWithRunningRtpSession(
|
|
|
|
final Account account, Jid with, String sessionId) {
|
2020-04-29 06:51:38 +00:00
|
|
|
runOnUiThread(() -> initializeActivityWithRunningRtpSession(account, with, sessionId));
|
2020-05-30 12:56:12 +00:00
|
|
|
resetIntent(account, with, sessionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resetIntent(final Account account, final Jid with, final String sessionId) {
|
2020-04-08 07:42:06 +00:00
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString());
|
|
|
|
intent.putExtra(EXTRA_WITH, with.toEscapedString());
|
|
|
|
intent.putExtra(EXTRA_SESSION_ID, sessionId);
|
|
|
|
setIntent(intent);
|
|
|
|
}
|
|
|
|
|
2020-04-15 11:21:21 +00:00
|
|
|
private void ensureSurfaceViewRendererIsSetup(final SurfaceViewRenderer surfaceViewRenderer) {
|
|
|
|
surfaceViewRenderer.setVisibility(View.VISIBLE);
|
|
|
|
try {
|
|
|
|
surfaceViewRenderer.init(requireRtpConnection().getEglBaseContext(), null);
|
2021-11-16 21:01:48 +00:00
|
|
|
} catch (final IllegalStateException e) {
|
2022-02-23 14:57:29 +00:00
|
|
|
// Log.d(Config.LOGTAG, "SurfaceViewRenderer was already initialized");
|
2020-04-14 17:06:39 +00:00
|
|
|
}
|
2020-04-15 11:21:21 +00:00
|
|
|
surfaceViewRenderer.setEnableHardwareScaler(true);
|
2020-04-14 17:06:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 12:22:12 +00:00
|
|
|
private void updateStateDisplay(final RtpEndUserState state) {
|
2022-11-28 10:39:26 +00:00
|
|
|
updateStateDisplay(state, Collections.emptySet(), null);
|
2020-04-29 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 10:39:26 +00:00
|
|
|
private void updateStateDisplay(final RtpEndUserState state, final Set<Media> media, final ContentAddition contentAddition) {
|
2020-04-07 11:15:24 +00:00
|
|
|
switch (state) {
|
|
|
|
case INCOMING_CALL:
|
2020-04-29 06:51:38 +00:00
|
|
|
Preconditions.checkArgument(media.size() > 0, "Media must not be empty");
|
|
|
|
if (media.contains(Media.VIDEO)) {
|
2020-04-15 16:28:04 +00:00
|
|
|
setTitle(R.string.rtp_state_incoming_video_call);
|
|
|
|
} else {
|
|
|
|
setTitle(R.string.rtp_state_incoming_call);
|
|
|
|
}
|
2020-04-07 11:15:24 +00:00
|
|
|
break;
|
2022-11-28 10:39:26 +00:00
|
|
|
case INCOMING_CONTENT_ADD:
|
|
|
|
if (contentAddition != null && contentAddition.media().contains(Media.VIDEO)) {
|
|
|
|
setTitle(R.string.rtp_state_content_add_video);
|
|
|
|
} else {
|
|
|
|
setTitle(R.string.rtp_state_content_add);
|
|
|
|
}
|
|
|
|
break;
|
2020-04-07 11:15:24 +00:00
|
|
|
case CONNECTING:
|
2020-04-14 17:35:26 +00:00
|
|
|
setTitle(R.string.rtp_state_connecting);
|
2020-04-07 11:15:24 +00:00
|
|
|
break;
|
|
|
|
case CONNECTED:
|
2020-04-14 17:35:26 +00:00
|
|
|
setTitle(R.string.rtp_state_connected);
|
2020-04-07 11:15:24 +00:00
|
|
|
break;
|
2021-11-11 13:40:15 +00:00
|
|
|
case RECONNECTING:
|
|
|
|
setTitle(R.string.rtp_state_reconnecting);
|
|
|
|
break;
|
2020-04-07 11:15:24 +00:00
|
|
|
case ACCEPTING_CALL:
|
2020-04-14 17:35:26 +00:00
|
|
|
setTitle(R.string.rtp_state_accepting_call);
|
2020-04-07 11:15:24 +00:00
|
|
|
break;
|
2020-04-07 12:22:12 +00:00
|
|
|
case ENDING_CALL:
|
2020-04-14 17:35:26 +00:00
|
|
|
setTitle(R.string.rtp_state_ending_call);
|
2020-04-07 12:22:12 +00:00
|
|
|
break;
|
2020-04-08 07:42:06 +00:00
|
|
|
case FINDING_DEVICE:
|
2020-04-14 17:35:26 +00:00
|
|
|
setTitle(R.string.rtp_state_finding_device);
|
2020-04-08 07:42:06 +00:00
|
|
|
break;
|
|
|
|
case RINGING:
|
2020-04-14 17:35:26 +00:00
|
|
|
setTitle(R.string.rtp_state_ringing);
|
2020-04-08 08:46:26 +00:00
|
|
|
break;
|
|
|
|
case DECLINED_OR_BUSY:
|
2020-04-14 17:35:26 +00:00
|
|
|
setTitle(R.string.rtp_state_declined_or_busy);
|
2020-04-08 13:27:17 +00:00
|
|
|
break;
|
2020-04-08 11:30:12 +00:00
|
|
|
case CONNECTIVITY_ERROR:
|
2020-04-14 17:35:26 +00:00
|
|
|
setTitle(R.string.rtp_state_connectivity_error);
|
2020-04-08 08:46:26 +00:00
|
|
|
break;
|
2020-06-12 05:56:59 +00:00
|
|
|
case CONNECTIVITY_LOST_ERROR:
|
|
|
|
setTitle(R.string.rtp_state_connectivity_lost_error);
|
|
|
|
break;
|
2020-04-21 20:46:46 +00:00
|
|
|
case RETRACTED:
|
|
|
|
setTitle(R.string.rtp_state_retracted);
|
|
|
|
break;
|
2020-04-09 13:22:03 +00:00
|
|
|
case APPLICATION_ERROR:
|
2020-04-14 17:35:26 +00:00
|
|
|
setTitle(R.string.rtp_state_application_failure);
|
2020-04-09 13:22:03 +00:00
|
|
|
break;
|
2021-05-04 08:10:30 +00:00
|
|
|
case SECURITY_ERROR:
|
|
|
|
setTitle(R.string.rtp_state_security_error);
|
|
|
|
break;
|
2020-04-09 15:37:21 +00:00
|
|
|
case ENDED:
|
2022-02-23 14:57:29 +00:00
|
|
|
throw new IllegalStateException(
|
|
|
|
"Activity should have called finishAndReleaseWakeLock();");
|
2020-04-09 15:37:21 +00:00
|
|
|
default:
|
2022-02-23 14:57:29 +00:00
|
|
|
throw new IllegalStateException(
|
|
|
|
String.format("State %s has not been handled in UI", state));
|
2020-04-07 12:22:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 08:41:05 +00:00
|
|
|
private void updateVerifiedShield(final boolean verified) {
|
|
|
|
if (isPictureInPicture()) {
|
|
|
|
this.binding.verified.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.binding.verified.setVisibility(verified ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:10:57 +00:00
|
|
|
private void updateIncomingCallScreen(final RtpEndUserState state) {
|
|
|
|
updateIncomingCallScreen(state, null);
|
2020-04-29 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 12:10:57 +00:00
|
|
|
private void updateIncomingCallScreen(final RtpEndUserState state, final Contact contact) {
|
2020-04-20 11:41:50 +00:00
|
|
|
if (state == RtpEndUserState.INCOMING_CALL || state == RtpEndUserState.ACCEPTING_CALL) {
|
|
|
|
final boolean show = getResources().getBoolean(R.bool.show_avatar_incoming_call);
|
|
|
|
if (show) {
|
|
|
|
binding.contactPhoto.setVisibility(View.VISIBLE);
|
2020-04-29 06:51:38 +00:00
|
|
|
if (contact == null) {
|
2022-02-23 14:57:29 +00:00
|
|
|
AvatarWorkerTask.loadAvatar(
|
|
|
|
getWith(), binding.contactPhoto, R.dimen.publish_avatar_size);
|
2020-04-29 06:51:38 +00:00
|
|
|
} else {
|
2022-02-23 14:57:29 +00:00
|
|
|
AvatarWorkerTask.loadAvatar(
|
|
|
|
contact, binding.contactPhoto, R.dimen.publish_avatar_size);
|
2020-04-29 06:51:38 +00:00
|
|
|
}
|
2020-04-20 11:41:50 +00:00
|
|
|
} else {
|
|
|
|
binding.contactPhoto.setVisibility(View.GONE);
|
|
|
|
}
|
2022-03-07 12:10:57 +00:00
|
|
|
final Account account = contact == null ? getWith().getAccount() : contact.getAccount();
|
|
|
|
binding.usingAccount.setVisibility(View.VISIBLE);
|
|
|
|
binding.usingAccount.setText(
|
|
|
|
getString(
|
|
|
|
R.string.using_account,
|
|
|
|
account.getJid().asBareJid().toEscapedString()));
|
2020-04-20 11:41:50 +00:00
|
|
|
} else {
|
2022-03-07 12:10:57 +00:00
|
|
|
binding.usingAccount.setVisibility(View.GONE);
|
2020-04-20 11:41:50 +00:00
|
|
|
binding.contactPhoto.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-15 16:28:04 +00:00
|
|
|
private Set<Media> getMedia() {
|
|
|
|
return requireRtpConnection().getMedia();
|
|
|
|
}
|
|
|
|
|
2022-11-28 10:39:26 +00:00
|
|
|
public ContentAddition getPendingContentAddition() {
|
|
|
|
return requireRtpConnection().getPendingContentAddition();
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:22:12 +00:00
|
|
|
private void updateButtonConfiguration(final RtpEndUserState state) {
|
2022-11-28 10:39:26 +00:00
|
|
|
updateButtonConfiguration(state, Collections.emptySet(), null);
|
2020-04-29 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("RestrictedApi")
|
2022-11-28 10:39:26 +00:00
|
|
|
private void updateButtonConfiguration(final RtpEndUserState state, final Set<Media> media, final ContentAddition contentAddition) {
|
2020-04-16 15:38:05 +00:00
|
|
|
if (state == RtpEndUserState.ENDING_CALL || isPictureInPicture()) {
|
|
|
|
this.binding.rejectCall.setVisibility(View.INVISIBLE);
|
|
|
|
this.binding.endCall.setVisibility(View.INVISIBLE);
|
|
|
|
this.binding.acceptCall.setVisibility(View.INVISIBLE);
|
|
|
|
} else if (state == RtpEndUserState.INCOMING_CALL) {
|
2020-08-31 15:30:54 +00:00
|
|
|
this.binding.rejectCall.setContentDescription(getString(R.string.dismiss_call));
|
2020-04-08 11:30:12 +00:00
|
|
|
this.binding.rejectCall.setOnClickListener(this::rejectCall);
|
|
|
|
this.binding.rejectCall.setImageResource(R.drawable.ic_call_end_white_48dp);
|
2020-04-10 07:31:39 +00:00
|
|
|
this.binding.rejectCall.setVisibility(View.VISIBLE);
|
|
|
|
this.binding.endCall.setVisibility(View.INVISIBLE);
|
2020-08-31 15:30:54 +00:00
|
|
|
this.binding.acceptCall.setContentDescription(getString(R.string.answer_call));
|
2020-04-08 11:30:12 +00:00
|
|
|
this.binding.acceptCall.setOnClickListener(this::acceptCall);
|
|
|
|
this.binding.acceptCall.setImageResource(R.drawable.ic_call_white_48dp);
|
2020-04-10 07:31:39 +00:00
|
|
|
this.binding.acceptCall.setVisibility(View.VISIBLE);
|
2022-11-28 10:39:26 +00:00
|
|
|
} else if (state == RtpEndUserState.INCOMING_CONTENT_ADD) {
|
|
|
|
this.binding.rejectCall.setContentDescription(getString(R.string.reject_switch_to_video));
|
|
|
|
this.binding.rejectCall.setOnClickListener(this::rejectContentAdd);
|
|
|
|
this.binding.rejectCall.setImageResource(R.drawable.ic_clear_white_48dp);
|
|
|
|
this.binding.rejectCall.setVisibility(View.VISIBLE);
|
|
|
|
this.binding.endCall.setVisibility(View.INVISIBLE);
|
|
|
|
this.binding.acceptCall.setContentDescription(getString(R.string.accept));
|
|
|
|
this.binding.acceptCall.setOnClickListener((v -> acceptContentAdd(contentAddition)));
|
|
|
|
this.binding.acceptCall.setImageResource(R.drawable.ic_baseline_check_24);
|
|
|
|
this.binding.acceptCall.setVisibility(View.VISIBLE);
|
2020-04-08 08:46:26 +00:00
|
|
|
} else if (state == RtpEndUserState.DECLINED_OR_BUSY) {
|
2020-08-31 15:30:54 +00:00
|
|
|
this.binding.rejectCall.setContentDescription(getString(R.string.exit));
|
2020-05-30 08:30:57 +00:00
|
|
|
this.binding.rejectCall.setOnClickListener(this::exit);
|
|
|
|
this.binding.rejectCall.setImageResource(R.drawable.ic_clear_white_48dp);
|
|
|
|
this.binding.rejectCall.setVisibility(View.VISIBLE);
|
|
|
|
this.binding.endCall.setVisibility(View.INVISIBLE);
|
2020-08-31 15:30:54 +00:00
|
|
|
this.binding.acceptCall.setContentDescription(getString(R.string.record_voice_mail));
|
2020-05-30 08:30:57 +00:00
|
|
|
this.binding.acceptCall.setOnClickListener(this::recordVoiceMail);
|
|
|
|
this.binding.acceptCall.setImageResource(R.drawable.ic_voicemail_white_24dp);
|
|
|
|
this.binding.acceptCall.setVisibility(View.VISIBLE);
|
2020-06-12 05:56:59 +00:00
|
|
|
} else if (asList(
|
2022-02-23 14:57:29 +00:00
|
|
|
RtpEndUserState.CONNECTIVITY_ERROR,
|
|
|
|
RtpEndUserState.CONNECTIVITY_LOST_ERROR,
|
|
|
|
RtpEndUserState.APPLICATION_ERROR,
|
|
|
|
RtpEndUserState.RETRACTED,
|
|
|
|
RtpEndUserState.SECURITY_ERROR)
|
|
|
|
.contains(state)) {
|
2020-08-31 15:30:54 +00:00
|
|
|
this.binding.rejectCall.setContentDescription(getString(R.string.exit));
|
2020-04-08 11:30:12 +00:00
|
|
|
this.binding.rejectCall.setOnClickListener(this::exit);
|
|
|
|
this.binding.rejectCall.setImageResource(R.drawable.ic_clear_white_48dp);
|
2020-04-10 07:31:39 +00:00
|
|
|
this.binding.rejectCall.setVisibility(View.VISIBLE);
|
|
|
|
this.binding.endCall.setVisibility(View.INVISIBLE);
|
2020-08-31 15:30:54 +00:00
|
|
|
this.binding.acceptCall.setContentDescription(getString(R.string.try_again));
|
2020-04-08 11:30:12 +00:00
|
|
|
this.binding.acceptCall.setOnClickListener(this::retry);
|
|
|
|
this.binding.acceptCall.setImageResource(R.drawable.ic_replay_white_48dp);
|
2020-04-10 07:31:39 +00:00
|
|
|
this.binding.acceptCall.setVisibility(View.VISIBLE);
|
2020-04-07 12:22:12 +00:00
|
|
|
} else {
|
2020-04-10 07:31:39 +00:00
|
|
|
this.binding.rejectCall.setVisibility(View.INVISIBLE);
|
2020-08-31 15:30:54 +00:00
|
|
|
this.binding.endCall.setContentDescription(getString(R.string.hang_up));
|
2020-04-08 11:30:12 +00:00
|
|
|
this.binding.endCall.setOnClickListener(this::endCall);
|
2020-04-08 08:46:26 +00:00
|
|
|
this.binding.endCall.setImageResource(R.drawable.ic_call_end_white_48dp);
|
2020-04-10 07:31:39 +00:00
|
|
|
this.binding.endCall.setVisibility(View.VISIBLE);
|
|
|
|
this.binding.acceptCall.setVisibility(View.INVISIBLE);
|
2020-04-07 11:15:24 +00:00
|
|
|
}
|
2020-04-29 06:51:38 +00:00
|
|
|
updateInCallButtonConfiguration(state, media);
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:38:05 +00:00
|
|
|
private boolean isPictureInPicture() {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
return isInPictureInPictureMode();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:53:23 +00:00
|
|
|
private void updateInCallButtonConfiguration() {
|
2022-02-23 14:57:29 +00:00
|
|
|
updateInCallButtonConfiguration(
|
|
|
|
requireRtpConnection().getEndUserState(), requireRtpConnection().getMedia());
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
2020-04-13 10:02:34 +00:00
|
|
|
|
2020-04-13 10:53:23 +00:00
|
|
|
@SuppressLint("RestrictedApi")
|
2022-02-23 14:57:29 +00:00
|
|
|
private void updateInCallButtonConfiguration(
|
|
|
|
final RtpEndUserState state, final Set<Media> media) {
|
2021-11-11 13:40:15 +00:00
|
|
|
if (STATES_CONSIDERED_CONNECTED.contains(state) && !isPictureInPicture()) {
|
2020-04-29 06:51:38 +00:00
|
|
|
Preconditions.checkArgument(media.size() > 0, "Media must not be empty");
|
|
|
|
if (media.contains(Media.VIDEO)) {
|
2020-05-02 15:15:46 +00:00
|
|
|
final JingleRtpConnection rtpConnection = requireRtpConnection();
|
2022-02-23 14:57:29 +00:00
|
|
|
updateInCallButtonConfigurationVideo(
|
|
|
|
rtpConnection.isVideoEnabled(), rtpConnection.isCameraSwitchable());
|
2020-04-15 17:16:47 +00:00
|
|
|
} else {
|
|
|
|
final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager();
|
|
|
|
updateInCallButtonConfigurationSpeaker(
|
|
|
|
audioManager.getSelectedAudioDevice(),
|
2022-02-23 14:57:29 +00:00
|
|
|
audioManager.getAudioDevices().size());
|
2020-05-02 15:15:46 +00:00
|
|
|
this.binding.inCallActionFarRight.setVisibility(View.GONE);
|
2020-04-15 17:16:47 +00:00
|
|
|
}
|
2020-05-08 19:15:54 +00:00
|
|
|
if (media.contains(Media.AUDIO)) {
|
2022-02-23 14:57:29 +00:00
|
|
|
updateInCallButtonConfigurationMicrophone(
|
|
|
|
requireRtpConnection().isMicrophoneEnabled());
|
2020-05-08 19:15:54 +00:00
|
|
|
} else {
|
|
|
|
this.binding.inCallActionLeft.setVisibility(View.GONE);
|
|
|
|
}
|
2020-04-13 10:02:34 +00:00
|
|
|
} else {
|
|
|
|
this.binding.inCallActionLeft.setVisibility(View.GONE);
|
|
|
|
this.binding.inCallActionRight.setVisibility(View.GONE);
|
2020-05-02 15:15:46 +00:00
|
|
|
this.binding.inCallActionFarRight.setVisibility(View.GONE);
|
2020-04-13 10:02:34 +00:00
|
|
|
}
|
2020-04-07 11:15:24 +00:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:53:23 +00:00
|
|
|
@SuppressLint("RestrictedApi")
|
2022-02-23 14:57:29 +00:00
|
|
|
private void updateInCallButtonConfigurationSpeaker(
|
|
|
|
final AppRTCAudioManager.AudioDevice selectedAudioDevice, final int numberOfChoices) {
|
2020-04-13 10:53:23 +00:00
|
|
|
switch (selectedAudioDevice) {
|
|
|
|
case EARPIECE:
|
2022-02-23 14:57:29 +00:00
|
|
|
this.binding.inCallActionRight.setImageResource(
|
|
|
|
R.drawable.ic_volume_off_black_24dp);
|
2020-04-13 10:53:23 +00:00
|
|
|
if (numberOfChoices >= 2) {
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionRight.setOnClickListener(this::switchToSpeaker);
|
2020-04-13 10:53:23 +00:00
|
|
|
} else {
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionRight.setOnClickListener(null);
|
|
|
|
this.binding.inCallActionRight.setClickable(false);
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIRED_HEADSET:
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionRight.setImageResource(R.drawable.ic_headset_black_24dp);
|
|
|
|
this.binding.inCallActionRight.setOnClickListener(null);
|
|
|
|
this.binding.inCallActionRight.setClickable(false);
|
2020-04-13 10:53:23 +00:00
|
|
|
break;
|
|
|
|
case SPEAKER_PHONE:
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionRight.setImageResource(R.drawable.ic_volume_up_black_24dp);
|
2020-04-13 10:53:23 +00:00
|
|
|
if (numberOfChoices >= 2) {
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionRight.setOnClickListener(this::switchToEarpiece);
|
2020-04-13 10:53:23 +00:00
|
|
|
} else {
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionRight.setOnClickListener(null);
|
|
|
|
this.binding.inCallActionRight.setClickable(false);
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BLUETOOTH:
|
2022-02-23 14:57:29 +00:00
|
|
|
this.binding.inCallActionRight.setImageResource(
|
|
|
|
R.drawable.ic_bluetooth_audio_black_24dp);
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionRight.setOnClickListener(null);
|
|
|
|
this.binding.inCallActionRight.setClickable(false);
|
2020-04-13 10:53:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionRight.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("RestrictedApi")
|
2022-02-23 14:57:29 +00:00
|
|
|
private void updateInCallButtonConfigurationVideo(
|
|
|
|
final boolean videoEnabled, final boolean isCameraSwitchable) {
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionRight.setVisibility(View.VISIBLE);
|
2020-05-02 15:15:46 +00:00
|
|
|
if (isCameraSwitchable) {
|
2022-02-23 14:57:29 +00:00
|
|
|
this.binding.inCallActionFarRight.setImageResource(
|
|
|
|
R.drawable.ic_flip_camera_android_black_24dp);
|
2020-05-02 15:15:46 +00:00
|
|
|
this.binding.inCallActionFarRight.setVisibility(View.VISIBLE);
|
|
|
|
this.binding.inCallActionFarRight.setOnClickListener(this::switchCamera);
|
|
|
|
} else {
|
|
|
|
this.binding.inCallActionFarRight.setVisibility(View.GONE);
|
|
|
|
}
|
2020-04-15 17:16:47 +00:00
|
|
|
if (videoEnabled) {
|
|
|
|
this.binding.inCallActionRight.setImageResource(R.drawable.ic_videocam_black_24dp);
|
|
|
|
this.binding.inCallActionRight.setOnClickListener(this::disableVideo);
|
|
|
|
} else {
|
|
|
|
this.binding.inCallActionRight.setImageResource(R.drawable.ic_videocam_off_black_24dp);
|
|
|
|
this.binding.inCallActionRight.setOnClickListener(this::enableVideo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 15:15:46 +00:00
|
|
|
private void switchCamera(final View view) {
|
2022-02-23 14:57:29 +00:00
|
|
|
Futures.addCallback(
|
|
|
|
requireRtpConnection().switchCamera(),
|
|
|
|
new FutureCallback<Boolean>() {
|
|
|
|
@Override
|
2022-08-22 09:29:04 +00:00
|
|
|
public void onSuccess(@Nullable Boolean isFrontCamera) {
|
2022-02-23 14:57:29 +00:00
|
|
|
binding.localVideo.setMirror(isFrontCamera);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull final Throwable throwable) {
|
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"could not switch camera",
|
|
|
|
Throwables.getRootCause(throwable));
|
|
|
|
Toast.makeText(
|
|
|
|
RtpSessionActivity.this,
|
|
|
|
R.string.could_not_switch_camera,
|
|
|
|
Toast.LENGTH_LONG)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
MainThreadExecutor.getInstance());
|
2020-05-02 15:15:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 17:16:47 +00:00
|
|
|
private void enableVideo(View view) {
|
2021-03-26 11:54:23 +00:00
|
|
|
try {
|
|
|
|
requireRtpConnection().setVideoEnabled(true);
|
|
|
|
} catch (final IllegalStateException e) {
|
|
|
|
Toast.makeText(this, R.string.unable_to_enable_video, Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
2020-05-02 15:15:46 +00:00
|
|
|
updateInCallButtonConfigurationVideo(true, requireRtpConnection().isCameraSwitchable());
|
2020-04-15 17:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void disableVideo(View view) {
|
2022-11-28 10:39:26 +00:00
|
|
|
final JingleRtpConnection rtpConnection = requireRtpConnection();
|
|
|
|
final ContentAddition pending = rtpConnection.getPendingContentAddition();
|
|
|
|
if (pending != null && pending.direction == ContentAddition.Direction.OUTGOING) {
|
|
|
|
rtpConnection.retractContentAdd();
|
|
|
|
return;
|
|
|
|
}
|
2020-04-15 17:16:47 +00:00
|
|
|
requireRtpConnection().setVideoEnabled(false);
|
2020-05-02 15:15:46 +00:00
|
|
|
updateInCallButtonConfigurationVideo(false, requireRtpConnection().isCameraSwitchable());
|
2020-04-15 17:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("RestrictedApi")
|
|
|
|
private void updateInCallButtonConfigurationMicrophone(final boolean microphoneEnabled) {
|
2020-04-13 10:53:23 +00:00
|
|
|
if (microphoneEnabled) {
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionLeft.setImageResource(R.drawable.ic_mic_black_24dp);
|
|
|
|
this.binding.inCallActionLeft.setOnClickListener(this::disableMicrophone);
|
2020-04-13 10:53:23 +00:00
|
|
|
} else {
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionLeft.setImageResource(R.drawable.ic_mic_off_black_24dp);
|
|
|
|
this.binding.inCallActionLeft.setOnClickListener(this::enableMicrophone);
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
2020-04-15 17:16:47 +00:00
|
|
|
this.binding.inCallActionLeft.setVisibility(View.VISIBLE);
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 09:14:39 +00:00
|
|
|
private void updateCallDuration() {
|
2022-02-23 14:57:29 +00:00
|
|
|
final JingleRtpConnection connection =
|
|
|
|
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
2020-05-09 09:14:39 +00:00
|
|
|
if (connection == null || connection.getMedia().contains(Media.VIDEO)) {
|
|
|
|
this.binding.duration.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
2021-11-11 15:52:18 +00:00
|
|
|
if (connection.zeroDuration()) {
|
2020-05-09 09:14:39 +00:00
|
|
|
this.binding.duration.setVisibility(View.GONE);
|
2021-11-11 15:52:18 +00:00
|
|
|
} else {
|
2022-02-23 14:57:29 +00:00
|
|
|
this.binding.duration.setText(
|
|
|
|
TimeFrameUtils.formatElapsedTime(connection.getCallDuration(), false));
|
2021-11-11 15:52:18 +00:00
|
|
|
this.binding.duration.setVisibility(View.VISIBLE);
|
2020-05-09 09:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-15 22:08:58 +00:00
|
|
|
private void updateVideoViews(final RtpEndUserState state) {
|
|
|
|
if (END_CARD.contains(state) || state == RtpEndUserState.ENDING_CALL) {
|
|
|
|
binding.localVideo.setVisibility(View.GONE);
|
2020-04-29 07:22:49 +00:00
|
|
|
binding.localVideo.release();
|
2021-05-09 06:56:07 +00:00
|
|
|
binding.remoteVideoWrapper.setVisibility(View.GONE);
|
2020-04-29 07:22:49 +00:00
|
|
|
binding.remoteVideo.release();
|
2020-04-17 13:06:13 +00:00
|
|
|
binding.pipLocalMicOffIndicator.setVisibility(View.GONE);
|
2020-04-16 15:38:05 +00:00
|
|
|
if (isPictureInPicture()) {
|
|
|
|
binding.appBarLayout.setVisibility(View.GONE);
|
|
|
|
binding.pipPlaceholder.setVisibility(View.VISIBLE);
|
2021-05-04 08:10:30 +00:00
|
|
|
if (Arrays.asList(
|
2022-02-23 14:57:29 +00:00
|
|
|
RtpEndUserState.APPLICATION_ERROR,
|
|
|
|
RtpEndUserState.CONNECTIVITY_ERROR,
|
|
|
|
RtpEndUserState.SECURITY_ERROR)
|
2021-05-04 08:10:30 +00:00
|
|
|
.contains(state)) {
|
2020-04-16 15:38:05 +00:00
|
|
|
binding.pipWarning.setVisibility(View.VISIBLE);
|
2020-04-17 09:44:20 +00:00
|
|
|
binding.pipWaiting.setVisibility(View.GONE);
|
2020-04-16 15:38:05 +00:00
|
|
|
} else {
|
|
|
|
binding.pipWarning.setVisibility(View.GONE);
|
2020-04-17 09:44:20 +00:00
|
|
|
binding.pipWaiting.setVisibility(View.GONE);
|
2020-04-16 15:38:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
binding.appBarLayout.setVisibility(View.VISIBLE);
|
|
|
|
binding.pipPlaceholder.setVisibility(View.GONE);
|
|
|
|
}
|
2020-04-15 22:08:58 +00:00
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
return;
|
|
|
|
}
|
2021-11-16 21:01:48 +00:00
|
|
|
if (isPictureInPicture() && STATES_SHOWING_PIP_PLACEHOLDER.contains(state)) {
|
2020-04-17 09:44:20 +00:00
|
|
|
binding.localVideo.setVisibility(View.GONE);
|
2021-05-09 06:56:07 +00:00
|
|
|
binding.remoteVideoWrapper.setVisibility(View.GONE);
|
2020-04-17 09:44:20 +00:00
|
|
|
binding.appBarLayout.setVisibility(View.GONE);
|
|
|
|
binding.pipPlaceholder.setVisibility(View.VISIBLE);
|
|
|
|
binding.pipWarning.setVisibility(View.GONE);
|
|
|
|
binding.pipWaiting.setVisibility(View.VISIBLE);
|
2020-04-17 13:06:13 +00:00
|
|
|
binding.pipLocalMicOffIndicator.setVisibility(View.GONE);
|
2020-04-17 09:44:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-29 06:51:38 +00:00
|
|
|
final Optional<VideoTrack> localVideoTrack = getLocalVideoTrack();
|
2020-04-16 15:38:05 +00:00
|
|
|
if (localVideoTrack.isPresent() && !isPictureInPicture()) {
|
2020-04-15 16:47:15 +00:00
|
|
|
ensureSurfaceViewRendererIsSetup(binding.localVideo);
|
2022-02-23 14:57:29 +00:00
|
|
|
// paint local view over remote view
|
2020-04-15 16:47:15 +00:00
|
|
|
binding.localVideo.setZOrderMediaOverlay(true);
|
2020-05-03 09:08:11 +00:00
|
|
|
binding.localVideo.setMirror(requireRtpConnection().isFrontCamera());
|
2020-05-27 13:53:05 +00:00
|
|
|
addSink(localVideoTrack.get(), binding.localVideo);
|
2020-04-15 16:47:15 +00:00
|
|
|
} else {
|
|
|
|
binding.localVideo.setVisibility(View.GONE);
|
|
|
|
}
|
2020-04-29 06:51:38 +00:00
|
|
|
final Optional<VideoTrack> remoteVideoTrack = getRemoteVideoTrack();
|
2020-04-15 16:47:15 +00:00
|
|
|
if (remoteVideoTrack.isPresent()) {
|
|
|
|
ensureSurfaceViewRendererIsSetup(binding.remoteVideo);
|
2020-05-27 13:53:05 +00:00
|
|
|
addSink(remoteVideoTrack.get(), binding.remoteVideo);
|
2021-05-09 06:56:07 +00:00
|
|
|
binding.remoteVideo.setScalingType(
|
|
|
|
RendererCommon.ScalingType.SCALE_ASPECT_FILL,
|
2022-02-23 14:57:29 +00:00
|
|
|
RendererCommon.ScalingType.SCALE_ASPECT_FIT);
|
2021-11-16 21:01:48 +00:00
|
|
|
if (state == RtpEndUserState.CONNECTED) {
|
2020-04-16 09:02:42 +00:00
|
|
|
binding.appBarLayout.setVisibility(View.GONE);
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
2021-05-09 06:56:07 +00:00
|
|
|
binding.remoteVideoWrapper.setVisibility(View.VISIBLE);
|
2020-04-16 09:02:42 +00:00
|
|
|
} else {
|
2021-11-16 21:01:48 +00:00
|
|
|
binding.appBarLayout.setVisibility(View.VISIBLE);
|
2020-04-16 09:02:42 +00:00
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
2021-05-09 06:56:07 +00:00
|
|
|
binding.remoteVideoWrapper.setVisibility(View.GONE);
|
2020-04-16 09:02:42 +00:00
|
|
|
}
|
2020-04-17 13:06:13 +00:00
|
|
|
if (isPictureInPicture() && !requireRtpConnection().isMicrophoneEnabled()) {
|
|
|
|
binding.pipLocalMicOffIndicator.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
binding.pipLocalMicOffIndicator.setVisibility(View.GONE);
|
|
|
|
}
|
2020-04-15 16:47:15 +00:00
|
|
|
} else {
|
2020-04-15 22:08:58 +00:00
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
2021-05-09 06:56:07 +00:00
|
|
|
binding.remoteVideoWrapper.setVisibility(View.GONE);
|
2020-04-17 13:06:13 +00:00
|
|
|
binding.pipLocalMicOffIndicator.setVisibility(View.GONE);
|
2020-04-15 16:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 06:51:38 +00:00
|
|
|
private Optional<VideoTrack> getLocalVideoTrack() {
|
2022-02-23 14:57:29 +00:00
|
|
|
final JingleRtpConnection connection =
|
|
|
|
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
2020-04-29 06:51:38 +00:00
|
|
|
if (connection == null) {
|
|
|
|
return Optional.absent();
|
|
|
|
}
|
|
|
|
return connection.getLocalVideoTrack();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Optional<VideoTrack> getRemoteVideoTrack() {
|
2022-02-23 14:57:29 +00:00
|
|
|
final JingleRtpConnection connection =
|
|
|
|
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
2020-04-29 06:51:38 +00:00
|
|
|
if (connection == null) {
|
|
|
|
return Optional.absent();
|
|
|
|
}
|
|
|
|
return connection.getRemoteVideoTrack();
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:53:23 +00:00
|
|
|
private void disableMicrophone(View view) {
|
2020-07-09 17:14:28 +00:00
|
|
|
final JingleRtpConnection rtpConnection = requireRtpConnection();
|
|
|
|
if (rtpConnection.setMicrophoneEnabled(false)) {
|
|
|
|
updateInCallButtonConfiguration();
|
|
|
|
}
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void enableMicrophone(View view) {
|
2020-07-09 17:14:28 +00:00
|
|
|
final JingleRtpConnection rtpConnection = requireRtpConnection();
|
|
|
|
if (rtpConnection.setMicrophoneEnabled(true)) {
|
|
|
|
updateInCallButtonConfiguration();
|
|
|
|
}
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void switchToEarpiece(View view) {
|
2022-02-23 14:57:29 +00:00
|
|
|
requireRtpConnection()
|
|
|
|
.getAudioManager()
|
|
|
|
.setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.EARPIECE);
|
2020-04-13 12:24:32 +00:00
|
|
|
acquireProximityWakeLock();
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void switchToSpeaker(View view) {
|
2022-02-23 14:57:29 +00:00
|
|
|
requireRtpConnection()
|
|
|
|
.getAudioManager()
|
|
|
|
.setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE);
|
2020-04-13 12:24:32 +00:00
|
|
|
releaseProximityWakeLock();
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 11:30:12 +00:00
|
|
|
private void retry(View view) {
|
2020-04-10 07:31:39 +00:00
|
|
|
final Intent intent = getIntent();
|
|
|
|
final Account account = extractAccount(intent);
|
2020-05-17 08:24:46 +00:00
|
|
|
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
2020-04-16 08:03:53 +00:00
|
|
|
final String lastAction = intent.getStringExtra(EXTRA_LAST_ACTION);
|
|
|
|
final String action = intent.getAction();
|
|
|
|
final Set<Media> media = actionToMedia(lastAction == null ? action : lastAction);
|
2020-04-10 07:31:39 +00:00
|
|
|
this.rtpConnectionReference = null;
|
2020-05-30 12:56:12 +00:00
|
|
|
Log.d(Config.LOGTAG, "attempting retry with " + with.toEscapedString());
|
2020-04-16 08:03:53 +00:00
|
|
|
proposeJingleRtpSession(account, with, media);
|
2020-04-08 11:30:12 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 08:30:57 +00:00
|
|
|
private void exit(final View view) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void recordVoiceMail(final View view) {
|
|
|
|
final Intent intent = getIntent();
|
|
|
|
final Account account = extractAccount(intent);
|
|
|
|
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
2022-02-23 14:57:29 +00:00
|
|
|
final Conversation conversation =
|
|
|
|
xmppConnectionService.findOrCreateConversation(account, with, false, true);
|
2020-05-30 08:30:57 +00:00
|
|
|
final Intent launchIntent = new Intent(this, ConversationsActivity.class);
|
|
|
|
launchIntent.setAction(ConversationsActivity.ACTION_VIEW_CONVERSATION);
|
|
|
|
launchIntent.putExtra(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid());
|
|
|
|
launchIntent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
2022-02-23 14:57:29 +00:00
|
|
|
launchIntent.putExtra(
|
|
|
|
ConversationsActivity.EXTRA_POST_INIT_ACTION,
|
|
|
|
ConversationsActivity.POST_ACTION_RECORD_VOICE);
|
2020-05-30 08:30:57 +00:00
|
|
|
startActivity(launchIntent);
|
2020-04-10 11:13:20 +00:00
|
|
|
finish();
|
2020-04-08 08:46:26 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 11:15:24 +00:00
|
|
|
private Contact getWith() {
|
|
|
|
final AbstractJingleConnection.Id id = requireRtpConnection().getId();
|
|
|
|
final Account account = id.account;
|
|
|
|
return account.getRoster().getContact(id.with);
|
|
|
|
}
|
|
|
|
|
|
|
|
private JingleRtpConnection requireRtpConnection() {
|
2022-02-23 14:57:29 +00:00
|
|
|
final JingleRtpConnection connection =
|
|
|
|
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
2020-04-07 11:15:24 +00:00
|
|
|
if (connection == null) {
|
|
|
|
throw new IllegalStateException("No RTP connection found");
|
|
|
|
}
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-02-23 14:57:29 +00:00
|
|
|
public void onJingleRtpConnectionUpdate(
|
|
|
|
Account account, Jid with, final String sessionId, RtpEndUserState state) {
|
2020-04-15 20:40:37 +00:00
|
|
|
Log.d(Config.LOGTAG, "onJingleRtpConnectionUpdate(" + state + ")");
|
|
|
|
if (END_CARD.contains(state)) {
|
2020-04-16 15:38:05 +00:00
|
|
|
Log.d(Config.LOGTAG, "end card reached");
|
2020-04-13 12:24:32 +00:00
|
|
|
releaseProximityWakeLock();
|
2022-02-23 14:57:29 +00:00
|
|
|
runOnUiThread(
|
|
|
|
() -> getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON));
|
2020-04-10 09:16:54 +00:00
|
|
|
}
|
2020-04-08 07:42:06 +00:00
|
|
|
if (with.isBareJid()) {
|
2020-04-09 15:37:21 +00:00
|
|
|
updateRtpSessionProposalState(account, with, state);
|
2020-04-08 07:42:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-03-06 08:45:42 +00:00
|
|
|
if (emptyReference(this.rtpConnectionReference)) {
|
2020-04-15 22:08:58 +00:00
|
|
|
if (END_CARD.contains(state)) {
|
2020-04-16 15:38:05 +00:00
|
|
|
Log.d(Config.LOGTAG, "not reinitializing session");
|
2020-04-15 22:08:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-02-23 14:57:29 +00:00
|
|
|
// this happens when going from proposed session to actual session
|
2020-05-30 12:56:12 +00:00
|
|
|
reInitializeActivityWithRunningRtpSession(account, with, sessionId);
|
2020-04-08 07:42:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-07 11:15:24 +00:00
|
|
|
final AbstractJingleConnection.Id id = requireRtpConnection().getId();
|
2021-03-03 08:41:05 +00:00
|
|
|
final boolean verified = requireRtpConnection().isVerified();
|
2020-04-29 06:51:38 +00:00
|
|
|
final Set<Media> media = getMedia();
|
2022-11-28 10:39:26 +00:00
|
|
|
final ContentAddition contentAddition = getPendingContentAddition();
|
2020-04-29 06:51:38 +00:00
|
|
|
final Contact contact = getWith();
|
2020-04-08 07:42:06 +00:00
|
|
|
if (account == id.account && id.with.equals(with) && id.sessionId.equals(sessionId)) {
|
2020-04-07 19:26:51 +00:00
|
|
|
if (state == RtpEndUserState.ENDED) {
|
2020-04-10 11:13:20 +00:00
|
|
|
finish();
|
2020-04-07 19:26:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-02-23 14:57:29 +00:00
|
|
|
runOnUiThread(
|
|
|
|
() -> {
|
2022-11-28 10:39:26 +00:00
|
|
|
updateStateDisplay(state, media, contentAddition);
|
2022-02-23 14:57:29 +00:00
|
|
|
updateVerifiedShield(
|
|
|
|
verified && STATES_SHOWING_SWITCH_TO_CHAT.contains(state));
|
2022-11-28 10:39:26 +00:00
|
|
|
updateButtonConfiguration(state, media, contentAddition);
|
2022-02-23 14:57:29 +00:00
|
|
|
updateVideoViews(state);
|
2022-03-07 12:10:57 +00:00
|
|
|
updateIncomingCallScreen(state, contact);
|
2022-02-23 14:57:29 +00:00
|
|
|
invalidateOptionsMenu();
|
|
|
|
});
|
2020-04-24 19:27:00 +00:00
|
|
|
if (END_CARD.contains(state)) {
|
2020-04-29 07:22:49 +00:00
|
|
|
final JingleRtpConnection rtpConnection = requireRtpConnection();
|
|
|
|
resetIntent(account, with, state, rtpConnection.getMedia());
|
|
|
|
releaseVideoTracks(rtpConnection);
|
2020-04-24 19:27:00 +00:00
|
|
|
this.rtpConnectionReference = null;
|
|
|
|
}
|
2020-04-07 11:15:24 +00:00
|
|
|
} else {
|
2020-04-07 16:50:39 +00:00
|
|
|
Log.d(Config.LOGTAG, "received update for other rtp session");
|
2020-04-07 11:15:24 +00:00
|
|
|
}
|
2020-04-08 07:42:06 +00:00
|
|
|
}
|
2020-04-07 09:36:28 +00:00
|
|
|
|
2020-04-13 10:02:34 +00:00
|
|
|
@Override
|
2022-02-23 14:57:29 +00:00
|
|
|
public void onAudioDeviceChanged(
|
|
|
|
AppRTCAudioManager.AudioDevice selectedAudioDevice,
|
|
|
|
Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
|
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"onAudioDeviceChanged in activity: selected:"
|
|
|
|
+ selectedAudioDevice
|
|
|
|
+ ", available:"
|
|
|
|
+ availableAudioDevices);
|
2020-04-13 10:53:23 +00:00
|
|
|
try {
|
2020-04-15 20:40:37 +00:00
|
|
|
if (getMedia().contains(Media.VIDEO)) {
|
2020-04-16 15:38:05 +00:00
|
|
|
Log.d(Config.LOGTAG, "nothing to do; in video mode");
|
2020-04-15 20:40:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
final RtpEndUserState endUserState = requireRtpConnection().getEndUserState();
|
|
|
|
if (endUserState == RtpEndUserState.CONNECTED) {
|
2020-04-13 10:53:23 +00:00
|
|
|
final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager();
|
2020-04-15 17:16:47 +00:00
|
|
|
updateInCallButtonConfigurationSpeaker(
|
2020-04-13 10:53:23 +00:00
|
|
|
audioManager.getSelectedAudioDevice(),
|
2022-02-23 14:57:29 +00:00
|
|
|
audioManager.getAudioDevices().size());
|
2020-04-15 20:40:37 +00:00
|
|
|
} else if (END_CARD.contains(endUserState)) {
|
2022-02-23 14:57:29 +00:00
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"onAudioDeviceChanged() nothing to do because end card has been reached");
|
2020-04-15 20:40:37 +00:00
|
|
|
} else {
|
2020-06-14 14:22:53 +00:00
|
|
|
putProximityWakeLockInProperState(selectedAudioDevice);
|
2020-04-13 10:53:23 +00:00
|
|
|
}
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
Log.d(Config.LOGTAG, "RTP connection was not available when audio device changed");
|
|
|
|
}
|
2020-04-13 10:02:34 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private void updateRtpSessionProposalState(
|
|
|
|
final Account account, final Jid with, final RtpEndUserState state) {
|
2020-04-09 15:37:21 +00:00
|
|
|
final Intent currentIntent = getIntent();
|
2022-02-23 14:57:29 +00:00
|
|
|
final String withExtra =
|
|
|
|
currentIntent == null ? null : currentIntent.getStringExtra(EXTRA_WITH);
|
2020-04-09 15:37:21 +00:00
|
|
|
if (withExtra == null) {
|
2020-04-08 07:42:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-09 15:37:21 +00:00
|
|
|
if (Jid.ofEscaped(withExtra).asBareJid().equals(with)) {
|
2022-02-23 14:57:29 +00:00
|
|
|
runOnUiThread(
|
|
|
|
() -> {
|
|
|
|
updateVerifiedShield(false);
|
|
|
|
updateStateDisplay(state);
|
|
|
|
updateButtonConfiguration(state);
|
2022-03-07 12:10:57 +00:00
|
|
|
updateIncomingCallScreen(state);
|
2022-02-23 14:57:29 +00:00
|
|
|
invalidateOptionsMenu();
|
|
|
|
});
|
2020-04-16 08:03:53 +00:00
|
|
|
resetIntent(account, with, state, actionToMedia(currentIntent.getAction()));
|
2020-04-08 07:42:06 +00:00
|
|
|
}
|
2020-04-07 09:36:28 +00:00
|
|
|
}
|
2020-04-09 15:37:21 +00:00
|
|
|
|
2020-04-10 11:13:20 +00:00
|
|
|
private void resetIntent(final Bundle extras) {
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.putExtras(extras);
|
|
|
|
setIntent(intent);
|
|
|
|
}
|
|
|
|
|
2022-02-23 14:57:29 +00:00
|
|
|
private void resetIntent(
|
|
|
|
final Account account, Jid with, final RtpEndUserState state, final Set<Media> media) {
|
2020-04-09 15:37:21 +00:00
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString());
|
2022-02-23 14:57:29 +00:00
|
|
|
if (account.getRoster()
|
|
|
|
.getContact(with)
|
|
|
|
.getPresences()
|
|
|
|
.anySupport(Namespace.JINGLE_MESSAGE)) {
|
2020-05-30 12:56:12 +00:00
|
|
|
intent.putExtra(EXTRA_WITH, with.asBareJid().toEscapedString());
|
|
|
|
} else {
|
|
|
|
intent.putExtra(EXTRA_WITH, with.toEscapedString());
|
|
|
|
}
|
2020-04-09 15:37:21 +00:00
|
|
|
intent.putExtra(EXTRA_LAST_REPORTED_STATE, state.toString());
|
2022-02-23 14:57:29 +00:00
|
|
|
intent.putExtra(
|
|
|
|
EXTRA_LAST_ACTION,
|
|
|
|
media.contains(Media.VIDEO) ? ACTION_MAKE_VIDEO_CALL : ACTION_MAKE_VOICE_CALL);
|
2020-04-09 15:37:21 +00:00
|
|
|
setIntent(intent);
|
|
|
|
}
|
2021-03-06 08:45:42 +00:00
|
|
|
|
|
|
|
private static boolean emptyReference(final WeakReference<?> weakReference) {
|
|
|
|
return weakReference == null || weakReference.get() == null;
|
|
|
|
}
|
2020-04-07 09:36:28 +00:00
|
|
|
}
|