From 16588c401ed77fb69aeaf8ca8c1622c2a96c3a1b Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Thu, 4 Apr 2024 11:53:05 -0400 Subject: [PATCH] Reduce verbosity of WebRtcViewModel event logging during calls. --- .../securesms/WebRtcCallActivity.java | 4 ++- .../securesms/events/CallParticipant.kt | 4 +++ .../securesms/events/CallParticipantId.java | 5 +++ .../securesms/events/WebRtcViewModel.kt | 36 +++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java index e5c34a8f92..8ede110fbb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java @@ -162,6 +162,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan private ControlsAndInfoController controlsAndInfo; private boolean enterPipOnResume; private long lastProcessedIntentTimestamp; + private WebRtcViewModel previousEvent = null; private Disposable ephemeralStateDisposable = Disposable.empty(); @@ -885,7 +886,8 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) public void onEventMainThread(@NonNull WebRtcViewModel event) { - Log.i(TAG, "Got message from service: " + event); + Log.i(TAG, "Got message from service: " + event.describeDifference(previousEvent)); + previousEvent = event; viewModel.setRecipient(event.getRecipient()); callScreen.setRecipient(event.getRecipient()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/events/CallParticipant.kt b/app/src/main/java/org/thoughtcrime/securesms/events/CallParticipant.kt index 5dbdf43971..456697e703 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/events/CallParticipant.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/events/CallParticipant.kt @@ -79,6 +79,10 @@ data class CallParticipant( return copy(handRaisedTimestamp = timestamp) } + override fun toString(): String { + return "CallParticipant(callParticipantId=$callParticipantId, isForwardingVideo=$isForwardingVideo, isVideoEnabled=$isVideoEnabled, isMicrophoneEnabled=$isMicrophoneEnabled, handRaisedTimestamp=$handRaisedTimestamp, isMediaKeysReceived=$isMediaKeysReceived, isScreenSharing=$isScreenSharing)" + } + enum class DeviceOrdinal { PRIMARY, SECONDARY } diff --git a/app/src/main/java/org/thoughtcrime/securesms/events/CallParticipantId.java b/app/src/main/java/org/thoughtcrime/securesms/events/CallParticipantId.java index 6f38886f1e..3ee98e5049 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/events/CallParticipantId.java +++ b/app/src/main/java/org/thoughtcrime/securesms/events/CallParticipantId.java @@ -64,6 +64,11 @@ public final class CallParticipantId implements Parcelable { dest.writeParcelable(recipientId, flags); } + @Override + public @NonNull String toString() { + return "CallParticipantId(demuxId=" + demuxId + ", recipientId=" + recipientId + ')'; + } + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override public CallParticipantId createFromParcel(Parcel in) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.kt index 058714ee55..433bc66663 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.kt @@ -124,6 +124,7 @@ class WebRtcViewModel(state: WebRtcServiceState) { PeerConnection.AdapterType.VPN, PeerConnection.AdapterType.LOOPBACK, PeerConnection.AdapterType.ADAPTER_TYPE_ANY -> false + PeerConnection.AdapterType.CELLULAR, PeerConnection.AdapterType.CELLULAR_2G, PeerConnection.AdapterType.CELLULAR_3G, @@ -157,4 +158,39 @@ class WebRtcViewModel(state: WebRtcServiceState) { } """.trimIndent() } + + fun describeDifference(previousEvent: WebRtcViewModel?): String { + return if (previousEvent == null) { + this.toString() + } else if (previousEvent == this) { + "" + } else { + val builder = StringBuilder() + if (state != previousEvent.state) builder.append(" state=$state\n") + if (recipient.id != previousEvent.recipient.id) builder.append(" recipient=${recipient.id}\n") + if (isRemoteVideoOffer != previousEvent.isRemoteVideoOffer) builder.append(" isRemoteVideoOffer=$isRemoteVideoOffer\n") + if (callConnectedTime != previousEvent.callConnectedTime) builder.append(" callConnectedTime=$callConnectedTime\n") + if (localParticipant != previousEvent.localParticipant) builder.append(" localParticipant=$localParticipant\n") + if (remoteParticipants != previousEvent.remoteParticipants) { + if (remoteParticipants.size <= 8) { + builder.append(" remoteParticipants=$remoteParticipants\n") + } else { + builder.append(" remoteParticipants=\n") + } + } + if (identityChangedParticipants != previousEvent.identityChangedParticipants) builder.append(" identityChangedParticipants=$identityChangedParticipants\n") + if (remoteDevicesCount != previousEvent.remoteDevicesCount) builder.append(" remoteDevicesCount=$remoteDevicesCount\n") + if (participantLimit != previousEvent.participantLimit) builder.append(" participantLimit=$participantLimit\n") + if (activeDevice != previousEvent.activeDevice) builder.append(" activeDevice=$activeDevice\n") + if (availableDevices != previousEvent.availableDevices) builder.append(" availableDevices=$availableDevices\n") + if (bluetoothPermissionDenied != previousEvent.bluetoothPermissionDenied) builder.append(" bluetoothPermissionDenied=$bluetoothPermissionDenied\n") + if (ringGroup != previousEvent.ringGroup) builder.append(" ringGroup=$ringGroup\n") + + if (builder.isEmpty()) { + "" + } else { + "WebRtcViewModel {\n$builder}" + } + } + } }