reverting webrtc
This commit is contained in:
parent
30d8d07c8a
commit
6d8e70ead1
2 changed files with 199 additions and 331 deletions
|
@ -1,8 +1,5 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.PictureInPictureParams;
|
||||
|
@ -36,7 +33,6 @@ import com.google.common.util.concurrent.FutureCallback;
|
|||
import com.google.common.util.concurrent.Futures;
|
||||
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
|
||||
import org.webrtc.RendererCommon;
|
||||
import org.webrtc.SurfaceViewRenderer;
|
||||
import org.webrtc.VideoTrack;
|
||||
|
||||
|
@ -56,7 +52,6 @@ import eu.siacs.conversations.services.AppRTCAudioManager;
|
|||
import eu.siacs.conversations.services.XmppConnectionService;
|
||||
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
||||
import eu.siacs.conversations.ui.util.MainThreadExecutor;
|
||||
import eu.siacs.conversations.ui.util.Rationals;
|
||||
import eu.siacs.conversations.utils.Namespace;
|
||||
import eu.siacs.conversations.utils.PermissionUtils;
|
||||
import eu.siacs.conversations.utils.TimeFrameUtils;
|
||||
|
@ -68,9 +63,10 @@ import eu.siacs.conversations.xmpp.jingle.Media;
|
|||
import eu.siacs.conversations.xmpp.jingle.RtpEndUserState;
|
||||
import me.drakeet.support.toast.ToastCompat;
|
||||
|
||||
public class RtpSessionActivity extends XmppActivity
|
||||
implements XmppConnectionService.OnJingleRtpConnectionUpdate,
|
||||
eu.siacs.conversations.ui.widget.SurfaceViewRenderer.OnAspectRatioChanged {
|
||||
import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class RtpSessionActivity extends XmppActivity implements XmppConnectionService.OnJingleRtpConnectionUpdate {
|
||||
|
||||
public static final String EXTRA_WITH = "with";
|
||||
public static final String EXTRA_SESSION_ID = "session_id";
|
||||
|
@ -82,31 +78,25 @@ public class RtpSessionActivity extends XmppActivity
|
|||
|
||||
private static final int CALL_DURATION_UPDATE_INTERVAL = 333;
|
||||
|
||||
private static final List<RtpEndUserState> END_CARD =
|
||||
Arrays.asList(
|
||||
private boolean shouldAllowBack = false;
|
||||
|
||||
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.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.SECURITY_ERROR
|
||||
);
|
||||
private static final List<RtpEndUserState> STATES_SHOWING_SWITCH_TO_CHAT = Arrays.asList(
|
||||
RtpEndUserState.CONNECTING,
|
||||
RtpEndUserState.CONNECTED,
|
||||
RtpEndUserState.RECONNECTING);
|
||||
private static final List<RtpEndUserState> STATES_CONSIDERED_CONNECTED =
|
||||
Arrays.asList(RtpEndUserState.CONNECTED, RtpEndUserState.RECONNECTING);
|
||||
private static final List<RtpEndUserState> STATES_SHOWING_PIP_PLACEHOLDER =
|
||||
Arrays.asList(
|
||||
RtpEndUserState.ACCEPTING_CALL,
|
||||
RtpEndUserState.CONNECTING,
|
||||
RtpEndUserState.RECONNECTING);
|
||||
RtpEndUserState.CONNECTED
|
||||
);
|
||||
private static final String PROXIMITY_WAKE_LOCK_TAG = "conversations:in-rtp-session";
|
||||
private static final int REQUEST_ACCEPT_CALL = 0x1111;
|
||||
private WeakReference<JingleRtpConnection> rtpConnectionReference;
|
||||
|
@ -115,8 +105,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
private PowerManager.WakeLock mProximityWakeLock;
|
||||
|
||||
private final Handler mHandler = new Handler();
|
||||
private final Runnable mTickExecutor =
|
||||
new Runnable() {
|
||||
private final Runnable mTickExecutor = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateCallDuration();
|
||||
|
@ -132,24 +121,18 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
}
|
||||
|
||||
private static void addSink(
|
||||
final VideoTrack videoTrack, final SurfaceViewRenderer surfaceViewRenderer) {
|
||||
private static void addSink(final VideoTrack videoTrack, final SurfaceViewRenderer surfaceViewRenderer) {
|
||||
try {
|
||||
videoTrack.addSink(surfaceViewRenderer);
|
||||
} catch (final IllegalStateException e) {
|
||||
Log.e(
|
||||
Config.LOGTAG,
|
||||
"possible race condition on trying to display video track. ignoring",
|
||||
e);
|
||||
Log.e(Config.LOGTAG, "possible race condition on trying to display video track. ignoring", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow()
|
||||
.addFlags(
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||
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);
|
||||
|
@ -172,8 +155,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
return STATES_SHOWING_HELP_BUTTON.contains(requireRtpConnection().getEndUserState());
|
||||
} catch (IllegalStateException e) {
|
||||
final Intent intent = getIntent();
|
||||
final String state =
|
||||
intent != null ? intent.getStringExtra(EXTRA_LAST_REPORTED_STATE) : null;
|
||||
final String state = intent != null ? intent.getStringExtra(EXTRA_LAST_REPORTED_STATE) : null;
|
||||
if (state != null) {
|
||||
return STATES_SHOWING_HELP_BUTTON.contains(RtpEndUserState.valueOf(state));
|
||||
} else {
|
||||
|
@ -183,17 +165,13 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
private boolean isSwitchToConversationVisible() {
|
||||
final JingleRtpConnection connection =
|
||||
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
return connection != null
|
||||
&& STATES_SHOWING_SWITCH_TO_CHAT.contains(connection.getEndUserState());
|
||||
final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
return connection != null && STATES_SHOWING_SWITCH_TO_CHAT.contains(connection.getEndUserState());
|
||||
}
|
||||
|
||||
private void switchToConversation() {
|
||||
final Contact contact = getWith();
|
||||
final Conversation conversation =
|
||||
xmppConnectionService.findOrCreateConversation(
|
||||
contact.getAccount(), contact.getJid(), false, true);
|
||||
final Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
|
||||
switchToConversation(conversation);
|
||||
}
|
||||
|
||||
|
@ -214,8 +192,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
try {
|
||||
startActivity(intent);
|
||||
} catch (final ActivityNotFoundException e) {
|
||||
ToastCompat.makeText(this, R.string.no_application_found_to_open_link, ToastCompat.LENGTH_LONG)
|
||||
.show();
|
||||
ToastCompat.makeText(this, R.string.no_application_found_to_open_link, ToastCompat.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,15 +215,10 @@ public class RtpSessionActivity extends XmppActivity
|
|||
final Account account = extractAccount(intent);
|
||||
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
||||
final String state = intent.getStringExtra(EXTRA_LAST_REPORTED_STATE);
|
||||
if (!Intent.ACTION_VIEW.equals(action)
|
||||
|| state == null
|
||||
|| !END_CARD.contains(RtpEndUserState.valueOf(state))) {
|
||||
resetIntent(
|
||||
account, with, RtpEndUserState.RETRACTED, actionToMedia(intent.getAction()));
|
||||
if (!Intent.ACTION_VIEW.equals(action) || state == null || !END_CARD.contains(RtpEndUserState.valueOf(state))) {
|
||||
resetIntent(account, with, RtpEndUserState.RETRACTED, actionToMedia(intent.getAction()));
|
||||
}
|
||||
xmppConnectionService
|
||||
.getJingleConnectionManager()
|
||||
.retractSessionProposal(account, with.asBareJid());
|
||||
xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid());
|
||||
}
|
||||
|
||||
private void rejectCall(View view) {
|
||||
|
@ -261,8 +233,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
private void requestPermissionsAndAcceptCall() {
|
||||
final List<String> permissions;
|
||||
if (getMedia().contains(Media.VIDEO)) {
|
||||
permissions =
|
||||
ImmutableList.of(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO);
|
||||
permissions = ImmutableList.of(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO);
|
||||
} else {
|
||||
permissions = ImmutableList.of(Manifest.permission.RECORD_AUDIO);
|
||||
}
|
||||
|
@ -273,7 +244,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
private void checkRecorderAndAcceptCall() {
|
||||
checkMicrophoneAvailabilityAsync();
|
||||
checkMicrophoneAvailability();
|
||||
try {
|
||||
requireRtpConnection().acceptCall();
|
||||
} catch (final IllegalStateException e) {
|
||||
|
@ -281,10 +252,6 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void checkMicrophoneAvailabilityAsync() {
|
||||
new Thread(this::checkMicrophoneAvailability).start();
|
||||
}
|
||||
|
||||
private void checkMicrophoneAvailability() {
|
||||
new Thread(() -> {
|
||||
final long start = SystemClock.elapsedRealtime();
|
||||
|
@ -295,7 +262,8 @@ public class RtpSessionActivity extends XmppActivity
|
|||
return;
|
||||
}
|
||||
runOnUiThread(() -> ToastCompat.makeText(this, R.string.microphone_unavailable, ToastCompat.LENGTH_LONG).show());
|
||||
}).start();
|
||||
}
|
||||
).start();
|
||||
}
|
||||
|
||||
private void putScreenInCallMode() {
|
||||
|
@ -305,13 +273,9 @@ public class RtpSessionActivity extends XmppActivity
|
|||
private void putScreenInCallMode(final Set<Media> media) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
if (!media.contains(Media.VIDEO)) {
|
||||
final JingleRtpConnection rtpConnection =
|
||||
rtpConnectionReference != null ? rtpConnectionReference.get() : null;
|
||||
final AppRTCAudioManager audioManager =
|
||||
rtpConnection == null ? null : rtpConnection.getAudioManager();
|
||||
if (audioManager == null
|
||||
|| audioManager.getSelectedAudioDevice()
|
||||
== AppRTCAudioManager.AudioDevice.EARPIECE) {
|
||||
final JingleRtpConnection rtpConnection = rtpConnectionReference != null ? rtpConnectionReference.get() : null;
|
||||
final AppRTCAudioManager audioManager = rtpConnection == null ? null : rtpConnection.getAudioManager();
|
||||
if (audioManager == null || audioManager.getSelectedAudioDevice() == AppRTCAudioManager.AudioDevice.EARPIECE) {
|
||||
acquireProximityWakeLock();
|
||||
}
|
||||
}
|
||||
|
@ -324,31 +288,30 @@ public class RtpSessionActivity extends XmppActivity
|
|||
Log.e(Config.LOGTAG, "power manager not available");
|
||||
return;
|
||||
}
|
||||
if (isFinishing()) {
|
||||
Log.e(Config.LOGTAG, "do not acquire wakelock. activity is finishing");
|
||||
return;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (this.mProximityWakeLock == null) {
|
||||
this.mProximityWakeLock =
|
||||
powerManager.newWakeLock(
|
||||
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, PROXIMITY_WAKE_LOCK_TAG);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseProximityWakeLock() {
|
||||
if (this.mProximityWakeLock != null && mProximityWakeLock.isHeld()) {
|
||||
Log.d(Config.LOGTAG, "releasing proximity wake lock");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
this.mProximityWakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
|
||||
} else {
|
||||
this.mProximityWakeLock.release();
|
||||
}
|
||||
this.mProximityWakeLock = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void putProximityWakeLockInProperState(
|
||||
final AppRTCAudioManager.AudioDevice audioDevice) {
|
||||
private void putProximityWakeLockInProperState(final AppRTCAudioManager.AudioDevice audioDevice) {
|
||||
if (audioDevice == AppRTCAudioManager.AudioDevice.EARPIECE) {
|
||||
acquireProximityWakeLock();
|
||||
} else {
|
||||
|
@ -357,7 +320,9 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void refreshUiReal() {}
|
||||
protected void refreshUiReal() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIntent(final Intent intent) {
|
||||
|
@ -365,9 +330,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
if (xmppConnectionService == null) {
|
||||
Log.d(
|
||||
Config.LOGTAG,
|
||||
"RtpSessionActivity: background service wasn't bound in onNewIntent()");
|
||||
Log.d(Config.LOGTAG, "RtpSessionActivity: background service wasn't bound in onNewIntent()");
|
||||
return;
|
||||
}
|
||||
final Account account = extractAccount(intent);
|
||||
|
@ -425,8 +388,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
binding.with.setText(account.getRoster().getContact(with).getDisplayName());
|
||||
} else if (Intent.ACTION_VIEW.equals(action)) {
|
||||
final String extraLastState = intent.getStringExtra(EXTRA_LAST_REPORTED_STATE);
|
||||
final RtpEndUserState state =
|
||||
extraLastState == null ? null : RtpEndUserState.valueOf(extraLastState);
|
||||
final RtpEndUserState state = extraLastState == null ? null : RtpEndUserState.valueOf(extraLastState);
|
||||
if (state != null) {
|
||||
Log.d(Config.LOGTAG, "restored last state from intent extra");
|
||||
updateButtonConfiguration(state);
|
||||
|
@ -436,15 +398,10 @@ public class RtpSessionActivity extends XmppActivity
|
|||
invalidateOptionsMenu();
|
||||
}
|
||||
binding.with.setText(account.getRoster().getContact(with).getDisplayName());
|
||||
if (xmppConnectionService
|
||||
.getJingleConnectionManager()
|
||||
.fireJingleRtpConnectionStateUpdates()) {
|
||||
if (xmppConnectionService.getJingleConnectionManager().fireJingleRtpConnectionStateUpdates()) {
|
||||
return;
|
||||
}
|
||||
if (END_CARD.contains(state)
|
||||
|| xmppConnectionService
|
||||
.getJingleConnectionManager()
|
||||
.hasMatchingProposal(account, with)) {
|
||||
if (END_CARD.contains(state) || xmppConnectionService.getJingleConnectionManager().hasMatchingProposal(account, with)) {
|
||||
return;
|
||||
}
|
||||
Log.d(Config.LOGTAG, "restored state (" + state + ") was not an end card. finishing");
|
||||
|
@ -452,18 +409,12 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void proposeJingleRtpSession(
|
||||
final Account account, final Jid with, final Set<Media> media) {
|
||||
checkMicrophoneAvailabilityAsync();
|
||||
private void proposeJingleRtpSession(final Account account, final Jid with, final Set<Media> media) {
|
||||
checkMicrophoneAvailability();
|
||||
if (with.isBareJid()) {
|
||||
xmppConnectionService
|
||||
.getJingleConnectionManager()
|
||||
.proposeJingleRtpSession(account, with, media);
|
||||
xmppConnectionService.getJingleConnectionManager().proposeJingleRtpSession(account, with, media);
|
||||
} else {
|
||||
final String sessionId =
|
||||
xmppConnectionService
|
||||
.getJingleConnectionManager()
|
||||
.initializeRtpSession(account, with, media);
|
||||
final String sessionId = xmppConnectionService.getJingleConnectionManager().initializeRtpSession(account, with, media);
|
||||
initializeActivityWithRunningRtpSession(account, with, sessionId);
|
||||
resetIntent(account, with, sessionId);
|
||||
}
|
||||
|
@ -471,8 +422,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(
|
||||
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
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) {
|
||||
|
@ -488,8 +438,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
} else {
|
||||
throw new IllegalStateException("Invalid permission result request");
|
||||
}
|
||||
ToastCompat.makeText(this, getString(res, getString(R.string.app_name)), ToastCompat.LENGTH_SHORT)
|
||||
.show();
|
||||
ToastCompat.makeText(this, getString(res, getString(R.string.app_name)), ToastCompat.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -497,18 +446,15 @@ public class RtpSessionActivity extends XmppActivity
|
|||
public void onStart() {
|
||||
super.onStart();
|
||||
mHandler.postDelayed(mTickExecutor, CALL_DURATION_UPDATE_INTERVAL);
|
||||
this.binding.remoteVideo.setOnAspectRatioChanged(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mHandler.removeCallbacks(mTickExecutor);
|
||||
binding.remoteVideo.release();
|
||||
binding.remoteVideo.setOnAspectRatioChanged(null);
|
||||
binding.localVideo.release();
|
||||
final WeakReference<JingleRtpConnection> weakReference = this.rtpConnectionReference;
|
||||
final JingleRtpConnection jingleRtpConnection =
|
||||
weakReference == null ? null : weakReference.get();
|
||||
final JingleRtpConnection jingleRtpConnection = weakReference == null ? null : weakReference.get();
|
||||
if (jingleRtpConnection != null) {
|
||||
releaseVideoTracks(jingleRtpConnection);
|
||||
}
|
||||
|
@ -534,10 +480,11 @@ public class RtpSessionActivity extends XmppActivity
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
endCall();
|
||||
}
|
||||
if (shouldAllowBack) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserLeaveHint() {
|
||||
|
@ -545,18 +492,15 @@ public class RtpSessionActivity extends XmppActivity
|
|||
if (switchToPictureInPicture()) {
|
||||
return;
|
||||
}
|
||||
// TODO apparently this method is not getting called on Android 10 when using the task
|
||||
// switcher
|
||||
//TODO apparently this method is not getting called on Android 10 when using the task switcher
|
||||
if (emptyReference(rtpConnectionReference) && xmppConnectionService != null) {
|
||||
retractSessionProposal();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isConnected() {
|
||||
final JingleRtpConnection connection =
|
||||
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
return connection != null
|
||||
&& STATES_CONSIDERED_CONNECTED.contains(connection.getEndUserState());
|
||||
final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
return connection != null && connection.getEndUserState() == RtpEndUserState.CONNECTED;
|
||||
}
|
||||
|
||||
private boolean switchToPictureInPicture() {
|
||||
|
@ -572,34 +516,17 @@ public class RtpSessionActivity extends XmppActivity
|
|||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private void startPictureInPicture() {
|
||||
try {
|
||||
final Rational rational = this.binding.remoteVideo.getAspectRatio();
|
||||
final Rational clippedRational = Rationals.clip(rational);
|
||||
Log.d(
|
||||
Config.LOGTAG,
|
||||
"suggested rational " + rational + ". clipped to " + clippedRational);
|
||||
enterPictureInPictureMode(
|
||||
new PictureInPictureParams.Builder().setAspectRatio(clippedRational).build());
|
||||
new PictureInPictureParams.Builder()
|
||||
.setAspectRatio(new Rational(10, 16))
|
||||
.build()
|
||||
);
|
||||
} catch (final IllegalStateException e) {
|
||||
//this sometimes happens on Samsung phones (possibly when Knox is enabled)
|
||||
Log.w(Config.LOGTAG, "unable to enter picture in picture mode", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAspectRatioChanged(final Rational rational) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isPictureInPicture()) {
|
||||
final Rational clippedRational = Rationals.clip(rational);
|
||||
Log.d(
|
||||
Config.LOGTAG,
|
||||
"suggested rational after aspect ratio change "
|
||||
+ rational
|
||||
+ ". clipped to "
|
||||
+ clippedRational);
|
||||
setPictureInPictureParams(
|
||||
new PictureInPictureParams.Builder().setAspectRatio(clippedRational).build());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean deviceSupportsPictureInPicture() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
|
||||
|
@ -611,31 +538,24 @@ public class RtpSessionActivity extends XmppActivity
|
|||
private boolean shouldBePictureInPicture() {
|
||||
try {
|
||||
final JingleRtpConnection rtpConnection = requireRtpConnection();
|
||||
return rtpConnection.getMedia().contains(Media.VIDEO)
|
||||
&& Arrays.asList(
|
||||
return rtpConnection.getMedia().contains(Media.VIDEO) && Arrays.asList(
|
||||
RtpEndUserState.ACCEPTING_CALL,
|
||||
RtpEndUserState.CONNECTING,
|
||||
RtpEndUserState.CONNECTED)
|
||||
.contains(rtpConnection.getEndUserState());
|
||||
RtpEndUserState.CONNECTED
|
||||
).contains(rtpConnection.getEndUserState());
|
||||
} catch (final IllegalStateException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean initializeActivityWithRunningRtpSession(
|
||||
final Account account, Jid with, String sessionId) {
|
||||
final WeakReference<JingleRtpConnection> reference =
|
||||
xmppConnectionService
|
||||
.getJingleConnectionManager()
|
||||
private boolean initializeActivityWithRunningRtpSession(final Account account, Jid with, String sessionId) {
|
||||
final WeakReference<JingleRtpConnection> reference = xmppConnectionService.getJingleConnectionManager()
|
||||
.findJingleRtpConnection(account, with, sessionId);
|
||||
if (reference == null || reference.get() == null) {
|
||||
final JingleConnectionManager.TerminatedRtpSession terminatedRtpSession =
|
||||
xmppConnectionService
|
||||
.getJingleConnectionManager()
|
||||
.getTerminalSessionState(with, sessionId);
|
||||
final JingleConnectionManager.TerminatedRtpSession terminatedRtpSession = xmppConnectionService
|
||||
.getJingleConnectionManager().getTerminalSessionState(with, sessionId);
|
||||
if (terminatedRtpSession == null) {
|
||||
throw new IllegalStateException(
|
||||
"failed to initialize activity with running rtp session. session not found");
|
||||
throw new IllegalStateException("failed to initialize activity with running rtp session. session not found");
|
||||
}
|
||||
initializeWithTerminatedSessionState(account, with, terminatedRtpSession);
|
||||
return true;
|
||||
|
@ -644,6 +564,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
final RtpEndUserState currentState = requireRtpConnection().getEndUserState();
|
||||
final boolean verified = requireRtpConnection().isVerified();
|
||||
if (currentState == RtpEndUserState.ENDED) {
|
||||
reference.get().throwStateTransitionException();
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
@ -651,8 +572,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
if (currentState == RtpEndUserState.INCOMING_CALL) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
if (JingleRtpConnection.STATES_SHOWING_ONGOING_CALL.contains(
|
||||
requireRtpConnection().getState())) {
|
||||
if (JingleRtpConnection.STATES_SHOWING_ONGOING_CALL.contains(requireRtpConnection().getState())) {
|
||||
putScreenInCallMode();
|
||||
}
|
||||
binding.with.setText(getWith().getDisplayName());
|
||||
|
@ -665,10 +585,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
return false;
|
||||
}
|
||||
|
||||
private void initializeWithTerminatedSessionState(
|
||||
final Account account,
|
||||
final Jid with,
|
||||
final JingleConnectionManager.TerminatedRtpSession terminatedRtpSession) {
|
||||
private void initializeWithTerminatedSessionState(final Account account, final Jid with, final JingleConnectionManager.TerminatedRtpSession terminatedRtpSession) {
|
||||
Log.d(Config.LOGTAG, "initializeWithTerminatedSessionState()");
|
||||
if (terminatedRtpSession.state == RtpEndUserState.ENDED) {
|
||||
finish();
|
||||
|
@ -685,8 +602,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
binding.with.setText(account.getRoster().getContact(with).getDisplayName());
|
||||
}
|
||||
|
||||
private void reInitializeActivityWithRunningRtpSession(
|
||||
final Account account, Jid with, String sessionId) {
|
||||
private void reInitializeActivityWithRunningRtpSession(final Account account, Jid with, String sessionId) {
|
||||
runOnUiThread(() -> initializeActivityWithRunningRtpSession(account, with, sessionId));
|
||||
resetIntent(account, with, sessionId);
|
||||
}
|
||||
|
@ -703,8 +619,8 @@ public class RtpSessionActivity extends XmppActivity
|
|||
surfaceViewRenderer.setVisibility(View.VISIBLE);
|
||||
try {
|
||||
surfaceViewRenderer.init(requireRtpConnection().getEglBaseContext(), null);
|
||||
} catch (final IllegalStateException e) {
|
||||
// Log.d(Config.LOGTAG, "SurfaceViewRenderer was already initialized");
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(Config.LOGTAG, "SurfaceViewRenderer was already initialized");
|
||||
}
|
||||
surfaceViewRenderer.setEnableHardwareScaler(true);
|
||||
}
|
||||
|
@ -716,6 +632,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
private void updateStateDisplay(final RtpEndUserState state, final Set<Media> media) {
|
||||
switch (state) {
|
||||
case INCOMING_CALL:
|
||||
shouldAllowBack = false;
|
||||
Preconditions.checkArgument(media.size() > 0, "Media must not be empty");
|
||||
if (media.contains(Media.VIDEO)) {
|
||||
setTitle(R.string.rtp_state_incoming_video_call);
|
||||
|
@ -724,50 +641,56 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
break;
|
||||
case CONNECTING:
|
||||
shouldAllowBack = false;
|
||||
setTitle(R.string.rtp_state_connecting);
|
||||
break;
|
||||
case CONNECTED:
|
||||
shouldAllowBack = false;
|
||||
setTitle(R.string.rtp_state_connected);
|
||||
break;
|
||||
case RECONNECTING:
|
||||
setTitle(R.string.rtp_state_reconnecting);
|
||||
break;
|
||||
case ACCEPTING_CALL:
|
||||
shouldAllowBack = false;
|
||||
setTitle(R.string.rtp_state_accepting_call);
|
||||
break;
|
||||
case ENDING_CALL:
|
||||
shouldAllowBack = false;
|
||||
setTitle(R.string.rtp_state_ending_call);
|
||||
break;
|
||||
case FINDING_DEVICE:
|
||||
shouldAllowBack = false;
|
||||
setTitle(R.string.rtp_state_finding_device);
|
||||
break;
|
||||
case RINGING:
|
||||
shouldAllowBack = false;
|
||||
setTitle(R.string.rtp_state_ringing);
|
||||
break;
|
||||
case DECLINED_OR_BUSY:
|
||||
shouldAllowBack = true;
|
||||
setTitle(R.string.rtp_state_declined_or_busy);
|
||||
break;
|
||||
case CONNECTIVITY_ERROR:
|
||||
shouldAllowBack = true;
|
||||
setTitle(R.string.rtp_state_connectivity_error);
|
||||
break;
|
||||
case CONNECTIVITY_LOST_ERROR:
|
||||
setTitle(R.string.rtp_state_connectivity_lost_error);
|
||||
break;
|
||||
case RETRACTED:
|
||||
shouldAllowBack = false;
|
||||
setTitle(R.string.rtp_state_retracted);
|
||||
break;
|
||||
case APPLICATION_ERROR:
|
||||
shouldAllowBack = true;
|
||||
setTitle(R.string.rtp_state_application_failure);
|
||||
break;
|
||||
case SECURITY_ERROR:
|
||||
setTitle(R.string.rtp_state_security_error);
|
||||
break;
|
||||
case ENDED:
|
||||
throw new IllegalStateException(
|
||||
"Activity should have called finishAndReleaseWakeLock();");
|
||||
shouldAllowBack = true;
|
||||
throw new IllegalStateException("Activity should have called finishAndReleaseWakeLock();");
|
||||
default:
|
||||
throw new IllegalStateException(
|
||||
String.format("State %s has not been handled in UI", state));
|
||||
throw new IllegalStateException(String.format("State %s has not been handled in UI", state));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -789,11 +712,9 @@ public class RtpSessionActivity extends XmppActivity
|
|||
if (show) {
|
||||
binding.contactPhoto.setVisibility(View.VISIBLE);
|
||||
if (contact == null) {
|
||||
AvatarWorkerTask.loadAvatar(
|
||||
getWith(), binding.contactPhoto, R.dimen.publish_avatar_size);
|
||||
AvatarWorkerTask.loadAvatar(getWith(), binding.contactPhoto, R.dimen.publish_avatar_size);
|
||||
} else {
|
||||
AvatarWorkerTask.loadAvatar(
|
||||
contact, binding.contactPhoto, R.dimen.publish_avatar_size);
|
||||
AvatarWorkerTask.loadAvatar(contact, binding.contactPhoto, R.dimen.publish_avatar_size);
|
||||
}
|
||||
} else {
|
||||
binding.contactPhoto.setVisibility(View.GONE);
|
||||
|
@ -842,8 +763,8 @@ public class RtpSessionActivity extends XmppActivity
|
|||
RtpEndUserState.CONNECTIVITY_LOST_ERROR,
|
||||
RtpEndUserState.APPLICATION_ERROR,
|
||||
RtpEndUserState.RETRACTED,
|
||||
RtpEndUserState.SECURITY_ERROR)
|
||||
.contains(state)) {
|
||||
RtpEndUserState.SECURITY_ERROR
|
||||
).contains(state)) {
|
||||
this.binding.rejectCall.setContentDescription(getString(R.string.exit));
|
||||
this.binding.rejectCall.setOnClickListener(this::exit);
|
||||
this.binding.rejectCall.setImageResource(R.drawable.ic_clear_white_48dp);
|
||||
|
@ -873,29 +794,26 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
private void updateInCallButtonConfiguration() {
|
||||
updateInCallButtonConfiguration(
|
||||
requireRtpConnection().getEndUserState(), requireRtpConnection().getMedia());
|
||||
updateInCallButtonConfiguration(requireRtpConnection().getEndUserState(), requireRtpConnection().getMedia());
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
private void updateInCallButtonConfiguration(
|
||||
final RtpEndUserState state, final Set<Media> media) {
|
||||
if (STATES_CONSIDERED_CONNECTED.contains(state) && !isPictureInPicture()) {
|
||||
private void updateInCallButtonConfiguration(final RtpEndUserState state, final Set<Media> media) {
|
||||
if (state == RtpEndUserState.CONNECTED && !isPictureInPicture()) {
|
||||
Preconditions.checkArgument(media.size() > 0, "Media must not be empty");
|
||||
if (media.contains(Media.VIDEO)) {
|
||||
final JingleRtpConnection rtpConnection = requireRtpConnection();
|
||||
updateInCallButtonConfigurationVideo(
|
||||
rtpConnection.isVideoEnabled(), rtpConnection.isCameraSwitchable());
|
||||
updateInCallButtonConfigurationVideo(rtpConnection.isVideoEnabled(), rtpConnection.isCameraSwitchable());
|
||||
} else {
|
||||
final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager();
|
||||
updateInCallButtonConfigurationSpeaker(
|
||||
audioManager.getSelectedAudioDevice(),
|
||||
audioManager.getAudioDevices().size());
|
||||
audioManager.getAudioDevices().size()
|
||||
);
|
||||
this.binding.inCallActionFarRight.setVisibility(View.GONE);
|
||||
}
|
||||
if (media.contains(Media.AUDIO)) {
|
||||
updateInCallButtonConfigurationMicrophone(
|
||||
requireRtpConnection().isMicrophoneEnabled());
|
||||
updateInCallButtonConfigurationMicrophone(requireRtpConnection().isMicrophoneEnabled());
|
||||
} else {
|
||||
this.binding.inCallActionLeft.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -907,12 +825,10 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
private void updateInCallButtonConfigurationSpeaker(
|
||||
final AppRTCAudioManager.AudioDevice selectedAudioDevice, final int numberOfChoices) {
|
||||
private void updateInCallButtonConfigurationSpeaker(final AppRTCAudioManager.AudioDevice selectedAudioDevice, final int numberOfChoices) {
|
||||
switch (selectedAudioDevice) {
|
||||
case EARPIECE:
|
||||
this.binding.inCallActionRight.setImageResource(
|
||||
R.drawable.ic_volume_off_black_24dp);
|
||||
this.binding.inCallActionRight.setImageResource(R.drawable.ic_volume_off_black_24dp);
|
||||
if (numberOfChoices >= 2) {
|
||||
this.binding.inCallActionRight.setOnClickListener(this::switchToSpeaker);
|
||||
} else {
|
||||
|
@ -935,8 +851,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
break;
|
||||
case BLUETOOTH:
|
||||
this.binding.inCallActionRight.setImageResource(
|
||||
R.drawable.ic_bluetooth_audio_black_24dp);
|
||||
this.binding.inCallActionRight.setImageResource(R.drawable.ic_bluetooth_audio_black_24dp);
|
||||
this.binding.inCallActionRight.setOnClickListener(null);
|
||||
this.binding.inCallActionRight.setClickable(false);
|
||||
break;
|
||||
|
@ -945,12 +860,10 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
private void updateInCallButtonConfigurationVideo(
|
||||
final boolean videoEnabled, final boolean isCameraSwitchable) {
|
||||
private void updateInCallButtonConfigurationVideo(final boolean videoEnabled, final boolean isCameraSwitchable) {
|
||||
this.binding.inCallActionRight.setVisibility(View.VISIBLE);
|
||||
if (isCameraSwitchable) {
|
||||
this.binding.inCallActionFarRight.setImageResource(
|
||||
R.drawable.ic_flip_camera_android_black_24dp);
|
||||
this.binding.inCallActionFarRight.setImageResource(R.drawable.ic_flip_camera_android_black_24dp);
|
||||
this.binding.inCallActionFarRight.setVisibility(View.VISIBLE);
|
||||
this.binding.inCallActionFarRight.setOnClickListener(this::switchCamera);
|
||||
} else {
|
||||
|
@ -966,9 +879,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
private void switchCamera(final View view) {
|
||||
Futures.addCallback(
|
||||
requireRtpConnection().switchCamera(),
|
||||
new FutureCallback<Boolean>() {
|
||||
Futures.addCallback(requireRtpConnection().switchCamera(), new FutureCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(@NullableDecl Boolean isFrontCamera) {
|
||||
binding.localVideo.setMirror(isFrontCamera);
|
||||
|
@ -976,18 +887,10 @@ public class RtpSessionActivity extends XmppActivity
|
|||
|
||||
@Override
|
||||
public void onFailure(@NonNull final Throwable throwable) {
|
||||
Log.d(
|
||||
Config.LOGTAG,
|
||||
"could not switch camera",
|
||||
Throwables.getRootCause(throwable));
|
||||
ToastCompat.makeText(
|
||||
RtpSessionActivity.this,
|
||||
R.string.could_not_switch_camera,
|
||||
ToastCompat.LENGTH_LONG)
|
||||
.show();
|
||||
Log.d(Config.LOGTAG, "could not switch camera", Throwables.getRootCause(throwable));
|
||||
ToastCompat.makeText(RtpSessionActivity.this, R.string.could_not_switch_camera, ToastCompat.LENGTH_LONG).show();
|
||||
}
|
||||
},
|
||||
MainThreadExecutor.getInstance());
|
||||
}, MainThreadExecutor.getInstance());
|
||||
}
|
||||
|
||||
private void enableVideo(View view) {
|
||||
|
@ -1003,6 +906,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
private void disableVideo(View view) {
|
||||
requireRtpConnection().setVideoEnabled(false);
|
||||
updateInCallButtonConfigurationVideo(false, requireRtpConnection().isCameraSwitchable());
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
|
@ -1018,18 +922,19 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
private void updateCallDuration() {
|
||||
final JingleRtpConnection connection =
|
||||
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
if (connection == null || connection.getMedia().contains(Media.VIDEO)) {
|
||||
this.binding.duration.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
if (connection.zeroDuration()) {
|
||||
this.binding.duration.setVisibility(View.GONE);
|
||||
} else {
|
||||
this.binding.duration.setText(
|
||||
TimeFrameUtils.formatElapsedTime(connection.getCallDuration(), false));
|
||||
final long rtpConnectionStarted = connection.getRtpConnectionStarted();
|
||||
final long rtpConnectionEnded = connection.getRtpConnectionEnded();
|
||||
if (rtpConnectionStarted != 0) {
|
||||
final long ended = rtpConnectionEnded == 0 ? SystemClock.elapsedRealtime() : rtpConnectionEnded;
|
||||
this.binding.duration.setText(TimeFrameUtils.formatTimePassed(rtpConnectionStarted, ended, false));
|
||||
this.binding.duration.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
this.binding.duration.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1037,17 +942,17 @@ public class RtpSessionActivity extends XmppActivity
|
|||
if (END_CARD.contains(state) || state == RtpEndUserState.ENDING_CALL) {
|
||||
binding.localVideo.setVisibility(View.GONE);
|
||||
binding.localVideo.release();
|
||||
binding.remoteVideoWrapper.setVisibility(View.GONE);
|
||||
binding.remoteVideo.setVisibility(View.GONE);
|
||||
binding.remoteVideo.release();
|
||||
binding.pipLocalMicOffIndicator.setVisibility(View.GONE);
|
||||
if (isPictureInPicture()) {
|
||||
binding.appBarLayout.setVisibility(View.GONE);
|
||||
binding.pipPlaceholder.setVisibility(View.VISIBLE);
|
||||
if (Arrays.asList(
|
||||
RtpEndUserState.APPLICATION_ERROR,
|
||||
RtpEndUserState.CONNECTIVITY_ERROR,
|
||||
RtpEndUserState.SECURITY_ERROR)
|
||||
.contains(state)) {
|
||||
binding.appBarLayout.setVisibility(View.GONE);
|
||||
binding.pipPlaceholder.setVisibility(View.VISIBLE);
|
||||
binding.pipWarning.setVisibility(View.VISIBLE);
|
||||
binding.pipWaiting.setVisibility(View.GONE);
|
||||
} else {
|
||||
|
@ -1061,9 +966,9 @@ public class RtpSessionActivity extends XmppActivity
|
|||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
return;
|
||||
}
|
||||
if (isPictureInPicture() && STATES_SHOWING_PIP_PLACEHOLDER.contains(state)) {
|
||||
if (isPictureInPicture() && (state == RtpEndUserState.CONNECTING || state == RtpEndUserState.ACCEPTING_CALL)) {
|
||||
binding.localVideo.setVisibility(View.GONE);
|
||||
binding.remoteVideoWrapper.setVisibility(View.GONE);
|
||||
binding.remoteVideo.setVisibility(View.GONE);
|
||||
binding.appBarLayout.setVisibility(View.GONE);
|
||||
binding.pipPlaceholder.setVisibility(View.VISIBLE);
|
||||
binding.pipWarning.setVisibility(View.GONE);
|
||||
|
@ -1085,17 +990,12 @@ public class RtpSessionActivity extends XmppActivity
|
|||
if (remoteVideoTrack.isPresent()) {
|
||||
ensureSurfaceViewRendererIsSetup(binding.remoteVideo);
|
||||
addSink(remoteVideoTrack.get(), binding.remoteVideo);
|
||||
binding.remoteVideo.setScalingType(
|
||||
RendererCommon.ScalingType.SCALE_ASPECT_FILL,
|
||||
RendererCommon.ScalingType.SCALE_ASPECT_FIT);
|
||||
if (state == RtpEndUserState.CONNECTED) {
|
||||
binding.appBarLayout.setVisibility(View.GONE);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
binding.remoteVideoWrapper.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
binding.appBarLayout.setVisibility(View.VISIBLE);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
binding.remoteVideoWrapper.setVisibility(View.GONE);
|
||||
binding.remoteVideo.setVisibility(View.GONE);
|
||||
}
|
||||
if (isPictureInPicture() && !requireRtpConnection().isMicrophoneEnabled()) {
|
||||
binding.pipLocalMicOffIndicator.setVisibility(View.VISIBLE);
|
||||
|
@ -1104,14 +1004,13 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
} else {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
binding.remoteVideoWrapper.setVisibility(View.GONE);
|
||||
binding.remoteVideo.setVisibility(View.GONE);
|
||||
binding.pipLocalMicOffIndicator.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<VideoTrack> getLocalVideoTrack() {
|
||||
final JingleRtpConnection connection =
|
||||
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
if (connection == null) {
|
||||
return Optional.absent();
|
||||
}
|
||||
|
@ -1119,8 +1018,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
private Optional<VideoTrack> getRemoteVideoTrack() {
|
||||
final JingleRtpConnection connection =
|
||||
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
if (connection == null) {
|
||||
return Optional.absent();
|
||||
}
|
||||
|
@ -1142,16 +1040,12 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
private void switchToEarpiece(View view) {
|
||||
requireRtpConnection()
|
||||
.getAudioManager()
|
||||
.setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.EARPIECE);
|
||||
requireRtpConnection().getAudioManager().setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.EARPIECE);
|
||||
acquireProximityWakeLock();
|
||||
}
|
||||
|
||||
private void switchToSpeaker(View view) {
|
||||
requireRtpConnection()
|
||||
.getAudioManager()
|
||||
.setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE);
|
||||
requireRtpConnection().getAudioManager().setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE);
|
||||
releaseProximityWakeLock();
|
||||
}
|
||||
|
||||
|
@ -1175,15 +1069,12 @@ public class RtpSessionActivity extends XmppActivity
|
|||
final Intent intent = getIntent();
|
||||
final Account account = extractAccount(intent);
|
||||
final Jid with = Jid.ofEscaped(intent.getStringExtra(EXTRA_WITH));
|
||||
final Conversation conversation =
|
||||
xmppConnectionService.findOrCreateConversation(account, with, false, true);
|
||||
final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, with, false, true);
|
||||
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);
|
||||
launchIntent.putExtra(
|
||||
ConversationsActivity.EXTRA_POST_INIT_ACTION,
|
||||
ConversationsActivity.POST_ACTION_RECORD_VOICE);
|
||||
launchIntent.putExtra(ConversationsActivity.EXTRA_POST_INIT_ACTION, ConversationsActivity.POST_ACTION_RECORD_VOICE);
|
||||
startActivity(launchIntent);
|
||||
finish();
|
||||
}
|
||||
|
@ -1195,8 +1086,7 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
private JingleRtpConnection requireRtpConnection() {
|
||||
final JingleRtpConnection connection =
|
||||
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||
if (connection == null) {
|
||||
throw new IllegalStateException("No RTP connection found");
|
||||
}
|
||||
|
@ -1204,14 +1094,12 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onJingleRtpConnectionUpdate(
|
||||
Account account, Jid with, final String sessionId, RtpEndUserState state) {
|
||||
public void onJingleRtpConnectionUpdate(Account account, Jid with, final String sessionId, RtpEndUserState state) {
|
||||
Log.d(Config.LOGTAG, "onJingleRtpConnectionUpdate(" + state + ")");
|
||||
if (END_CARD.contains(state)) {
|
||||
Log.d(Config.LOGTAG, "end card reached");
|
||||
releaseProximityWakeLock();
|
||||
runOnUiThread(
|
||||
() -> getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON));
|
||||
runOnUiThread(() -> getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON));
|
||||
}
|
||||
if (with.isBareJid()) {
|
||||
updateRtpSessionProposalState(account, with, state);
|
||||
|
@ -1235,11 +1123,9 @@ public class RtpSessionActivity extends XmppActivity
|
|||
finish();
|
||||
return;
|
||||
}
|
||||
runOnUiThread(
|
||||
() -> {
|
||||
runOnUiThread(() -> {
|
||||
updateStateDisplay(state, media);
|
||||
updateVerifiedShield(
|
||||
verified && STATES_SHOWING_SWITCH_TO_CHAT.contains(state));
|
||||
updateVerifiedShield(verified && STATES_SHOWING_SWITCH_TO_CHAT.contains(state));
|
||||
updateButtonConfiguration(state, media);
|
||||
updateVideoViews(state);
|
||||
updateProfilePicture(state, contact);
|
||||
|
@ -1257,15 +1143,8 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAudioDeviceChanged(
|
||||
AppRTCAudioManager.AudioDevice selectedAudioDevice,
|
||||
Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
|
||||
Log.d(
|
||||
Config.LOGTAG,
|
||||
"onAudioDeviceChanged in activity: selected:"
|
||||
+ selectedAudioDevice
|
||||
+ ", available:"
|
||||
+ availableAudioDevices);
|
||||
public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
|
||||
Log.d(Config.LOGTAG, "onAudioDeviceChanged in activity: selected:" + selectedAudioDevice + ", available:" + availableAudioDevices);
|
||||
try {
|
||||
if (getMedia().contains(Media.VIDEO)) {
|
||||
Log.d(Config.LOGTAG, "nothing to do; in video mode");
|
||||
|
@ -1276,11 +1155,10 @@ public class RtpSessionActivity extends XmppActivity
|
|||
final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager();
|
||||
updateInCallButtonConfigurationSpeaker(
|
||||
audioManager.getSelectedAudioDevice(),
|
||||
audioManager.getAudioDevices().size());
|
||||
audioManager.getAudioDevices().size()
|
||||
);
|
||||
} else if (END_CARD.contains(endUserState)) {
|
||||
Log.d(
|
||||
Config.LOGTAG,
|
||||
"onAudioDeviceChanged() nothing to do because end card has been reached");
|
||||
Log.d(Config.LOGTAG, "onAudioDeviceChanged() nothing to do because end card has been reached");
|
||||
} else {
|
||||
putProximityWakeLockInProperState(selectedAudioDevice);
|
||||
}
|
||||
|
@ -1289,17 +1167,14 @@ public class RtpSessionActivity extends XmppActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void updateRtpSessionProposalState(
|
||||
final Account account, final Jid with, final RtpEndUserState state) {
|
||||
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);
|
||||
final String withExtra = currentIntent == null ? null : currentIntent.getStringExtra(EXTRA_WITH);
|
||||
if (withExtra == null) {
|
||||
return;
|
||||
}
|
||||
if (Jid.ofEscaped(withExtra).asBareJid().equals(with)) {
|
||||
runOnUiThread(
|
||||
() -> {
|
||||
runOnUiThread(() -> {
|
||||
updateVerifiedShield(false);
|
||||
updateStateDisplay(state);
|
||||
updateButtonConfiguration(state);
|
||||
|
@ -1316,22 +1191,16 @@ public class RtpSessionActivity extends XmppActivity
|
|||
setIntent(intent);
|
||||
}
|
||||
|
||||
private void resetIntent(
|
||||
final Account account, Jid with, final RtpEndUserState state, final Set<Media> media) {
|
||||
private void resetIntent(final Account account, Jid with, final RtpEndUserState state, final Set<Media> media) {
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString());
|
||||
if (account.getRoster()
|
||||
.getContact(with)
|
||||
.getPresences()
|
||||
.anySupport(Namespace.JINGLE_MESSAGE)) {
|
||||
if (account.getRoster().getContact(with).getPresences().anySupport(Namespace.JINGLE_MESSAGE)) {
|
||||
intent.putExtra(EXTRA_WITH, with.asBareJid().toEscapedString());
|
||||
} else {
|
||||
intent.putExtra(EXTRA_WITH, with.toEscapedString());
|
||||
}
|
||||
intent.putExtra(EXTRA_LAST_REPORTED_STATE, state.toString());
|
||||
intent.putExtra(
|
||||
EXTRA_LAST_ACTION,
|
||||
media.contains(Media.VIDEO) ? ACTION_MAKE_VIDEO_CALL : ACTION_MAKE_VOICE_CALL);
|
||||
intent.putExtra(EXTRA_LAST_ACTION, media.contains(Media.VIDEO) ? ACTION_MAKE_VIDEO_CALL : ACTION_MAKE_VOICE_CALL);
|
||||
setIntent(intent);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ public enum RtpEndUserState {
|
|||
INCOMING_CALL, //received a 'propose' message
|
||||
CONNECTING, //session-initiate or session-accepted but no webrtc peer connection yet
|
||||
CONNECTED, //session-accepted and webrtc peer connection is connected
|
||||
RECONNECTING, //session-accepted and webrtc peer connection was connected once but is currently disconnected or failed
|
||||
FINDING_DEVICE, //'propose' has been sent out; no 184 ack yet
|
||||
RINGING, //'propose' has been sent out and it has been 184 acked
|
||||
ACCEPTING_CALL, //'proceed' message has been sent; but no session-initiate has been received
|
||||
|
|
Loading…
Add table
Reference in a new issue