mapbox / mapbox-gl-native-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
217 stars 114 forks source link

ANR : Reason: Broadcast of Intent - When App Resume From Background After Some Time #126

Closed johngreendrivehailify closed 4 years ago

johngreendrivehailify commented 4 years ago

Hi,

I am facing ANR issue when resume application from background after some time.

PID: 4836 Reason: Broadcast of Intent { act=com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED flg=0x10 (has extras) }

Can you please suggest how to fix this issue ? Its comes randomly when app is background and open again.

I am using below library version. implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.5.0' implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:4.8.0'

Thanks

tobrun commented 4 years ago

@mapbox/mobile-telemetry

johngreendrivehailify commented 4 years ago

Hey @tobrun , @nkukday , @harvsu

Thanks

is any update for this issue ? now i am not using the Mapbox location engine but still i am facing this issue.

LocationComponentActivationOptions -> useDefaultLocationEngine(false)

Please help for ANR issue : Reason: Broadcast of Intent { act=com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED flg=0x10 (has extras) }

Thanks

nkukday commented 4 years ago

@johngreendrivehailify could you share logs and device/os details if possible?

johngreendrivehailify commented 4 years ago

Hi @nkukday

Thanks for resposne.

Here below log added. Issue not reproduce any specific steps its generate randomly. In my code i am not using location engine of mapbox, still that error comes. Issue Produce on many devices here is two device model specification:

ActivityManager: ANR in ... PID: 18654 Reason: Broadcast of Intent { act=com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED flg=0x10 (has extras) } Load: 8.87 / 10.06 / 8.6 CPU usage from 0ms to 7664ms later (2020-02-12 10:20:20.878 to 2020-02-12 10:20:28.541): 97% 18654/com.gomo.drive.staging.debug: 15% user + 81% kernel / faults: 2378 minor 21 major 39% 900/media.codec: 25% user + 14% kernel / faults: 37840 minor 353 major 24% 1795/system_server: 13% user + 11% kernel / faults: 5921 minor 615 major 10% 2697/com.google.android.gms.persistent: 7.4% user + 3.1% kernel / faults: 4742 minor 216 major 6.7% 3219/com.android.launcher3: 4.8% user + 1.9% kernel / faults: 6337 minor 5.2% 2201/com.google.android.inputmethod.latin: 2.8% user + 2.3% kernel / faults: 2914 minor 319 major 5% 2223/com.android.systemui: 3.2% user + 1.8% kernel / faults: 4063 minor 301 major 5% 31034/com.google.android.apps.messaging: 3.9% user + 1.1% kernel / faults: 3555 minor 4.1% 558/android.hardware.audio@2.0-service: 0% user + 4.1% kernel / faults: 1 major 3.9% 809/surfaceflinger: 2.8% user + 1% kernel / faults: 313 minor 6 major 2.2% 2437/com.android.phone: 1.3% user + 0.9% kernel / faults: 2617 minor 422 major 2% 827/audioserver: 0.9% user + 1.1% kernel / faults: 176 minor 23 major 1.9% 2892/adbd: 0.7% user + 1.1% kernel / faults: 12415 minor 1.8% 13985/kworker/u16:2: 0% user + 1.8% kernel 1.6% 436/ueventd: 1.1% user + 0.5% kernel 1.6% 10787/com.google.android.gms: 1.4% user + 0.2% kernel / faults: 2214 minor 0% 3206/com.qualcomm.qti.services.secureui:sui_service: 0% user + 0% kernel / faults: 2421 minor 328 major 1% 180/kswapd0: 0% user + 1% kernel 1% 881/mediaserver: 0% user + 1% kernel / faults: 84 minor 32 major 1% 893/statsd: 1% user + 0% kernel 1% 20387/kworker/u16:0: 0% user + 1% kernel 0.9% 872/media.extractor: 0.5% user + 0.3% kernel / faults: 2407 minor 59 major 0.7% 575/android.hardware.sensors@1.0-service: 0.3% user + 0.3% kernel 0.7% 2390/.dataservices: 0.3% user + 0.3% kernel / faults: 2180 minor 373 major 0% 3171/com.goodix.fingerprint: 0% user + 0% kernel / faults: 2224 minor 296 major 0.7% 17848/app_process32: 0.2% user + 0.5% kernel / faults: 11 minor 0.6% 356/mmc-cmdqd/0: 0% user + 0.6% kernel 0.6% 569/android.hardware.graphics.composer@2.1-service: 0.1% user + 0.5% kernel / faults: 15 minor 0.6% 2410/com.qualcomm.qti.telephonyservice: 0.3% user + 0.2% kernel / faults: 2072 minor 327 major 0% 2426/se.dirac.acs: 0% user + 0% kernel / faults: 2228 minor 328 major 0% 3185/com.android.se: 0% user + 0% kernel / faults: 2208 minor 300 major 0.6% 20992/com.google.android.googlequicksearchbox:search: 0.6% user + 0% kernel / faults: 257 minor 1 major 0.5% 456/logd: 0.2% user + 0.2% kernel 0.5% 626/sensors.qti: 0% user + 0.5% kernel / faults: 2 minor 0.5% 2172/com.android.bluetooth: 0.1% user + 0.3% kernel / faults: 252 minor 41 major 0.5% 19411/com.android.chrome:sandboxed_process0: 0.5% user + 0% kernel / faults: 56 minor 1 major 0.3% 264/kgsl_worker_thr: 0% user + 0.3% kernel 0.3% 557/healthd: 0% user + 0.3% kernel 0.3% 570/android.hardware.health@2.0-service: 0.1% user + 0.2% kernel 0.3% 823/hvdcp_opti: 0.1% user + 0.2% kernel 0.3% 17143/kworker/u16:3: 0% user + 0.3% kernel 0.3% 20538/kworker/u16:9: 0% user + 0.3% kernel 0.2% 7/rcu_preempt: 0% user + 0.2% kernel 0.2% 793/jbd2/dm-1-8: 0% user + 0.2% kernel 0% 828/cameraserver: 0% user + 0% kernel / faults: 68 minor 20 major 0% 865/mediadrmserver: 0% user + 0% kernel / faults: 381 minor 59 major 0% 924/tombstoned: 0% user + 0% kernel / faults: 103 minor 46 major 0.2% 10753/com.google.process.gservices: 0.1% user + 0.1% kernel / faults: 24 minor 0.2% 16917/mdss_fb0: 0% user + 0.2% kernel 0.2% 18947/com.lexa.fakegps: 0.1% user + 0.1% kernel / faults: 8 minor 0.2% 19722/logcat: 0% user + 0.2% kernel 0.2% 19933/kworker/u17:2: 0% user + 0.2% kernel 0.2% 21238/kworker/u17:1: 0% user + 0.2% kerne

nkukday commented 4 years ago

@johngreendrivehailify this is not an issue with our SDK, the logs probably print this way because the system attempts to deliver the broadcast to the app in an ANR state.

johngreendrivehailify commented 4 years ago

Hi Neeraja,

Thank you for your response..

But why mapbox sdk send location broadcast to app, I have not used location engine of mapbox. I have set false for location engine...

Waiting for reply.

Thanks

On Thu, Feb 13, 2020, 2:39 AM Neeraja Kukday notifications@github.com wrote:

@johngreendrivehailify https://github.com/johngreendrivehailify this is not an issue with our SDK, the logs probably print this way because the system attempts to deliver the broadcast to the app in an ANR https://developer.android.com/topic/performance/vitals/an state.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-gl-native-android/issues/126?email_source=notifications&email_token=AMRHPS5LLGX5CYR2CB6QVUTRCRQPNA5CNFSM4KCPACUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELSMOUA#issuecomment-585418576, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMRHPS2ABC67K7D2PER5JFLRCRQPNANCNFSM4KCPACUA .

nkukday commented 4 years ago

@johngreendrivehailify we're not sending a broadcast but registering to receive it. More on our sdk here.

alfwatt commented 4 years ago

Closing as resolved

sarimk80 commented 4 years ago

I am having this same error sometimes the app crashes or just hangs I am also using firebase to update the symbols. This crash happens when the app is active.

