Эх сурвалжийг харах

Merge pull request #1698 from nextcloud/addLoggingForCalls

add logging for calls
Marcel Hibbe 3 жил өмнө
parent
commit
3bc4c0c983

+ 11 - 1
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_FROM_NOTIFICATION_START_CALL
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
 import com.nextcloud.talk.utils.preferences.AppPreferences
 import com.nextcloud.talk.utils.preferences.AppPreferences
+import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder
 import io.reactivex.Observer
 import io.reactivex.Observer
 import io.reactivex.disposables.Disposable
 import io.reactivex.disposables.Disposable
 import io.reactivex.schedulers.Schedulers
 import io.reactivex.schedulers.Schedulers
@@ -81,8 +82,11 @@ import javax.crypto.Cipher
 import javax.crypto.NoSuchPaddingException
 import javax.crypto.NoSuchPaddingException
 import javax.inject.Inject
 import javax.inject.Inject
 
 
+@SuppressLint("LongLogTag")
 @AutoInjector(NextcloudTalkApplication::class)
 @AutoInjector(NextcloudTalkApplication::class)
 class MagicFirebaseMessagingService : FirebaseMessagingService() {
 class MagicFirebaseMessagingService : FirebaseMessagingService() {
+    private val TAG = "MagicFirebaseMessagingService"
+
     @JvmField
     @JvmField
     @Inject
     @Inject
     var appPreferences: AppPreferences? = null
     var appPreferences: AppPreferences? = null
@@ -112,11 +116,13 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
 
 
     @Subscribe(threadMode = ThreadMode.BACKGROUND)
     @Subscribe(threadMode = ThreadMode.BACKGROUND)
     fun onMessageEvent(event: CallNotificationClick) {
     fun onMessageEvent(event: CallNotificationClick) {
+        Log.d(TAG, "CallNotification was clicked")
         isServiceInForeground = false
         isServiceInForeground = false
         stopForeground(true)
         stopForeground(true)
     }
     }
 
 
     override fun onDestroy() {
     override fun onDestroy() {
+        Log.d(TAG, "onDestroy")
         isServiceInForeground = false
         isServiceInForeground = false
         eventBus?.unregister(this)
         eventBus?.unregister(this)
         stopForeground(true)
         stopForeground(true)
@@ -128,12 +134,13 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
         super.onNewToken(token)
         super.onNewToken(token)
         sharedApplication!!.componentApplication.inject(this)
         sharedApplication!!.componentApplication.inject(this)
         appPreferences!!.pushToken = token
         appPreferences!!.pushToken = token
+        Log.d(TAG, "onNewToken. token = $token")
         val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build()
         val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build()
         WorkManager.getInstance().enqueue(pushRegistrationWork)
         WorkManager.getInstance().enqueue(pushRegistrationWork)
     }
     }
 
 
-    @SuppressLint("LongLogTag")
     override fun onMessageReceived(remoteMessage: RemoteMessage) {
     override fun onMessageReceived(remoteMessage: RemoteMessage) {
+        Log.d(TAG, "onMessageReceived")
         sharedApplication!!.componentApplication.inject(this)
         sharedApplication!!.componentApplication.inject(this)
         if (!remoteMessage.data["subject"].isNullOrEmpty() && !remoteMessage.data["signature"].isNullOrEmpty()) {
         if (!remoteMessage.data["subject"].isNullOrEmpty() && !remoteMessage.data["signature"].isNullOrEmpty()) {
             decryptMessage(remoteMessage.data["subject"]!!, remoteMessage.data["signature"]!!)
             decryptMessage(remoteMessage.data["subject"]!!, remoteMessage.data["signature"]!!)
@@ -160,6 +167,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
                         DecryptedPushMessage::class.java
                         DecryptedPushMessage::class.java
                     )
                     )
                     decryptedPushMessage?.apply {
                     decryptedPushMessage?.apply {
+                        Log.d(TAG, this.toString())
                         timestamp = System.currentTimeMillis()
                         timestamp = System.currentTimeMillis()
                         if (delete) {
                         if (delete) {
                             cancelExistingNotificationWithId(
                             cancelExistingNotificationWithId(
@@ -296,6 +304,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
         signatureVerification: SignatureVerification,
         signatureVerification: SignatureVerification,
         decryptedPushMessage: DecryptedPushMessage
         decryptedPushMessage: DecryptedPushMessage
     ) {
     ) {
+        Log.d(TAG, "checkIfCallIsActive")
         val ncApi = retrofit!!.newBuilder()
         val ncApi = retrofit!!.newBuilder()
             .client(okHttpClient!!.newBuilder().cookieJar(JavaNetCookieJar(CookieManager())).build()).build()
             .client(okHttpClient!!.newBuilder().cookieJar(JavaNetCookieJar(CookieManager())).build()).build()
             .create(NcApi::class.java)
             .create(NcApi::class.java)
@@ -336,6 +345,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
                     }
                     }
 
 
                     if (!hasParticipantsInCall || inCallOnDifferentDevice) {
                     if (!hasParticipantsInCall || inCallOnDifferentDevice) {
+                        Log.d(TAG, "no participants in call OR inCallOnDifferentDevice")
                         stopForeground(true)
                         stopForeground(true)
                         handler.removeCallbacksAndMessages(null)
                         handler.removeCallbacksAndMessages(null)
                     } else if (isServiceInForeground) {
                     } else if (isServiceInForeground) {

+ 13 - 9
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -1084,6 +1084,7 @@ public class CallActivity extends CallBaseActivity {
     }
     }
 
 
     private void fetchSignalingSettings() {
     private void fetchSignalingSettings() {
+        Log.d(TAG, "fetchSignalingSettings");
         int apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[]{ApiUtils.APIv3, 2, 1});
         int apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[]{ApiUtils.APIv3, 2, 1});
 
 
         ncApi.getSignalingSettings(credentials, ApiUtils.getUrlForSignalingSettings(apiVersion, baseUrl))
         ncApi.getSignalingSettings(credentials, ApiUtils.getUrlForSignalingSettings(apiVersion, baseUrl))
@@ -1098,9 +1099,7 @@ public class CallActivity extends CallBaseActivity {
 
 
                 @Override
                 @Override
                 public void onNext(@io.reactivex.annotations.NonNull SignalingSettingsOverall signalingSettingsOverall) {
                 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();
                         externalSignalingServer = new ExternalSignalingServer();
 
 
                         if (!TextUtils.isEmpty(signalingSettingsOverall.getOcs().getSettings().getExternalSignalingServer()) &&
                         if (!TextUtils.isEmpty(signalingSettingsOverall.getOcs().getSettings().getExternalSignalingServer()) &&
@@ -1112,6 +1111,7 @@ public class CallActivity extends CallBaseActivity {
                         } else {
                         } else {
                             hasExternalSignalingServer = false;
                             hasExternalSignalingServer = false;
                         }
                         }
+                        Log.d(TAG, "   hasExternalSignalingServer: " + hasExternalSignalingServer);
 
 
                         if (!conversationUser.getUserId().equals("?")) {
                         if (!conversationUser.getUserId().equals("?")) {
                             try {
                             try {
@@ -1137,6 +1137,7 @@ public class CallActivity extends CallBaseActivity {
                                 for (IceServer stunServer : stunServers) {
                                 for (IceServer stunServer : stunServers) {
                                     if (stunServer.getUrls() != null) {
                                     if (stunServer.getUrls() != null) {
                                         for (String url : stunServer.getUrls()) {
                                         for (String url : stunServer.getUrls()) {
+                                            Log.d(TAG, "   STUN server url: " + url);
                                             iceServers.add(new PeerConnection.IceServer(url));
                                             iceServers.add(new PeerConnection.IceServer(url));
                                         }
                                         }
                                     }
                                     }
@@ -1144,6 +1145,7 @@ public class CallActivity extends CallBaseActivity {
                             } else {
                             } else {
                                 if (signalingSettingsOverall.getOcs().getSettings().getStunServers() != null) {
                                 if (signalingSettingsOverall.getOcs().getSettings().getStunServers() != null) {
                                     for (IceServer stunServer : stunServers) {
                                     for (IceServer stunServer : stunServers) {
+                                        Log.d(TAG, "   STUN server url: " + stunServer.getUrl());
                                         iceServers.add(new PeerConnection.IceServer(stunServer.getUrl()));
                                         iceServers.add(new PeerConnection.IceServer(stunServer.getUrl()));
                                     }
                                     }
                                 }
                                 }
@@ -1156,6 +1158,7 @@ public class CallActivity extends CallBaseActivity {
                             for (IceServer turnServer : turnServers) {
                             for (IceServer turnServer : turnServers) {
                                 if (turnServer.getUrls() != null) {
                                 if (turnServer.getUrls() != null) {
                                     for (String url : turnServer.getUrls()) {
                                     for (String url : turnServer.getUrls()) {
+                                        Log.d(TAG, "   TURN server url: " + url);
                                         iceServers.add(new PeerConnection.IceServer(
                                         iceServers.add(new PeerConnection.IceServer(
                                             url, turnServer.getUsername(), turnServer.getCredential()
                                             url, turnServer.getUsername(), turnServer.getCredential()
                                         ));
                                         ));
@@ -1616,10 +1619,11 @@ public class CallActivity extends CallBaseActivity {
 
 
     private void processUsersInRoom(List<HashMap<String, Object>> users) {
     private void processUsersInRoom(List<HashMap<String, Object>> users) {
         List<String> newSessions = new ArrayList<>();
         List<String> newSessions = new ArrayList<>();
-        Set<String> oldSesssions = new HashSet<>();
+        Set<String> oldSessions = new HashSet<>();
 
 
         hasMCU = hasExternalSignalingServer && webSocketClient != null && webSocketClient.hasMCU();
         hasMCU = hasExternalSignalingServer && webSocketClient != null && webSocketClient.hasMCU();
 
 
+
         // The signaling session is the same as the Nextcloud session only when the MCU is not used.
         // The signaling session is the same as the Nextcloud session only when the MCU is not used.
         String currentSessiondId = callSession;
         String currentSessiondId = callSession;
         if (hasMCU) {
         if (hasMCU) {
@@ -1639,22 +1643,22 @@ public class CallActivity extends CallBaseActivity {
                 if (isNewSession) {
                 if (isNewSession) {
                     newSessions.add(participant.get("sessionId").toString());
                     newSessions.add(participant.get("sessionId").toString());
                 } else {
                 } else {
-                    oldSesssions.add(participant.get("sessionId").toString());
+                    oldSessions.add(participant.get("sessionId").toString());
                 }
                 }
             }
             }
         }
         }
 
 
         for (MagicPeerConnectionWrapper magicPeerConnectionWrapper : magicPeerConnectionWrapperList) {
         for (MagicPeerConnectionWrapper magicPeerConnectionWrapper : magicPeerConnectionWrapperList) {
             if (!magicPeerConnectionWrapper.isMCUPublisher()) {
             if (!magicPeerConnectionWrapper.isMCUPublisher()) {
-                oldSesssions.add(magicPeerConnectionWrapper.getSessionId());
+                oldSessions.add(magicPeerConnectionWrapper.getSessionId());
             }
             }
         }
         }
 
 
         // Calculate sessions that left the call
         // Calculate sessions that left the call
-        oldSesssions.removeAll(newSessions);
+        oldSessions.removeAll(newSessions);
 
 
         // Calculate sessions that join the call
         // Calculate sessions that join the call
-        newSessions.removeAll(oldSesssions);
+        newSessions.removeAll(oldSessions);
 
 
         if (!isConnectionEstablished() && !currentCallStatus.equals(CallStatus.CONNECTING)) {
         if (!isConnectionEstablished() && !currentCallStatus.equals(CallStatus.CONNECTING)) {
             return;
             return;
@@ -1677,7 +1681,7 @@ public class CallActivity extends CallBaseActivity {
             setCallState(CallStatus.IN_CONVERSATION);
             setCallState(CallStatus.IN_CONVERSATION);
         }
         }
 
 
-        for (String sessionId : oldSesssions) {
+        for (String sessionId : oldSessions) {
             endPeerConnection(sessionId, false);
             endPeerConnection(sessionId, false);
         }
         }
     }
     }

+ 17 - 8
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -268,6 +268,8 @@ class ChatController(args: Bundle) :
     var currentlyPlayedVoiceMessage: ChatMessage? = null
     var currentlyPlayedVoiceMessage: ChatMessage? = null
 
 
     init {
     init {
+        Log.d(TAG, "init ChatController")
+
         setHasOptionsMenu(true)
         setHasOptionsMenu(true)
         NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
         NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
 
 
@@ -276,7 +278,10 @@ class ChatController(args: Bundle) :
         this.roomToken = args.getString(KEY_ROOM_TOKEN, "")
         this.roomToken = args.getString(KEY_ROOM_TOKEN, "")
         this.sharedText = args.getString(BundleKeys.KEY_SHARED_TEXT, "")
         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)) {
         if (args.containsKey(KEY_ACTIVE_CONVERSATION)) {
             this.currentConversation = Parcels.unwrap<Conversation>(args.getParcelable(KEY_ACTIVE_CONVERSATION))
             this.currentConversation = Parcels.unwrap<Conversation>(args.getParcelable(KEY_ACTIVE_CONVERSATION))
@@ -298,7 +303,6 @@ class ChatController(args: Bundle) :
     }
     }
 
 
     private fun getRoomInfo() {
     private fun getRoomInfo() {
-        Log.d(TAG, "getRoomInfo")
         val shouldRepeat = CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "webinary-lobby")
         val shouldRepeat = CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "webinary-lobby")
         if (shouldRepeat) {
         if (shouldRepeat) {
             checkingLobbyStatus = true
             checkingLobbyStatus = true
@@ -318,8 +322,7 @@ class ChatController(args: Bundle) :
                     @Suppress("Detekt.TooGenericExceptionCaught")
                     @Suppress("Detekt.TooGenericExceptionCaught")
                     override fun onNext(roomOverall: RoomOverall) {
                     override fun onNext(roomOverall: RoomOverall) {
                         currentConversation = roomOverall.ocs.data
                         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()
                         loadAvatarForStatusBar()
 
 
                         setTitle()
                         setTitle()
@@ -431,7 +434,6 @@ class ChatController(args: Bundle) :
 
 
     override fun onViewBound(view: View) {
     override fun onViewBound(view: View) {
         actionBar?.show()
         actionBar?.show()
-        Log.d(TAG, "onViewBound")
         var adapterWasNull = false
         var adapterWasNull = false
 
 
         if (adapter == null) {
         if (adapter == null) {
@@ -1487,6 +1489,7 @@ class ChatController(args: Bundle) :
 
 
     override fun onAttach(view: View) {
     override fun onAttach(view: View) {
         super.onAttach(view)
         super.onAttach(view)
+        Log.d(TAG, "onAttach")
         eventBus?.register(this)
         eventBus?.register(this)
 
 
         if (conversationUser?.userId != "?" &&
         if (conversationUser?.userId != "?" &&
@@ -1537,6 +1540,7 @@ class ChatController(args: Bundle) :
             if (wasDetached) {
             if (wasDetached) {
                 currentConversation?.sessionId = "0"
                 currentConversation?.sessionId = "0"
                 wasDetached = false
                 wasDetached = false
+                Log.d(TAG, "execute joinRoomWithPassword in onAttach")
                 joinRoomWithPassword()
                 joinRoomWithPassword()
             }
             }
         }
         }
@@ -1561,6 +1565,7 @@ class ChatController(args: Bundle) :
 
 
     override fun onDetach(view: View) {
     override fun onDetach(view: View) {
         super.onDetach(view)
         super.onDetach(view)
+        Log.d(TAG, "onDetach")
         eventBus?.unregister(this)
         eventBus?.unregister(this)
 
 
         if (activity != null) {
         if (activity != null) {
@@ -1622,9 +1627,9 @@ class ChatController(args: Bundle) :
 
 
     private fun joinRoomWithPassword() {
     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
             var apiVersion = 1
             // FIXME Fix API checking with guests?
             // FIXME Fix API checking with guests?
             if (conversationUser != null) {
             if (conversationUser != null) {
@@ -1704,6 +1709,7 @@ class ChatController(args: Bundle) :
     }
     }
 
 
     private fun leaveRoom() {
     private fun leaveRoom() {
+        Log.d(TAG, "leaveRoom")
         var apiVersion = 1
         var apiVersion = 1
         // FIXME Fix API checking with guests?
         // FIXME Fix API checking with guests?
         if (conversationUser != null) {
         if (conversationUser != null) {
@@ -1737,6 +1743,8 @@ class ChatController(args: Bundle) :
                             "",
                             "",
                             currentConversation?.sessionId
                             currentConversation?.sessionId
                         )
                         )
+                    } else {
+                        Log.e(TAG, "magicWebSocketInstance or currentConversation were null! Failed to leave the room!")
                     }
                     }
 
 
                     if (!isDestroyed && !isBeingDestroyed && !wasDetached) {
                     if (!isDestroyed && !isBeingDestroyed && !wasDetached) {
@@ -1848,6 +1856,7 @@ class ChatController(args: Bundle) :
                 magicWebSocketInstance =
                 magicWebSocketInstance =
                     WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id)
                     WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id)
             } else {
             } else {
+                Log.d(TAG, "magicWebSocketInstance became null")
                 magicWebSocketInstance = null
                 magicWebSocketInstance = null
             }
             }
         }
         }

+ 3 - 0
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) {
     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";
         return getUrlForRoom(version, baseUrl, token) + "/participants";
     }
     }
 
 

+ 3 - 0
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) {
     public void joinRoomWithRoomTokenAndSession(String roomToken, String normalBackendSession) {
+        Log.d(TAG, "joinRoomWithRoomTokenAndSession");
+        Log.d(TAG, "   roomToken: " + roomToken);
+        Log.d(TAG, "   session: " + normalBackendSession);
         try {
         try {
             String message = LoganSquare.serialize(webSocketConnectionHelper.getAssembledJoinOrLeaveRoomModel(roomToken, normalBackendSession));
             String message = LoganSquare.serialize(webSocketConnectionHelper.getAssembledJoinOrLeaveRoomModel(roomToken, normalBackendSession));
             if (!connected || reconnecting) {
             if (!connected || reconnecting) {

+ 6 - 1
app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java

@@ -20,6 +20,9 @@
 
 
 package com.nextcloud.talk.webrtc;
 package com.nextcloud.talk.webrtc;
 
 
+import android.annotation.SuppressLint;
+import android.util.Log;
+
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.models.database.UserEntity;
 import com.nextcloud.talk.models.database.UserEntity;
 import com.nextcloud.talk.models.json.signaling.NCMessageWrapper;
 import com.nextcloud.talk.models.json.signaling.NCMessageWrapper;
@@ -47,6 +50,7 @@ import okhttp3.OkHttpClient;
 
 
 @AutoInjector(NextcloudTalkApplication.class)
 @AutoInjector(NextcloudTalkApplication.class)
 public class WebSocketConnectionHelper {
 public class WebSocketConnectionHelper {
+    public static final String TAG = "WebSocketConnectionHelper";
     private static Map<Long, MagicWebSocketInstance> magicWebSocketInstanceMap = new HashMap<>();
     private static Map<Long, MagicWebSocketInstance> magicWebSocketInstanceMap = new HashMap<>();
 
 
     @Inject
     @Inject
@@ -57,11 +61,12 @@ public class WebSocketConnectionHelper {
         NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
         NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
     }
     }
 
 
+    @SuppressLint("LongLogTag")
     public static synchronized MagicWebSocketInstance getMagicWebSocketInstanceForUserId(long userId) {
     public static synchronized MagicWebSocketInstance getMagicWebSocketInstanceForUserId(long userId) {
         if (userId != -1 && magicWebSocketInstanceMap.containsKey(userId)) {
         if (userId != -1 && magicWebSocketInstanceMap.containsKey(userId)) {
             return magicWebSocketInstanceMap.get(userId);
             return magicWebSocketInstanceMap.get(userId);
         }
         }
-
+        Log.d(TAG, "no magicWebSocketInstance found");
         return null;
         return null;
     }
     }