-
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 f466427
Showing
18 changed files
with
653 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
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 |
81 changes: 81 additions & 0 deletions
81
...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,81 @@ | ||
/* | ||
* 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 adding and removing `TextAndInputPrivacy` for a specific view in Session Replay. | ||
* Once added, this override will impact the privacy of the view and it's children | ||
* taking priority over the global privacy level | ||
* | ||
* @param level the TextAndInputPrivacy to set for the view, | ||
* or pass null to remove the override | ||
*/ | ||
fun View.ddSessionReplayOverrideTextAndInputPrivacy(level: TextAndInputPrivacy?) { | ||
if (id == View.NO_ID) return | ||
|
||
if (level == null) { | ||
PrivacyOverrideManager.removeTextAndInputPrivacyOverride(id) | ||
} else { | ||
PrivacyOverrideManager.addPrivacyOverride(id, level) | ||
} | ||
} | ||
|
||
/** | ||
* Allows adding and removing `TouchPrivacy` for a specific view in Session Replay. | ||
* Once added, this override will impact the privacy of the view and it's children | ||
* taking priority over the global privacy level | ||
* | ||
* @param level the TouchPrivacy to set for the view, | ||
* or pass null to remove the override | ||
*/ | ||
fun View.ddSessionReplayOverrideTouchPrivacy(level: TouchPrivacy?) { | ||
if (id == View.NO_ID) return | ||
|
||
if (level == null) { | ||
PrivacyOverrideManager.removeTouchPrivacyOverride(id) | ||
} else { | ||
PrivacyOverrideManager.addPrivacyOverride(id, level) | ||
} | ||
} | ||
|
||
/** | ||
* Allows adding and removing `ImagePrivacy` for a specific view in Session Replay. | ||
* Once added, this override will impact the privacy of the view and it's children | ||
* taking priority over the global privacy level | ||
* | ||
* @param level the ImagePrivacy to set for the view, | ||
* or pass null to remove the override | ||
*/ | ||
fun View.ddSessionReplayOverrideImagePrivacy(level: ImagePrivacy?) { | ||
if (id == View.NO_ID) return | ||
|
||
if (level == null) { | ||
PrivacyOverrideManager.removeImagePrivacyOverride(id) | ||
} else { | ||
PrivacyOverrideManager.addPrivacyOverride(id, level) | ||
} | ||
} | ||
|
||
/** | ||
* Allows setting a view to be "hidden" in the hierarchy in Session Replay. | ||
* When hidden the view will be replaced with an opaque square 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 (id == View.NO_ID) return | ||
|
||
if (hide) { | ||
PrivacyOverrideManager.setViewHidden(id) | ||
} else { | ||
PrivacyOverrideManager.setViewNotHidden(id) | ||
} | ||
} |
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 | ||
) |
89 changes: 89 additions & 0 deletions
89
...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,89 @@ | ||
/* | ||
* 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.PrivacyLevel | ||
import com.datadog.android.sessionreplay.TextAndInputPrivacy | ||
import com.datadog.android.sessionreplay.TouchPrivacy | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
internal object PrivacyOverrideManager { | ||
private val overridesMap = ConcurrentHashMap<Int, PrivacyOverride>() | ||
|
||
internal fun addPrivacyOverride(id: Int, level: PrivacyLevel?) { | ||
val existingPrivacy = overridesMap[id] ?: PrivacyOverride() | ||
|
||
overridesMap[id] = | ||
when (level) { | ||
is ImagePrivacy -> existingPrivacy.copy( | ||
imagePrivacy = level | ||
) | ||
|
||
is TextAndInputPrivacy -> existingPrivacy.copy( | ||
textAndInputPrivacy = level | ||
) | ||
|
||
is TouchPrivacy -> existingPrivacy.copy( | ||
touchPrivacy = level | ||
) | ||
|
||
else -> return | ||
} | ||
} | ||
|
||
internal fun setViewHidden(id: Int) { | ||
val existingPrivacy = overridesMap[id] ?: PrivacyOverride() | ||
overridesMap[id] = existingPrivacy.copy( | ||
hiddenPrivacy = true | ||
) | ||
} | ||
|
||
internal fun removeTextAndInputPrivacyOverride(id: Int) { | ||
val existingPrivacy = overridesMap[id] ?: return | ||
|
||
overridesMap[id] = existingPrivacy.copy( | ||
textAndInputPrivacy = null | ||
) | ||
} | ||
|
||
internal fun removeTouchPrivacyOverride(id: Int) { | ||
val existingPrivacy = overridesMap[id] ?: return | ||
|
||
overridesMap[id] = existingPrivacy.copy( | ||
touchPrivacy = null | ||
) | ||
} | ||
|
||
internal fun removeImagePrivacyOverride(id: Int) { | ||
val existingPrivacy = overridesMap[id] ?: return | ||
|
||
overridesMap[id] = existingPrivacy.copy( | ||
imagePrivacy = null | ||
) | ||
} | ||
|
||
internal fun setViewNotHidden(id: Int) { | ||
val existingPrivacy = overridesMap[id] ?: return | ||
|
||
overridesMap[id] = existingPrivacy.copy( | ||
hiddenPrivacy = false | ||
) | ||
} | ||
|
||
internal fun getPrivacyOverrides(id: Int): PrivacyOverride? { | ||
return overridesMap[id] | ||
} | ||
|
||
internal fun clearOverrides() { | ||
overridesMap.clear() | ||
} | ||
|
||
internal fun isHidden(id: Int): Boolean { | ||
return overridesMap[id]?.hiddenPrivacy == true | ||
} | ||
} |
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.