FileDocCategorySizeDatePackage
MountServiceIdler.javaAPI DocAndroid 5.1 API4229Thu Mar 12 22:22:42 GMT 2015com.android.server

MountServiceIdler

public class MountServiceIdler extends android.app.job.JobService

Fields Summary
private static final String
TAG
private static android.content.ComponentName
sIdleService
private static int
MOUNT_JOB_ID
private boolean
mStarted
private android.app.job.JobParameters
mJobParams
private Runnable
mFinishCallback
Constructors Summary
Methods Summary
public booleanonStartJob(android.app.job.JobParameters params)


    
        
        // First have the activity manager do its idle maintenance.  (Yes this job
        // is really more than just mount, some day it should be renamed to be system
        // idleer).
        try {
            ActivityManagerNative.getDefault().performIdleMaintenance();
        } catch (RemoteException e) {
        }
        // The mount service will run an fstrim operation asynchronously
        // on a designated separate thread, so we provide it with a callback
        // that lets us cleanly end our idle timeslice.  It's safe to call
        // finishIdle() from any thread.
        mJobParams = params;
        MountService ms = MountService.sSelf;
        if (ms != null) {
            synchronized (mFinishCallback) {
                mStarted = true;
            }
            ms.runIdleMaintenance(mFinishCallback);
        }
        return ms != null;
    
public booleanonStopJob(android.app.job.JobParameters params)

        // Once we kick off the fstrim we aren't actually interruptible; just note
        // that we don't need to call jobFinished(), and let everything happen in
        // the callback from the mount service.
        synchronized (mFinishCallback) {
            mStarted = false;
        }
        return false;
    
public static voidscheduleIdlePass(android.content.Context context)
Schedule the idle job that will ping the mount service

        JobScheduler tm = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

        Calendar calendar = tomorrowMidnight();
        final long timeToMidnight = calendar.getTimeInMillis() - System.currentTimeMillis();

        JobInfo.Builder builder = new JobInfo.Builder(MOUNT_JOB_ID, sIdleService);
        builder.setRequiresDeviceIdle(true);
        builder.setRequiresCharging(true);
        builder.setMinimumLatency(timeToMidnight);
        tm.schedule(builder.build());
    
private static java.util.CalendartomorrowMidnight()

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.HOUR_OF_DAY, 3);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        return calendar;