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;