一、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包名
classjob的类名,这个类继承于JobService
uid应用uid
constraintsjob被调度的条件
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();
}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部