Skip to content

Commit

Permalink
Merge pull request #1910 from DataDog/xgouchet/RUM-3455/fix_sr_bugs
Browse files Browse the repository at this point in the history
RUM-3455 Cleanup SR code
  • Loading branch information
xgouchet authored Mar 15, 2024
2 parents 0f9e699 + a5ca09d commit 9859578
Show file tree
Hide file tree
Showing 131 changed files with 3,367 additions and 2,249 deletions.
1 change: 1 addition & 0 deletions dd-sdk-android-core/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ val NULL_MAP_VALUE: Object
object com.datadog.android.core.internal.utils.JsonSerializer
fun toJsonElement(Any?): com.google.gson.JsonElement
fun Map<String, Any?>.safeMapValuesToJson(com.datadog.android.api.InternalLogger): Map<String, com.google.gson.JsonElement>
const val HEX_RADIX: Int
fun Int.toHexString(): String
fun Long.toHexString(): String
fun java.math.BigInteger.toHexString(): String
Expand Down
1 change: 1 addition & 0 deletions dd-sdk-android-core/api/dd-sdk-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ public final class com/datadog/android/core/internal/utils/MapUtilsKt {
}

public final class com/datadog/android/core/internal/utils/NumberExtKt {
public static final field HEX_RADIX I
public static final fun toHexString (I)Ljava/lang/String;
public static final fun toHexString (J)Ljava/lang/String;
public static final fun toHexString (Ljava/math/BigInteger;)Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ package com.datadog.android.core.internal.utils
import com.datadog.android.lint.InternalApi
import java.math.BigInteger

internal const val HEX_RADIX = 16
/**
* Radix used to convert numbers to hexadecimal strings.
*/
const val HEX_RADIX: Int = 16

/**
* Converts [Int] into hexadecimal representation.
Expand Down
7 changes: 6 additions & 1 deletion detekt_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ datadog:
- "java.io.PrintWriter.constructor(java.io.Writer):java.lang.NullPointerException"
- "java.lang.Character.toChars(kotlin.Int):java.lang.IllegalArgumentException"
- "java.lang.Class.forName(kotlin.String?):java.lang.LinkageError,java.lang.ExceptionInInitializerError,java.lang.ClassNotFoundException"
- "java.lang.Class.getDeclaredField(kotlin.String):java.lang.NoSuchFieldException,java.lang.SecurityException,java.lang.NullPointerException"
- "java.lang.Class.getDeclaredField(kotlin.String?):java.lang.NoSuchFieldException,java.lang.SecurityException,java.lang.NullPointerException"
- "java.lang.reflect.Field.get(kotlin.Any?):java.lang.IllegalArgumentException,java.lang.IllegalAccessException"
- "java.lang.Class.getMethod(kotlin.String?, kotlin.Array?):java.lang.NoSuchMethodException,java.lang.SecurityException,java.lang.NullPointerException"
- "java.lang.Class.isAssignableFrom(java.lang.Class?):java.lang.NullPointerException"
- "java.lang.Runtime.addShutdownHook(java.lang.Thread):java.lang.IllegalArgumentException,java.lang.IllegalStateException,java.lang.SecurityException"
Expand Down Expand Up @@ -442,6 +443,7 @@ datadog:
- "android.graphics.drawable.Drawable.setBounds(kotlin.Int, kotlin.Int, kotlin.Int, kotlin.Int)"
- "android.graphics.drawable.LayerDrawable.safeGetDrawable(kotlin.Int, com.datadog.android.api.InternalLogger)"
- "android.graphics.drawable.RippleDrawable.safeGetDrawable(kotlin.Int, com.datadog.android.api.InternalLogger)"
- "android.graphics.drawable.RippleDrawable.findIndexByLayerId(kotlin.Int)"
- "android.graphics.Point.constructor()"
- "android.graphics.Rect.centerX()"
- "android.graphics.Rect.centerY()"
Expand Down Expand Up @@ -984,6 +986,7 @@ datadog:
- "kotlin.collections.listOf(com.datadog.android.sessionreplay.model.MobileSegment.Wireframe.PlaceholderWireframe)"
- "kotlin.collections.listOf(com.datadog.android.sessionreplay.model.MobileSegment.Wireframe.ShapeWireframe)"
- "kotlin.collections.listOf(com.datadog.android.sessionreplay.model.MobileSegment.Wireframe.TextWireframe)"
- "kotlin.collections.listOf(com.datadog.android.sessionreplay.model.MobileSegment.Wireframe)"
- "kotlin.collections.listOf(java.io.File)"
- "kotlin.collections.listOf(kotlin.Array)"
- "kotlin.collections.listOf(kotlin.String)"
Expand Down Expand Up @@ -1124,6 +1127,7 @@ datadog:
- "kotlin.text.String(kotlin.ByteArray, java.nio.charset.Charset)"
- "kotlin.text.String(kotlin.CharArray)"
- "kotlin.text.StringBuilder()"
- "kotlin.text.buildString(kotlin.Function1)"
# endregion
# region Kotlin Misc
- "kotlin.Any.resolveViewUrl()"
Expand All @@ -1135,6 +1139,7 @@ datadog:
- "kotlin.Throwable.fillInStackTrace()"
- "kotlin.Throwable.stackTraceToString()"
- "kotlin.ranges.IntRange.reversed()"
- "kotlin.ranges.IntRange.map(kotlin.Function1)"
- "kotlin.text.Regex.constructor(kotlin.String)"
- "kotlin.text.Regex.matchEntire(kotlin.CharSequence)"
# endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,30 @@ import android.widget.TextView
import com.datadog.android.sessionreplay.internal.recorder.mapper.MaskInputTextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.WireframeMapper
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.utils.UniqueIdentifierGenerator
import com.datadog.android.sessionreplay.utils.ViewUtils
import com.datadog.android.sessionreplay.utils.ColorStringFormatter
import com.datadog.android.sessionreplay.utils.DrawableToColorMapper
import com.datadog.android.sessionreplay.utils.ViewBoundsResolver
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver

internal class MaskInputTabWireframeMapper(
viewUtils: ViewUtils = ViewUtils,
uniqueIdentifierGenerator: UniqueIdentifierGenerator = UniqueIdentifierGenerator,
textViewMapper: WireframeMapper<TextView, MobileSegment.Wireframe> =
MaskInputTextViewMapper()
) : TabWireframeMapper(viewUtils, uniqueIdentifierGenerator, textViewMapper)
internal class MaskInputTabWireframeMapper internal constructor(
viewIdentifierResolver: ViewIdentifierResolver,
viewBoundsResolver: ViewBoundsResolver,
textViewMapper: WireframeMapper<TextView, MobileSegment.Wireframe>
) : TabWireframeMapper(
viewIdentifierResolver,
viewBoundsResolver,
textViewMapper
) {

constructor(
viewIdentifierResolver: ViewIdentifierResolver,
colorStringFormatter: ColorStringFormatter,
viewBoundsResolver: ViewBoundsResolver,
drawableToColorMapper: DrawableToColorMapper
) : this(
viewIdentifierResolver, viewBoundsResolver,
MaskInputTextViewMapper(
viewIdentifierResolver, colorStringFormatter, viewBoundsResolver, drawableToColorMapper
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
package com.datadog.android.sessionreplay.material

import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.utils.StringUtils
import com.datadog.android.sessionreplay.utils.UniqueIdentifierGenerator
import com.datadog.android.sessionreplay.utils.ViewUtils
import com.datadog.android.sessionreplay.utils.ColorStringFormatter
import com.datadog.android.sessionreplay.utils.ViewBoundsResolver
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver

internal open class MaskSliderWireframeMapper(
viewUtils: ViewUtils = ViewUtils,
stringUtils: StringUtils = StringUtils,
uniqueIdentifierGenerator: UniqueIdentifierGenerator =
UniqueIdentifierGenerator
) : SliderWireframeMapper(viewUtils, stringUtils, uniqueIdentifierGenerator) {
viewIdentifierResolver: ViewIdentifierResolver,
colorStringFormatter: ColorStringFormatter,
viewBoundsResolver: ViewBoundsResolver
) : SliderWireframeMapper(viewIdentifierResolver, colorStringFormatter, viewBoundsResolver) {

override fun resolveViewAsWireframesList(
nonActiveTrackWireframe: MobileSegment.Wireframe.ShapeWireframe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,30 @@ import android.widget.TextView
import com.datadog.android.sessionreplay.internal.recorder.mapper.MaskTextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.WireframeMapper
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.utils.UniqueIdentifierGenerator
import com.datadog.android.sessionreplay.utils.ViewUtils
import com.datadog.android.sessionreplay.utils.ColorStringFormatter
import com.datadog.android.sessionreplay.utils.DrawableToColorMapper
import com.datadog.android.sessionreplay.utils.ViewBoundsResolver
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver

internal class MaskTabWireframeMapper(
viewUtils: ViewUtils = ViewUtils,
uniqueIdentifierGenerator: UniqueIdentifierGenerator = UniqueIdentifierGenerator,
textViewMapper: WireframeMapper<TextView, MobileSegment.Wireframe> =
MaskTextViewMapper()
) : TabWireframeMapper(viewUtils, uniqueIdentifierGenerator, textViewMapper)
internal class MaskTabWireframeMapper internal constructor(
viewIdentifierResolver: ViewIdentifierResolver,
viewBoundsResolver: ViewBoundsResolver,
textViewMapper: WireframeMapper<TextView, MobileSegment.Wireframe>
) : TabWireframeMapper(
viewIdentifierResolver,
viewBoundsResolver,
textViewMapper
) {

constructor(
viewIdentifierResolver: ViewIdentifierResolver,
colorStringFormatter: ColorStringFormatter,
viewBoundsResolver: ViewBoundsResolver,
drawableToColorMapper: DrawableToColorMapper
) : this(
viewIdentifierResolver, viewBoundsResolver,
MaskTextViewMapper(
viewIdentifierResolver, colorStringFormatter, viewBoundsResolver, drawableToColorMapper
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ import android.view.View
import com.datadog.android.sessionreplay.ExtensionSupport
import com.datadog.android.sessionreplay.SessionReplayPrivacy
import com.datadog.android.sessionreplay.internal.recorder.OptionSelectorDetector
import com.datadog.android.sessionreplay.internal.recorder.mapper.MaskTextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.TextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.WireframeMapper
import com.datadog.android.sessionreplay.utils.ColorStringFormatter
import com.datadog.android.sessionreplay.utils.DefaultColorStringFormatter
import com.datadog.android.sessionreplay.utils.DefaultViewBoundsResolver
import com.datadog.android.sessionreplay.utils.DefaultViewIdentifierResolver
import com.datadog.android.sessionreplay.utils.DrawableToColorMapper
import com.datadog.android.sessionreplay.utils.ViewBoundsResolver
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver
import com.google.android.material.slider.Slider
import com.google.android.material.tabs.TabLayout

Expand All @@ -19,13 +28,49 @@ import com.google.android.material.tabs.TabLayout
* configuration.
*/
class MaterialExtensionSupport : ExtensionSupport {

private val viewIdentifierResolver: ViewIdentifierResolver = DefaultViewIdentifierResolver
private val colorStringFormatter: ColorStringFormatter = DefaultColorStringFormatter
private val viewBoundsResolver: ViewBoundsResolver = DefaultViewBoundsResolver
private val drawableToColorMapper: DrawableToColorMapper = DrawableToColorMapper.getDefault()

@Suppress("UNCHECKED_CAST")
override fun getCustomViewMappers(): Map<SessionReplayPrivacy, Map<Class<*>, WireframeMapper<View, *>>> {
val maskUserInputSliderMapper = MaskSliderWireframeMapper() as WireframeMapper<View, *>
val maskSliderMapper = MaskSliderWireframeMapper() as WireframeMapper<View, *>
val allowSliderMapper = SliderWireframeMapper() as WireframeMapper<View, *>
val maskTabWireframeMapper = MaskTabWireframeMapper() as WireframeMapper<View, *>
val allowTabWireframeMapper = TabWireframeMapper() as WireframeMapper<View, *>
val maskUserInputSliderMapper = MaskSliderWireframeMapper(
viewIdentifierResolver,
colorStringFormatter,
viewBoundsResolver
) as WireframeMapper<View, *>
val maskSliderMapper = MaskSliderWireframeMapper(
viewIdentifierResolver,
colorStringFormatter,
viewBoundsResolver
) as WireframeMapper<View, *>
val allowSliderMapper = SliderWireframeMapper(
viewIdentifierResolver,
colorStringFormatter,
viewBoundsResolver
) as WireframeMapper<View, *>

val maskTabWireframeMapper =
MaskTabWireframeMapper(
viewIdentifierResolver,
viewBoundsResolver,
MaskTextViewMapper(
viewIdentifierResolver,
colorStringFormatter,
viewBoundsResolver,
drawableToColorMapper
)
) as WireframeMapper<View, *>

val allowTabWireframeMapper =
TabWireframeMapper(
viewIdentifierResolver,
viewBoundsResolver,
TextViewMapper(viewIdentifierResolver, colorStringFormatter, viewBoundsResolver, drawableToColorMapper)
) as WireframeMapper<View, *>

return mapOf(
SessionReplayPrivacy.ALLOW to mapOf(
Slider::class.java to allowSliderMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,37 @@
package com.datadog.android.sessionreplay.material

import android.content.res.ColorStateList
import com.datadog.android.sessionreplay.internal.AsyncJobStatusCallback
import com.datadog.android.sessionreplay.internal.recorder.MappingContext
import com.datadog.android.sessionreplay.internal.recorder.mapper.WireframeMapper
import com.datadog.android.sessionreplay.material.internal.densityNormalized
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.utils.StringUtils
import com.datadog.android.sessionreplay.utils.UniqueIdentifierGenerator
import com.datadog.android.sessionreplay.utils.ViewUtils
import com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback
import com.datadog.android.sessionreplay.utils.ColorStringFormatter
import com.datadog.android.sessionreplay.utils.ViewBoundsResolver
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver
import com.google.android.material.slider.Slider

internal open class SliderWireframeMapper(
private val viewUtils: ViewUtils = ViewUtils,
private val stringUtils: StringUtils = StringUtils,
private val uniqueIdentifierGenerator: UniqueIdentifierGenerator =
UniqueIdentifierGenerator
) :
WireframeMapper<Slider, MobileSegment.Wireframe> {
private val viewIdentifierResolver: ViewIdentifierResolver,
private val colorStringFormatter: ColorStringFormatter,
private val viewBoundsResolver: ViewBoundsResolver
) : WireframeMapper<Slider, MobileSegment.Wireframe> {

@Suppress("LongMethod")
override fun map(view: Slider, mappingContext: MappingContext, asyncJobStatusCallback: AsyncJobStatusCallback):
List<MobileSegment.Wireframe> {
val activeTrackId = uniqueIdentifierGenerator
val activeTrackId = viewIdentifierResolver
.resolveChildUniqueIdentifier(view, TRACK_ACTIVE_KEY_NAME)
val nonActiveTrackId = uniqueIdentifierGenerator
val nonActiveTrackId = viewIdentifierResolver
.resolveChildUniqueIdentifier(view, TRACK_NON_ACTIVE_KEY_NAME)
val thumbId = uniqueIdentifierGenerator.resolveChildUniqueIdentifier(view, THUMB_KEY_NAME)
val thumbId = viewIdentifierResolver.resolveChildUniqueIdentifier(view, THUMB_KEY_NAME)

if (activeTrackId == null || thumbId == null || nonActiveTrackId == null) {
return emptyList()
}

val screenDensity = mappingContext.systemInformation.screenDensity
val viewGlobalBounds = viewUtils.resolveViewGlobalBounds(view, screenDensity)
val viewGlobalBounds = viewBoundsResolver.resolveViewGlobalBounds(view, screenDensity)
val normalizedSliderValue = view.normalizedValue()
val viewAlpha = view.alpha

Expand All @@ -52,15 +50,15 @@ internal open class SliderWireframeMapper(
val trackActiveColor = view.trackActiveTintList.getColor(drawableState)
val trackNonActiveColor = view.trackInactiveTintList.getColor(drawableState)
val thumbColor = view.thumbTintList.getColor(drawableState)
val trackActiveColorAsHexa = stringUtils.formatColorAndAlphaAsHexa(
val trackActiveColorAsHexa = colorStringFormatter.formatColorAndAlphaAsHexString(
trackActiveColor,
OPAQUE_ALPHA_VALUE
)
val trackNonActiveColorAsHexa = stringUtils.formatColorAndAlphaAsHexa(
val trackNonActiveColorAsHexa = colorStringFormatter.formatColorAndAlphaAsHexString(
trackNonActiveColor,
PARTIALLY_OPAQUE_ALPHA_VALUE
)
val thumbColorAsHexa = stringUtils.formatColorAndAlphaAsHexa(thumbColor, OPAQUE_ALPHA_VALUE)
val thumbColorAsHexa = colorStringFormatter.formatColorAndAlphaAsHexString(thumbColor, OPAQUE_ALPHA_VALUE)

// track dimensions
val trackWidth = view.trackWidth.toLong().densityNormalized(screenDensity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,42 @@
package com.datadog.android.sessionreplay.material

import android.widget.TextView
import com.datadog.android.sessionreplay.internal.AsyncJobStatusCallback
import com.datadog.android.sessionreplay.internal.recorder.MappingContext
import com.datadog.android.sessionreplay.internal.recorder.SystemInformation
import com.datadog.android.sessionreplay.internal.recorder.mapper.TextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.WireframeMapper
import com.datadog.android.sessionreplay.material.internal.densityNormalized
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.utils.UniqueIdentifierGenerator
import com.datadog.android.sessionreplay.utils.ViewUtils
import com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback
import com.datadog.android.sessionreplay.utils.ColorStringFormatter
import com.datadog.android.sessionreplay.utils.DrawableToColorMapper
import com.datadog.android.sessionreplay.utils.ViewBoundsResolver
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.TabView

internal open class TabWireframeMapper(
private val viewUtils: ViewUtils = ViewUtils,
private val uniqueIdentifierGenerator: UniqueIdentifierGenerator =
UniqueIdentifierGenerator,
internal val textViewMapper: WireframeMapper<TextView, MobileSegment.Wireframe> = TextViewMapper()
internal open class TabWireframeMapper internal constructor(
private val viewIdentifierResolver: ViewIdentifierResolver,
private val viewBoundsResolver: ViewBoundsResolver,
internal val textViewMapper: WireframeMapper<TextView, MobileSegment.Wireframe>
) : WireframeMapper<TabLayout.TabView, MobileSegment.Wireframe> {

constructor(
viewIdentifierResolver: ViewIdentifierResolver,
colorStringFormatter: ColorStringFormatter,
viewBoundsResolver: ViewBoundsResolver,
drawableToColorMapper: DrawableToColorMapper
) : this(
viewIdentifierResolver,
viewBoundsResolver,
TextViewMapper(
viewIdentifierResolver,
colorStringFormatter,
viewBoundsResolver,
drawableToColorMapper
)
)

override fun map(
view: TabView,
mappingContext: MappingContext,
Expand Down Expand Up @@ -54,12 +71,12 @@ internal open class TabWireframeMapper(
systemInformation: SystemInformation,
wireframe: MobileSegment.Wireframe?
): MobileSegment.Wireframe? {
val selectorId = uniqueIdentifierGenerator.resolveChildUniqueIdentifier(
val selectorId = viewIdentifierResolver.resolveChildUniqueIdentifier(
view,
SELECTED_TAB_INDICATOR_KEY_NAME
) ?: return null
val screenDensity = systemInformation.screenDensity
val viewBounds = viewUtils.resolveViewGlobalBounds(view, screenDensity)
val viewBounds = viewBoundsResolver.resolveViewGlobalBounds(view, screenDensity)
val selectionIndicatorHeight = SELECTED_TAB_INDICATOR_HEIGHT_IN_PX
.densityNormalized(screenDensity)
val paddingStart = view.paddingStart.toLong().densityNormalized(screenDensity)
Expand Down
Loading

0 comments on commit 9859578

Please sign in to comment.