From 9028ffd8f4e9a34877117dcaf5d026c75561292a Mon Sep 17 00:00:00 2001 From: Timur Valeev Date: Wed, 18 Dec 2024 17:12:36 +0000 Subject: [PATCH 1/2] RUM-7005: updating dependencies, adjusting detekt rules, fix tests --- detekt_custom.yml | 5 ++-- .../AndroidXFragmentLifecycleCallbacks.kt | 27 ++++++++----------- .../AndroidXFragmentLifecycleCallbacksTest.kt | 8 +++--- gradle/libs.versions.toml | 2 +- .../com/datadog/android/compose/Navigation.kt | 2 +- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/detekt_custom.yml b/detekt_custom.yml index 988918490f..2ff236c6a3 100644 --- a/detekt_custom.yml +++ b/detekt_custom.yml @@ -357,6 +357,7 @@ datadog: - "android.app.FragmentManager.FragmentLifecycleCallbacks.onFragmentResumed(android.app.FragmentManager?, android.app.Fragment?)" - "android.app.FragmentManager.FragmentLifecycleCallbacks.onFragmentStarted(android.app.FragmentManager, android.app.Fragment)" - "android.app.FragmentManager.FragmentLifecycleCallbacks.onFragmentStopped(android.app.FragmentManager?, android.app.Fragment?)" + - "androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks.onFragmentViewCreated(androidx.fragment.app.FragmentManager, androidx.fragment.app.Fragment, android.view.View, android.os.Bundle?)" - "android.app.FragmentManager.registerFragmentLifecycleCallbacks(android.app.FragmentManager.FragmentLifecycleCallbacks?, kotlin.Boolean)" - "android.app.FragmentManager.unregisterFragmentLifecycleCallbacks(android.app.FragmentManager.FragmentLifecycleCallbacks?)" - "android.content.ComponentName.resolveViewUrl()" @@ -537,8 +538,8 @@ datadog: - "androidx.compose.ui.semantics.SemanticsConfiguration.firstOrNull(kotlin.Function1)" - "androidx.compose.ui.semantics.SemanticsConfiguration.getOrNull(androidx.compose.ui.semantics.SemanticsPropertyKey)" - "androidx.compose.ui.text.AnnotatedString.getStringAnnotations(kotlin.Int, kotlin.Int)" - - "androidx.core.view.GestureDetectorCompat.constructor(android.content.Context?, android.view.GestureDetector.OnGestureListener?)" - - "androidx.core.view.GestureDetectorCompat.onTouchEvent(android.view.MotionEvent?)" + - "androidx.core.view.GestureDetectorCompat.constructor(android.content.Context, android.view.GestureDetector.OnGestureListener)" + - "androidx.core.view.GestureDetectorCompat.onTouchEvent(android.view.MotionEvent)" - "androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks.onFragmentActivityCreated(androidx.fragment.app.FragmentManager, androidx.fragment.app.Fragment, android.os.Bundle?)" - "androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks.onFragmentAttached(androidx.fragment.app.FragmentManager, androidx.fragment.app.Fragment, android.content.Context)" - "androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks.onFragmentDestroyed(androidx.fragment.app.FragmentManager, androidx.fragment.app.Fragment)" diff --git a/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/tracking/AndroidXFragmentLifecycleCallbacks.kt b/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/tracking/AndroidXFragmentLifecycleCallbacks.kt index ad2d1147d3..ab9fae5623 100644 --- a/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/tracking/AndroidXFragmentLifecycleCallbacks.kt +++ b/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/tracking/AndroidXFragmentLifecycleCallbacks.kt @@ -7,6 +7,7 @@ package com.datadog.android.rum.internal.tracking import android.os.Bundle +import android.view.View import androidx.annotation.MainThread import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment @@ -57,23 +58,17 @@ internal open class AndroidXFragmentLifecycleCallbacks( } // endregion + override fun onFragmentViewCreated(fm: FragmentManager, f: Fragment, v: View, savedInstanceState: Bundle?) { + super.onFragmentViewCreated(fm, f, v, savedInstanceState) + startGesturesTracking(f) + } - // TODO RUM-3793 Update Androidx packages and handle deprecated APIs - @MainThread - override fun onFragmentActivityCreated( - fm: FragmentManager, - f: Fragment, - savedInstanceState: Bundle? - ) { - super.onFragmentActivityCreated(fm, f, savedInstanceState) - - val context = f.context - - if (f is DialogFragment && context != null && this::sdkCore.isInitialized) { - val window = f.dialog?.window - val gesturesTracker = rumFeature.actionTrackingStrategy.getGesturesTracker() - gesturesTracker.startTracking(window, context, sdkCore) - } + private fun startGesturesTracking(f: Fragment) { + val context = f.context ?: return + if (f !is DialogFragment || !this::sdkCore.isInitialized) return + + rumFeature.actionTrackingStrategy.getGesturesTracker() + .startTracking(f.dialog?.window, context, sdkCore) } @MainThread diff --git a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/tracking/AndroidXFragmentLifecycleCallbacksTest.kt b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/tracking/AndroidXFragmentLifecycleCallbacksTest.kt index 9c643d271b..dc1110e192 100644 --- a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/tracking/AndroidXFragmentLifecycleCallbacksTest.kt +++ b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/tracking/AndroidXFragmentLifecycleCallbacksTest.kt @@ -281,23 +281,23 @@ internal class AndroidXFragmentLifecycleCallbacksTest { // endregion @Test - fun `when fragment activity created on DialogFragment, it will register a Window Callback`() { + fun `when fragment view created on DialogFragment, it will register a Window Callback`() { val mockDialogFragment: DialogFragment = mock() whenever(mockDialogFragment.context) doReturn mockContext whenever(mockDialogFragment.dialog) doReturn mockDialog whenever(mockDialog.window) doReturn mockWindow testedLifecycleCallbacks.register(mockFragmentActivity, mockSdkCore) - testedLifecycleCallbacks.onFragmentActivityCreated(mock(), mockDialogFragment, null) + testedLifecycleCallbacks.onFragmentViewCreated(mock(), mockDialogFragment, mock(), null) verify(mockGesturesTracker).startTracking(mockWindow, mockContext, mockSdkCore) } @Test - fun `when fragment activity created on Fragment, registers nothing`() { + fun `when fragment view created on Fragment, registers nothing`() { whenever(mockFragment.context) doReturn mockContext - testedLifecycleCallbacks.onFragmentActivityCreated(mock(), mockFragment, null) + testedLifecycleCallbacks.onFragmentViewCreated(mock(), mockFragment, mock(), null) verifyNoInteractions(mockGesturesTracker) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 979d39fee0..9b07e04284 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,7 +22,7 @@ androidXFragment = "1.2.4" androidXLeanback = "1.0.0" androidXMetrics = "1.0.0-alpha04" androidXMultidex = "2.0.1" -androidXNavigation = "2.3.0" +androidXNavigation = "2.8.0" androidXRecyclerView = "1.1.0" androidXWorkManager = "2.8.1" googleAccompanist = "0.20.2" diff --git a/integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/Navigation.kt b/integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/Navigation.kt index 005050b545..ea18bf559e 100644 --- a/integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/Navigation.kt +++ b/integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/Navigation.kt @@ -13,7 +13,7 @@ import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.NonRestartableComposable import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberUpdatedState -import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.navigation.NavController import androidx.navigation.NavDestination import com.datadog.android.Datadog From 474a55b48aab1fe82995c518552e8783ee8239f4 Mon Sep 17 00:00:00 2001 From: Timur Valeev Date: Wed, 18 Dec 2024 18:39:37 +0000 Subject: [PATCH 2/2] RUM-7005: downgrading to 2.7.7 hoping to fix licence info absence --- gradle/libs.versions.toml | 2 +- .../src/main/kotlin/com/datadog/android/compose/Navigation.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9b07e04284..872ffd6366 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,7 +22,7 @@ androidXFragment = "1.2.4" androidXLeanback = "1.0.0" androidXMetrics = "1.0.0-alpha04" androidXMultidex = "2.0.1" -androidXNavigation = "2.8.0" +androidXNavigation = "2.7.7" androidXRecyclerView = "1.1.0" androidXWorkManager = "2.8.1" googleAccompanist = "0.20.2" diff --git a/integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/Navigation.kt b/integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/Navigation.kt index ea18bf559e..005050b545 100644 --- a/integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/Navigation.kt +++ b/integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/Navigation.kt @@ -13,7 +13,7 @@ import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.NonRestartableComposable import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberUpdatedState -import androidx.lifecycle.compose.LocalLifecycleOwner +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.navigation.NavController import androidx.navigation.NavDestination import com.datadog.android.Datadog