Methods Summary |
---|
public boolean | onStartJob(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 boolean | onStopJob(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 void | scheduleIdlePass(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.Calendar | tomorrowMidnight()
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;
|