-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUM-6218: Add privacy override for hidden views
- Loading branch information
1 parent
7ba01ef
commit 601398b
Showing
17 changed files
with
588 additions
and
36 deletions.
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
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
13 changes: 13 additions & 0 deletions
13
...-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/PrivacyLevel.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,13 @@ | ||
/* | ||
* 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 | ||
|
||
/** | ||
* Common interface for Session Replay privacy levels. | ||
* Privacy levels determine the degree of masking applied to sessions. | ||
*/ | ||
interface PrivacyLevel |
25 changes: 25 additions & 0 deletions
25
...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,25 @@ | ||
/* | ||
* 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.internal.PrivacyOverrideManager | ||
|
||
/** | ||
* 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.ddSessionReplayOverrideHidden(hide: Boolean) { | ||
if (hide) { | ||
PrivacyOverrideManager.addHiddenOverride(this) | ||
} else { | ||
PrivacyOverrideManager.removeHiddenOverride(this) | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...sion-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/PrivacyOverride.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,18 @@ | ||
/* | ||
* 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 | ||
|
||
import com.datadog.android.sessionreplay.ImagePrivacy | ||
import com.datadog.android.sessionreplay.TextAndInputPrivacy | ||
import com.datadog.android.sessionreplay.TouchPrivacy | ||
|
||
internal data class PrivacyOverride( | ||
val imagePrivacy: ImagePrivacy? = null, | ||
val touchPrivacy: TouchPrivacy? = null, | ||
val textAndInputPrivacy: TextAndInputPrivacy? = null, | ||
val hiddenPrivacy: Boolean = false | ||
) |
107 changes: 107 additions & 0 deletions
107
...play/src/main/kotlin/com/datadog/android/sessionreplay/internal/PrivacyOverrideManager.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,107 @@ | ||
/* | ||
* 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 | ||
|
||
import android.view.View | ||
import com.datadog.android.sessionreplay.ImagePrivacy | ||
import com.datadog.android.sessionreplay.PrivacyLevel | ||
import com.datadog.android.sessionreplay.TextAndInputPrivacy | ||
import com.datadog.android.sessionreplay.TouchPrivacy | ||
import java.lang.ref.WeakReference | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
internal object PrivacyOverrideManager { | ||
private val overridesMap = ConcurrentHashMap<WeakViewKey, PrivacyOverride>() | ||
|
||
internal fun addPrivacyOverride(view: View, level: PrivacyLevel?) { | ||
val key = WeakViewKey(view) | ||
val existingPrivacy = overridesMap[key] ?: PrivacyOverride() | ||
|
||
overridesMap[key] = | ||
when (level) { | ||
is ImagePrivacy -> existingPrivacy.copy( | ||
imagePrivacy = level | ||
) | ||
|
||
is TextAndInputPrivacy -> existingPrivacy.copy( | ||
textAndInputPrivacy = level | ||
) | ||
|
||
is TouchPrivacy -> existingPrivacy.copy( | ||
touchPrivacy = level | ||
) | ||
|
||
else -> return | ||
} | ||
} | ||
|
||
internal fun removeTextAndInputPrivacyOverride(view: View) { | ||
val key = WeakViewKey(view) | ||
val existingPrivacy = overridesMap[key] ?: return | ||
|
||
overridesMap[key] = existingPrivacy.copy( | ||
textAndInputPrivacy = null | ||
) | ||
} | ||
|
||
internal fun removeTouchPrivacyOverride(view: View) { | ||
val key = WeakViewKey(view) | ||
val existingPrivacy = overridesMap[key] ?: return | ||
|
||
overridesMap[key] = existingPrivacy.copy( | ||
touchPrivacy = null | ||
) | ||
} | ||
|
||
internal fun removeImagePrivacyOverride(view: View) { | ||
val key = WeakViewKey(view) | ||
val existingPrivacy = overridesMap[key] ?: return | ||
|
||
overridesMap[key] = existingPrivacy.copy( | ||
imagePrivacy = null | ||
) | ||
} | ||
|
||
internal fun addHiddenOverride(view: View) { | ||
val key = WeakViewKey(view) | ||
val existingPrivacy = overridesMap[key] ?: PrivacyOverride() | ||
|
||
overridesMap[key] = existingPrivacy.copy( | ||
hiddenPrivacy = true | ||
) | ||
} | ||
|
||
internal fun removeHiddenOverride(view: View) { | ||
val key = WeakViewKey(view) | ||
val existingPrivacy = overridesMap[key] ?: return | ||
|
||
overridesMap[key] = existingPrivacy.copy( | ||
hiddenPrivacy = false | ||
) | ||
} | ||
|
||
internal fun getPrivacyOverrides(view: View): PrivacyOverride? { | ||
val key = WeakViewKey(view) | ||
return overridesMap[key] | ||
} | ||
|
||
internal fun isHidden(view: View): Boolean { | ||
val key = WeakViewKey(view) | ||
return overridesMap[key]?.hiddenPrivacy == true | ||
} | ||
|
||
private class WeakViewKey(view: View) : WeakReference<View>(view) { | ||
override fun equals(other: Any?): Boolean { | ||
val otherValue = (other as? WeakViewKey)?.get() | ||
return get() == otherValue | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return get()?.hashCode() ?: 0 | ||
} | ||
} | ||
} |
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
Oops, something went wrong.