解读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();
}
相关推荐
法迪2 天前
DataWind 查看单个维度的2个版本间数据差异值的方法
功耗
乌夷3 天前
在pom.xml中通过repositories在Maven构建过程中访问setting.xml之外的仓库
xml·java·maven
振宇i3 天前
Mybatis xml动态SQL 判断失效问题
xml·sql·mybatis
程序员老王wd5 天前
java xml 文本解析
xml·java
法迪5 天前
【功耗现象】com.gorgeous.lite后台Camera 使用2小时平均电流200mA耗电量400mAh现象
功耗
小百菜6 天前
dom4j解析含有命名空间的XML
xml·dom4j
黎明晓月7 天前
MyBatis XML一个方法执行插入或更新操做(PostgreSQL)
xml·postgresql·mybatis
GoKu~7 天前
项目配置文件选择(Json,xml,Yaml, INI)
xml·json
枫叶落雨2227 天前
mybatis-plus: mapper-locations: “classpath*:/mapper/**/*.xml“配置!!!解释
xml·java·mybatis
double丶flower7 天前
mybatis在mapper.xml中怎么处理大于、小于、不等于号
xml·java·mybatis