@@ -5,17 +5,35 @@ import androidx.compose.ui.semantics.getOrNull
55import com.launchdarkly.observability.replay.MaskMatcher
66
77/* *
8- * The [PrivacyProfile] class encapsulates options and functionality related to privacy of session
8+ * [PrivacyProfile] encapsulates options and functionality related to privacy of session
99 * replay functionality.
1010 *
11- * By default, session replay will apply an opaque mask to elemetns that match the [builtInMatchers].
12- * To customize this behavior, use one of [strict], [optIn], [optOut]
11+ * By default, session replay will apply an opaque mask to text inputs, text, and sensitive views.
12+ * See [sensitiveMatcher] for specific details.
13+ *
14+ * @param maskTextInputs set to false to turn off masking text inputs
15+ * @param maskText set to false to turn off masking text
16+ * @param maskSensitive set to false to turn off masking sensitive views
17+ * @param maskAdditionalMatchers list of additional [MaskMatcher]s that will be masked when they match
1318 **/
14- data class PrivacyProfile private constructor(
15- internal val maskMatchers : List <MaskMatcher >,
19+ data class PrivacyProfile (
20+ val maskTextInputs : Boolean = true ,
21+ val maskText : Boolean = true ,
22+ val maskSensitive : Boolean = true ,
23+ val maskAdditionalMatchers : List <MaskMatcher > = emptyList(),
1624) {
17- companion object {
1825
26+ /* *
27+ * Converts this [PrivacyProfile] into its equivalent [MaskMatcher] list.
28+ */
29+ internal fun asMatchersList (): List <MaskMatcher > = buildList {
30+ if (maskTextInputs) add(textInputMatcher)
31+ if (maskText) add(textMatcher)
32+ if (maskSensitive) add(sensitiveMatcher)
33+ addAll(maskAdditionalMatchers)
34+ }
35+
36+ companion object {
1937 /* *
2038 * This matcher will match most text inputs, but there may be special cases where it will
2139 * miss as we can't account for all possible future semantic properties.
@@ -81,88 +99,6 @@ data class PrivacyProfile private constructor(
8199 }
82100 }
83101
84- /* *
85- * The list of built in matchers.
86- */
87- val builtInMatchers = listOf (textInputMatcher, textMatcher, sensitiveMatcher)
88-
89- /* *
90- * A [PrivacyProfile] that will perform no masking.
91- *
92- * @sample
93- * ```kotlin
94- * ReplayInstrumentation(
95- * options = ReplayOptions(
96- * privacyProfile = PrivacyProfile.noMasking()
97- * )
98- * )
99- * ```
100- */
101- fun noMasking () = PrivacyProfile (
102- maskMatchers = emptyList(),
103- )
104-
105- /* *
106- * A [PrivacyProfile] that uses [builtInMatchers] plus any additional [MaskMatcher]s provided.
107- *
108- * Matchers should not do heavy work, should execute synchronously, and not dispatch to other
109- * threads for performance reasons. If you add a matcher and notice jitter, this may be
110- * the cause.
111- *
112- * @sample
113- * ```kotlin
114- * ReplayInstrumentation(
115- * options = ReplayOptions(
116- * privacyProfile = PrivacyProfile.strict()
117- * )
118- * )
119- * ```
120- *
121- * @param additionalMatchers additional matchers that will also run after built in matchers
122- */
123- fun strict (additionalMatchers : List <MaskMatcher > = emptyList()) = PrivacyProfile (
124- maskMatchers = buildList {
125- addAll(builtInMatchers)
126- addAll(additionalMatchers)
127- },
128- )
129-
130- /* *
131- * A [PrivacyProfile] that uses only the provided [MaskMatcher]s
132- *
133- * @sample
134- * ```kotlin
135- * ReplayInstrumentation(
136- * options = ReplayOptions(
137- * privacyProfile = PrivacyProfile.optIn(listOf(PrivacyProfile.sensitiveMatcher))
138- * )
139- * )
140- * ```
141- *
142- * @param matchers the matchers to use
143- */
144- fun optIn (matchers : List <MaskMatcher >) = PrivacyProfile (
145- maskMatchers = matchers,
146- )
147-
148- /* *
149- * A [PrivacyProfile] that uses all [builtInMatchers] except those provided.
150- *
151- * @sample
152- * ```kotlin
153- * ReplayInstrumentation(
154- * options = ReplayOptions(
155- * privacyProfile = PrivacyProfile.optOut(listOf(PrivacyProfile.textMatcher))
156- * )
157- * )
158- * ```
159- *
160- * @param matchers the matchers to NOT use
161- */
162- fun optOut (matchers : List <MaskMatcher >) = PrivacyProfile (
163- maskMatchers = builtInMatchers.filter { it !in matchers },
164- )
165-
166102 // this list of sensitive keywords is used to detect sensitive content descriptions
167103 private val sensitiveKeywords = listOf (
168104 " sensitive" ,
0 commit comments