Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c9655b3 authored by Christopher Tate's avatar Christopher Tate
Browse files

If we're out of space, retry background dexopting later

Give it 4 hours to give the user time to do stuff, then retry;
repeat until we have space to work in.

Bug 20468442

Change-Id: Id4b11abcc38a9e2a50a062f0067a13ce0ae831ad
parent 3aa16d76
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.pm;

import android.app.AlarmManager;
import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
@@ -34,6 +35,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class BackgroundDexOptService extends JobService {
    static final String TAG = "BackgroundDexOptService";

    static final long RETRY_LATENCY = 4 * AlarmManager.INTERVAL_HOUR;

    static final int BACKGROUND_DEXOPT_JOB = 800;
    private static ComponentName sDexoptServiceName = new ComponentName(
            "android",
@@ -46,11 +49,12 @@ public class BackgroundDexOptService extends JobService {

    final AtomicBoolean mIdleTime = new AtomicBoolean(false);

    public static void schedule(Context context) {
    public static void schedule(Context context, long minLatency) {
        JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo job = new JobInfo.Builder(BACKGROUND_DEXOPT_JOB, sDexoptServiceName)
                .setRequiresDeviceIdle(true)
                .setRequiresCharging(true)
                .setMinimumLatency(minLatency)
                .build();
        js.schedule(job);
    }
@@ -62,6 +66,7 @@ public class BackgroundDexOptService extends JobService {
                (PackageManagerService)ServiceManager.getService("package");

        if (pm.isStorageLow()) {
            schedule(BackgroundDexOptService.this, RETRY_LATENCY);
            return false;
        }
        final ArraySet<String> pkgs = pm.getPackagesThatNeedDexOpt();
@@ -77,7 +82,7 @@ public class BackgroundDexOptService extends JobService {
                for (String pkg : pkgs) {
                    if (!mIdleTime.get()) {
                        // stopped while still working, so we need to reschedule
                        schedule(BackgroundDexOptService.this);
                        schedule(BackgroundDexOptService.this, 0);
                        return;
                    }
                    if (sFailedPackageNames.contains(pkg)) {
+1 −1
Original line number Diff line number Diff line
@@ -958,7 +958,7 @@ public final class SystemServer {

                try {
                    Slog.i(TAG, "BackgroundDexOptService");
                    BackgroundDexOptService.schedule(context);
                    BackgroundDexOptService.schedule(context, 0);
                } catch (Throwable e) {
                    reportWtf("starting BackgroundDexOptService", e);
                }