Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit ee409edc authored by DaVinci9196's avatar DaVinci9196 Committed by GitHub
Browse files

Maps: Add callback delay for Huawei (#3266)

parent 13822ef3
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -621,7 +621,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
                if (loaded) {
                    Log.d(TAG, "Invoking callback instantly, as map is loaded")
                    try {
                        callback.onMapLoaded()
                        scheduleExecute { callback.onMapLoaded() }
                    } catch (e: Exception) {
                        Log.w(TAG, e)
                    }
@@ -848,6 +848,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
            }
            internalOnInitializedCallbackList.clear()
            fakeWatermark { Log.d(TAG_LOGO, "fakeWatermark success") }
            scheduleExecute { loadedCallback?.onMapLoaded() }

            mapView?.visibility = View.VISIBLE
        }
@@ -955,7 +956,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
            Log.d("$TAG:$tag", "Invoking callback now, as map is initialized")
            val wasCallbackActive = isInvokingInitializedCallbacks.getAndSet(true)
            runOnMainLooper(forceQueue = wasCallbackActive) {
                runCallbacks()
                scheduleExecute { runCallbacks() }
            }
            if (!wasCallbackActive) isInvokingInitializedCallbacks.set(false)
        } else {
@@ -974,10 +975,17 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
                Log.w(TAG, "onTransact [unknown]: $code, $data, $flags"); false
            }


    private fun scheduleExecute(block:() -> Unit) {
        Handler(Looper.getMainLooper()).postDelayed({
            try { block.invoke() } catch (_: Exception) {}
        }, ON_MAP_CALLBACK_DELAY)
    }

    companion object {
        private const val TAG = "GmsGoogleMap"

        private const val TAG_LOGO = "fakeWatermark"
        private const val MAX_TIMES = 300
        private const val ON_MAP_CALLBACK_DELAY = 300L
    }
}