-
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.
- Loading branch information
1 parent
774c798
commit fb3e526
Showing
29 changed files
with
524 additions
and
112 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
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
...ession-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/PrivacyHelper.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.internal | ||
|
||
import com.datadog.android.api.InternalLogger | ||
|
||
internal class PrivacyHelper(private val internalLogger: InternalLogger) { | ||
internal fun logInvalidPrivacyLevelError(e: Exception) { | ||
internalLogger.log( | ||
InternalLogger.Level.ERROR, | ||
listOf(InternalLogger.Target.USER, InternalLogger.Target.TELEMETRY), | ||
{ INVALID_PRIVACY_LEVEL_ERROR }, | ||
e | ||
) | ||
} | ||
|
||
internal companion object { | ||
internal const val INVALID_PRIVACY_LEVEL_ERROR = "Invalid privacy level" | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/TouchPrivacyManager.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,65 @@ | ||
/* | ||
* 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.graphics.Point | ||
import android.graphics.Rect | ||
import androidx.annotation.UiThread | ||
import androidx.annotation.VisibleForTesting | ||
import com.datadog.android.sessionreplay.TouchPrivacy | ||
|
||
internal class TouchPrivacyManager( | ||
private val globalTouchPrivacy: TouchPrivacy | ||
) { | ||
// areas on screen where overrides are applied | ||
@VisibleForTesting internal val currentOverrideSnapshot = HashMap<Rect, TouchPrivacy>() | ||
|
||
// built during the view traversal and copied to currentOverrideSnapshot at the end | ||
@VisibleForTesting internal val nextOverrideSnapshot = HashMap<Rect, TouchPrivacy>() | ||
|
||
@UiThread | ||
internal fun addTouchOverrideArea(bounds: Rect, touchPrivacy: TouchPrivacy) { | ||
nextOverrideSnapshot[bounds] = touchPrivacy | ||
} | ||
|
||
@UiThread | ||
internal fun copyNextSnapshotToCurrentSnapshot() { | ||
currentOverrideSnapshot.clear() | ||
@Suppress("UnsafeThirdPartyFunctionCall") // NPE cannot happen here | ||
currentOverrideSnapshot.putAll(nextOverrideSnapshot) | ||
nextOverrideSnapshot.clear() | ||
} | ||
|
||
@UiThread | ||
internal fun resolveTouchPrivacy(touchLocation: Point): TouchPrivacy { | ||
var showOverrideSet = false | ||
|
||
// avoid having the collection change while we iterate through it | ||
val overrideAreas = HashMap<Rect, TouchPrivacy>() | ||
@Suppress("UnsafeThirdPartyFunctionCall") // NPE cannot happen here | ||
overrideAreas.putAll(currentOverrideSnapshot) | ||
|
||
@Suppress("UnsafeThirdPartyFunctionCall") // ConcurrentModification cannot happen here | ||
overrideAreas.forEach { entry -> | ||
val area = entry.key | ||
val overrideValue = entry.value | ||
|
||
if (isWithinOverrideArea(touchLocation, area)) { | ||
when (overrideValue) { | ||
TouchPrivacy.HIDE -> return TouchPrivacy.HIDE | ||
TouchPrivacy.SHOW -> showOverrideSet = true | ||
} | ||
} | ||
} | ||
|
||
return if (showOverrideSet) TouchPrivacy.SHOW else globalTouchPrivacy | ||
} | ||
|
||
private fun isWithinOverrideArea(touchPoint: Point, overrideArea: Rect): Boolean = | ||
touchPoint.x in overrideArea.left..overrideArea.right && | ||
touchPoint.y in overrideArea.top..overrideArea.bottom | ||
} |
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
Oops, something went wrong.