03-30 14:38:48.109 1659-1852/? E/ActivityManager: ANR in com.example.mapchat
    PID: 19090
    Reason: Broadcast of Intent { act=com.mapbox.scheduler_flusher flg=0x14 (has extras) }
    Load: 0.0 / 0.0 / 0.0
    CPU usage from 419873ms to 0ms ago:
      5% 1659/system_server: 3.3% user + 1.7% kernel / faults: 96905 minor 410 major
      0.6% 340/surfaceflinger: 0.3% user + 0.3% kernel / faults: 685 minor
      0.6% 2389/com.android.systemui: 0.3% user + 0.2% kernel / faults: 7454 minor 2418 major
      0.5% 15243/kworker/u8:2: 0% user + 0.5% kernel
      0.4% 13272/com.google.android.gms: 0.3% user + 0.1% kernel / faults: 19576 minor 41 major
      0.4% 559/adbd: 0% user + 0.3% kernel / faults: 173 minor
      0.3% 12370/kworker/u8:3: 0% user + 0.3% kernel
      0.3% 2910/com.google.android.gms.persistent: 0.2% user + 0% kernel / faults: 15487 minor 256 major
      0.3% 159/mmcqd/0: 0% user + 0.3% kernel
      0.2% 15127/kworker/u8:5: 0% user + 0.2% kernel
      0.2% 98/kswapd0: 0% user + 0.2% kernel
      0.1% 23814/android.process.acore: 0.1% user + 0% kernel / faults: 5706 minor 30 major
      0.1% 18162/logcat: 0% user + 0.1% kernel / faults: 46 minor
      0.1% 2669/bitpit.launcher: 0% user + 0% kernel / faults: 6656 minor 5 major
      0.1% 15500/mdss_fb0: 0% user + 0.1% kernel
      0.1% 28378/com.android.vending: 0% user + 0% kernel / faults: 10242 minor 20 major
      0% 1996/mediaserver: 0% user + 0% kernel / faults: 398 minor 440 major
      0% 338/servicemanager: 0% user + 0% kernel / faults: 57 minor 2 major
      0% 487/zygote: 0% user + 0% kernel / faults: 29762 minor
      0% 2356/com.android.phone: 0% user + 0% kernel / faults: 3455 minor 146 major
      0% 14025/com.google.android.youtube: 0% user + 0% kernel / faults: 2195 minor 116 major
      0% 22013/com.sec.spp.push: 0% user + 0% kernel / faults: 3980 minor 1098 major
      0% 16312/kworker/0:0: 0% user + 0% kernel
      0% 7/rcu_preempt: 0% user + 0% kernel
      0% 218/jbd2/mmcblk0p28: 0% user + 0% kernel
      0% 37/kworker/u9:0: 0% user + 0% kernel
      0% 155/cfinteractive: 0% user + 0% kernel
      0% 424/smdexe: 0% user + 0% kernel / faults: 15 minor
      0% 3425/com.sec.imsservice: 0% user + 0% kernel / faults: 1330 minor 183 major
      0% 17416/kworker/3:1: 0% user + 0% kernel
      0% 3/ksoftirqd/0: 0% user + 0% kernel
      0% 334/healthd: 0% user + 0% kernel / faults: 15 minor
      0% 336/lmkd: 0% user + 0% kernel / faults: 38 minor
      0% 32669/VosRXThread: 0% user + 0% kernel
      0% 32673/wpa_supplicant: 0% user + 0% kernel / faults: 69 minor
      0% 4634/com.sec.android.inputmethod: 0% user + 0% kernel / faults: 5532 minor 65 major
      0% 8550/com.sec.android.daemonapp: 0% user + 0% kernel / faults: 1795 minor 150 major
      0% 13205/com.samsung.android.sm.provider: 0% user + 0% kernel / faults: 2919 minor 6 major
      0% 3958/com.android.bluetooth: 0% user + 0% kernel / faults: 1778 minor 101 major
      0% 14/ksoftirqd/1: 0% user + 0% kernel
      0% 19/ksoftirqd/2: 0% user + 0% kernel
      0% 773/rild: 0% user + 0% kernel / faults: 317 minor 40 major
      0% 18778/kworker/1:0: 0% user + 0% kernel
      0% 128/hwrng: 0% user + 0% kernel
      0% 17223/kworker/2:0: 0% user + 0% kernel
      0% 32667/VosMCThread: 0% user + 0% kernel
      0% 32668/VosTXThread: 0% user + 0% kernel
      0% 1//init: 0% user + 0% kernel / faults: 99 minor 1 major
      0% 378/qmuxd: 0% user + 0% kernel / faults: 43 minor
      0% 384/netd: 0% user + 0% kernel / faults: 308 minor 20 major
      0% 33/kworker/0:1H: 0% user + 0% kernel
      0% 380/edmaudit: 0% user + 0% kernel / faults: 46 minor
      0% 402/installd: 0% user + 0% kernel / faults: 129 minor
      0% 4404/com.eyefilter.nightmode.bluelightfilter:Helper: 0% user + 0% kernel / faults: 4211 minor 44 major
      0% 6833/com.samsung.android.beaconmanager: 0% user + 0% kernel / faults: 463 minor 8 major
      0% 24/ksoftirqd/3: 0% user + 0% kernel
      0% 69/system: 0% user + 0% kernel
      0% 2513/com.android.systemui.recents: 0% user + 0% kernel / faults: 1742 minor 5 major
      0% 3408/com.samsung.android.providers.context: 0% user + 0% kernel / faults: 1054 minor 16 major
      0% 4377/com.eyefilter.nightmode.bluelightfilter:background: 0% user + 0% kernel / faults: 476 minor 2 major
      0% 14791/kworker/0:2: 0% user + 0% kernel
      0% 150/
03-30 14:38:48.119 1659-19651/? E/android.os.Debug: ro.product_ship = true
03-30 14:38:48.119 1659-19651/? E/android.os.Debug: ro.debug_level = 0x4f4c
03-30 14:38:48.119 1659-19651/? E/android.os.Debug: sys.mobilecare.preload = false
vidhi1011 commented 4 years ago

@nkukday @alfwatt I am using mapbox navigation view in android. when my screen is open for some more minutes then it causes this ANR. I can only use navigation for max 1-2 mins then this appears. Also i am using fragment to load navigation with bottom tabs.

Library i have used : 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.6'

ANR in com.flashmarket.delivery
    PID: 15025
    Reason: Broadcast of Intent { act=com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED flg=0x10 hwFlg=0x300 (has extras) }
    Load: 46.51 / 45.27 / 44.97
    CPU usage from 137983ms to 0ms ago (2020-05-19 17:10:53.170 to 2020-05-19 17:13:11.153):
      13% 656/surfaceflinger: 7% user + 6% kernel / faults: 2061 minor
      9.5% 1320/system_server: 6.4% user + 3% kernel / faults: 37300 minor 8 major
      5.3% 622/vendor.huawei.hardware.hwdisplay.displayengine@1.2-service: 2.8% user + 2.5% kernel
      4.9% 605/android.hardware.graphics.composer@2.2-service: 2.3% user + 2.6% kernel / faults: 113 minor
      4.7% 3472/com.google.android.googlequicksearchbox:search: 3% user + 1.7% kernel / faults: 23587 minor 28 major
      3.5% 2073/com.huawei.android.launcher: 2.3% user + 1.2% kernel / faults: 25493 minor
      3.2% 843/hwpged: 0% user + 3.2% kernel / faults: 91 minor
      2.7% 13056/kworker/u16:2: 0% user + 2.7% kernel / faults: 10 minor
      2.4% 13063/kworker/u16:15: 0% user + 2.4% kernel / faults: 1 minor
      2% 10020/com.android.vending: 1.6% user + 0.3% kernel / faults: 26183 minor 30 major
      1.9% 869/hiview: 1.5% user + 0.4% kernel / faults: 2601 minor 179 major
      1.9% 1779/com.android.systemui: 1.2% user + 0.7% kernel / faults: 14103 minor 33 major
      1.5% 13064/kworker/u16:16: 0% user + 1.5% kernel / faults: 86 minor
      1.4% 14800/kworker/u16:1: 0% user + 1.4% kernel / faults: 233 minor
      1.2% 21493/adbd: 0.3% user + 0.9% kernel / faults: 1191 minor
      1.1% 3112/com.google.android.gms: 0.8% user + 0.2% kernel / faults: 9567 minor 33 major
      0.8% 2029/com.huawei.iaware: 0.5% user + 0.3% kernel / faults: 3531 minor
      0.8% 9/rcu_preempt: 0% user + 0.8% kernel
      0.7% 13775/kworker/u16:0: 0% user + 0.7% kernel
      0.7% 2283/com.google.android.gms.persistent: 0.5% user + 0.2% kernel / faults: 3307 minor 15 major
      0.7% 454/logd: 0.2% user + 0.4% kernel / faults: 55 minor
      0.6% 455/servicemanager: 0.2% user + 0.4% kernel
      0.4% 1039/hisi_frw/0: 0% user + 0.4% kernel
      0.4% 11402/kworker/u17:4: 0% user + 0.4% kernel
      0.4% 662/powerlogd: 0.3% user + 0.1% kernel / faults: 7 minor
      0.1% 2951/sugov:4: 0% user + 0.1% kernel
      0.3% 648/audioserver: 0.2% user + 0.1% kernel / faults: 64 minor
      0.3% 13256/kworker/u17:0: 0% user + 0.3% kernel
      0.3% 15880/kworker/1:0H: 0% user + 0.3% kernel
      0.3% 17288/zygote64: 0.1% user + 0.1% kernel / faults: 854 minor 18 major
      0.2% 652/lmkd: 0% user + 0.2% kernel / faults: 3 minor
      0.2% 2949/sugov:0: 0% user + 0.2% kernel
      0.2% 805/dubaid: 0.1% user + 0.1% kernel / faults: 440 minor
      0.2% 824/thermal-daemon: 0% user + 0.2% kernel
      0% 799/ITouchservice: 0% user + 0% kernel / faults: 20 minor 2 major
      0.2% 1048/hisi_hcc: 0% user + 0.2% kernel
      0.2% 2055/com.android.phone: 0.1% user + 0% kernel / faults: 330 minor
      0.2% 262/mmc-cmdqd/0: 0% user + 0.2% kernel
      0% 819/mediaserver: 0% user + 0% kernel / faults: 201 minor
      0% 9542/com.google.android.tts: 0% user + 0% kernel / faults: 5466 minor 41 major
      0% 13057/kworker/u16:5: 0% user + 0% kernel
      0.1% 584/zygote64: 0% user + 0.1% kernel / faults: 1872 minor
      0.1% 821/statsd: 0% user + 0% kernel / faults: 6 minor
      0% 2341/com.google.android.ext.services: 0% user + 0% kernel / faults: 1019 minor
      0.1% 1049/hisi_rxdata: 0% user + 0.1% kernel
      0.1% 851/vendor.huawei.hardware.sensors@1.0-service: 0% user + 0% kernel
      0.1% 1933/com.huawei.hiview: 0% user + 0% kernel / faults: 115 minor
      0.1% 583/netd: 0% user + 0% kernel / faults: 486 minor
      0.1% 1034/oal_gpio_rx_dat: 0% user + 0.1% kernel
      0.1% 2112/com.huawei.systemmanager:service: 0.1% user + 0% kernel / faults: 798 minor
      0.1% 612/vendor.huawei.hardware.audio@5.0-service: 0% user + 0% kernel / faults: 65 minor
      0% 811/installd: 0% user + 0% kernel / faults: 145 minor
      0.1% 3388/transport: 0% user + 0% kernel / faults: 3 minor
      0.1% 18/ksoftirqd/1: 0% user + 0.1% kernel
      0% 852/media.swcodec: 0% user + 0% kernel / faults: 99 minor
      0.1% 647/ashmemd: 0% user + 0% kernel
      0.1% 803/displayengine

Here is my fragment code :

