解读JobScheduler的jobs.xml

一、jobs.xml

注册的job记录文件

  • 源码路径:/frameworks/base/services/core/java/com/android/server/job/JobStore.java

  • 系统中的job记录在文件jobs.xml,完整路径是/data/system/job/jobs.xml

      private JobStore(Context context, File dataDir) {
          mContext = context;
          mDirtyOperations = 0;
    
          File systemDir = new File(dataDir, "system");
          File jobDir = new File(systemDir, "job");
          jobDir.mkdirs();
          mJobsFile = new AtomicFile(new File(jobDir, "jobs.xml"));
    
          mJobSet = new ArraySet<JobStatus>();
    
          readJobMapFromDisk(mJobSet);
      }
    

小米手机的jobs.xml

root@Xiaomi:/data/system/job # cat jobs.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<job-info version="0">
    <job jobid="137303610" package="com.google.android.apps.maps" class="com.google.android.apps.gmm.offline.OfflineAutoUpdateJobService" uid="10099">
        <constraints connectivity="true" idle="true" charging="true" />
        <periodic period="86400000" delay="1485554596322" />
        <extras />
    </job>
    <job jobid="137303609" package="com.google.android.apps.maps" class="com.google.android.apps.gmm.offline.OfflineAutoUpdateJobService" uid="10099">
        <constraints connectivity="true" idle="true" charging="true" />
        <one-off delay="1485444550825" />
        <extras />
    </job>
    <job jobid="1" package="com.example.wfcvs" class="com.example.wfcvs.wenfengService" uid="10146">
        <constraints charging="true" />
        <one-off delay="1485348887275" />
        <extras />
    </job>
    <job jobid="20537" package="android" class="com.android.server.backup.KeyValueBackupJob" uid="1000">
        <constraints connectivity="true" charging="true" />
        <one-off deadline="1485591350955" delay="1485519812187" />
        <extras />
    </job>
    <job jobid="808" package="android" class="com.android.server.MountServiceIdler" uid="1000">
        <constraints idle="true" charging="true" />
        <one-off delay="1485417599095" />
        <extras />
    </job>
</job-info>

二、job参数解释

参数 解释
jobid 每个job的id,android.app.job.JobInfo.Builder.Builder(int jobId, ComponentName jobService) 指定
package 包名
class job的类名,这个类继承于JobService
uid 应用uid
constraints job被调度的条件
one-off 跟时间相关,记录job的deadline,和延时执行的时间,注意这个是时间点,由函数systemclock.elapsedrealtime()生成,即系统启动的时间,到这个时间点job会被触发

例如: <constraints connectivity="true" charging="true" /> 代表网络连接并且在充电状态下,job会被调度 <one-off delay="1485348887275" /> 代表job在满足条件的情况下,必须要等到1485348887275这个时间点才会被执行

jobs.xml文件需要手机root情况下才能查看,没有root要怎么查看呢?当然有方法,执行adb shell dumpsys jobscheduler

三、adb shell dumpsys jobscheduler

void dump(IndentingPrintWriter pw) {
    pw.println("Settings:");
    pw.increaseIndent();
    pw.print(KEY_MIN_READY_NON_ACTIVE_JOBS_COUNT,
            MIN_READY_NON_ACTIVE_JOBS_COUNT).println();
    pw.print(KEY_MAX_NON_ACTIVE_JOB_BATCH_DELAY_MS,
            MAX_NON_ACTIVE_JOB_BATCH_DELAY_MS).println();
    pw.print(KEY_HEAVY_USE_FACTOR, HEAVY_USE_FACTOR).println();
    pw.print(KEY_MODERATE_USE_FACTOR, MODERATE_USE_FACTOR).println();

    pw.print(KEY_MIN_LINEAR_BACKOFF_TIME_MS, MIN_LINEAR_BACKOFF_TIME_MS).println();
    pw.print(KEY_MIN_EXP_BACKOFF_TIME_MS, MIN_EXP_BACKOFF_TIME_MS).println();
    pw.print(KEY_CONN_CONGESTION_DELAY_FRAC, CONN_CONGESTION_DELAY_FRAC).println();
    pw.print(KEY_CONN_PREFETCH_RELAX_FRAC, CONN_PREFETCH_RELAX_FRAC).println();

    pw.print(KEY_ENABLE_API_QUOTAS, ENABLE_API_QUOTAS).println();
    pw.print(KEY_API_QUOTA_SCHEDULE_COUNT, API_QUOTA_SCHEDULE_COUNT).println();
    pw.print(KEY_API_QUOTA_SCHEDULE_WINDOW_MS, API_QUOTA_SCHEDULE_WINDOW_MS).println();
    pw.print(KEY_API_QUOTA_SCHEDULE_THROW_EXCEPTION,
            API_QUOTA_SCHEDULE_THROW_EXCEPTION).println();
    pw.print(KEY_API_QUOTA_SCHEDULE_RETURN_FAILURE_RESULT,
            API_QUOTA_SCHEDULE_RETURN_FAILURE_RESULT).println();

    pw.print(KEY_RUNTIME_MIN_GUARANTEE_MS, RUNTIME_MIN_GUARANTEE_MS).println();
    pw.print(KEY_RUNTIME_MIN_EJ_GUARANTEE_MS, RUNTIME_MIN_EJ_GUARANTEE_MS).println();
    pw.print(KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS, RUNTIME_FREE_QUOTA_MAX_LIMIT_MS)
            .println();

    pw.decreaseIndent();
}
相关推荐
天天进步20157 小时前
X2JS: XML与JSON的完美转换工具
xml·json
残花月伴21 小时前
配置文件格式(xml、properties、yml/yaml)
xml·java
zhangxiang_ouc21 小时前
Caché/IRIS file2Xml 一个将文件转换成Studio导出的xml格式的工具
xml
小_太_阳2 天前
hadoop_mapred-site.xml
xml·hadoop·mapreduce
小_太_阳2 天前
hadoop_yarn-site.xml
xml·大数据·hadoop·yarn
咩咩觉主2 天前
Unity数据持久化 之 Xml入门精要 (从语法入门到序列与反序列化)
xml·unity·c#
( •̀∀•́ )9203 天前
使用 Logback 的最佳实践:`logback.xml` 与 `logback-spring.xml` 的区别与用法
xml·spring·logback
孑么4 天前
GDPU Andriod移动应用 Fragment碎片与简易版的新闻应用
android·xml·java·kotlin·gradle·android-studio
人间造梦工厂4 天前
清单文件 AndroidManifest.xml
xml