diff --git a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt index 0c0ec6dff..4708f42e1 100644 --- a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt +++ b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt @@ -63,6 +63,7 @@ import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FROM_NOTIFICATION_START_CALL import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY import com.nextcloud.talk.utils.preferences.AppPreferences +import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder import io.reactivex.Observer import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers @@ -81,8 +82,11 @@ import javax.crypto.Cipher import javax.crypto.NoSuchPaddingException import javax.inject.Inject +@SuppressLint("LongLogTag") @AutoInjector(NextcloudTalkApplication::class) class MagicFirebaseMessagingService : FirebaseMessagingService() { + private val TAG = "MagicFirebaseMessagingService" + @JvmField @Inject var appPreferences: AppPreferences? = null @@ -112,11 +116,13 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() { @Subscribe(threadMode = ThreadMode.BACKGROUND) fun onMessageEvent(event: CallNotificationClick) { + Log.d(TAG, "CallNotification was clicked") isServiceInForeground = false stopForeground(true) } override fun onDestroy() { + Log.d(TAG, "onDestroy") isServiceInForeground = false eventBus?.unregister(this) stopForeground(true) @@ -128,12 +134,13 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() { super.onNewToken(token) sharedApplication!!.componentApplication.inject(this) appPreferences!!.pushToken = token + Log.d(TAG, "onNewToken. token = $token") val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() WorkManager.getInstance().enqueue(pushRegistrationWork) } - @SuppressLint("LongLogTag") override fun onMessageReceived(remoteMessage: RemoteMessage) { + Log.d(TAG, "onMessageReceived") sharedApplication!!.componentApplication.inject(this) if (!remoteMessage.data["subject"].isNullOrEmpty() && !remoteMessage.data["signature"].isNullOrEmpty()) { decryptMessage(remoteMessage.data["subject"]!!, remoteMessage.data["signature"]!!) @@ -160,6 +167,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() { DecryptedPushMessage::class.java ) decryptedPushMessage?.apply { + Log.d(TAG, this.toString()) timestamp = System.currentTimeMillis() if (delete) { cancelExistingNotificationWithId( @@ -296,6 +304,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() { signatureVerification: SignatureVerification, decryptedPushMessage: DecryptedPushMessage ) { + Log.d(TAG, "checkIfCallIsActive") val ncApi = retrofit!!.newBuilder() .client(okHttpClient!!.newBuilder().cookieJar(JavaNetCookieJar(CookieManager())).build()).build() .create(NcApi::class.java) @@ -336,6 +345,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() { } if (!hasParticipantsInCall || inCallOnDifferentDevice) { + Log.d(TAG, "no participants in call OR inCallOnDifferentDevice") stopForeground(true) handler.removeCallbacksAndMessages(null) } else if (isServiceInForeground) { diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index c55e63844..03c1deabb 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -1084,6 +1084,7 @@ public class CallActivity extends CallBaseActivity { } private void fetchSignalingSettings() { + Log.d(TAG, "fetchSignalingSettings"); int apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[]{ApiUtils.APIv3, 2, 1}); ncApi.getSignalingSettings(credentials, ApiUtils.getUrlForSignalingSettings(apiVersion, baseUrl)) @@ -1098,9 +1099,7 @@ public class CallActivity extends CallBaseActivity { @Override public void onNext(@io.reactivex.annotations.NonNull SignalingSettingsOverall signalingSettingsOverall) { - if (signalingSettingsOverall != null && signalingSettingsOverall.getOcs() != null && - signalingSettingsOverall.getOcs().getSettings() != null) { - + if (signalingSettingsOverall.getOcs() != null && signalingSettingsOverall.getOcs().getSettings() != null) { externalSignalingServer = new ExternalSignalingServer(); if (!TextUtils.isEmpty(signalingSettingsOverall.getOcs().getSettings().getExternalSignalingServer()) && @@ -1112,6 +1111,7 @@ public class CallActivity extends CallBaseActivity { } else { hasExternalSignalingServer = false; } + Log.d(TAG, " hasExternalSignalingServer: " + hasExternalSignalingServer); if (!conversationUser.getUserId().equals("?")) { try { @@ -1137,6 +1137,7 @@ public class CallActivity extends CallBaseActivity { for (IceServer stunServer : stunServers) { if (stunServer.getUrls() != null) { for (String url : stunServer.getUrls()) { + Log.d(TAG, " STUN server url: " + url); iceServers.add(new PeerConnection.IceServer(url)); } } @@ -1144,6 +1145,7 @@ public class CallActivity extends CallBaseActivity { } else { if (signalingSettingsOverall.getOcs().getSettings().getStunServers() != null) { for (IceServer stunServer : stunServers) { + Log.d(TAG, " STUN server url: " + stunServer.getUrl()); iceServers.add(new PeerConnection.IceServer(stunServer.getUrl())); } } @@ -1156,6 +1158,7 @@ public class CallActivity extends CallBaseActivity { for (IceServer turnServer : turnServers) { if (turnServer.getUrls() != null) { for (String url : turnServer.getUrls()) { + Log.d(TAG, " TURN server url: " + url); iceServers.add(new PeerConnection.IceServer( url, turnServer.getUsername(), turnServer.getCredential() )); @@ -1616,10 +1619,11 @@ public class CallActivity extends CallBaseActivity { private void processUsersInRoom(List> users) { List newSessions = new ArrayList<>(); - Set oldSesssions = new HashSet<>(); + Set oldSessions = new HashSet<>(); hasMCU = hasExternalSignalingServer && webSocketClient != null && webSocketClient.hasMCU(); + // The signaling session is the same as the Nextcloud session only when the MCU is not used. String currentSessiondId = callSession; if (hasMCU) { @@ -1639,22 +1643,22 @@ public class CallActivity extends CallBaseActivity { if (isNewSession) { newSessions.add(participant.get("sessionId").toString()); } else { - oldSesssions.add(participant.get("sessionId").toString()); + oldSessions.add(participant.get("sessionId").toString()); } } } for (MagicPeerConnectionWrapper magicPeerConnectionWrapper : magicPeerConnectionWrapperList) { if (!magicPeerConnectionWrapper.isMCUPublisher()) { - oldSesssions.add(magicPeerConnectionWrapper.getSessionId()); + oldSessions.add(magicPeerConnectionWrapper.getSessionId()); } } // Calculate sessions that left the call - oldSesssions.removeAll(newSessions); + oldSessions.removeAll(newSessions); // Calculate sessions that join the call - newSessions.removeAll(oldSesssions); + newSessions.removeAll(oldSessions); if (!isConnectionEstablished() && !currentCallStatus.equals(CallStatus.CONNECTING)) { return; @@ -1677,7 +1681,7 @@ public class CallActivity extends CallBaseActivity { setCallState(CallStatus.IN_CONVERSATION); } - for (String sessionId : oldSesssions) { + for (String sessionId : oldSessions) { endPeerConnection(sessionId, false); } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 3d066ab9c..0ed221e10 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -268,6 +268,8 @@ class ChatController(args: Bundle) : var currentlyPlayedVoiceMessage: ChatMessage? = null init { + Log.d(TAG, "init ChatController") + setHasOptionsMenu(true) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) @@ -276,7 +278,10 @@ class ChatController(args: Bundle) : this.roomToken = args.getString(KEY_ROOM_TOKEN, "") this.sharedText = args.getString(BundleKeys.KEY_SHARED_TEXT, "") - Log.d(TAG, "roomToken = " + roomToken) + Log.d(TAG, " roomToken = $roomToken") + if (roomToken.isNullOrEmpty()){ + Log.d(TAG, " roomToken was null or empty!") + } if (args.containsKey(KEY_ACTIVE_CONVERSATION)) { this.currentConversation = Parcels.unwrap(args.getParcelable(KEY_ACTIVE_CONVERSATION)) @@ -298,7 +303,6 @@ class ChatController(args: Bundle) : } private fun getRoomInfo() { - Log.d(TAG, "getRoomInfo") val shouldRepeat = CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "webinary-lobby") if (shouldRepeat) { checkingLobbyStatus = true @@ -318,8 +322,7 @@ class ChatController(args: Bundle) : @Suppress("Detekt.TooGenericExceptionCaught") override fun onNext(roomOverall: RoomOverall) { currentConversation = roomOverall.ocs.data - Log.d(TAG, "currentConversation.toString : " + currentConversation.toString()) - Log.d(TAG, "currentConversation.sessionId : " + currentConversation?.sessionId) + Log.d(TAG, "getRoomInfo. token: " + currentConversation?.getToken() + " sessionId: " + currentConversation?.sessionId) loadAvatarForStatusBar() setTitle() @@ -431,7 +434,6 @@ class ChatController(args: Bundle) : override fun onViewBound(view: View) { actionBar?.show() - Log.d(TAG, "onViewBound") var adapterWasNull = false if (adapter == null) { @@ -1487,6 +1489,7 @@ class ChatController(args: Bundle) : override fun onAttach(view: View) { super.onAttach(view) + Log.d(TAG, "onAttach") eventBus?.register(this) if (conversationUser?.userId != "?" && @@ -1537,6 +1540,7 @@ class ChatController(args: Bundle) : if (wasDetached) { currentConversation?.sessionId = "0" wasDetached = false + Log.d(TAG, "execute joinRoomWithPassword in onAttach") joinRoomWithPassword() } } @@ -1561,6 +1565,7 @@ class ChatController(args: Bundle) : override fun onDetach(view: View) { super.onDetach(view) + Log.d(TAG, "onDetach") eventBus?.unregister(this) if (activity != null) { @@ -1622,9 +1627,9 @@ class ChatController(args: Bundle) : private fun joinRoomWithPassword() { - if (currentConversation == null || TextUtils.isEmpty(currentConversation?.sessionId) || - currentConversation?.sessionId == "0" - ) { + if (currentConversation == null + || TextUtils.isEmpty(currentConversation?.sessionId) + || currentConversation?.sessionId == "0") { var apiVersion = 1 // FIXME Fix API checking with guests? if (conversationUser != null) { @@ -1704,6 +1709,7 @@ class ChatController(args: Bundle) : } private fun leaveRoom() { + Log.d(TAG, "leaveRoom") var apiVersion = 1 // FIXME Fix API checking with guests? if (conversationUser != null) { @@ -1737,6 +1743,8 @@ class ChatController(args: Bundle) : "", currentConversation?.sessionId ) + } else { + Log.e(TAG, "magicWebSocketInstance or currentConversation were null! Failed to leave the room!") } if (!isDestroyed && !isBeingDestroyed && !wasDetached) { @@ -1848,6 +1856,7 @@ class ChatController(args: Bundle) : magicWebSocketInstance = WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id) } else { + Log.d(TAG, "magicWebSocketInstance became null") magicWebSocketInstance = null } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index 7bc3ee1ea..413c8c72a 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -197,6 +197,9 @@ public class ApiUtils { } public static String getUrlForParticipants(int version, String baseUrl, String token) { + if (token == null || token.isEmpty()){ + Log.e(TAG, "token was null or empty"); + } return getUrlForRoom(version, baseUrl, token) + "/participants"; } diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java index 2b005db4e..300aee3a6 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java @@ -332,6 +332,9 @@ public class MagicWebSocketInstance extends WebSocketListener { } public void joinRoomWithRoomTokenAndSession(String roomToken, String normalBackendSession) { + Log.d(TAG, "joinRoomWithRoomTokenAndSession"); + Log.d(TAG, " roomToken: " + roomToken); + Log.d(TAG, " session: " + normalBackendSession); try { String message = LoganSquare.serialize(webSocketConnectionHelper.getAssembledJoinOrLeaveRoomModel(roomToken, normalBackendSession)); if (!connected || reconnecting) { diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java index 3ae978c30..5e52df862 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java @@ -20,6 +20,9 @@ package com.nextcloud.talk.webrtc; +import android.annotation.SuppressLint; +import android.util.Log; + import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.json.signaling.NCMessageWrapper; @@ -47,6 +50,7 @@ import okhttp3.OkHttpClient; @AutoInjector(NextcloudTalkApplication.class) public class WebSocketConnectionHelper { + public static final String TAG = "WebSocketConnectionHelper"; private static Map magicWebSocketInstanceMap = new HashMap<>(); @Inject @@ -57,11 +61,12 @@ public class WebSocketConnectionHelper { NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); } + @SuppressLint("LongLogTag") public static synchronized MagicWebSocketInstance getMagicWebSocketInstanceForUserId(long userId) { if (userId != -1 && magicWebSocketInstanceMap.containsKey(userId)) { return magicWebSocketInstanceMap.get(userId); } - + Log.d(TAG, "no magicWebSocketInstance found"); return null; }