import android.annotation.SuppressLint
import android.content.Context
import android.location.Address
import android.location.Geocoder
import android.location.Location
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import androidx.appcompat.app.AppCompatDelegate
import androidx.fragment.app.Fragment
import com.fm.R
import com.fm.base.BaseFragment
import com.fm.model.DeliveryListData
import com.fm.model.LatLongData
import com.fm.model.Message
import com.fm.model.RouteData
import com.fm.utils.Log
import com.mapbox.api.directions.v5.models.DirectionsResponse
import com.mapbox.api.directions.v5.models.DirectionsRoute
import com.mapbox.geojson.Point
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.services.android.navigation.ui.v5.NavigationViewOptions
import com.mapbox.services.android.navigation.ui.v5.OnNavigationReadyCallback
import com.mapbox.services.android.navigation.ui.v5.listeners.NavigationListener
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute
import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress
import kotlinx.android.synthetic.main.fragment_navigation.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.util.*
import kotlin.collections.ArrayList

class NavigationFragment : BaseFragment(), OnNavigationReadyCallback, NavigationListener,
    ProgressChangeListener {

    private var directionsRoute: DirectionsRoute? = null
    private var ORIGIN_LONGITUDE: Double = 0.0
    private var ORIGIN_LATITUDE: Double = 0.0
    private var DESTINATION_LONGITUDE: Double = 0.0
    private var DESTINATION_LATITUDE: Double = 0.0
    private var routeInfo: List<RouteData.RouteInfo.Route?> =
        ArrayList()
    private var total_count: String = ""
    private var collected_count: String = ""

    private var selectedItems: ArrayList<DeliveryListData.Data?> =
        ArrayList()

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_navigation, container, false)
        return view
    }

    @SuppressLint("ResourceType")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        navigationView?.onCreate(savedInstanceState)
        navigationView?.initialize(this)
    }

    override fun onStart() {
        try {
            EventBus.getDefault().register(this)
            super.onStart()
            navigationView?.onStart()
        } catch (e: Exception) {
        }
    }

    override fun onResume() {
        try {
            super.onResume()
            navigationView?.onResume()
        } catch (e: Exception) {
        }
    }

    override fun onSaveInstanceState(outState: Bundle) {
        try {
            navigationView?.onSaveInstanceState(outState)
            super.onSaveInstanceState(outState)
        } catch (e: Exception) {
        }
    }

    override fun onPause() {
        try {
            super.onPause()
            navigationView?.onPause()
        } catch (e: Exception) {
        }
    }

    override fun onStop() {
        try {
            EventBus.getDefault().unregister(this)
            super.onStop()
            navigationView?.onStop()
            stopNavigation()
        } catch (e: Exception) {
        }

    }

    override fun onLowMemory() {
        try {
            super.onLowMemory()
            navigationView?.onLowMemory()
        } catch (e: Exception) {
        }
    }

    override fun onNavigationReady(isRunning: Boolean) {
        val origin = Point.fromLngLat(ORIGIN_LONGITUDE, ORIGIN_LATITUDE)
        val destination = Point.fromLngLat(DESTINATION_LONGITUDE, DESTINATION_LATITUDE)
        showProgressDialog()

        fetchRoute(origin, destination)
    }

    override fun onCancelNavigation() {
        try {
            navigationView?.stopNavigation()
            stopNavigation()
        } catch (e: Exception) {
        }
    }

    override fun onNavigationFinished() {

    }

    override fun onNavigationRunning() {

    }

    override fun onProgressChange(location: Location, routeProgress: RouteProgress) {
        // Update InstructionView data from RouteProgress

        /*val isInTunnel = routeProgress.inTunnel()
        val wasInTunnel = wasInTunnel()
        if (isInTunnel) {
            if (!wasInTunnel) {
                updateWasInTunnel(true)
                updateCurrentNightMode(AppCompatDelegate.MODE_NIGHT_YES)
            }
        } else {
            if (wasInTunnel) {
                updateWasInTunnel(false)
                updateCurrentNightMode(AppCompatDelegate.MODE_NIGHT_AUTO)
            }
        }*/

        Log.e("progress", "" + routeProgress.distanceRemaining())
        if (routeProgress.distanceRemaining() <= 50.0) {
            val fragment: Fragment?
            fragment = if (selectedItems.size == 1) {
                EventBus.getDefault()
                    .postSticky(Message("1", selectedItems, "collection", "", "single"))
                CollectionRouteFragment()

            } else {
                EventBus.getDefault()
                    .postSticky(Message("1", selectedItems, "collection", "", "bulk"))
                CollectionRouteFragment()
            }

            val transaction = activity?.supportFragmentManager?.beginTransaction()
            transaction?.replace(R.id.container, fragment)
            transaction?.commit()

            try {
                navigationView?.onStop()
                stopNavigation()
            } catch (e: Exception) {
            }

        }

    }

    private fun fetchRoute(origin: Point, destination: Point) {
        NavigationRoute.builder(context)
            .accessToken(Mapbox.getAccessToken()!!)
            .origin(origin)
            .destination(destination)
            .build()
            .getRoute(object : Callback<DirectionsResponse> {
                override fun onResponse(
                    call: Call<DirectionsResponse>,
                    response: Response<DirectionsResponse>
                ) {
                    directionsRoute = response.body()!!.routes()[0]
                    try {
                        startNavigation()
                    } catch (e: Exception) {
                    }
                }

                override fun onFailure(call: Call<DirectionsResponse>, t: Throwable) {}
            })
    }

    private fun startNavigation() {

        if (directionsRoute == null) {
            return
        }
        val options = NavigationViewOptions.builder()
            .directionsRoute(directionsRoute)
            .shouldSimulateRoute(true)
            .navigationListener(this)
            .progressChangeListener(this)
            .build()

        try {
            navigationView?.startNavigation(options)

            navigationView?.findViewById<View>(R.id.summaryBottomSheet)?.visibility = View.GONE
            navigationView?.findViewById<View>(R.id.feedbackFab)?.visibility = View.GONE
            navigationView?.findViewById<View>(R.id.soundFab)?.visibility = View.GONE

            val param =
                navigationView!!.findViewById<View>(R.id.instructionLayout).layoutParams as ViewGroup.MarginLayoutParams
            param.setMargins(40, 100, 40, 0)
            navigationView!!.findViewById<View>(R.id.instructionLayout).layoutParams = param

            val vto: ViewTreeObserver =
                navigationView?.findViewById<View>(R.id.instructionLayout)!!.getViewTreeObserver()
            vto.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
                override fun onGlobalLayout() {
                    navigationView?.findViewById<View>(R.id.instructionLayout)!!
                        .getViewTreeObserver()
                        .removeOnGlobalLayoutListener(this)

                    val bottom: Int =
                        navigationView?.findViewById<View>(R.id.instructionLayout)!!.bottom

                    val height: Int =
                        navigationView?.findViewById<View>(R.id.instructionLayout)!!
                            .measuredHeight

                    Log.e("height", "" + height)
                    Log.e(
                        "height-bottom",
                        "" + navigationView?.findViewById<View>(R.id.instructionLayout)!!.bottom
                    )

                    val param = llMain.layoutParams as ViewGroup.MarginLayoutParams
                    param.setMargins(40, height + 130, 40, 0)
                    llMain.layoutParams = param

                    llMain.visibility = View.VISIBLE
                    dismissProgressDialog()
                }
            })

        } catch (e: Exception) {
        }

    }

    private fun wasInTunnel(): Boolean {
        val context: Context? = getContext()
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        return preferences.getBoolean("was_in_tunnel", false)
    }

    private fun updateWasInTunnel(wasInTunnel: Boolean) {
        val context: Context? = getContext()
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        val editor = preferences.edit()
        editor.putBoolean("was_in_tunnel", wasInTunnel)
        editor.apply()
    }

    private fun updateCurrentNightMode(nightMode: Int) {
        AppCompatDelegate.setDefaultNightMode(nightMode)
        activity?.recreate()
    }

    @Subscribe(sticky = true)
    fun onMessage(event: LatLongData) {

        ORIGIN_LONGITUDE = event.start_lng
        ORIGIN_LATITUDE = event.start_lat
        DESTINATION_LATITUDE = event.end_lat
        DESTINATION_LONGITUDE = event.end_lng
        routeInfo = event.routeInfo
        total_count = event.total_count
        collected_count = event.collected_count

        tvDeliveries?.text = collected_count + "/" + total_count

        selectedItems = event.selectedItems!!

        tvStartSubrub.text = generateAddress(ORIGIN_LATITUDE, ORIGIN_LONGITUDE)

        EventBus.getDefault().removeStickyEvent(event)
    }

    override fun onDestroy() {
        super.onDestroy()
        try {
            if (navigationView != null) {
                navigationView?.onStop()
                stopNavigation()

            }
        } catch (e: Exception) {
        }
    }

    private fun stopNavigation() {
        // hide navigation view
        navigationView.visibility = View.GONE
        try {
            navigationView.stopNavigation()
        } catch (e: Exception) {
        }
    }

    fun generateAddress(latitude: Double, longitude: Double): String {
        val addresses: List<Address>
        val geocoder = Geocoder(context, Locale.getDefault())

        addresses = geocoder.getFromLocation(
            latitude,
            longitude,
            1
        ) // Here 1 represent max location result to returned, by documents it recommended 1 to 5

        val address: String = addresses[0]
            .getAddressLine(0) // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()

        val city: String = addresses[0].locality
        val state: String = addresses[0].adminArea
        val country: String = addresses[0].countryName
        val postalCode: String = addresses[0].postalCode
        val knownName: String = addresses[0].featureName // Only if available else return NULL

        return "$address $city $postalCode $state $country"

    }

}
BrieucV commented 4 years ago

Hello guys,

I am also facing this problem for the last fews weeks now... and it happens quite often. Libraries I am using : implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.0-alpha.2') implementation('com.mapbox.mapboxsdk:mapbox-android-navigation:0.43.0-alpha.1') implementation('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.43.0-alpha.1')

and here is my logs:

