Skip to content

Commit 44e4d36

Browse files
natiginfogithub-actions[bot]
authored andcommitted
[maps-android] create separate scheduleThreadServiceTypeReset (#5203)
GitOrigin-RevId: a516d62fc37c72b7f40177f011c76880509106fc
1 parent ec8e8f5 commit 44e4d36

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

maps-sdk/src/main/java/com/mapbox/maps/renderer/MapboxRenderThread.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,24 @@ internal class MapboxRenderThread : Choreographer.FrameCallback {
707707
}
708708
}
709709

710+
/**
711+
* Schedules a resetThreadServiceType on the render thread after a specified delay.
712+
* This method is called on resume to ensure CPU affinity is properly set
713+
* when coming back from background, addressing timing issues where CPU affinity
714+
* might not be immediately available.
715+
*/
716+
@OptIn(MapboxExperimental::class)
717+
fun scheduleThreadServiceTypeReset() {
718+
logI(TAG, "Scheduling thread service type reset with delay")
719+
postNonRenderEvent(
720+
RenderEvent({
721+
logI(TAG, "Executing thread service type reset")
722+
mapboxRenderer.resetThreadServiceType()
723+
}, false),
724+
RESET_THREAD_SERVICE_TYPE_DELAY_MS
725+
)
726+
}
727+
710728
@UiThread
711729
fun pause() {
712730
paused = true
@@ -717,12 +735,6 @@ internal class MapboxRenderThread : Choreographer.FrameCallback {
717735
fun resume() {
718736
paused = false
719737
logI(TAG, "Renderer resumed, renderThreadPrepared=$renderThreadPrepared, surface.isValid=${surface?.isValid}")
720-
postNonRenderEvent(
721-
RenderEvent({
722-
mapboxRenderer.resetThreadServiceType()
723-
}, false),
724-
RESET_THREAD_SERVICE_TYPE_DELAY_MS
725-
)
726738
// schedule render if we resume not after first create (e.g. bring map back to front)
727739
renderPreparedGuardedRun(::postPrepareRenderFrame)
728740
}

maps-sdk/src/main/java/com/mapbox/maps/renderer/MapboxRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ internal abstract class MapboxRenderer(mapName: String) : DelegatingMapClient {
147147

148148
@UiThread
149149
fun onResume() {
150-
renderThread.resume()
150+
renderThread.scheduleThreadServiceTypeReset()
151151
}
152152

153153
@RenderThread

maps-sdk/src/test/java/com/mapbox/maps/renderer/MapboxRendererTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal abstract class MapboxRendererTest {
7878
@Test
7979
fun onResumeTest() {
8080
mapboxRenderer.onResume()
81-
verify { renderThread.resume() }
81+
verify { renderThread.scheduleThreadServiceTypeReset() }
8282
}
8383

8484
@Test

plugin-animation/api/Release/metalava.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package com.mapbox.maps.plugin.animation {
33

44
public final class CameraAnimationsUtils {
5+
method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) @kotlin.jvm.JvmSynthetic public static com.mapbox.maps.CameraAnimationHint! calculateCameraAnimationHint(android.animation.AnimatorSet, java.util.List<? extends java.lang.Float> fractions, com.mapbox.maps.CameraState? startCameraState = null);
6+
method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) @kotlin.jvm.JvmSynthetic public static <T extends com.mapbox.maps.plugin.animation.animator.CameraAnimator<?>> com.mapbox.maps.CameraAnimationHint! calculateCameraAnimationHint(java.util.List<? extends T>, java.util.List<? extends java.lang.Float> fractions, com.mapbox.maps.CameraState? startCameraState = null);
57
method public static com.mapbox.common.Cancelable easeTo(com.mapbox.maps.plugin.delegates.MapPluginExtensionsDelegate, com.mapbox.maps.CameraOptions cameraOptions, com.mapbox.maps.plugin.animation.MapAnimationOptions? animationOptions = null, android.animation.Animator.AnimatorListener? animatorListener = null);
68
method public static com.mapbox.common.Cancelable easeTo(com.mapbox.maps.plugin.delegates.MapPluginExtensionsDelegate, com.mapbox.maps.CameraOptions cameraOptions, com.mapbox.maps.plugin.animation.MapAnimationOptions? animationOptions = null);
79
method public static com.mapbox.common.Cancelable easeTo(com.mapbox.maps.plugin.delegates.MapPluginExtensionsDelegate, com.mapbox.maps.CameraOptions cameraOptions);

plugin-lifecycle-lint-rules/src/main/java/com/mapbox/maps/lint/lifecycle/LifecycleMethodDetector.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.jetbrains.uast.UCallExpression
99
*/
1010
class LifecycleMethodDetector : Detector(), Detector.UastScanner {
1111

12-
override fun getApplicableMethodNames() = listOf(ON_START, ON_STOP, ON_DESTROY, ON_LOW_MEMORY)
12+
override fun getApplicableMethodNames() = listOf(ON_START, ON_STOP, ON_RESUME, ON_DESTROY, ON_LOW_MEMORY)
1313

1414
override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) {
1515
if (context.evaluator.isMemberInClass(method, "com.mapbox.maps.MapView")) {
@@ -23,14 +23,14 @@ class LifecycleMethodDetector : Detector(), Detector.UastScanner {
2323
companion object Issues {
2424
private const val ON_START = "onStart"
2525
private const val ON_STOP = "onStop"
26-
private const val ON_PAUSE = "onPause"
26+
private const val ON_RESUME = "onResume"
2727
private const val ON_DESTROY = "onDestroy"
2828
private const val ON_LOW_MEMORY = "onLowMemory"
2929
private const val ISSUE_ID = "Lifecycle"
3030
private const val BRIEF_DESCRIPTION = "Redundant method call"
3131
private const val PRIORITY = 8
3232
private const val REPORT_MESSAGE =
33-
"It's no longer required to manually invoke onStart/onStop/onPause/onDestroy/onLowMemory MapView lifecycle methods explicitly. The Mapbox Maps SDK for Android depends on the plugin-lifecycle that leverages androidx.lifecycle to make the MapView a lifecycle aware component. This behavior is automatically enforced when appcompact 1.3.0+ is used. The plugin-lifecycle can be removed from class path to opt-out of the associated behavior."
33+
"It's no longer required to manually invoke onStart/onStop/onResume/onDestroy/onLowMemory MapView lifecycle methods explicitly. The Mapbox Maps SDK for Android depends on the plugin-lifecycle that leverages androidx.lifecycle to make the MapView a lifecycle aware component. This behavior is automatically enforced when appcompact 1.3.0+ is used. The plugin-lifecycle can be removed from class path to opt-out of the associated behavior."
3434

3535
private val IMPLEMENTATION = Implementation(
3636
LifecycleMethodDetector::class.java, Scope.JAVA_FILE_SCOPE

0 commit comments

Comments
 (0)