-
Notifications
You must be signed in to change notification settings - Fork 81
PANA-5681: Integrate HeatmapIdentifierRegistry into RUM for heatmaps [3 of 4] #3205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gonzalezreal
wants to merge
3
commits into
feature/heatmaps
Choose a base branch
from
gonzalezreal/PANA-5681/rum-heatmaps
base: feature/heatmaps
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
.../src/main/java/com/datadog/android/internal/heatmaps/HeatmapIdentifierRegistryProvider.kt
This file contains hidden or 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,16 @@ | ||
| /* | ||
| * 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.internal.heatmaps | ||
|
|
||
| /** | ||
| * Implemented by SDK features that own a [HeatmapIdentifierRegistry], allowing peer features | ||
| * to obtain a typed reference via [com.datadog.android.api.feature.FeatureScope.unwrap]. | ||
| */ | ||
| interface HeatmapIdentifierRegistryProvider { | ||
| /** The [HeatmapIdentifierRegistry] owned by this feature. */ | ||
| val heatmapIdentifierRegistry: HeatmapIdentifierRegistry | ||
| } |
This file contains hidden or 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
30 changes: 30 additions & 0 deletions
30
...dk-android-internal/src/main/java/com/datadog/android/internal/heatmaps/HeatmapViewKey.kt
This file contains hidden or 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,30 @@ | ||
| /* | ||
| * 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.internal.heatmaps | ||
|
|
||
| import android.view.View | ||
|
|
||
| // Polynomial coefficient — matches Java's standard hashCode convention. | ||
| internal const val HEATMAP_VIEW_KEY_COEFFICIENT = 31L | ||
|
|
||
| /** | ||
| * Returns the key used to store and look up a view's [HeatmapIdentifier] in a | ||
| * [HeatmapIdentifierRegistry]. | ||
| * | ||
| * The key combines the identity hash of the view with the identity hash of its direct parent | ||
| * using a polynomial combination with coefficient 31 (the same coefficient used by Java's | ||
| * standard `hashCode` convention). This makes the combinator non-commutative: swapping the | ||
| * view and parent hashes produces a different key. | ||
| * | ||
| * Note: the returned value is an opaque 64-bit quantity and may be negative, since | ||
| * [System.identityHashCode] returns a signed [Int] that is sign-extended on widening to [Long]. | ||
| * Callers must not assume the key is non-negative. | ||
| */ | ||
| fun heatmapViewKey(view: View): Long { | ||
| val parentHash = view.parent?.let { System.identityHashCode(it) } ?: 0 | ||
| return HEATMAP_VIEW_KEY_COEFFICIENT * System.identityHashCode(view).toLong() + parentHash.toLong() | ||
| } |
21 changes: 21 additions & 0 deletions
21
...dk-android-internal/src/main/java/com/datadog/android/internal/heatmaps/TapTargetUtils.kt
This file contains hidden or 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,21 @@ | ||
| /* | ||
| * 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.internal.heatmaps | ||
|
|
||
| import android.view.View | ||
|
|
||
| /** | ||
| * Single canonical tap-target predicate shared by the RUM gesture layer and Session Replay, | ||
| * so both subsystems stay in sync automatically. | ||
| * | ||
| * Note: [View.isEnabled] is intentionally not checked. Disabled views retain [View.isClickable] | ||
| * = true on Android but never receive touch events, so the RUM gesture layer never fires for | ||
| * them. Excluding `isEnabled` here keeps the predicate identical to RUM's existing behaviour. | ||
| */ | ||
| fun View.isValidTapTarget(): Boolean { | ||
| return isClickable && visibility == View.VISIBLE | ||
| } | ||
94 changes: 94 additions & 0 deletions
94
...ndroid-internal/src/test/java/com/datadog/android/internal/heatmaps/HeatmapViewKeyTest.kt
This file contains hidden or 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,94 @@ | ||
| /* | ||
| * 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.internal.heatmaps | ||
|
|
||
| import android.view.View | ||
| import android.view.ViewParent | ||
| import com.datadog.android.internal.forge.Configurator | ||
| import fr.xgouchet.elmyr.junit5.ForgeConfiguration | ||
| import fr.xgouchet.elmyr.junit5.ForgeExtension | ||
| import org.assertj.core.api.Assertions.assertThat | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.extension.ExtendWith | ||
| import org.junit.jupiter.api.extension.Extensions | ||
| import org.mockito.junit.jupiter.MockitoExtension | ||
| import org.mockito.junit.jupiter.MockitoSettings | ||
| import org.mockito.kotlin.mock | ||
| import org.mockito.kotlin.whenever | ||
| import org.mockito.quality.Strictness | ||
|
|
||
| @Extensions( | ||
| ExtendWith(MockitoExtension::class), | ||
| ExtendWith(ForgeExtension::class) | ||
| ) | ||
| @MockitoSettings(strictness = Strictness.LENIENT) | ||
| @ForgeConfiguration(Configurator::class) | ||
| internal class HeatmapViewKeyTest { | ||
|
|
||
| @Test | ||
| fun `M include parent hash W heatmapViewKey() {view has parent}`() { | ||
| // Given | ||
| val fakeView: View = mock() | ||
| val fakeParent: ViewParent = mock() | ||
| whenever(fakeView.parent).thenReturn(fakeParent) | ||
|
|
||
| // When | ||
| val key = heatmapViewKey(fakeView) | ||
|
|
||
| // Then | ||
| val expected = HEATMAP_VIEW_KEY_COEFFICIENT * System.identityHashCode(fakeView).toLong() + | ||
| System.identityHashCode(fakeParent).toLong() | ||
| assertThat(key).isEqualTo(expected) | ||
| } | ||
|
|
||
| @Test | ||
| fun `M use zero for parent hash W heatmapViewKey() {view has no parent}`() { | ||
| // Given | ||
| val fakeView: View = mock() | ||
| whenever(fakeView.parent).thenReturn(null) | ||
|
|
||
| // When | ||
| val key = heatmapViewKey(fakeView) | ||
|
|
||
| // Then | ||
| assertThat(key).isEqualTo(HEATMAP_VIEW_KEY_COEFFICIENT * System.identityHashCode(fakeView).toLong()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `M return distinct keys W heatmapViewKey() {two views with same parent}`() { | ||
| // Given | ||
| val fakeParent: ViewParent = mock() | ||
| val fakeView1: View = mock() | ||
| val fakeView2: View = mock() | ||
| whenever(fakeView1.parent).thenReturn(fakeParent) | ||
| whenever(fakeView2.parent).thenReturn(fakeParent) | ||
|
|
||
| // When / Then | ||
| assertThat(heatmapViewKey(fakeView1)).isNotEqualTo(heatmapViewKey(fakeView2)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `M return distinct keys W heatmapViewKey() {view and parent hashes swapped}`() { | ||
| // Given — verifies the combinator is non-commutative: | ||
| // key(view=A, parent=B) must not equal key(view=B, parent=A). | ||
| // We wire fakeViewA's parent to fakeParentB and fakeViewB's parent to fakeParentA, | ||
| // so the two keys use the same pair of identity hashes but in opposite roles. | ||
| // | ||
| // Note: the assertion relies on the four mock objects having distinct identity hashes. | ||
| // Two mocks could theoretically collide (probability < 1/2^32 per run), which would make | ||
| // the assertion trivially true but for the wrong reason. This is considered acceptable. | ||
| val fakeViewA: View = mock() | ||
| val fakeViewB: View = mock() | ||
| val fakeParentA: ViewParent = mock() | ||
| val fakeParentB: ViewParent = mock() | ||
| whenever(fakeViewA.parent).thenReturn(fakeParentB) | ||
| whenever(fakeViewB.parent).thenReturn(fakeParentA) | ||
|
|
||
| // When / Then | ||
| assertThat(heatmapViewKey(fakeViewA)).isNotEqualTo(heatmapViewKey(fakeViewB)) | ||
| } | ||
| } |
86 changes: 86 additions & 0 deletions
86
...ndroid-internal/src/test/java/com/datadog/android/internal/heatmaps/TapTargetUtilsTest.kt
This file contains hidden or 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,86 @@ | ||
| /* | ||
| * 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.internal.heatmaps | ||
|
|
||
| import android.view.View | ||
| import com.datadog.android.internal.forge.Configurator | ||
| import fr.xgouchet.elmyr.junit5.ForgeConfiguration | ||
| import fr.xgouchet.elmyr.junit5.ForgeExtension | ||
| import org.assertj.core.api.Assertions.assertThat | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.extension.ExtendWith | ||
| import org.junit.jupiter.api.extension.Extensions | ||
| import org.mockito.junit.jupiter.MockitoExtension | ||
| import org.mockito.junit.jupiter.MockitoSettings | ||
| import org.mockito.kotlin.mock | ||
| import org.mockito.kotlin.whenever | ||
| import org.mockito.quality.Strictness | ||
|
|
||
| @Extensions( | ||
| ExtendWith(MockitoExtension::class), | ||
| ExtendWith(ForgeExtension::class) | ||
| ) | ||
| @MockitoSettings(strictness = Strictness.LENIENT) | ||
| @ForgeConfiguration(Configurator::class) | ||
| internal class TapTargetUtilsTest { | ||
|
|
||
| @Test | ||
| fun `M return true W isValidTapTarget() {clickable and VISIBLE}`() { | ||
| // Given | ||
| val fakeView: View = mock() | ||
| whenever(fakeView.isClickable).thenReturn(true) | ||
| whenever(fakeView.visibility).thenReturn(View.VISIBLE) | ||
|
|
||
| // When / Then | ||
| assertThat(fakeView.isValidTapTarget()).isTrue() | ||
| } | ||
|
|
||
| @Test | ||
| fun `M return false W isValidTapTarget() {clickable and INVISIBLE}`() { | ||
| // Given | ||
| val fakeView: View = mock() | ||
| whenever(fakeView.isClickable).thenReturn(true) | ||
| whenever(fakeView.visibility).thenReturn(View.INVISIBLE) | ||
|
|
||
| // When / Then | ||
| assertThat(fakeView.isValidTapTarget()).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `M return false W isValidTapTarget() {clickable and GONE}`() { | ||
| // Given | ||
| val fakeView: View = mock() | ||
| whenever(fakeView.isClickable).thenReturn(true) | ||
| whenever(fakeView.visibility).thenReturn(View.GONE) | ||
|
|
||
| // When / Then | ||
| assertThat(fakeView.isValidTapTarget()).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `M return false W isValidTapTarget() {not clickable and VISIBLE}`() { | ||
| // Given | ||
| val fakeView: View = mock() | ||
| whenever(fakeView.isClickable).thenReturn(false) | ||
| whenever(fakeView.visibility).thenReturn(View.VISIBLE) | ||
|
|
||
| // When / Then | ||
| assertThat(fakeView.isValidTapTarget()).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `M return true W isValidTapTarget() {disabled but clickable and VISIBLE}`() { | ||
| // Given | ||
| val fakeView: View = mock() | ||
| whenever(fakeView.isEnabled).thenReturn(false) | ||
| whenever(fakeView.isClickable).thenReturn(true) | ||
| whenever(fakeView.visibility).thenReturn(View.VISIBLE) | ||
|
|
||
| // When / Then | ||
| assertThat(fakeView.isValidTapTarget()).isTrue() | ||
| } | ||
| } |
This file contains hidden or 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
15 changes: 15 additions & 0 deletions
15
...id-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/HeatmapActionData.kt
This file contains hidden or 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,15 @@ | ||
| /* | ||
| * 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.rum.internal.domain.scope | ||
|
|
||
| internal data class HeatmapActionData( | ||
| val viewKey: Long, | ||
| val positionX: Long, | ||
| val positionY: Long, | ||
| val targetWidth: Long?, | ||
| val targetHeight: Long? | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to have it in
-internalmodule? seems like it is used only in-rum.normally
-internalmodule shouldn't be visible on the user side, but if they add it, they will have this extension.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be used also by session replay in the next pr