Skip to content

Commit 0506891

Browse files
authored
Merge pull request #2148 from DataDog/mconstantin/merge-develop-into-release-2-12-0
Merge develop into release 2 12 0
2 parents 6319509 + 3bea83e commit 0506891

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/resources/DefaultImageWireframeHelper.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ internal class DefaultImageWireframeHelper(
9494
if (imagePrivacy == ImagePrivacy.MASK_ALL) {
9595
return createContentPlaceholderWireframe(
9696
id = id,
97-
x = x,
98-
y = y,
97+
view = view,
9998
density = density,
100-
drawableProperties = drawableProperties,
10199
label = MASK_ALL_CONTENT_LABEL
102100
)
103101
}
@@ -106,10 +104,8 @@ internal class DefaultImageWireframeHelper(
106104
if (shouldMaskContextualImage(imagePrivacy, usePIIPlaceholder, drawable, density)) {
107105
return createContentPlaceholderWireframe(
108106
id = id,
109-
x = x,
110-
y = y,
107+
view = view,
111108
density = density,
112-
drawableProperties = drawableProperties,
113109
label = MASK_CONTEXTUAL_CONTENT_LABEL
114110
)
115111
}
@@ -241,19 +237,23 @@ internal class DefaultImageWireframeHelper(
241237
}
242238

243239
private fun createContentPlaceholderWireframe(
240+
view: View,
244241
id: Long,
245-
x: Long,
246-
y: Long,
247242
density: Float,
248-
drawableProperties: DrawableProperties,
249243
label: String
250244
): MobileSegment.Wireframe.PlaceholderWireframe {
245+
val coordinates = IntArray(2)
246+
@Suppress("UnsafeThirdPartyFunctionCall") // this will always have size >= 2
247+
view.getLocationOnScreen(coordinates)
248+
val viewX = coordinates[0].densityNormalized(density).toLong()
249+
val viewY = coordinates[1].densityNormalized(density).toLong()
250+
251251
return MobileSegment.Wireframe.PlaceholderWireframe(
252252
id,
253-
x,
254-
y,
255-
drawableProperties.drawableWidth.densityNormalized(density).toLong(),
256-
drawableProperties.drawableHeight.densityNormalized(density).toLong(),
253+
viewX,
254+
viewY,
255+
view.width.densityNormalized(density).toLong(),
256+
view.height.densityNormalized(density).toLong(),
257257
label = label
258258
)
259259
}

features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/resources/DefaultImageWireframeHelperTest.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.datadog.android.sessionreplay.utils.GlobalBounds
2929
import com.datadog.android.sessionreplay.utils.ImageWireframeHelper
3030
import com.datadog.android.sessionreplay.utils.ImageWireframeHelper.Companion.DRAWABLE_CHILD_NAME
3131
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver
32+
import com.datadog.android.utils.isCloseTo
3233
import com.datadog.android.utils.verifyLog
3334
import fr.xgouchet.elmyr.Forge
3435
import fr.xgouchet.elmyr.annotation.IntForgery
@@ -663,12 +664,19 @@ internal class DefaultImageWireframeHelperTest {
663664
// Given
664665
whenever(mockImageTypeResolver.isDrawablePII(any(), any())).thenReturn(true)
665666

666-
val fakeGlobalX = forge.aPositiveLong()
667-
val fakeGlobalY = forge.aPositiveLong()
667+
val fakeGlobalX = forge.aPositiveInt()
668+
val fakeGlobalY = forge.aPositiveInt()
668669
whenever(mockResources.displayMetrics).thenReturn(mockDisplayMetrics)
669670
mockDisplayMetrics.density = 1f
670671
whenever(mockContext.applicationContext).thenReturn(mockContext)
671672
val mockView: View = mock {
673+
whenever(it.getLocationOnScreen(any())).thenAnswer { location ->
674+
val coords = location.arguments[0] as IntArray
675+
coords[0] = fakeGlobalX
676+
coords[1] = fakeGlobalY
677+
null
678+
}
679+
672680
whenever(it.resources).thenReturn(mockResources)
673681
whenever(it.context).thenReturn(mockContext)
674682
}
@@ -678,8 +686,8 @@ internal class DefaultImageWireframeHelperTest {
678686
view = mockView,
679687
imagePrivacy = ImagePrivacy.MASK_LARGE_ONLY,
680688
currentWireframeIndex = forge.aPositiveInt(),
681-
x = fakeGlobalX,
682-
y = fakeGlobalY,
689+
x = forge.aPositiveLong(),
690+
y = forge.aPositiveLong(),
683691
width = forge.aPositiveInt(),
684692
height = forge.aPositiveInt(),
685693
drawable = mockDrawable,
@@ -691,8 +699,8 @@ internal class DefaultImageWireframeHelperTest {
691699

692700
// Then
693701
verifyNoInteractions(mockResourceResolver)
694-
assertThat(result.x).isEqualTo(fakeGlobalX)
695-
assertThat(result.y).isEqualTo(fakeGlobalY)
702+
assertThat(isCloseTo(result.x.toInt(), fakeGlobalX)).isTrue
703+
assertThat(isCloseTo(result.y.toInt(), fakeGlobalY)).isTrue
696704
}
697705

698706
@Test

0 commit comments

Comments
 (0)