-
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.
RUM-6566: Implement touch privacy override
- Loading branch information
1 parent
1972959
commit 5d21381
Showing
26 changed files
with
492 additions
and
97 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
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
72 changes: 72 additions & 0 deletions
72
...-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,72 @@ | ||
/* | ||
* 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 | ||
private val currentOverrideAreas = HashMap<Rect, TouchPrivacy>() | ||
|
||
// built during the view traversal and copied to currentOverrideSnapshot at the end | ||
private val nextOverrideAreas = HashMap<Rect, TouchPrivacy>() | ||
|
||
@UiThread | ||
internal fun addTouchOverrideArea(bounds: Rect, touchPrivacy: TouchPrivacy) { | ||
nextOverrideAreas[bounds] = touchPrivacy | ||
} | ||
|
||
@UiThread | ||
internal fun updateCurrentTouchOverrideSnapshot() { | ||
currentOverrideAreas.clear() | ||
// NPE cannot happen here | ||
@Suppress("UnsafeThirdPartyFunctionCall") | ||
currentOverrideAreas.putAll(nextOverrideAreas) | ||
nextOverrideAreas.clear() | ||
} | ||
|
||
@UiThread | ||
internal fun shouldRecordTouch(touchLocation: Point): Boolean { | ||
var isOverriddenToShowTouch = false | ||
|
||
// Everything is UiThread, so ConcurrentModification cannot happen here | ||
@Suppress("UnsafeThirdPartyFunctionCall") | ||
currentOverrideAreas.forEach { entry -> | ||
val area = entry.key | ||
val overrideValue = entry.value | ||
|
||
if (isWithinOverrideArea(touchLocation, area)) { | ||
when (overrideValue) { | ||
TouchPrivacy.HIDE -> return false | ||
TouchPrivacy.SHOW -> isOverriddenToShowTouch = true | ||
} | ||
} | ||
} | ||
|
||
return if (isOverriddenToShowTouch) true else globalTouchPrivacy == TouchPrivacy.SHOW | ||
} | ||
|
||
@VisibleForTesting | ||
internal fun getCurrentOverrideSnapshot(): Map<Rect, TouchPrivacy> { | ||
return currentOverrideAreas | ||
} | ||
|
||
@VisibleForTesting | ||
internal fun getNextOverrideSnapshot(): Map<Rect, TouchPrivacy> { | ||
return nextOverrideAreas | ||
} | ||
|
||
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
Oops, something went wrong.