-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2291 from DataDog/jmoskovich/rum-6218/implement-h…
…idden-privacy-override RUM-6218: Add privacy override for hidden views
- Loading branch information
Showing
10 changed files
with
287 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ion-replay/src/main/kotlin/com/datadog/android/sessionreplay/PrivacyOverrideExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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 | ||
|
||
import android.view.View | ||
|
||
/** | ||
* Allows setting a view to be "hidden" in the hierarchy in Session Replay. | ||
* When hidden the view will be replaced with a placeholder in the replay and | ||
* no attempt will be made to record it's children. | ||
* | ||
* @param hide pass `true` to hide the view, or `false` to remove the override | ||
*/ | ||
fun View.setSessionReplayHidden(hide: Boolean) { | ||
if (hide) { | ||
this.setTag(R.id.datadog_hidden, true) | ||
} else { | ||
this.setTag(R.id.datadog_hidden, null) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ain/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/HiddenViewMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.view.View | ||
import com.datadog.android.api.InternalLogger | ||
import com.datadog.android.sessionreplay.model.MobileSegment | ||
import com.datadog.android.sessionreplay.recorder.MappingContext | ||
import com.datadog.android.sessionreplay.recorder.mapper.WireframeMapper | ||
import com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback | ||
import com.datadog.android.sessionreplay.utils.ViewBoundsResolver | ||
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver | ||
|
||
internal class HiddenViewMapper( | ||
val viewIdentifierResolver: ViewIdentifierResolver, | ||
val viewBoundsResolver: ViewBoundsResolver | ||
) : WireframeMapper<View> { | ||
override fun map( | ||
view: View, | ||
mappingContext: MappingContext, | ||
asyncJobStatusCallback: AsyncJobStatusCallback, | ||
internalLogger: InternalLogger | ||
): List<MobileSegment.Wireframe> { | ||
val id = viewIdentifierResolver.resolveChildUniqueIdentifier(view, HIDDEN_KEY_NAME) | ||
?: return emptyList() | ||
|
||
val density = mappingContext.systemInformation.screenDensity | ||
val viewGlobalBounds = viewBoundsResolver.resolveViewGlobalBounds(view, density) | ||
|
||
return listOf( | ||
MobileSegment.Wireframe.PlaceholderWireframe( | ||
id = id, | ||
x = viewGlobalBounds.x, | ||
y = viewGlobalBounds.y, | ||
width = viewGlobalBounds.width, | ||
height = viewGlobalBounds.height, | ||
label = HIDDEN_VIEW_PLACEHOLDER_TEXT | ||
) | ||
) | ||
} | ||
|
||
internal companion object { | ||
internal const val HIDDEN_VIEW_PLACEHOLDER_TEXT = "Hidden" | ||
private const val HIDDEN_KEY_NAME = "hidden" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
features/dd-sdk-android-session-replay/src/main/res/values/ids.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
~ 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. | ||
--> | ||
|
||
<resources> | ||
<item name="datadog_hidden" type="id"/> | ||
</resources> |
55 changes: 55 additions & 0 deletions
55
...replay/src/test/kotlin/com/datadog/android/sessionreplay/PrivacyOverrideExtensionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 | ||
|
||
import android.view.View | ||
import com.datadog.android.sessionreplay.forge.ForgeConfigurator | ||
import fr.xgouchet.elmyr.junit5.ForgeConfiguration | ||
import fr.xgouchet.elmyr.junit5.ForgeExtension | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.junit.jupiter.api.extension.Extensions | ||
import org.mockito.Mockito.mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.junit.jupiter.MockitoSettings | ||
import org.mockito.kotlin.eq | ||
import org.mockito.kotlin.isNull | ||
import org.mockito.kotlin.verify | ||
import org.mockito.quality.Strictness | ||
|
||
@Extensions( | ||
ExtendWith(MockitoExtension::class), | ||
ExtendWith(ForgeExtension::class) | ||
) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
@ForgeConfiguration(ForgeConfigurator::class) | ||
internal class PrivacyOverrideExtensionsTest { | ||
|
||
@Test | ||
fun `M set tag W setSessionReplayHidden() { hide is true }`() { | ||
// Given | ||
val mockView = mock<View>() | ||
|
||
// When | ||
mockView.setSessionReplayHidden(true) | ||
|
||
// Then | ||
verify(mockView).setTag(eq(R.id.datadog_hidden), eq(true)) | ||
} | ||
|
||
@Test | ||
fun `M set tag to null W setSessionReplayHidden() { hide is false }`() { | ||
// Given | ||
val mockView = mock<View>() | ||
|
||
// When | ||
mockView.setSessionReplayHidden(false) | ||
|
||
// Then | ||
verify(mockView).setTag(eq(R.id.datadog_hidden), isNull()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.