From 11d089485e0d1afc99b82c6462c6d38fce3b4a92 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 20 Jan 2023 09:31:44 +0100 Subject: [PATCH] avoid NPE when answering call this could happen very rarely when clicking very fast to accept the call before the conversation was set. Exception java.lang.NullPointerException: at com.nextcloud.talk.activities.CallNotificationActivity.proceedToCall (CallNotificationActivity.kt:156) at com.nextcloud.talk.activities.CallNotificationActivity.initClickListeners$lambda$0 (CallNotificationActivity.kt:126) at com.nextcloud.talk.activities.CallNotificationActivity.$r8$lambda$0cnB_UmYcTD4PyxIBSZCZs1m_6s at com.nextcloud.talk.activities.CallNotificationActivity$$ExternalSyntheticLambda0.onClick at android.view.View.performClick (View.java:6612) at android.view.View.performClickInternal (View.java:6581) at android.view.View.access$3100 (View.java:785) at android.view.View$PerformClick.run (View.java:25904) at android.os.Handler.handleCallback (Handler.java:873) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loop (Looper.java:280) at android.app.ActivityThread.main (ActivityThread.java:6706) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858) Signed-off-by: Marcel Hibbe --- .../activities/CallNotificationActivity.kt | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.kt index ace335318..23fac6413 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.kt @@ -153,25 +153,29 @@ class CallNotificationActivity : CallBaseActivity() { } private fun proceedToCall() { - originalBundle!!.putString(KEY_ROOM_TOKEN, currentConversation!!.token) - originalBundle!!.putString(KEY_CONVERSATION_NAME, currentConversation!!.displayName) + if (currentConversation != null) { + originalBundle!!.putString(KEY_ROOM_TOKEN, currentConversation!!.token) + originalBundle!!.putString(KEY_CONVERSATION_NAME, currentConversation!!.displayName) - val participantPermission = ParticipantPermissions( - userBeingCalled!!, - currentConversation!! - ) - originalBundle!!.putBoolean( - BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO, - participantPermission.canPublishAudio() - ) - originalBundle!!.putBoolean( - BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO, - participantPermission.canPublishVideo() - ) + val participantPermission = ParticipantPermissions( + userBeingCalled!!, + currentConversation!! + ) + originalBundle!!.putBoolean( + BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO, + participantPermission.canPublishAudio() + ) + originalBundle!!.putBoolean( + BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO, + participantPermission.canPublishVideo() + ) - val intent = Intent(this, CallActivity::class.java) - intent.putExtras(originalBundle!!) - startActivity(intent) + val intent = Intent(this, CallActivity::class.java) + intent.putExtras(originalBundle!!) + startActivity(intent) + } else { + Log.w(TAG, "conversation was still null when clicked to answer call. User has to click another time.") + } } @Suppress("MagicNumber")