request camera permissions

This commit is contained in:
Daniel Gultsch 2020-04-15 18:47:15 +02:00
parent 5a20faaf0f
commit 445009c558
3 changed files with 38 additions and 24 deletions

View File

@ -25,6 +25,7 @@ import org.webrtc.VideoTrack;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Set; import java.util.Set;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
@ -108,7 +109,13 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
} }
private void requestPermissionsAndAcceptCall() { private void requestPermissionsAndAcceptCall() {
if (PermissionUtils.hasPermission(this, ImmutableList.of(Manifest.permission.RECORD_AUDIO), REQUEST_ACCEPT_CALL)) { 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)) {
//TODO like wise the propose; we might just wait here for the audio manager to come up //TODO like wise the propose; we might just wait here for the audio manager to come up
putScreenInCallMode(); putScreenInCallMode();
requireRtpConnection().acceptCall(); requireRtpConnection().acceptCall();
@ -285,6 +292,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
putScreenInCallMode(); putScreenInCallMode();
} }
binding.with.setText(getWith().getDisplayName()); binding.with.setText(getWith().getDisplayName());
updateVideoViews();
updateStateDisplay(currentState); updateStateDisplay(currentState);
updateButtonConfiguration(currentState); updateButtonConfiguration(currentState);
} }
@ -300,26 +308,6 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
setIntent(intent); setIntent(intent);
} }
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);
}
}
private void ensureSurfaceViewRendererIsSetup(final SurfaceViewRenderer surfaceViewRenderer) { private void ensureSurfaceViewRendererIsSetup(final SurfaceViewRenderer surfaceViewRenderer) {
surfaceViewRenderer.setVisibility(View.VISIBLE); surfaceViewRenderer.setVisibility(View.VISIBLE);
try { try {
@ -477,6 +465,26 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
this.binding.inCallActionRight.setVisibility(View.VISIBLE); this.binding.inCallActionRight.setVisibility(View.VISIBLE);
} }
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);
}
}
private void disableMicrophone(View view) { private void disableMicrophone(View view) {
JingleRtpConnection rtpConnection = requireRtpConnection(); JingleRtpConnection rtpConnection = requireRtpConnection();
rtpConnection.setMicrophoneEnabled(false); rtpConnection.setMicrophoneEnabled(false);

View File

@ -820,7 +820,13 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
private void setupWebRTC(final Set<Media> media, final List<PeerConnection.IceServer> iceServers) throws WebRTCWrapper.InitializationException { private void setupWebRTC(final Set<Media> media, final List<PeerConnection.IceServer> iceServers) throws WebRTCWrapper.InitializationException {
this.webRTCWrapper.setup(this.xmppConnectionService); final AppRTCAudioManager.SpeakerPhonePreference speakerPhonePreference;
if (media.contains(Media.VIDEO)) {
speakerPhonePreference = AppRTCAudioManager.SpeakerPhonePreference.SPEAKER;
} else {
speakerPhonePreference = AppRTCAudioManager.SpeakerPhonePreference.EARPIECE;
}
this.webRTCWrapper.setup(this.xmppConnectionService, speakerPhonePreference);
this.webRTCWrapper.initializePeerConnection(media, iceServers); this.webRTCWrapper.initializePeerConnection(media, iceServers);
} }

View File

@ -145,14 +145,14 @@ public class WebRTCWrapper {
this.eventCallback = eventCallback; this.eventCallback = eventCallback;
} }
public void setup(final Context context) { public void setup(final Context context, final AppRTCAudioManager.SpeakerPhonePreference speakerPhonePreference) {
PeerConnectionFactory.initialize( PeerConnectionFactory.initialize(
PeerConnectionFactory.InitializationOptions.builder(context).createInitializationOptions() PeerConnectionFactory.InitializationOptions.builder(context).createInitializationOptions()
); );
this.eglBase = EglBase.create(); this.eglBase = EglBase.create();
this.context = context; this.context = context;
mainHandler.post(() -> { mainHandler.post(() -> {
appRTCAudioManager = AppRTCAudioManager.create(context, AppRTCAudioManager.SpeakerPhonePreference.EARPIECE); appRTCAudioManager = AppRTCAudioManager.create(context, speakerPhonePreference);
appRTCAudioManager.start(audioManagerEvents); appRTCAudioManager.start(audioManagerEvents);
eventCallback.onAudioDeviceChanged(appRTCAudioManager.getSelectedAudioDevice(), appRTCAudioManager.getAudioDevices()); eventCallback.onAudioDeviceChanged(appRTCAudioManager.getSelectedAudioDevice(), appRTCAudioManager.getAudioDevices());
}); });