Why I see: Unsatisfied constraints: CONNECTIVITY in JobScheduler debug info

旧时模样 提交于 2020-12-10 13:20:24

问题


I set for the job:

 val job = JobInfo.Builder(2, ComponentName(context, JobRunner::class.java)).apply {
            setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
            setRequiresBatteryNotLow(true)
            for (triggerUri in triggers) {
                addTriggerContentUri(JobInfo.TriggerContentUri(triggerUri, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS))
            }
            setTriggerContentUpdateDelay(TimeUnit.MINUTES.toMillis(1))
            setTriggerContentMaxDelay(TimeUnit.MINUTES.toMillis(10))
        }.build()
        
        jobScheduler.schedule(job)

If I execute: adb shell dumpsys jobscheduler

I have the following job info:

JOB #u0a302/2: 89f4090 com.abc.debug/com.abc.mobile.service.job.JobRunner
    u0a302 tag=*job*/com.abc.debug/com.abc.mobile.service.job.JobRunner
    Source: uid=u0a302 user=0 pkg=com.abc.debug
    JobInfo:
      Service: com.abc.debug/com.abc.mobile.service.job.JobRunner
      Internal flags: 1 HAS_FOREGROUND_EXEMPTION
      Requires: charging=false batteryNotLow=true deviceIdle=false
      Trigger content URIs:
        1 content://media/internal/images/media
        1 content://media/external/images/media
        1 content://media/internal/video/media
        1 content://media/external/video/media
      Trigger update delay: +1m0s0ms
      Trigger max delay: +10m0s0ms
      Network type: NetworkRequest [ NONE id=0, [ Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&VALIDATED Unwanted:  Uid: 10302] ]
      Backoff: policy=1 initial=+30s0ms
    Required constraints: BATTERY_NOT_LOW CONNECTIVITY CONTENT_TRIGGER [0x14000002]
    Satisfied constraints: CHARGING BATTERY_NOT_LOW CONTENT_TRIGGER DEVICE_NOT_DOZING BACKGROUND_NOT_RESTRICTED [0x6400003]
    Unsatisfied constraints: CONNECTIVITY [0x10000000]
    Tracking: BATTERY CONNECTIVITY CONTENT
    Standby bucket: RARE
    Base heartbeat: 285
    Enqueue time: -20h50m38s25ms
    Run time: earliest=none, latest=none
    Last run heartbeat: 285
    Ready: false (job=false user=true !pending=true !active=true !backingup=true comp=true)

As seen from the log above I need:

Network type: NetworkRequest [ NONE id=0, [ Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&VALIDATED Unwanted: Uid: 10302] ]

I have made another small application on the same device to check the active network capabilities:

 val connMgr = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
 val networkCap = connMgr.getNetworkCapabilities(connMgr.activeNetwork)
 Log.d("NETWORK_CHECK", "NetworkCapabilities: [$networkCap]")

As seen by the result:

[ Transports: WIFI Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&VALIDATED&NOT_ROAMING&FOREGROUND&NOT_CONGESTED&NOT_SUSPENDED LinkUpBandwidth>=1048576Kbps LinkDnBandwidth>=1048576Kbps SignalStrength: -43]

I have all the capabilities I need. Why I still see the constrain as unsatisfied?

Unsatisfied constraints: CONNECTIVITY [0x10000000]

Is there something else that might be related which is not exactly capability?

I have checked here, but nothing useful have I found: ConnectivityController

I have found from another log the following in the Connectivity section:

ConnectivityController:
  Requested standby exceptions: 10336 (1 jobs) 10342 (1 jobs) 10391 (1 jobs)

10391 is my id. What does Requested standby exceptions means?

So as per the below suggestion, I am most likely with restricted Network usage, because I am in the RARE standby bucket. Check here :

https://developer.android.com/topic/performance/power/power-details

The problem for me is that in the job info above: ~21h hours have passed from the last trigger, and often on some phones I see even 2 days. But the docs are saying:

Deferred up to 24 hours

So I would like to find more info on what exactly is happening so I could improve. Not much we have found.

But the disabling of battery optimization makes a huge difference. Also when the device is charging we have no problem.

https://developer.android.com/training/monitoring-device-state/doze-standby#support_for_other_use_cases


回答1:


It is important to note that your application is in the RARE standy bucket:

 Standby bucket: RARE

This means that, even if the device has connectivity, your jobs are going to have access to the network only once a day.

This is documented in the Power Manager restriction guide with the note:

If network access is restricted, the app is granted a window of 10 minutes to use the network at the specified interval.

This is probably an application that spends a lot of time in the background with little or no interaction from the user. A possible solution is to increase foreground time adding some functionality that drives the user to open the app.



来源:https://stackoverflow.com/questions/64878968/why-i-see-unsatisfied-constraints-connectivity-in-jobscheduler-debug-info

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!