From 1224430f808f2762bc2a13dd679d85594121c51e Mon Sep 17 00:00:00 2001 From: luyi Date: Thu, 24 Oct 2024 16:26:06 +0200 Subject: [PATCH] Fix checkable mapper privacy issue --- .../internal/recorder/mapper/CheckableTextViewMapper.kt | 2 +- .../internal/recorder/mapper/CheckableWireframeMapper.kt | 9 +++++++++ .../internal/recorder/mapper/SwitchCompatMapper.kt | 4 ++-- .../recorder/mapper/BaseCheckableTextViewMapperTest.kt | 4 ++-- .../internal/recorder/mapper/SwitchCompatMapperTest.kt | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/CheckableTextViewMapper.kt b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/CheckableTextViewMapper.kt index b9f8c54468..e7968644aa 100644 --- a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/CheckableTextViewMapper.kt +++ b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/CheckableTextViewMapper.kt @@ -111,7 +111,7 @@ internal abstract class CheckableTextViewMapper( ) mappingContext.imageWireframeHelper.createImageWireframe( view = view, - imagePrivacy = mappingContext.imagePrivacy, + imagePrivacy = mapInputPrivacyToImagePrivacy(mappingContext.textAndInputPrivacy), currentWireframeIndex = 0, x = checkBoxBounds.x, y = checkBoxBounds.y, diff --git a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/CheckableWireframeMapper.kt b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/CheckableWireframeMapper.kt index b0518452a8..42458e289a 100644 --- a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/CheckableWireframeMapper.kt +++ b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/CheckableWireframeMapper.kt @@ -10,6 +10,7 @@ import android.view.View import android.widget.Checkable import androidx.annotation.UiThread import com.datadog.android.api.InternalLogger +import com.datadog.android.sessionreplay.ImagePrivacy import com.datadog.android.sessionreplay.TextAndInputPrivacy import com.datadog.android.sessionreplay.model.MobileSegment import com.datadog.android.sessionreplay.recorder.MappingContext @@ -52,6 +53,14 @@ internal abstract class CheckableWireframeMapper( return mainWireframes } + protected fun mapInputPrivacyToImagePrivacy(inputPrivacy: TextAndInputPrivacy): ImagePrivacy { + return when (inputPrivacy) { + TextAndInputPrivacy.MASK_SENSITIVE_INPUTS -> ImagePrivacy.MASK_NONE + TextAndInputPrivacy.MASK_ALL_INPUTS, + TextAndInputPrivacy.MASK_ALL -> ImagePrivacy.MASK_ALL + } + } + @UiThread abstract fun resolveMainWireframes( view: T, diff --git a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/SwitchCompatMapper.kt b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/SwitchCompatMapper.kt index 9ff0e2f564..f7c512b906 100644 --- a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/SwitchCompatMapper.kt +++ b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/SwitchCompatMapper.kt @@ -80,7 +80,7 @@ internal open class SwitchCompatMapper( }?.let { drawable -> mappingContext.imageWireframeHelper.createImageWireframe( view = view, - imagePrivacy = mappingContext.imagePrivacy, + imagePrivacy = mapInputPrivacyToImagePrivacy(mappingContext.textAndInputPrivacy), currentWireframeIndex = prevIndex + 1, x = trackBounds.x.densityNormalized(mappingContext.systemInformation.screenDensity).toLong(), y = trackBounds.y.densityNormalized(mappingContext.systemInformation.screenDensity).toLong(), @@ -111,7 +111,7 @@ internal open class SwitchCompatMapper( thumbBounds?.let { thumbBounds -> mappingContext.imageWireframeHelper.createImageWireframe( view = view, - imagePrivacy = mappingContext.imagePrivacy, + imagePrivacy = mapInputPrivacyToImagePrivacy(mappingContext.textAndInputPrivacy), currentWireframeIndex = prevIndex + 1, x = thumbBounds.x.densityNormalized(mappingContext.systemInformation.screenDensity).toLong(), y = thumbBounds.y.densityNormalized(mappingContext.systemInformation.screenDensity).toLong(), diff --git a/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/BaseCheckableTextViewMapperTest.kt b/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/BaseCheckableTextViewMapperTest.kt index 1772af9427..c9b337a7f6 100644 --- a/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/BaseCheckableTextViewMapperTest.kt +++ b/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/BaseCheckableTextViewMapperTest.kt @@ -218,7 +218,7 @@ internal abstract class BaseCheckableTextViewMapperTest : // Then verify(fakeMappingContext.imageWireframeHelper).createImageWireframe( view = eq(mockCheckableTextView), - imagePrivacy = eq(ImagePrivacy.MASK_LARGE_ONLY), + imagePrivacy = eq(ImagePrivacy.MASK_NONE), currentWireframeIndex = anyInt(), x = eq(expectedX), y = eq(expectedY), @@ -261,7 +261,7 @@ internal abstract class BaseCheckableTextViewMapperTest : // Then verify(fakeMappingContext.imageWireframeHelper).createImageWireframe( view = eq(mockCheckableTextView), - imagePrivacy = eq(ImagePrivacy.MASK_LARGE_ONLY), + imagePrivacy = eq(ImagePrivacy.MASK_NONE), currentWireframeIndex = anyInt(), x = eq(expectedX), y = eq(expectedY), diff --git a/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/SwitchCompatMapperTest.kt b/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/SwitchCompatMapperTest.kt index f284438bca..02957c992e 100644 --- a/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/SwitchCompatMapperTest.kt +++ b/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/SwitchCompatMapperTest.kt @@ -89,7 +89,7 @@ internal class SwitchCompatMapperTest : BaseSwitchCompatMapperTest() { verify(fakeMappingContext.imageWireframeHelper, times(2)).createImageWireframe( view = eq(mockSwitch), - imagePrivacy = eq(ImagePrivacy.MASK_LARGE_ONLY), + imagePrivacy = eq(ImagePrivacy.MASK_NONE), currentWireframeIndex = ArgumentMatchers.anyInt(), x = xCaptor.capture(), y = yCaptor.capture(),