Skip to content

Commit

Permalink
Revert "RUM-1002 Implement base64 for imageviews"
Browse files Browse the repository at this point in the history
This reverts commit 3100b41.
  • Loading branch information
jonathanmos committed Oct 3, 2023
1 parent c757420 commit e135321
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import android.view.View
import android.widget.Button
import android.widget.CheckBox
import android.widget.CheckedTextView
import android.widget.EditText
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.NumberPicker
import android.widget.RadioButton
Expand All @@ -26,7 +28,8 @@ import com.datadog.android.sessionreplay.internal.recorder.mapper.BasePickerMapp
import com.datadog.android.sessionreplay.internal.recorder.mapper.ButtonMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.CheckBoxMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.CheckedTextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.ImageViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.EditTextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.ImageButtonMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.MapperTypeWrapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.MaskCheckBoxMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.MaskCheckedTextViewMapper
Expand All @@ -42,6 +45,8 @@ import com.datadog.android.sessionreplay.internal.recorder.mapper.SeekBarWirefra
import com.datadog.android.sessionreplay.internal.recorder.mapper.SwitchCompatMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.TextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.UnsupportedViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.ViewScreenshotWireframeMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.ViewWireframeMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.WireframeMapper
import com.datadog.android.sessionreplay.utils.UniqueIdentifierGenerator
import androidx.appcompat.widget.Toolbar as AppCompatToolbar
Expand Down Expand Up @@ -81,14 +86,17 @@ enum class SessionReplayPrivacy {
val imageWireframeHelper = ImageWireframeHelper(base64Serializer = base64Serializer)
val uniqueIdentifierGenerator = UniqueIdentifierGenerator

val viewWireframeMapper = ViewWireframeMapper()
val unsupportedViewMapper = UnsupportedViewMapper()
val imageViewMapper = ImageViewMapper(
val imageButtonMapper = ImageButtonMapper(
base64Serializer = base64Serializer,
imageWireframeHelper = imageWireframeHelper,
uniqueIdentifierGenerator = uniqueIdentifierGenerator
)
val imageMapper: ViewScreenshotWireframeMapper
val textMapper: TextViewMapper
val buttonMapper: ButtonMapper
val editTextViewMapper: EditTextViewMapper
val checkedTextViewMapper: CheckedTextViewMapper
val checkBoxMapper: CheckBoxMapper
val radioButtonMapper: RadioButtonMapper
Expand All @@ -97,11 +105,13 @@ enum class SessionReplayPrivacy {
val numberPickerMapper: BasePickerMapper?
when (this) {
ALLOW -> {
imageMapper = ViewScreenshotWireframeMapper(viewWireframeMapper)
textMapper = TextViewMapper(
imageWireframeHelper = imageWireframeHelper,
uniqueIdentifierGenerator = uniqueIdentifierGenerator
)
buttonMapper = ButtonMapper(textMapper)
editTextViewMapper = EditTextViewMapper(textMapper)
checkedTextViewMapper = CheckedTextViewMapper(textMapper)
checkBoxMapper = CheckBoxMapper(textMapper)
radioButtonMapper = RadioButtonMapper(textMapper)
Expand All @@ -110,11 +120,13 @@ enum class SessionReplayPrivacy {
numberPickerMapper = getNumberPickerMapper()
}
MASK -> {
imageMapper = ViewScreenshotWireframeMapper(viewWireframeMapper)
textMapper = MaskTextViewMapper(
imageWireframeHelper = imageWireframeHelper,
uniqueIdentifierGenerator = uniqueIdentifierGenerator
)
buttonMapper = ButtonMapper(textMapper)
editTextViewMapper = EditTextViewMapper(textMapper)
checkedTextViewMapper = MaskCheckedTextViewMapper(textMapper)
checkBoxMapper = MaskCheckBoxMapper(textMapper)
radioButtonMapper = MaskRadioButtonMapper(textMapper)
Expand All @@ -123,11 +135,13 @@ enum class SessionReplayPrivacy {
numberPickerMapper = getMaskNumberPickerMapper()
}
MASK_USER_INPUT -> {
imageMapper = ViewScreenshotWireframeMapper(viewWireframeMapper)
textMapper = MaskInputTextViewMapper(
imageWireframeHelper = imageWireframeHelper,
uniqueIdentifierGenerator = uniqueIdentifierGenerator
)
buttonMapper = ButtonMapper(textMapper)
editTextViewMapper = EditTextViewMapper(textMapper)
checkedTextViewMapper = MaskCheckedTextViewMapper(textMapper)
checkBoxMapper = MaskCheckBoxMapper(textMapper)
radioButtonMapper = MaskRadioButtonMapper(textMapper)
Expand All @@ -142,8 +156,10 @@ enum class SessionReplayPrivacy {
MapperTypeWrapper(CheckBox::class.java, checkBoxMapper.toGenericMapper()),
MapperTypeWrapper(CheckedTextView::class.java, checkedTextViewMapper.toGenericMapper()),
MapperTypeWrapper(Button::class.java, buttonMapper.toGenericMapper()),
MapperTypeWrapper(ImageButton::class.java, imageButtonMapper.toGenericMapper()),
MapperTypeWrapper(EditText::class.java, editTextViewMapper.toGenericMapper()),
MapperTypeWrapper(TextView::class.java, textMapper.toGenericMapper()),
MapperTypeWrapper(ImageView::class.java, imageViewMapper.toGenericMapper()),
MapperTypeWrapper(ImageView::class.java, imageMapper.toGenericMapper()),
MapperTypeWrapper(AppCompatToolbar::class.java, unsupportedViewMapper.toGenericMapper())
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.sessionreplay.internal.recorder.mapper

import android.widget.EditText
import com.datadog.android.sessionreplay.SessionReplayPrivacy
import com.datadog.android.sessionreplay.internal.AsyncJobStatusCallback
import com.datadog.android.sessionreplay.internal.recorder.MappingContext
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

/**
* A [WireframeMapper] implementation to map a [EditText] component in case the
* [SessionReplayPrivacy.ALLOW] rule was used in the configuration.
* In this case the mapper will use the provided [textViewMapper] used for the current privacy
* level and will only mask the [EditText] for which the input type is considered sensible
* (password, email, address, postal address, numeric password) with the static mask: [***].
*/
internal open class EditTextViewMapper(
internal val textViewMapper: TextViewMapper,
private val uniqueIdentifierGenerator: UniqueIdentifierGenerator = UniqueIdentifierGenerator,
viewUtils: ViewUtils = ViewUtils,
stringUtils: StringUtils = StringUtils
) : BaseWireframeMapper<EditText, MobileSegment.Wireframe>(
viewUtils = viewUtils,
stringUtils = stringUtils
) {

override fun map(
view: EditText,
mappingContext: MappingContext,
asyncJobStatusCallback: AsyncJobStatusCallback
):
List<MobileSegment.Wireframe> {
val mainWireframeList = textViewMapper.map(view, mappingContext, asyncJobStatusCallback)
resolveUnderlineWireframe(view, mappingContext.systemInformation.screenDensity)
?.let { wireframe ->
return mainWireframeList + wireframe
}
return mainWireframeList
}

private fun resolveUnderlineWireframe(
parent: EditText,
pixelsDensity: Float
): MobileSegment.Wireframe? {
val identifier = uniqueIdentifierGenerator.resolveChildUniqueIdentifier(
parent,
UNDERLINE_KEY_NAME
) ?: return null
val viewGlobalBounds = resolveViewGlobalBounds(parent, pixelsDensity)
val fieldUnderlineColor = resolveUnderlineColor(parent)
return MobileSegment.Wireframe.ShapeWireframe(
identifier,
viewGlobalBounds.x,
viewGlobalBounds.y + viewGlobalBounds.height - UNDERLINE_HEIGHT_IN_PIXELS,
viewGlobalBounds.width,
UNDERLINE_HEIGHT_IN_PIXELS,
shapeStyle = MobileSegment.ShapeStyle(
backgroundColor = fieldUnderlineColor,
opacity = parent.alpha
)
)
}

private fun resolveUnderlineColor(view: EditText): String {
view.backgroundTintList?.let {
return colorAndAlphaAsStringHexa(
it.defaultColor,
OPAQUE_ALPHA_VALUE
)
}
return colorAndAlphaAsStringHexa(view.currentTextColor, OPAQUE_ALPHA_VALUE)
}

companion object {
internal const val UNDERLINE_HEIGHT_IN_PIXELS = 1L
internal const val UNDERLINE_KEY_NAME = "underline"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package com.datadog.android.sessionreplay.internal.recorder.mapper

import android.widget.ImageView
import android.widget.ImageButton
import com.datadog.android.sessionreplay.internal.AsyncJobStatusCallback
import com.datadog.android.sessionreplay.internal.recorder.MappingContext
import com.datadog.android.sessionreplay.internal.recorder.base64.Base64Serializer
Expand All @@ -16,16 +16,16 @@ import com.datadog.android.sessionreplay.internal.recorder.densityNormalized
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.utils.UniqueIdentifierGenerator

internal class ImageViewMapper(
internal class ImageButtonMapper(
private val base64Serializer: Base64Serializer,
private val imageWireframeHelper: ImageWireframeHelper,
uniqueIdentifierGenerator: UniqueIdentifierGenerator
) : BaseAsyncBackgroundWireframeMapper<ImageView>(
) : BaseAsyncBackgroundWireframeMapper<ImageButton>(
imageWireframeHelper = imageWireframeHelper,
uniqueIdentifierGenerator = uniqueIdentifierGenerator
) {
override fun map(
view: ImageView,
view: ImageButton,
mappingContext: MappingContext,
asyncJobStatusCallback: AsyncJobStatusCallback
): List<MobileSegment.Wireframe> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import android.view.View
import android.widget.Button
import android.widget.CheckBox
import android.widget.CheckedTextView
import android.widget.EditText
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.NumberPicker
import android.widget.RadioButton
Expand All @@ -21,7 +23,8 @@ import androidx.appcompat.widget.SwitchCompat
import com.datadog.android.sessionreplay.internal.recorder.mapper.ButtonMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.CheckBoxMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.CheckedTextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.ImageViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.EditTextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.ImageButtonMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.MapperTypeWrapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.MaskCheckBoxMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.MaskCheckedTextViewMapper
Expand All @@ -37,6 +40,7 @@ import com.datadog.android.sessionreplay.internal.recorder.mapper.SeekBarWirefra
import com.datadog.android.sessionreplay.internal.recorder.mapper.SwitchCompatMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.TextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.UnsupportedViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.ViewScreenshotWireframeMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.WireframeMapper
import com.datadog.tools.unit.setStaticValue
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -106,12 +110,16 @@ internal class SessionReplayPrivacyTest {

// BASE
private val mockButtonMapper: ButtonMapper = mock()
private val mockEditTextViewMapper: EditTextViewMapper = mock()
private val mockImageMapper: ViewScreenshotWireframeMapper = mock()
private val mockUnsupportedViewMapper: UnsupportedViewMapper = mock()
private val mockImageViewMapper: ImageViewMapper = mock()
private val mockImageButtonViewMapper: ImageButtonMapper = mock()

private val baseMappers = listOf(
MapperTypeWrapper(Button::class.java, mockButtonMapper.toGenericMapper()),
MapperTypeWrapper(ImageView::class.java, mockImageViewMapper.toGenericMapper()),
MapperTypeWrapper(EditText::class.java, mockEditTextViewMapper.toGenericMapper()),
MapperTypeWrapper(ImageView::class.java, mockImageMapper.toGenericMapper()),
MapperTypeWrapper(ImageButton::class.java, mockImageButtonViewMapper.toGenericMapper()),
MapperTypeWrapper(AppCompatToolbar::class.java, mockUnsupportedViewMapper.toGenericMapper())
)

Expand Down
Loading

0 comments on commit e135321

Please sign in to comment.