Skip to content
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

RUM-7005: updating dependencies, adjusting detekt rules, fix tests #2463

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions detekt_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
Expand Down Expand Up @@ -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)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,23 +58,17 @@ internal open class AndroidXFragmentLifecycleCallbacks(
}

// endregion
override fun onFragmentViewCreated(fm: FragmentManager, f: Fragment, v: View, savedInstanceState: Bundle?) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onFragmentActivityCreated is now deprecated and according to comment here it seems we can safely move its logic into onFragmentViewCreated.

@xgouchet, please let me know if I'm mistaken.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good to me 👍

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down