PID: 25008 Reason: Broadcast of Intent { act=com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED flg=0x10 launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } (has extras) } Load: 2.96 / 4.23 / 3.78 CPU usage from 33460ms to 0ms ago (2020-05-25 21:53:02.469 to 2020-05-25 21:53:35.930): 8.1% 2691/system_server: 5.5% user + 2.6% kernel / faults: 496 minor 51 major 3% 2226/gpsd: 2.4% user + 0.5% kernel / faults: 2 minor 3 major 2.2% 3449/com.google.android.gms.persistent: 1.4% user + 0.8% kernel / faults: 167 minor 10 major 1.7% 22591/kworker/u8:2: 0% user + 1.7% kernel 0.7% 2781/irq/565-bhy: 0% user + 0.7% kernel 0.6% 23613/kworker/0:1: 0% user + 0.6% kernel 0.6% 25047/irq/453-1380000: 0% user + 0.6% kernel 0.6% 25542/kworker/0:4: 0% user + 0.6% kernel 0.6% 2130/dhd_dpc: 0% user + 0.6% kernel 0.6% 4314/wpa_supplicant: 0.1% user + 0.4% kernel 0.3% 7053/com.android.bluetooth: 0.2% user + 0.1% kernel / faults: 46 minor 0.3% 2997/com.android.systemui: 0.2% user + 0.1% kernel / faults: 63 minor 4 major 0.3% 1133/mmcqd/0: 0% user + 0.3% kernel 0.3% 25008/com.naver.labs.tourgeneration: 0.2% user + 0% kernel / faults: 3 minor 0.2% 2113/logd: 0.1% user + 0.1% kernel / faults: 6 minor 4 major 0.2% 24918/cfinteractive0: 0% user + 0.2% kernel 0.2% 2213/surfaceflinger: 0.1% user + 0.1% kernel / faults: 32 minor 1 major 0.2% 30980/jp.naver.line.android: 0.1% user + 0% kernel / faults: 14 minor 3 major 0.2% 23938/kworker/1:3: 0% user + 0.2% kernel 0.2% 26521/com.android.chrome: 0% user + 0.1% kernel / faults: 217 minor 10 major 0.1% 2224/argosd: 0% user + 0% kernel 0.1% 24583/kworker/u8:3: 0% user + 0.1% kernel 0.1% 2129/dhd_watchdog_th: 0% user + 0.1% kernel 0.1% 8/rcu_preempt: 0% user + 0.1% kernel 0% 2104/jbd2/mmcblk0p23: 0% user + 0% kernel 0% 2980/com.android.phone: 0% user + 0% kernel / faults: 3 minor 6 major 0% 21442/kworker/2:1: 0% user + 0% kernel 0% 26564/com.android.chrome:sandboxed_process0: 0% user + 0% kernel 0% 2212/servicemanager: 0% user + 0% kernel 0% 3576/iod: 0% user + 0% kernel 0% 1//init: 0% user + 0% kernel 0% 1359/s3c-fb-vsync: 0% user + 0% kernel 0% 2208/healthd: 0% user + 0% kernel 0% 2218/edmaudit: 0% user + 0% kernel 0% 2227/diagexe: 0% user + 0% kernel 0% 2243/rild: 0% user + 0% kernel 0% 2244/smdexe: 0% user + 0% kernel 0% 3413/com.android.nfc: 0% user + 0% kernel / faults: 152 minor 14 major 0% 6979/com.samsung.android.beaconmanager: 0% user + 0% kernel 0% 26377/com.whatsapp: 0% user + 0% kernel / faults: 4 minor 5.1% TOTAL: 2.2% user + 2.7% kernel + 0.1% iowait + 0% irq + 0% softirq CPU usage from 3887ms to 4415ms later (2020-05-25 21:53:39.817 to 2020-05-25 21:53:40.345) with 99% awake: 12% 2691/system_server: 3.7% user + 9.2% kernel / faults: 11 minor 7.4% 2749/ActivityManager: 0% user + 7.4% kernel 1.8% 2784/SensorService: 1.8% user + 0% kernel 1.1% 2130/dhd_dpc: 0% user + 1.1% kernel 1.2% 3576/iod: 0% user + 1.2% kernel 1.6% 22591/kworker/u8:2: 0% user + 1.6% kernel 1.6% 25008/com.naver.labs.tourgeneration: 1.6% user + 0% kernel / faults: 10 minor 3.3% TOTAL: 0.4% user + 2.4% kernel + 0.4% softirq

vidhi1011 commented 4 years ago

@nkukday Now i am using this navigation in activity instead of fragment. but it only works once. next time i start navigation then causing this same ANR. Please help!

nkukday commented 4 years ago

We are actively investigating this issue, will keep this thread updated.

vidhi1011 commented 4 years ago

@nkukday Any update on this ANR? i have been facing this in whole app whenever i use normal maps also. in some minutes getting ANR only. Please review the issue

nkukday commented 4 years ago

We are continuing to actively investigate this issue and could use help reproducing this reliably. If possible, please share steps to repro and/or device information. cc @alfwatt @harvsu @mapbox/maps-android @mapbox/navigation-android

vidhi1011 commented 4 years ago

@nkukday I am facing this issue in every devices. particularly currently i have tested in huawei p30 lite. Also i have used navigation ui dependency 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.6' . i have already shared whole code in above comment. Also i am facing issue in foreground only. when navigation is on going after some mins app becomes not responding.

[ANR in com.flashmarket.delivery
    PID: 25810
    Reason: Broadcast of Intent { act=com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED flg=0x10 hwFlg=0x100 (has extras) }
    Load: 46.35 / 46.33 / 46.39
    CPU usage from 90220ms to 0ms ago (2020-06-08 10:25:41.659 to 2020-06-08 10:27:11.876):
      140% 25810/com.flashmarket.delivery: 73% user + 66% kernel / faults: 34043 minor
      19% 656/surfaceflinger: 11% user + 8.3% kernel / faults: 1025 minor 1 major
      6.7% 12579/system_server: 4.2% user + 2.5% kernel / faults: 3120 minor
      6.2% 622/vendor.huawei.hardware.hwdisplay.displayengine@1.2-service: 3.7% user + 2.4% kernel
      4.4% 605/android.hardware.graphics.composer@2.2-service: 2.4% user + 1.9% kernel / faults: 2 minor
      3.9% 13146/com.huawei.android.launcher: 2.6% user + 1.3% kernel / faults: 16513 minor
      3% 20550/kworker/u16:23: 0% user + 3% kernel
      2.3% 23733/kworker/u16:27: 0% user + 2.3% kernel
      2% 23730/kworker/u16:24: 0% user + 2% kernel
      1.7% 23720/kworker/u16:11: 0% user + 1.7% kernel
      1.5% 12850/com.android.systemui: 1% user + 0.4% kernel / faults: 1467 minor
      0.9% 12375/audioserver: 0.8% user + 0% kernel / faults: 24 minor
      0.8% 20923/adbd: 0.1% user + 0.7% kernel / faults: 112 minor
      0.8% 9/rcu_preempt: 0% user + 0.8% kernel
      0.8% 455/servicemanager: 0.4% user + 0.3% kernel
      0.6% 13346/com.huawei.iaware: 0.4% user + 0.2% kernel / faults: 1748 minor
      0.6% 7156/com.google.android.gms.persistent: 0.4% user + 0.1% kernel / faults: 258 minor
      0.6% 454/logd: 0.2% user + 0.3% kernel / faults: 3 minor
      0.6% 15237/kworker/u17:0: 0% user + 0.6% kernel
      0.5% 12377/mediaserver: 0.3% user + 0.2% kernel / faults: 227 minor
      0.4% 2951/sugov:4: 0% user + 0.4% kernel
      0.4% 25437/kworker/u17:2: 0% user + 0.4% kernel
      0.4% 1039/hisi_frw/0: 0% user + 0.4% kernel
      0.4% 24683/kworker/u17:4: 0% user + 0.4% kernel
      0.4% 662/powerlogd: 0.3% user + 0% kernel / faults: 3 minor
      0.4% 799/ITouchservice: 0.2% user + 0.1% kernel
      0.4% 12380/vendor.huawei.hardware.audio@5.0-service: 0.1% user + 0.2% kernel / faults: 2 minor
      0.3% 869/hiview: 0% user + 0.2% kernel / faults: 30 minor
      0.3% 852/media.swcodec: 0.1% user + 0.1% kernel / faults: 194 minor
      0.3% 2949/sugov:0: 0% user + 0.3% kernel
      0.3% 19495/kworker/1:2H: 0% user + 0.3% kernel
      0.2% 824/thermal-daemon: 0% user + 0.2% kernel
      0.2% 851/vendor.huawei.hardware.sensors@1.0-service: 0.1% user + 0.1% kernel
      0.2% 13368/com.android.phone: 0.1% user + 0% kernel / faults: 396 minor 3 major
      0.2% 805/dubaid: 0.1% user + 0.1% kernel / faults: 141 minor
      0.2% 17880/com.huawei.health:DaemonService: 0.1% user + 0% kernel / faults: 8 minor
      0.2% 25670/logcat: 0.1% user + 0.1% kernel
      0.2% 1262/com.google.process.gapps: 0% user + 0.1% kernel / faults: 100 minor
      0.1% 597/android.system.suspend@1.0-service: 0% user + 0.1% kernel
      0.1% 8769/com.android.vending:instant_app_installer: 0% user + 0% kernel / faults: 1896 minor 1 major
      0.1% 13518/com.google.android.ext.services: 0.1% user + 0% kernel / faults: 227 minor
      0.1% 262/mmc-cmdqd/0: 0% user + 0.1% kernel
      0.1% 821/statsd: 0% user + 0% kernel
      0.1% 26017/com.google.android.apps.docs: 0% user + 0% kernel / faults: 1235 minor 13 major
      0.1% 803/displayengineserver: 0% user + 0% kernel / faults: 1 minor
      0.1% 13243/com.huawei.hiview: 0% user + 0% kernel / faults: 130 minor
      0.1% 73/mailbox-16: 0% user + 0.1% kernel
      0.1% 13306/com.huawei.HwOPServer: 0% user + 0% kernel / faults: 1174 minor 52 major
      0.1% 18/ksoftirqd/1: 0% user + 0.1% kernel
      0.1% 1048/hisi_hcc: 0% user + 0.1% kernel
      0% 12/migration/0: 0% user + 0% kernel
      0% 843/hwpged: 0% user + 0% kernel
      0% 1312/gnss_engine_hisi: 0% user + 0% kernel
      0% 12378/netd: 0% user + 0% kernel / faults: 203 minor
      0% 25489/kworker/3:2: 0% user + 0% kernel
      0% 25539/kworker/1:2: 0% user + 0% kernel
      0% 8/ksoftirqd/0: 0% user + 0% kernel
      0% 23955/kworker/0:2H: 0% user + 0% kernel
      0% 25729/kworker/3:0H: 0% user + 0% kernel
      0% 47/migration/6: 0% user + 0% kernel]
