-
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 27524eb
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 currentOverrideAreas at the end | ||
// We use two hashmaps because touch handling happens in parallel to the view traversal | ||
// and we don't know which will happen first. | ||
// Secondly, because we don't want to have to keep track of the lifecycle of the overridden views in order to remove | ||
// the overrides when they are no longer needed. | ||
private val nextOverrideAreas = HashMap<Rect, TouchPrivacy>() | ||
|
||
@UiThread | ||
internal fun addTouchOverrideArea(bounds: Rect, touchPrivacy: TouchPrivacy) { | ||
nextOverrideAreas[bounds] = touchPrivacy | ||
} | ||
|
||
@UiThread | ||
internal fun updateCurrentTouchOverrideAreas() { | ||
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 (area.contains(touchLocation.x, touchLocation.y)) { | ||
when (overrideValue) { | ||
TouchPrivacy.HIDE -> return false | ||
TouchPrivacy.SHOW -> isOverriddenToShowTouch = true | ||
} | ||
} | ||
} | ||
|
||
return if (isOverriddenToShowTouch) true else globalTouchPrivacy == TouchPrivacy.SHOW | ||
} | ||
|
||
@VisibleForTesting | ||
internal fun getCurrentOverrideAreas(): Map<Rect, TouchPrivacy> { | ||
return currentOverrideAreas | ||
} | ||
|
||
@VisibleForTesting | ||
internal fun getNextOverrideAreas(): Map<Rect, TouchPrivacy> { | ||
return nextOverrideAreas | ||
} | ||
} |
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.