2020-04-07 09:36:28 +00:00
|
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
|
2020-04-09 17:45:21 +00:00
|
|
|
|
import android.Manifest;
|
2020-04-10 07:31:39 +00:00
|
|
|
|
import android.annotation.SuppressLint;
|
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-07 09:36:28 +00:00
|
|
|
|
import android.databinding.DataBindingUtil;
|
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-04-10 09:16:54 +00:00
|
|
|
|
import android.os.PowerManager;
|
2020-04-09 17:45:21 +00:00
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
import android.support.annotation.StringRes;
|
2020-04-07 11:15:24 +00:00
|
|
|
|
import android.util.Log;
|
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;
|
|
|
|
|
|
2020-04-14 17:06:39 +00:00
|
|
|
|
import com.google.common.base.Optional;
|
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-04-07 09:36:28 +00:00
|
|
|
|
|
2020-04-14 19:06:26 +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-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-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-09 17:45:21 +00:00
|
|
|
|
import eu.siacs.conversations.utils.PermissionUtils;
|
2020-04-07 11:15:24 +00:00
|
|
|
|
import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection;
|
|
|
|
|
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;
|
|
|
|
|
import rocks.xmpp.addr.Jid;
|
2020-04-07 09:36:28 +00:00
|
|
|
|
|
2020-04-09 17:45:21 +00:00
|
|
|
|
import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
|
2020-04-08 07:42:06 +00:00
|
|
|
|
import static java.util.Arrays.asList;
|
|
|
|
|
|
2020-04-07 11:15:24 +00:00
|
|
|
|
public class RtpSessionActivity extends XmppActivity implements XmppConnectionService.OnJingleRtpConnectionUpdate {
|
2020-04-07 09:36:28 +00:00
|
|
|
|
|
2020-04-10 09:16:54 +00:00
|
|
|
|
private static final String PROXIMITY_WAKE_LOCK_TAG = "conversations:in-rtp-session";
|
|
|
|
|
|
2020-04-09 17:45:21 +00:00
|
|
|
|
private static final int REQUEST_ACCEPT_CALL = 0x1111;
|
|
|
|
|
|
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-07 11:15:24 +00:00
|
|
|
|
|
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-04-07 16:50:39 +00:00
|
|
|
|
|
2020-04-14 17:06:39 +00:00
|
|
|
|
|
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
|
|
|
|
|
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);
|
2020-04-07 16:50:39 +00:00
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
|
|
|
|
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
|
|
|
|
|
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
2020-04-10 09:16:54 +00:00
|
|
|
|
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
2020-04-07 16:50:39 +00:00
|
|
|
|
Log.d(Config.LOGTAG, "RtpSessionActivity.onCreate()");
|
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-04-07 14:17:29 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onStart() {
|
|
|
|
|
super.onStart();
|
2020-04-07 16:50:39 +00:00
|
|
|
|
Log.d(Config.LOGTAG, "RtpSessionActivity.onStart()");
|
2020-04-07 14:17:29 +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) {
|
|
|
|
|
final Intent intent = getIntent();
|
|
|
|
|
final Account account = extractAccount(intent);
|
|
|
|
|
final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH));
|
|
|
|
|
xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid());
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void requestPermissionsAndAcceptCall() {
|
2020-04-15 16:47:15 +00:00
|
|
|
|
final List<String> permissions;
|
|
|
|
|
if (getMedia().contains(Media.VIDEO)) {
|
|
|
|
|
permissions = ImmutableList.of(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO);
|
|
|
|
|
} else {
|
|
|
|
|
permissions = ImmutableList.of(Manifest.permission.RECORD_AUDIO);
|
|
|
|
|
}
|
|
|
|
|
if (PermissionUtils.hasPermission(this, permissions, REQUEST_ACCEPT_CALL)) {
|
2020-04-13 13:16:26 +00:00
|
|
|
|
//TODO like wise the propose; we might just wait here for the audio manager to come up
|
2020-04-10 09:16:54 +00:00
|
|
|
|
putScreenInCallMode();
|
2020-04-09 17:45:21 +00:00
|
|
|
|
requireRtpConnection().acceptCall();
|
|
|
|
|
}
|
2020-04-07 09:36:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-10 09:16:54 +00:00
|
|
|
|
@SuppressLint("WakelockTimeout")
|
|
|
|
|
private void putScreenInCallMode() {
|
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
2020-04-13 12:24:32 +00:00
|
|
|
|
final JingleRtpConnection rtpConnection = rtpConnectionReference != null ? rtpConnectionReference.get() : null;
|
2020-04-13 13:16:26 +00:00
|
|
|
|
final AppRTCAudioManager audioManager = rtpConnection == null ? null : rtpConnection.getAudioManager();
|
|
|
|
|
if (audioManager == null || audioManager.getSelectedAudioDevice() == AppRTCAudioManager.AudioDevice.EARPIECE) {
|
2020-04-13 12:24:32 +00:00
|
|
|
|
acquireProximityWakeLock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
2020-04-11 17:47:30 +00:00
|
|
|
|
if (this.mProximityWakeLock == null) {
|
|
|
|
|
this.mProximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, PROXIMITY_WAKE_LOCK_TAG);
|
|
|
|
|
}
|
2020-04-10 09:16:54 +00:00
|
|
|
|
if (!this.mProximityWakeLock.isHeld()) {
|
2020-04-13 12:24:32 +00:00
|
|
|
|
Log.d(Config.LOGTAG, "acquiring proximity wake lock");
|
2020-04-10 09:16:54 +00:00
|
|
|
|
this.mProximityWakeLock.acquire();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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");
|
2020-04-10 09:16:54 +00:00
|
|
|
|
this.mProximityWakeLock.release();
|
|
|
|
|
this.mProximityWakeLock = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 12:55:07 +00:00
|
|
|
|
private void putProximityWakeLockInProperState() {
|
|
|
|
|
if (requireRtpConnection().getAudioManager().getSelectedAudioDevice() == AppRTCAudioManager.AudioDevice.EARPIECE) {
|
|
|
|
|
acquireProximityWakeLock();
|
|
|
|
|
} else {
|
|
|
|
|
releaseProximityWakeLock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-07 09:36:28 +00:00
|
|
|
|
@Override
|
|
|
|
|
protected void refreshUiReal() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-07 19:26:51 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onNewIntent(final Intent intent) {
|
|
|
|
|
super.onNewIntent(intent);
|
2020-04-11 18:51:37 +00:00
|
|
|
|
setIntent(intent);
|
|
|
|
|
if (xmppConnectionService == null) {
|
2020-04-13 10:02:34 +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);
|
|
|
|
|
final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH));
|
|
|
|
|
final String sessionId = intent.getStringExtra(EXTRA_SESSION_ID);
|
|
|
|
|
if (sessionId != null) {
|
|
|
|
|
Log.d(Config.LOGTAG, "reinitializing from onNewIntent()");
|
2020-04-13 12:24:32 +00:00
|
|
|
|
initializeActivityWithRunningRtpSession(account, with, sessionId);
|
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
|
|
|
|
}
|
|
|
|
|
} 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-04-08 07:42:06 +00:00
|
|
|
|
final Jid with = Jid.of(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-13 12:24:32 +00:00
|
|
|
|
initializeActivityWithRunningRtpSession(account, with, sessionId);
|
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)) {
|
|
|
|
|
final Set<Media> media;
|
|
|
|
|
if (ACTION_MAKE_VIDEO_CALL.equals(action)) {
|
|
|
|
|
media = ImmutableSet.of(Media.AUDIO, Media.VIDEO);
|
|
|
|
|
} else {
|
|
|
|
|
media = ImmutableSet.of(Media.AUDIO);
|
|
|
|
|
}
|
|
|
|
|
proposeJingleRtpSession(account, with, media);
|
2020-04-08 07:42:06 +00:00
|
|
|
|
binding.with.setText(account.getRoster().getContact(with).getDisplayName());
|
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);
|
|
|
|
|
if (extraLastState != null) {
|
|
|
|
|
Log.d(Config.LOGTAG, "restored last state from intent extra");
|
|
|
|
|
RtpEndUserState state = RtpEndUserState.valueOf(extraLastState);
|
|
|
|
|
updateButtonConfiguration(state);
|
|
|
|
|
updateStateDisplay(state);
|
|
|
|
|
}
|
|
|
|
|
binding.with.setText(account.getRoster().getContact(with).getDisplayName());
|
2020-04-07 11:15:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 08:49:38 +00:00
|
|
|
|
private void proposeJingleRtpSession(final Account account, final Jid with, final Set<Media> media) {
|
|
|
|
|
xmppConnectionService.getJingleConnectionManager().proposeJingleRtpSession(account, with, media);
|
2020-04-13 12:55:07 +00:00
|
|
|
|
//TODO maybe we don’t want to acquire a wake lock just yet and wait for audio manager to discover what speaker we are using
|
2020-04-10 09:16:54 +00:00
|
|
|
|
putScreenInCallMode();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 17:45:21 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
|
if (PermissionUtils.allGranted(grantResults)) {
|
|
|
|
|
if (requestCode == REQUEST_ACCEPT_CALL) {
|
|
|
|
|
requireRtpConnection().acceptCall();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
@StringRes int res;
|
|
|
|
|
final String firstDenied = getFirstDenied(grantResults, permissions);
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
Toast.makeText(this, res, Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-10 11:13:20 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onStop() {
|
2020-04-14 19:06:26 +00:00
|
|
|
|
binding.remoteVideo.release();
|
|
|
|
|
binding.localVideo.release();
|
2020-04-13 12:24:32 +00:00
|
|
|
|
releaseProximityWakeLock();
|
2020-04-11 17:47:30 +00:00
|
|
|
|
//TODO maybe we want to finish if call had ended
|
2020-04-10 11:13:20 +00:00
|
|
|
|
super.onStop();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-10 08:35:00 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
endCall();
|
|
|
|
|
super.onBackPressed();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 07:42:06 +00:00
|
|
|
|
|
2020-04-13 12:24:32 +00:00
|
|
|
|
private void initializeActivityWithRunningRtpSession(final Account account, Jid with, String sessionId) {
|
2020-04-08 07:42:06 +00:00
|
|
|
|
final WeakReference<JingleRtpConnection> reference = xmppConnectionService.getJingleConnectionManager()
|
|
|
|
|
.findJingleRtpConnection(account, with, sessionId);
|
|
|
|
|
if (reference == null || reference.get() == null) {
|
2020-04-10 11:13:20 +00:00
|
|
|
|
finish();
|
2020-04-08 07:42:06 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.rtpConnectionReference = reference;
|
|
|
|
|
final RtpEndUserState currentState = requireRtpConnection().getEndUserState();
|
|
|
|
|
if (currentState == RtpEndUserState.ENDED) {
|
2020-04-10 11:13:20 +00:00
|
|
|
|
finish();
|
2020-04-08 07:42:06 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-04-11 18:51:37 +00:00
|
|
|
|
if (currentState == RtpEndUserState.INCOMING_CALL) {
|
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
|
}
|
2020-04-10 13:19:56 +00:00
|
|
|
|
if (JingleRtpConnection.STATES_SHOWING_ONGOING_CALL.contains(requireRtpConnection().getState())) {
|
|
|
|
|
putScreenInCallMode();
|
|
|
|
|
}
|
2020-04-08 07:42:06 +00:00
|
|
|
|
binding.with.setText(getWith().getDisplayName());
|
2020-04-15 16:47:15 +00:00
|
|
|
|
updateVideoViews();
|
2020-04-08 07:42:06 +00:00
|
|
|
|
updateStateDisplay(currentState);
|
|
|
|
|
updateButtonConfiguration(currentState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reInitializeActivityWithRunningRapSession(final Account account, Jid with, String sessionId) {
|
|
|
|
|
runOnUiThread(() -> {
|
2020-04-13 12:24:32 +00:00
|
|
|
|
initializeActivityWithRunningRtpSession(account, with, 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);
|
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
|
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) {
|
2020-04-07 11:15:24 +00:00
|
|
|
|
switch (state) {
|
|
|
|
|
case INCOMING_CALL:
|
2020-04-15 16:28:04 +00:00
|
|
|
|
if (getMedia().contains(Media.VIDEO)) {
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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-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;
|
2020-04-09 15:37:21 +00:00
|
|
|
|
case ENDED:
|
2020-04-10 09:16:54 +00:00
|
|
|
|
throw new IllegalStateException("Activity should have called finishAndReleaseWakeLock();");
|
2020-04-09 15:37:21 +00:00
|
|
|
|
default:
|
|
|
|
|
throw new IllegalStateException(String.format("State %s has not been handled in UI", state));
|
2020-04-07 12:22:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 16:28:04 +00:00
|
|
|
|
private Set<Media> getMedia() {
|
|
|
|
|
return requireRtpConnection().getMedia();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-10 07:31:39 +00:00
|
|
|
|
@SuppressLint("RestrictedApi")
|
2020-04-07 12:22:12 +00:00
|
|
|
|
private void updateButtonConfiguration(final RtpEndUserState state) {
|
|
|
|
|
if (state == RtpEndUserState.INCOMING_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-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);
|
2020-04-07 12:22:12 +00:00
|
|
|
|
} else if (state == RtpEndUserState.ENDING_CALL) {
|
2020-04-10 07:31:39 +00:00
|
|
|
|
this.binding.rejectCall.setVisibility(View.INVISIBLE);
|
|
|
|
|
this.binding.endCall.setVisibility(View.INVISIBLE);
|
|
|
|
|
this.binding.acceptCall.setVisibility(View.INVISIBLE);
|
2020-04-08 08:46:26 +00:00
|
|
|
|
} else if (state == RtpEndUserState.DECLINED_OR_BUSY) {
|
2020-04-10 07:31:39 +00:00
|
|
|
|
this.binding.rejectCall.setVisibility(View.INVISIBLE);
|
2020-04-08 11:30:12 +00:00
|
|
|
|
this.binding.endCall.setOnClickListener(this::exit);
|
2020-04-08 08:46:26 +00:00
|
|
|
|
this.binding.endCall.setImageResource(R.drawable.ic_clear_white_48dp);
|
2020-04-10 07:31:39 +00:00
|
|
|
|
this.binding.endCall.setVisibility(View.VISIBLE);
|
|
|
|
|
this.binding.acceptCall.setVisibility(View.INVISIBLE);
|
2020-04-09 13:22:03 +00:00
|
|
|
|
} else if (state == RtpEndUserState.CONNECTIVITY_ERROR || state == RtpEndUserState.APPLICATION_ERROR) {
|
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-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-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-13 10:53:23 +00:00
|
|
|
|
updateInCallButtonConfiguration(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateInCallButtonConfiguration() {
|
|
|
|
|
updateInCallButtonConfiguration(requireRtpConnection().getEndUserState());
|
|
|
|
|
}
|
2020-04-13 10:02:34 +00:00
|
|
|
|
|
2020-04-13 10:53:23 +00:00
|
|
|
|
@SuppressLint("RestrictedApi")
|
|
|
|
|
private void updateInCallButtonConfiguration(final RtpEndUserState state) {
|
2020-04-13 10:02:34 +00:00
|
|
|
|
if (state == RtpEndUserState.CONNECTED) {
|
2020-04-15 17:16:47 +00:00
|
|
|
|
if (getMedia().contains(Media.VIDEO)) {
|
|
|
|
|
updateInCallButtonConfigurationVideo(requireRtpConnection().isVideoEnabled());
|
|
|
|
|
} else {
|
|
|
|
|
final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager();
|
|
|
|
|
updateInCallButtonConfigurationSpeaker(
|
|
|
|
|
audioManager.getSelectedAudioDevice(),
|
|
|
|
|
audioManager.getAudioDevices().size()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
updateInCallButtonConfigurationMicrophone(requireRtpConnection().isMicrophoneEnabled());
|
2020-04-13 10:02:34 +00:00
|
|
|
|
} else {
|
|
|
|
|
this.binding.inCallActionLeft.setVisibility(View.GONE);
|
|
|
|
|
this.binding.inCallActionRight.setVisibility(View.GONE);
|
|
|
|
|
}
|
2020-04-07 11:15:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 10:53:23 +00:00
|
|
|
|
@SuppressLint("RestrictedApi")
|
2020-04-15 17:16:47 +00:00
|
|
|
|
private void updateInCallButtonConfigurationSpeaker(final AppRTCAudioManager.AudioDevice selectedAudioDevice, final int numberOfChoices) {
|
2020-04-13 10:53:23 +00:00
|
|
|
|
switch (selectedAudioDevice) {
|
|
|
|
|
case EARPIECE:
|
2020-04-15 17:16:47 +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:
|
2020-04-15 17:16:47 +00:00
|
|
|
|
this.binding.inCallActionRight.setImageResource(R.drawable.ic_bluetooth_audio_black_24dp);
|
|
|
|
|
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")
|
|
|
|
|
private void updateInCallButtonConfigurationVideo(final boolean videoEnabled) {
|
|
|
|
|
this.binding.inCallActionRight.setVisibility(View.VISIBLE);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void enableVideo(View view) {
|
|
|
|
|
requireRtpConnection().setVideoEnabled(true);
|
|
|
|
|
updateInCallButtonConfigurationVideo(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void disableVideo(View view) {
|
|
|
|
|
requireRtpConnection().setVideoEnabled(false);
|
|
|
|
|
updateInCallButtonConfigurationVideo(false);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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-04-15 16:47:15 +00:00
|
|
|
|
private void updateVideoViews() {
|
|
|
|
|
final Optional<VideoTrack> localVideoTrack = requireRtpConnection().geLocalVideoTrack();
|
|
|
|
|
if (localVideoTrack.isPresent()) {
|
|
|
|
|
ensureSurfaceViewRendererIsSetup(binding.localVideo);
|
|
|
|
|
//paint local view over remote view
|
|
|
|
|
binding.localVideo.setZOrderMediaOverlay(true);
|
|
|
|
|
binding.localVideo.setMirror(true);
|
|
|
|
|
localVideoTrack.get().addSink(binding.localVideo);
|
|
|
|
|
} else {
|
|
|
|
|
binding.localVideo.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
final Optional<VideoTrack> remoteVideoTrack = requireRtpConnection().getRemoteVideoTrack();
|
|
|
|
|
if (remoteVideoTrack.isPresent()) {
|
|
|
|
|
ensureSurfaceViewRendererIsSetup(binding.remoteVideo);
|
|
|
|
|
remoteVideoTrack.get().addSink(binding.remoteVideo);
|
|
|
|
|
} else {
|
|
|
|
|
binding.remoteVideo.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 10:53:23 +00:00
|
|
|
|
private void disableMicrophone(View view) {
|
|
|
|
|
JingleRtpConnection rtpConnection = requireRtpConnection();
|
|
|
|
|
rtpConnection.setMicrophoneEnabled(false);
|
|
|
|
|
updateInCallButtonConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void enableMicrophone(View view) {
|
|
|
|
|
JingleRtpConnection rtpConnection = requireRtpConnection();
|
|
|
|
|
rtpConnection.setMicrophoneEnabled(true);
|
|
|
|
|
updateInCallButtonConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void switchToEarpiece(View view) {
|
|
|
|
|
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) {
|
|
|
|
|
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-09 17:45:21 +00:00
|
|
|
|
Log.d(Config.LOGTAG, "attempting retry");
|
2020-04-10 07:31:39 +00:00
|
|
|
|
final Intent intent = getIntent();
|
|
|
|
|
final Account account = extractAccount(intent);
|
|
|
|
|
final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH));
|
|
|
|
|
this.rtpConnectionReference = null;
|
2020-04-15 11:21:21 +00:00
|
|
|
|
proposeJingleRtpSession(account, with, ImmutableSet.of(Media.AUDIO, Media.VIDEO));
|
2020-04-08 11:30:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 08:46:26 +00:00
|
|
|
|
private void exit(View view) {
|
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() {
|
|
|
|
|
final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
|
|
|
|
if (connection == null) {
|
|
|
|
|
throw new IllegalStateException("No RTP connection found");
|
|
|
|
|
}
|
|
|
|
|
return connection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2020-04-08 07:42:06 +00:00
|
|
|
|
public void onJingleRtpConnectionUpdate(Account account, Jid with, final String sessionId, RtpEndUserState state) {
|
2020-04-10 09:16:54 +00:00
|
|
|
|
if (Arrays.asList(RtpEndUserState.APPLICATION_ERROR, RtpEndUserState.DECLINED_OR_BUSY, RtpEndUserState.DECLINED_OR_BUSY).contains(state)) {
|
2020-04-13 12:24:32 +00:00
|
|
|
|
releaseProximityWakeLock();
|
2020-04-10 09:16:54 +00:00
|
|
|
|
}
|
2020-04-08 08:46:26 +00:00
|
|
|
|
Log.d(Config.LOGTAG, "onJingleRtpConnectionUpdate(" + state + ")");
|
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;
|
|
|
|
|
}
|
|
|
|
|
if (this.rtpConnectionReference == null) {
|
|
|
|
|
//this happens when going from proposed session to actual session
|
|
|
|
|
reInitializeActivityWithRunningRapSession(account, with, sessionId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-04-07 11:15:24 +00:00
|
|
|
|
final AbstractJingleConnection.Id id = requireRtpConnection().getId();
|
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;
|
2020-04-09 15:37:21 +00:00
|
|
|
|
} else if (asList(RtpEndUserState.APPLICATION_ERROR, RtpEndUserState.DECLINED_OR_BUSY, RtpEndUserState.CONNECTIVITY_ERROR).contains(state)) {
|
|
|
|
|
resetIntent(account, with, state);
|
2020-04-07 19:26:51 +00:00
|
|
|
|
}
|
2020-04-07 16:50:39 +00:00
|
|
|
|
runOnUiThread(() -> {
|
2020-04-07 12:22:12 +00:00
|
|
|
|
updateStateDisplay(state);
|
|
|
|
|
updateButtonConfiguration(state);
|
2020-04-14 17:06:39 +00:00
|
|
|
|
updateVideoViews();
|
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-10 07:31:39 +00:00
|
|
|
|
//TODO if we only ever have one; we might just switch over? Maybe!
|
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
|
|
|
|
|
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 17:16:47 +00:00
|
|
|
|
if (requireRtpConnection().getEndUserState() == RtpEndUserState.CONNECTED && !getMedia().contains(Media.VIDEO)) {
|
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(),
|
2020-04-15 17:16:47 +00:00
|
|
|
|
audioManager.getAudioDevices().size()
|
2020-04-13 10:53:23 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
2020-04-13 12:55:07 +00:00
|
|
|
|
putProximityWakeLockInProperState();
|
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
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 15:37:21 +00:00
|
|
|
|
private void updateRtpSessionProposalState(final Account account, final Jid with, final RtpEndUserState state) {
|
|
|
|
|
final Intent currentIntent = getIntent();
|
|
|
|
|
final String withExtra = currentIntent == null ? null : currentIntent.getStringExtra(EXTRA_WITH);
|
|
|
|
|
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)) {
|
2020-04-08 07:42:06 +00:00
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
|
updateStateDisplay(state);
|
|
|
|
|
updateButtonConfiguration(state);
|
|
|
|
|
});
|
2020-04-09 15:37:21 +00:00
|
|
|
|
resetIntent(account, with, state);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 15:37:21 +00:00
|
|
|
|
private void resetIntent(final Account account, Jid with, final RtpEndUserState state) {
|
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
|
intent.putExtra(EXTRA_WITH, with.asBareJid().toEscapedString());
|
|
|
|
|
intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString());
|
|
|
|
|
intent.putExtra(EXTRA_LAST_REPORTED_STATE, state.toString());
|
|
|
|
|
setIntent(intent);
|
|
|
|
|
}
|
2020-04-07 09:36:28 +00:00
|
|
|
|
}
|