lognaturel commented 4 years ago

In Google Play Console, we are seeing ANRs that look like what @sarimk80 has reported at https://github.com/mapbox/mapbox-gl-native-android/issues/126#issuecomment-605897452. I can file a separate issue if it seems likely to be something different.

Unfortunately we haven't been able to reproduce. It affects hundreds of our users daily. This is the trace we get from the Play Console:

"main" prio=5 tid=1 Native
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x765ade18 self=0x7338c14c00
  | sysTid=16845 nice=0 cgrp=default sched=0/0 handle=0x73bf2c9560
  | state=R schedstat=( 279349583954 13571296805 104906 ) utm=3158 stm=24776 core=1 HZ=100
  | stack=0x7fe5d14000-0x7fe5d16000 stackSize=8MB
  | held mutexes=
  #00  pc 000000000001f1f0  /system/lib64/libc.so (syscall+32)
  #01  pc 0000000000022880  /system/lib64/libc.so (__futex_wait_ex(void volatile*, bool, int, bool, timespec const*)+140)
  #02  pc 00000000000846a4  /system/lib64/libc.so (NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*)+664)
  #03  pc 00000000002cd9fc  /data/app/org.odk.collect.android-TdHSFjaPVvtcC_vouAdIWg==/lib/arm64/libmapbox-gl.so (std::__ndk1::mutex::lock()+8)
  #04  pc 00000000001410a8  /data/app/org.odk.collect.android-TdHSFjaPVvtcC_vouAdIWg==/lib/arm64/libmapbox-gl.so (???)
  #05  pc 000000000009398c  /data/app/org.odk.collect.android-TdHSFjaPVvtcC_vouAdIWg==/lib/arm64/libmapbox-gl.so (???)
  #06  pc 0000000000092410  /data/app/org.odk.collect.android-TdHSFjaPVvtcC_vouAdIWg==/lib/arm64/libmapbox-gl.so (???)
  #07  pc 00000000000141c0  /system/lib64/libutils.so (android::Looper::pollInner(int)+856)
  #08  pc 0000000000013dcc  /system/lib64/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+60)
  #09  pc 00000000001298f4  /system/lib64/libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long, int)+44)
  at android.os.MessageQueue.nativePollOnce (Native method)
  at android.os.MessageQueue.next (MessageQueue.java:326)
  at android.os.Looper.loop (Looper.java:181)
  at android.app.ActivityThread.main (ActivityThread.java:7091)
  at java.lang.reflect.Method.invoke (Native method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)

I don't know whether it is related but we're seeing a similar rate of crashes in libmapbox-gl.so. We have different clusters with errors like signal 11 (SIGSEGV), code 1 (SEGV_MAPERR). Happy to share more details if it could be related.

The application is open source and can be found at https://github.com/getodk/collect.

Here is where the Mapbox libraries are specified in the gradle file: https://github.com/getodk/collect/blob/d674fea88431e94c43c4980a1adf9a82effe5064/collect_app/build.gradle#L221

The code that likely triggers the issue is at https://github.com/getodk/collect/pull/3853/files#diff-587fa336330bb907832356ee77ed08d1R402. Our users work in disconnected environments and sometimes use offline mbtiles layers. We added that code so that offline layers would be available even when they're accessed offline the first time.

Chaoba commented 4 years ago

While blocking the main thread without Location Component, will generate ANR

Reason: Broadcast of Intent { act=com.mapbox.scheduler_flusher flg=0x80014 (has extras) }

While blocking the main thread with Location Component, will generate ANR:

Reason: Broadcast of Intent { act=com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED flg=0x10 (has extras) }

With the main thread blocked, broadcast receivers will also be blocked in main thread and finally cause ANR. Based on the above analyses, this issue is not related with telemetry, but should be something in nav or other places that blocks the main thread.

@lognaturel thanks for your information, can you provide more stack info to help us to make sure it 's the same with this one?

lognaturel commented 4 years ago

@Chaoba thanks so much for following up so quickly. Do you have a sense of which stack info could be helpful? Again, we can't reproduce locally, we just have Play Console reports.

I just realized that in Google Play Console we also see the ANR from the original issue in addition to the scheduler_flusher one:

Broadcast of Intent { act=com.mapbox.android.telemetry.location.locationupdatespendingintent.action.LOCATION_UPDATED flg=0x10 (has extras) }

"main" tid=1 Native
"main" prio=5 tid=1 Native
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x715c6e58 self=0x701c0bdc00
  | sysTid=16848 nice=0 cgrp=default sched=0/0 handle=0x701d629ed0
  | state=R schedstat=( 351436253297 2601704912 22849 ) utm=5367 stm=29776 core=1 HZ=100
  | stack=0x7fbfda6000-0x7fbfda8000 stackSize=8192KB
  | held mutexes=
  #00  pc 0000000000080340  /apex/com.android.runtime/lib64/bionic/libc.so (syscall+32)
  #01  pc 00000000000838a8  /apex/com.android.runtime/lib64/bionic/libc.so (__futex_wait_ex(void volatile*, bool, int, bool, timespec const*)+140)
  #02  pc 00000000000e77c8  /apex/com.android.runtime/lib64/bionic/libc.so (NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*)+596)
  #03  pc 00000000002cd9fc  /data/app/org.odk.collect.android-0jaQF1LieE0LIVmPAZPF3Q==/lib/arm64/libmapbox-gl.so (std::__ndk1::mutex::lock()+8)
  #04  pc 00000000001410a8  /data/app/org.odk.collect.android-0jaQF1LieE0LIVmPAZPF3Q==/lib/arm64/libmapbox-gl.so (???)
  #05  pc 000000000009398c  /data/app/org.odk.collect.android-0jaQF1LieE0LIVmPAZPF3Q==/lib/arm64/libmapbox-gl.so (???)
  #06  pc 0000000000092410  /data/app/org.odk.collect.android-0jaQF1LieE0LIVmPAZPF3Q==/lib/arm64/libmapbox-gl.so (???)
  #07  pc 000000000001836c  /system/lib64/libutils.so (android::Looper::pollInner(int)+832)
  #08  pc 0000000000017f8c  /system/lib64/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+56)
  #09  pc 000000000013b920  /system/lib64/libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long, int)+44)
  at android.os.MessageQueue.nativePollOnce (Native method)
  at android.os.MessageQueue.next (MessageQueue.java:336)
  at android.os.Looper.loop (Looper.java:174)
  at android.app.ActivityThread.main (ActivityThread.java:7403)
  at java.lang.reflect.Method.invoke (Native method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:492)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:935)

There are lots of crashes that do look related. Here's an example:

  #00  pc 000000000002237c  /system/lib64/libc.so (abort+116)
  #01  pc 0000000000091b88  /system/lib64/libc.so (__fortify_fatal(char const*, ...)+120)
  #02  pc 00000000000911f0  /system/lib64/libc.so (HandleUsingDestroyedMutex(pthread_mutex_t*, char const*)+52)
  #03  pc 000000000009106c  /system/lib64/libc.so (pthread_mutex_lock+228)
  #04  pc 00000000002cd9fc  /data/app/org.odk.collect.android-SK9uN5XRIOL3P-5ftrwIjw==/lib/arm64/libmapbox-gl.so (std::__ndk1::mutex::lock()+8)
  #05  pc 00000000001410a8  /data/app/org.odk.collect.android-SK9uN5XRIOL3P-5ftrwIjw==/lib/arm64/libmapbox-gl.so
  #06  pc 000000000009398c  /data/app/org.odk.collect.android-SK9uN5XRIOL3P-5ftrwIjw==/lib/arm64/libmapbox-gl.so
  #07  pc 0000000000092410  /data/app/org.odk.collect.android-SK9uN5XRIOL3P-5ftrwIjw==/lib/arm64/libmapbox-gl.so
  #08  pc 0000000000014ff8  /system/lib64/libutils.so (android::Looper::pollInner(int)+836)
  #09  pc 0000000000014c18  /system/lib64/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+60)
  #10  pc 00000000001278d4  /system/lib64/libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long, int)+44)
  #11  pc 00000000003e5fec  /system/framework/arm64/boot-framework.oat (offset 0x3d1000) (android.media.MediaExtractor.seekTo [DEDUPED]+140)
  #12  pc 0000000000abbb30  /system/framework/arm64/boot-framework.oat (offset 0x3d1000) (android.os.MessageQueue.next+240)
  #13  pc 0000000000ab94bc  /system/framework/arm64/boot-framework.oat (offset 0x3d1000) (android.os.Looper.loop+636)
  #14  pc 00000000008842b8  /system/framework/arm64/boot-framework.oat (offset 0x3d1000) (android.app.ActivityThread.main+664)
  #15  pc 000000000055764c  /system/lib64/libart.so (art_quick_invoke_static_stub+604)
  #16  pc 00000000000cfd14  /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+232)
  #17  pc 000000000045de68  /system/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
  #18  pc 000000000045f8bc  /system/lib64/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned long)+1440)
  #19  pc 00000000003ef4f0  /system/lib64/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*)+52)
  #20  pc 000000000011e6d4  /system/framework/arm64/boot-core-oj.oat (offset 0x114000) (java.lang.Class.getDeclaredMethodInternal [DEDUPED]+180)
  #21  pc 0000000000bf0828  /system/framework/arm64/boot-framework.oat (offset 0x3d1000) (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run+136)
  #22  pc 0000000000bf7a10  /system/framework/arm64/boot-framework.oat (offset 0x3d1000) (com.android.internal.os.ZygoteInit.main+3088)
  #23  pc 000000000055764c  /system/lib64/libart.so (art_quick_invoke_static_stub+604)
  #24  pc 00000000000cfd14  /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+232)
  #25  pc 000000000045de68  /system/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
  #26  pc 000000000045dac8  /system/lib64/libart.so (art::InvokeWithVarArgs(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, std::__va_list)+424)
  #27  pc 0000000000362cf0  /system/lib64/libart.so (art::JNI::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, std::__va_list)+652)
  #28  pc 00000000000b2e8c  /system/lib64/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+116)
  #29  pc 00000000000b58b0  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+752)
  #30  pc 000000000000251c  /system/bin/app_process64 (main+2000)
  #31  pc 00000000000c8918  /system/lib64/libc.so (__libc_init+88)
