android-maps-compose icon indicating copy to clipboard operation
android-maps-compose copied to clipboard

StrictMode detectDiskReads() causes Google Maps to be extremely laggy and ANRs

Open mkpazon opened this issue 2 years ago • 3 comments

Thanks for stopping by to let us know something could be better!


PLEASE READ

If you have a support contract with Google, please create an issue in the support console. This will ensure a timely response.

Discover additional support services for the Google Maps Platform, including developer communities, technical guidance, and expert support at the Google Maps Platform support resources page.

If your bug or feature request is not related to this particular library, please visit the Google Maps Platform issue trackers.

Check for answers on StackOverflow with the google-maps tag.


Please be sure to include as much information as possible:

Environment details

Library version: Tested with Maps Compose 1.2.0 and 2.2.1

Steps to reproduce

  1. Enable detect disk reads in StrictMode (see code example)

Code example

StrictMode.setThreadPolicy(
    ThreadPolicy.Builder()
        .detectDiskReads()
        .build()
)

mkpazon avatar Jun 29 '22 06:06 mkpazon

I'm getting this log when using StrictMode:

StrictMode policy violation: android.os.strictmode.IncorrectContextUseViolation: The API:ViewConfiguration needs a proper configuration. Use UI contexts such as an activity or a context created via createWindowContext(Display, int, Bundle) or  createConfigurationContext(Configuration) with a proper configuration.
                                                                                        	at android.os.StrictMode.onIncorrectContextUsed(StrictMode.java:2261)
                                                                                        	at android.os.StrictMode.assertConfigurationContext(StrictMode.java:2297)
                                                                                        	at android.view.ViewConfiguration.get(ViewConfiguration.java:522)
                                                                                        	at android.view.View.<init>(View.java:5330)
                                                                                        	at android.view.TextureView.<init>(TextureView.java:146)
                                                                                        	at com.google.maps.api.android.lib6.gmm6.vector.av.<init>(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):1)
                                                                                        	at com.google.maps.api.android.lib6.gmm6.vector.ac.<init>(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):1)
                                                                                        	at com.google.maps.api.android.lib6.gmm6.api.ac.<init>(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):1)
                                                                                        	at com.google.maps.api.android.lib6.impl.bk.aD(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):54)
                                                                                        	at com.google.maps.api.android.lib6.impl.cu.d(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):2)
                                                                                        	at com.google.android.gms.maps.internal.q.bb(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190400-0):21)

This is my code.

GoogleMap(
        modifier = Modifier
            .fillMaxSize()
            .background(color = Color.Gray),
        cameraPositionState = cameraPositionState,
        contentPadding = paddings,
        uiSettings = mapSettings,
    ) {
        latLng?.let {
            VehicleMarker(it, onSetupEvent)
            MapEffect(latLng) {
                cameraPositionState.animate(
                    CameraUpdateFactory.newLatLngZoom(latLng, 16f),
                )
            }
        }
    }

hlandim avatar May 19 '23 10:05 hlandim

I see the same issue with maps-compose 3.1.1.

My current workaround where GoogleMaps composable is used:

  if (strictModeEnabled) {
       DisposableEffect(Unit) {
           val prevThreadPolicy = StrictMode.allowThreadDiskReads()
           onDispose {
               StrictMode.setThreadPolicy(prevThreadPolicy)
           }
       }
   }

ulfandersson avatar Oct 24 '23 06:10 ulfandersson

@hlandim your StrictMode problem looks very different from what this issue is about. Consider creating a new issue?

bubenheimer avatar Oct 25 '23 21:10 bubenheimer