FileDocCategorySizeDatePackage
BackgroundDexOptService.javaAPI DocAndroid 5.1 API3683Thu Mar 12 22:22:42 GMT 2015com.android.server.pm

BackgroundDexOptService

public class BackgroundDexOptService extends android.app.job.JobService
{@hide}

Fields Summary
static final String
TAG
static final int
BACKGROUND_DEXOPT_JOB
private static android.content.ComponentName
sDexoptServiceName
static final android.util.ArraySet
sFailedPackageNames
Set of failed packages remembered across job runs.
final AtomicBoolean
mIdleTime
Constructors Summary
Methods Summary
public booleanonStartJob(android.app.job.JobParameters params)

        Log.i(TAG, "onIdleStart");
        final PackageManagerService pm =
                (PackageManagerService)ServiceManager.getService("package");

        if (pm.isStorageLow()) {
            return false;
        }
        final ArraySet<String> pkgs = pm.getPackagesThatNeedDexOpt();
        if (pkgs == null) {
            return false;
        }

        final JobParameters jobParams = params;
        mIdleTime.set(true);
        new Thread("BackgroundDexOptService_DexOpter") {
            @Override
            public void run() {
                for (String pkg : pkgs) {
                    if (!mIdleTime.get()) {
                        // stopped while still working, so we need to reschedule
                        schedule(BackgroundDexOptService.this);
                        return;
                    }
                    if (sFailedPackageNames.contains(pkg)) {
                        // skip previously failing package
                        continue;
                    }
                    if (!pm.performDexOpt(pkg, null /* instruction set */, true)) {
                        // there was a problem running dexopt,
                        // remember this so we do not keep retrying.
                        sFailedPackageNames.add(pkg);
                    }
                }
                // ran to completion, so we abandon our timeslice and do not reschedule
                jobFinished(jobParams, false);
            }
        }.start();
        return true;
    
public booleanonStopJob(android.app.job.JobParameters params)

        Log.i(TAG, "onIdleStop");
        mIdleTime.set(false);
        return false;
    
public static voidschedule(android.content.Context context)


         
        JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo job = new JobInfo.Builder(BACKGROUND_DEXOPT_JOB, sDexoptServiceName)
                .setRequiresDeviceIdle(true)
                .setRequiresCharging(true)
                .build();
        js.schedule(job);