Chaoba commented 4 years ago

@vidhi1011 In your code, you didn't call navigationView?.onDestory() correctly, so it will block the main thread and cause this ANR.

    override fun onDestroy() {
        super.onDestroy()
        try {
            if (navigationView != null) {
                navigationView?.onStop()
                stopNavigation()
            }
        } catch (e: Exception) {
        }
    }

It seems all errors that could block the main thread can cause this ANR, which will hidden the real ANR. So IMHO, we should increase the priority of https://github.com/mapbox/mobile-telemetry/issues/757

vidhi1011 commented 4 years ago

@Chaoba Is it the code that i need to replace ? actually currently i am using activity that also causing this ANR. Please review my activity stop as well


class NavigationActivity : BaseAppCompatActivity(), OnNavigationReadyCallback, NavigationListener,
    ProgressChangeListener, OnDataNavigationListener {
    private lateinit var message: LatLongData
    private var directionsRoute: DirectionsRoute? = null
    private var ORIGIN_LONGITUDE: Double = 0.0
    private var ORIGIN_LATITUDE: Double = 0.0
    private var DESTINATION_LONGITUDE: Double = 0.0
    private var DESTINATION_LATITUDE: Double = 0.0

    private var isNavigation: Boolean = true

    private var total_count: String = ""
    private var collected_count: String = ""

    var tabName: String = ""
    var tabTitle: String = ""
    var routeId = ""

    companion object {
        const val TAB_NAME: String = "TAB_NAME"
    }

    private var selectedItems: ArrayList<DeliveryListData.Data?> =
        ArrayList()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Mapbox.getInstance(this, getString(R.string.access_token))

        setContentView(R.layout.fragment_navigation)
        navigationView.onCreate(savedInstanceState)
        navigationView.initialize(this)

        if (intent != null && intent.hasExtra("data")) {
            message = getIntent().getSerializableExtra("data") as LatLongData
            getData(message)
        }

        initView()

    }

    private fun initView() {

        navigationView?.findViewById<View>(R.id.summaryBottomSheet)?.visibility = View.GONE
        navigationView?.findViewById<View>(R.id.feedbackFab)?.visibility = View.GONE
        navigationView?.findViewById<View>(R.id.soundFab)?.visibility = View.GONE

        val param =
            navigationView!!.findViewById<View>(R.id.instructionLayout).layoutParams as ViewGroup.MarginLayoutParams
        param.setMargins(40, 100, 40, 0)
        navigationView!!.findViewById<View>(R.id.instructionLayout).layoutParams = param

        val vto: ViewTreeObserver =
            navigationView?.findViewById<View>(R.id.instructionLayout)!!.getViewTreeObserver()
        vto.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
            override fun onGlobalLayout() {
                navigationView?.findViewById<View>(R.id.instructionLayout)!!
                    .getViewTreeObserver()
                    .removeOnGlobalLayoutListener(this)

                val bottom: Int =
                    navigationView?.findViewById<View>(R.id.instructionView)!!.bottom

                val height: Int =
                    navigationView?.findViewById<View>(R.id.instructionLayout)!!
                        .measuredHeight

                val param = llMain.layoutParams as ViewGroup.MarginLayoutParams
                param.setMargins(40, height + 100, 40, 0)
                llMain.layoutParams = param

                llMain.visibility = View.VISIBLE
                dismissProgressDialog()
            }
        })

    }

    public override fun onStart() {
        super.onStart()
        try {
            navigationView.visibility = View.VISIBLE
            navigationView.onStart()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    public override fun onResume() {
        super.onResume()
        try {
            navigationView.visibility = View.VISIBLE
            navigationView.onResume()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    public override fun onSaveInstanceState(outState: Bundle) {
        navigationView.onSaveInstanceState(outState)
        super.onSaveInstanceState(outState)
    }

    public override fun onPause() {
        super.onPause()
        stopNavigation()
        navigationView!!.onPause()
    }

    public override fun onStop() {
        super.onStop()
        navigationView!!.onStop()
        stopNavigation()
    }

    override fun onLowMemory() {
        super.onLowMemory()
        navigationView!!.onLowMemory()
    }

    override fun onNavigationReady(isRunning: Boolean) {
        val origin = Point.fromLngLat(ORIGIN_LONGITUDE, ORIGIN_LATITUDE)
        val destination = Point.fromLngLat(DESTINATION_LONGITUDE, DESTINATION_LATITUDE)
        fetchRoute(origin, destination)
    }

    override fun onCancelNavigation() {
        navigationView!!.stopNavigation()
        stopNavigation()
    }

    override fun onNavigationFinished() {
// no-op
    }

    override fun onNavigationRunning() {
// no-op
    }

    override fun onProgressChange(location: Location, routeProgress: RouteProgress) {
        val isInTunnel = routeProgress.inTunnel()
        val wasInTunnel = wasInTunnel()
        if (isInTunnel) {
            if (!wasInTunnel) {
                updateWasInTunnel(true)
                updateCurrentNightMode(AppCompatDelegate.MODE_NIGHT_YES)
            }
        } else {
            if (wasInTunnel) {
                updateWasInTunnel(false)
                updateCurrentNightMode(AppCompatDelegate.MODE_NIGHT_AUTO)
            }
        }

        Log.e("progress", "" + routeProgress.distanceRemaining())
        if (routeProgress.distanceRemaining() <= 50.0) {
            if (isNavigation) {

                isNavigation = false

                val walletIntent = Intent(this, HomeActivity::class.java)
                walletIntent.flags =
                    Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK

                if (selectedItems.size == 1) {

                    walletIntent.putExtra(
                        "data", Message(
                            "6",
                            selectedItems,
                            "collection",
                            routeId,
                            "single",
                            tabName,
                            tabTitle
                        )
                    )

                } else {

                    walletIntent.putExtra(
                        "data", Message(
                            "6",
                            selectedItems,
                            "collection",
                            routeId,
                            "bulk",
                            tabName,
                            tabTitle
                        )
                    )
                }

                if (tabName == Constants.TAB_ACCEPTED) {
                    walletIntent.putExtra(HomeActivity.EXTRA_SELECTED_TAB, Constants.TAB_ACCEPTED)
                } else {
                    walletIntent.putExtra(HomeActivity.EXTRA_SELECTED_TAB, Constants.TAB_ON_THE_WAY)

                }

                walletIntent.putExtra("isCollectionFlow", true)
                walletIntent.putExtra("routeId", routeId)
                startActivity(walletIntent)

                try {
                    navigationView?.onStop()
                    stopNavigation()
                } catch (e: Exception) {
                }

            }

        }

    }

    @SuppressLint("WrongConstant")
    private fun updateNightMode() {
        if (wasNavigationStopped()) {
            updateWasNavigationStopped(false)
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO)
            recreate()
        }
    }

    private fun fetchRoute(origin: Point, destination: Point) {
        NavigationRoute.builder(this)
            .accessToken(Mapbox.getAccessToken()!!)
            .origin(origin)
            .destination(destination)
            .build()
            .getRoute(object : Callback<DirectionsResponse> {
                override fun onResponse(
                    call: Call<DirectionsResponse>,
                    response: Response<DirectionsResponse>
                ) {
                    try {
                        directionsRoute = response.body()!!.routes()[0]
                        startNavigation()
                    } catch (e: Exception) {
                        e.printStackTrace()
                    }
                }

                override fun onFailure(call: Call<DirectionsResponse>, t: Throwable) {}
            })
    }

    private fun startNavigation() {
        if (directionsRoute == null) {
            return
        }
        val options = NavigationViewOptions.builder()
            .directionsRoute(directionsRoute)
            .shouldSimulateRoute(true)
            .navigationListener(this)
            .progressChangeListener(this)
            .build()
        navigationView!!.startNavigation(options)
    }

    private fun wasInTunnel(): Boolean {
        val context: Context = this
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        return preferences.getBoolean("was_in_tunnel", false)
    }

    private fun updateWasInTunnel(wasInTunnel: Boolean) {
        val context: Context = this
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        val editor = preferences.edit()
        editor.putBoolean("was_in_tunnel", wasInTunnel)
        editor.apply()
    }

    private fun updateCurrentNightMode(nightMode: Int) {
        AppCompatDelegate.setDefaultNightMode(nightMode)
        recreate()
    }

    private fun wasNavigationStopped(): Boolean {
        val context: Context = this
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        return preferences.getBoolean("was_navigation_stopped", false)
    }

    fun updateWasNavigationStopped(wasNavigationStopped: Boolean) {
        val context: Context = this
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        val editor = preferences.edit()
        editor.putBoolean("was_navigation_stopped", wasNavigationStopped)
        editor.apply()
    }

    override fun onBackPressed() {
        super.onBackPressed()
        stopNavigation()
    }

    private fun stopNavigation() {
        // hide navigation view
        navigationView.visibility = View.GONE
        try {
            navigationView.stopNavigation()
        } catch (e: Exception) {
        }
    }

    override fun sendData(message: LatLongData?) {
        getData(message)

    }

    fun getData(message: LatLongData?) {
        ORIGIN_LONGITUDE = message!!.startLng
        ORIGIN_LATITUDE = message.startLat
        DESTINATION_LATITUDE = message.endLat
        DESTINATION_LONGITUDE = message.endLng
        total_count = message.totalCount
        collected_count = message.collectedCount
        routeId = message.routeId
        tabName = message.tabName
        tabTitle = message.tabTitle

        initActionBar(tabTitle)

        Log.e("start-lat-long", "" + ORIGIN_LONGITUDE + " | " + ORIGIN_LATITUDE)
        Log.e("end-lat-long", "" + DESTINATION_LONGITUDE + " | " + DESTINATION_LATITUDE)

        tvDeliveries?.text = total_count + "/" + collected_count

        selectedItems = message.selectedItems!!

        tvStartSubrub.text = generateAddress(DESTINATION_LATITUDE, DESTINATION_LONGITUDE)

        try {
            stopNavigation()
            navigationView.visibility = View.VISIBLE
            navigationView.onStart()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

}
Chaoba commented 4 years ago

@vidhi1011 As I have said before, you must call navigationView?.onDestory() in onDestory method. Please refer to the demo in doc.

vidhi1011 commented 4 years ago

@Chaoba Still getting ANR :

 Reason: Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. waitqueue length = 42, head.seq = 466095, Wait queue head age: 5952.9ms.)
    Parent: com.flashmarket.delivery/com.fm.activity.HomeActivity
    Load: 46.86 / 46.72 / 46.43
    CPU usage from 53865ms to 0ms ago (2020-06-10 12:51:57.023 to 2020-06-10 12:52:50.888):
      17% 656/surfaceflinger: 10% user + 7.5% kernel / faults: 1635 minor
      16% 12579/system_server: 10% user + 5.4% kernel / faults: 52910 minor 6 major
      7% 605/android.hardware.graphics.composer@2.2-service: 3.3% user + 3.7% kernel / faults: 129 minor
      5.2% 13146/com.huawei.android.launcher: 3.6% user + 1.6% kernel / faults: 15481 minor 1 major
      4.4% 622/vendor.huawei.hardware.hwdisplay.displayengine@1.2-service: 2.4% user + 2% kernel
      3.5% 12850/com.android.systemui: 2.6% user + 0.9% kernel / faults: 4468 minor 2 major
      2% 24429/com.lexa.fakegps: 1.3% user + 0.6% kernel / faults: 33612 minor 107 major
      1.6% 5471/adbd: 0.4% user + 1.2% kernel / faults: 475 minor
      1.5% 19068/kworker/u16:7: 0% user + 1.5% kernel
      1.4% 843/hwpged: 0.1% user + 1.3% kernel
      1.4% 869/hiview: 0.2% user + 1.1% kernel / faults: 528 minor 7 major
      1.3% 27351/kworker/u16:21: 0% user + 1.3% kernel
      1.3% 662/powerlogd: 0.8% user + 0.4% kernel / faults: 8 minor
      1.3% 27348/kworker/u16:18: 0% user + 1.3% kernel
      1.2% 27174/kworker/u16:8: 0% user + 1.2% kernel
      1.2% 16996/com.google.android.tts: 1.1% user + 0.1% kernel / faults: 14271 minor
      1.1% 13346/com.huawei.iaware: 0.7% user + 0.4% kernel / faults: 1828 minor
      1% 7156/com.google.android.gms.persistent: 0.6% user + 0.4% kernel / faults: 679 minor
      1% 19287/kworker/u16:10: 0% user + 1% kernel
      1% 454/logd: 0.3% user + 0.6% kernel / faults: 17 minor
      1% 455/servicemanager: 0.4% user + 0.5% kernel
      1% 27289/kworker/u16:11: 0% user + 1% kernel
      0.9% 12298/com.google.android.gms: 0.7% user + 0.2% kernel / faults: 4129 minor 1 major
      0.9% 27175/kworker/u16:9: 0% user + 0.9% kernel
      0.8% 25203/kworker/u17:0: 0% user + 0.8% kernel
      0.7% 27291/kworker/u16:13: 0% user + 0.7% kernel
      0.7% 21592/kworker/u17:2: 0% user + 0.7% kernel
      0.7% 9/rcu_preempt: 0% user + 0.7% kernel
      0.6% 805/dubaid: 0.2% user + 0.4% kernel / faults: 862 minor
      0.5% 604/android.hardware.graphics.allocator@2.0-service: 0.1% user + 0.4% kernel / faults: 84 minor
      0.5% 14425/kworker/0:1H: 0% user + 0.5% kernel
      0.5% 26915/kworker/u17:1: 0% user + 0.5% kernel
      0.4% 799/ITouchservice: 0.2% user + 0.1% kernel
      0.4% 95/sys_heap: 0% user + 0.4% kernel
      0.3% 1039/hisi_frw/0: 0% user + 0.3% kernel
      0.3% 1048/hisi_hcc: 0% user + 0.3% kernel
      0.3% 8307/com.google.process.gapps: 0.1% user + 0.2% kernel / faults: 108 minor
      0.3% 597/android.system.suspend@1.0-service: 0.1% user + 0.2% kernel
      0.3% 249/ts_thread:0: 0% user + 0.3% kernel
      0.3% 1049/hisi_rxdata: 0% user + 0.3% kernel
      0.3% 2949/sugov:0: 0% user + 0.3% kernel
      0.3% 2951/sugov:4: 0% user + 0.3% kernel
      0.3% 27290/kworker/u16:12: 0% user + 0.3% kernel
      0.2% 652/lmkd: 0% user + 0.2% kernel
      0.2% 824/thermal-daemon: 0% user + 0.2% kernel
      0.2% 12378/netd: 0% user + 0.2% kernel / faults: 523 minor
      0.2% 13368/com.android.phone: 0.1% user + 0.1% kernel / faults: 204 minor
      0.2% 262/mmc-cmdqd/0: 0% user + 0.2% kernel
      0.2% 27294/kworker/u16:16: 0% user + 0.2% kernel
      0.2% 27735/kworker/u16:26: 0% user + 0.2% kernel
      0.2% 1034/oal_gpio_rx_dat: 0% user + 0.2% kernel
      0.2% 28233/kworker/u16:33: 0% user + 0.2% kernel
      0.2% 821/statsd: 0.1% user + 0% kernel / faults: 1 minor
      0.1% 1/init: 0.1% user + 0% kernel
      0.1% 17880/com.huawei.health:DaemonService: 0.1% user + 0% kernel / faults: 10 minor
      0.1% 726/aptouch_daemon: 0% user + 0% kernel
      0.1% 13009/com.touchtype.swiftkey: 0% user + 0% kernel / faults: 41 minor
      0.1% 27968/kworker/0:1: 0% user + 0.1% kernel
      0.1% 20071/
class NavigationFragment : BaseFragment(), OnNavigationReadyCallback, NavigationListener,
    ProgressChangeListener, OnDataNavigationListener {

    private var ORIGIN_LONGITUDE: Double = 0.0
    private var ORIGIN_LATITUDE: Double = 0.0
    private var DESTINATION_LONGITUDE: Double = 0.0
    private var DESTINATION_LATITUDE: Double = 0.0

    private var isNavigation: Boolean = true
    private var mOnDataListner: OnDataUpdateListener? = null
    private lateinit var mLatLongData: LatLongData
    private var mDirectionsRoute: DirectionsRoute? = null
    private var mTotalCount: String = ""
    private var mCollectedCount: String = ""
    private var mTabName: String = ""
    private var mTabTitle: String = ""
    private var mRouteId = ""
    private var mSelectedItems: ArrayList<DeliveryListData.Data?> = ArrayList()

    companion object {
        const val TAB_NAME: String = "TAB_NAME"
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_navigation, container, false)
        return view
    }

    @SuppressLint("ResourceType")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        navigationView?.onCreate(savedInstanceState)
        navigationView?.initialize(this)

        mLatLongData = arguments?.getSerializable("data") as LatLongData
        getData(mLatLongData)

        initView()
    }

    private fun initView() {

        navigationView?.findViewById<View>(R.id.summaryBottomSheet)?.visibility = View.GONE
        navigationView?.findViewById<View>(R.id.feedbackFab)?.visibility = View.GONE
        navigationView?.findViewById<View>(R.id.soundFab)?.visibility = View.GONE

        val param =
            navigationView!!.findViewById<View>(R.id.instructionLayout).layoutParams as ViewGroup.MarginLayoutParams
        param.setMargins(40, 100, 40, 0)
        navigationView!!.findViewById<View>(R.id.instructionLayout).layoutParams = param

        val vto: ViewTreeObserver =
            navigationView?.findViewById<View>(R.id.instructionLayout)!!.getViewTreeObserver()
        vto.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
            override fun onGlobalLayout() {
                navigationView?.findViewById<View>(R.id.instructionLayout)!!
                    .getViewTreeObserver()
                    .removeOnGlobalLayoutListener(this)

                val bottom: Int =
                    navigationView?.findViewById<View>(R.id.instructionView)!!.bottom

                val height: Int =
                    navigationView?.findViewById<View>(R.id.instructionLayout)!!
                        .measuredHeight

                val param = llMain.layoutParams as ViewGroup.MarginLayoutParams
                param.setMargins(40, height + 100, 40, 0)
                llMain.layoutParams = param

                llMain.visibility = View.VISIBLE
//                dismissProgressDialog()
            }
        })

    }

    override fun onNavigationReady(isRunning: Boolean) {
        val origin = Point.fromLngLat(ORIGIN_LONGITUDE, ORIGIN_LATITUDE)
        val destination = Point.fromLngLat(DESTINATION_LONGITUDE, DESTINATION_LATITUDE)
//        showProgressDialog()

        fetchRoute(origin, destination)
    }

    override fun onNavigationFinished() {

    }

    override fun onNavigationRunning() {

    }

    override fun onCancelNavigation() {
        navigationView.stopNavigation()
        stopNavigation()
    }

    override fun onProgressChange(location: Location, routeProgress: RouteProgress) {
        val isInTunnel = routeProgress.inTunnel()
        val wasInTunnel = wasInTunnel()
        if (isInTunnel) {
            if (!wasInTunnel) {
                updateWasInTunnel(true)
                updateCurrentNightMode(AppCompatDelegate.MODE_NIGHT_YES)
            }
        } else {
            if (wasInTunnel) {
                updateWasInTunnel(false)
                updateCurrentNightMode(AppCompatDelegate.MODE_NIGHT_AUTO)
            }
        }

        Log.e("progress", "" + routeProgress.distanceRemaining())
        if (routeProgress.distanceRemaining() <= 50.0) {
            if (isNavigation) {

                isNavigation = false

                if (mSelectedItems.size == 1) {
                    mOnDataListner?.sendData(
                        Message(
                            "6",
                            mSelectedItems,
                            "collection",
                            mRouteId,
                            "single",
                            mTabName,
                            mTabTitle
                        )
                    )
                }else {
                    mOnDataListner?.sendData(
                        Message(
                            "6",
                            mSelectedItems,
                            "collection",
                            mRouteId,
                            "bulk",
                            mTabName,
                            mTabTitle
                        )
                    )
                }

            }

        }

    }

    @SuppressLint("WrongConstant")
    private fun updateNightMode() {
        if (wasNavigationStopped()) {
            updateWasNavigationStopped(false)
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO)
//            recreate()
        }
    }

    private fun fetchRoute(origin: Point, destination: Point) {
        NavigationRoute.builder(context)
            .accessToken(Mapbox.getAccessToken()!!)
            .origin(origin)
            .destination(destination)
            .build()
            .getRoute(object : Callback<DirectionsResponse> {
                override fun onResponse(
                    call: Call<DirectionsResponse>,
                    response: Response<DirectionsResponse>
                ) {
                    try {
                        mDirectionsRoute = response.body()!!.routes()[0]
                        startNavigation()
                    } catch (e: Exception) {
                        e.printStackTrace()
                    }
                }

                override fun onFailure(call: Call<DirectionsResponse>, t: Throwable) {}
            })
    }

    private fun startNavigation() {
        if (mDirectionsRoute == null) {
            return
        }
        val options = NavigationViewOptions.builder()
            .directionsRoute(mDirectionsRoute)
            .shouldSimulateRoute(true)
            .navigationListener(this)
            .progressChangeListener(this)
            .build()
        navigationView!!.startNavigation(options)
    }

    private fun wasInTunnel(): Boolean {
        val context: Context? = getContext()
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        return preferences.getBoolean("was_in_tunnel", false)
    }

    private fun updateWasInTunnel(wasInTunnel: Boolean) {
        val context: Context? = getContext()
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        val editor = preferences.edit()
        editor.putBoolean("was_in_tunnel", wasInTunnel)
        editor.apply()
    }

    private fun updateCurrentNightMode(nightMode: Int) {
        AppCompatDelegate.setDefaultNightMode(nightMode)
//        recreate()
    }

    private fun wasNavigationStopped(): Boolean {
        val context: Context? = getContext()
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        return preferences.getBoolean("was_navigation_stopped", false)
    }

    fun updateWasNavigationStopped(wasNavigationStopped: Boolean) {
        val context: Context? = getContext()
        val preferences = PreferenceManager.getDefaultSharedPreferences(context)
        val editor = preferences.edit()
        editor.putBoolean("was_navigation_stopped", wasNavigationStopped)
        editor.apply()
    }

    override fun sendData(message: LatLongData?) {
        getData(message)

    }

    fun getData(message: LatLongData?) {
        ORIGIN_LONGITUDE = message!!.startLng
        ORIGIN_LATITUDE = message.startLat
        DESTINATION_LATITUDE = message.endLat
        DESTINATION_LONGITUDE = message.endLng
        mTotalCount = message.totalCount
        mCollectedCount = message.collectedCount
        mRouteId = message.routeId
        mTabName = message.tabName
        mTabTitle = message.tabTitle

//        initActionBar(mTabTitle)
        tvTitle1.visibility = View.VISIBLE
        tvTitle1.text = mTabTitle

        Log.e("start-lat-long", "" + ORIGIN_LONGITUDE + " | " + ORIGIN_LATITUDE)
        Log.e("end-lat-long", "" + DESTINATION_LONGITUDE + " | " + DESTINATION_LATITUDE)

        tvDeliveries?.text = mTotalCount + "/" + mCollectedCount

        mSelectedItems = message.selectedItems!!

        tvStartSubrub.text = generateAddress(DESTINATION_LATITUDE, DESTINATION_LONGITUDE)

        try {
            stopNavigation()
            navigationView.visibility = View.VISIBLE
            navigationView.onStart()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun onStart() {
        super.onStart()
        navigationView.onStart()
    }

    override fun onResume() {
        super.onResume()
        navigationView.onResume()
    }

    /*public fun onSaveInstanceState(@NonNull outState: Bundle?) {
        navigationView.onSaveInstanceState(outState)
        super.onSaveInstanceState(outState!!)
    }
*/
    override fun onViewStateRestored(@Nullable savedInstanceState: Bundle?) {
        super.onViewStateRestored(savedInstanceState)
        if (savedInstanceState != null) {
            navigationView.onRestoreInstanceState(savedInstanceState)
        }
    }

    override fun onPause() {
        super.onPause()
        navigationView.onPause()
    }

    override fun onStop() {
        super.onStop()
        navigationView.onStop()
    }

    override fun onLowMemory() {
        super.onLowMemory()
        navigationView.onLowMemory()
    }

    override fun onDestroyView() {
        super.onDestroyView()
        navigationView.onDestroy()
    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        try {
            mOnDataListner = activity as OnDataUpdateListener
        } catch (e: ClassCastException) {
            throw ClassCastException(
                activity.toString() + " must implement onSomeEventListener"
            )
        }
    }

    private fun stopNavigation() {
        val activity: FragmentActivity? = activity
        if (activity != null && activity is HomeActivity) {
            val fragmentNavigationActivity: HomeActivity =
                activity as HomeActivity
//            fragmentNavigationActivity.showPlaceholderFragment()
//            fragmentNavigationActivity.showNavigationFab()
            updateWasNavigationStopped(true)
            updateWasInTunnel(false)
        }
    }

}
Chaoba commented 4 years ago

@vidhi1011 It's not to review your codes here. It would be nice if you could create a minimal project and upload it to Github then share it with me.

vidhi1011 commented 4 years ago

Hi @Chaoba Please check code here : https://drive.google.com/file/d/1UbxIXL3z31yzjMnITJEPyfTW60S1tQ2B/view?usp=sharing

Steps to reproduce ANR :

  1. Finish full navigation
  2. Will be redirected to map screen click next button
  3. Will be redirected to navigation screen again

When we go to navigation screen again then in some minutes getting this ANR.

vidhi1011 commented 4 years ago

Hi @Chaoba Do let me know if you are facing any issue in my code or not able to reproduce.

Chaoba commented 4 years ago

@vidhi1011 Yeah, your demo could reproduce ANR, but as I said before, it's not caused by the Location Update receiver but something else. In your demo, it seems related to the style in SecondFragment, change the style to something like Style.DARK it will not happen again. I don't know why the style could block the main thread here, but it's irrelevant to this issue. You can create a new issue to track this problem in https://github.com/mapbox/mapbox-navigation-android

vidhi1011 commented 4 years ago

@Chaoba No it is not due to navigation or theme something. if you remove map from second fragment then navigation will work perfectly as many times you want. issue is with map that it does not destroy at all. Please try this way might be you will get issue

Chaoba commented 4 years ago

@vidhi1011 Have you tried to change the style in second fragment?

vidhi1011 commented 4 years ago

@Chaoba I don't know other styles

Chaoba commented 4 years ago

In your demo, it seems related to the style in SecondFragment, change the style to something like Style.DARK it will not happen again.

@vidhi1011 see details in https://github.com/mapbox/mapbox-gl-native-android/issues/126#issuecomment-643176434

vidhi1011 commented 4 years ago

@Chaoba Please verify this code. This is not the issue of style. Please verify with same steps : https://drive.google.com/file/d/1UbxIXL3z31yzjMnITJEPyfTW60S1tQ2B/view?usp=sharing

vidhi1011 commented 4 years ago

@Chaoba Any update on this? have you verified ?

Chaoba commented 4 years ago

@vidhi1011 Sorry I don't have the bandwidth for this recently. But in my last test, it will not crash if change style to Sytel.DARK.

vidhi1011 commented 4 years ago

@Chaoba I have changed to same style now still not working. please assign this to any one else. as my application is not at all working due to this, can't make app live because of this issue. please assign to any other member. It's really critical for my application and really urgent to do

vidhi1011 commented 4 years ago

@Chaoba @Guardiola31337 @abhishek1508 @nkukday

lognaturel commented 4 years ago

@Chaoba thanks for the support you're providing here. I saw your thumbs up on https://github.com/mapbox/mapbox-gl-native-android/issues/126#issuecomment-641397047, did that provide useful information or is there more I could provide? I got a little lost in the back and forth. It sounds like you believe there is an underlying issue in the Mapbox code that you are looking into, is that right?

Chaoba commented 4 years ago

@lognaturel Yes, your information is definitely helpful for us. There should be an ANR that is blocked by the location update receiver because a receiver has a shorter time to trigger ANR. So, the original ANR may be caused by anywhere in your app.

Chaoba commented 4 years ago

@vidhi1011 You need to follow https://docs.mapbox.com/android/maps/overview/#5-lifecycle-methods and call mapview.onDestroy() inside the fragment's onDestroyView() method rather than onDestroy().

lognaturel commented 4 years ago

@Chaoba we do create a MapView that we don't hold a reference to and thus never destroy. Could this possibly be related to the crashes and ANRs? I don't see any evidence of a leak and can't reproduce the crash but it seems it could be related.

// This "one weird trick" lets us initialize MapBox at app start when the internet is
// most likely to be available. This is needed for offline tiles to work.
MapView mapView = new MapView(this);
FrameLayout mapboxContainer = findViewById(R.id.mapbox_container);
mapboxContainer.addView(mapView);
mapView.getMapAsync(mapBoxMap -> mapBoxMap.setStyle(Style.MAPBOX_STREETS, style -> {
    metaSharedPreferences.edit().putBoolean(KEY_MAPBOX_INITIALIZED, true).apply();
}));
Chaoba commented 4 years ago

@lognaturel Yes, it is. You must handle all lifecycle methods correctly.

lognaturel commented 4 years ago

Thanks very much for your help, @Chaoba. I can confirm that handling all lifecycle methods for our initialization has resolved the crashes and ANRs. Perhaps you could consider a documentation change that explicitly mentions that failing to handle lifecycle methods could lead to crashes and ANRs? In retrospect it makes sense that leaks into native code might not be detected by Android tooling but we didn't consider that so our usage seemed safe.

Chaoba commented 4 years ago

@lognaturel Thanks for your feedback. A ticket has been created to track it.