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

Commit f992cb31 authored by Keun young Park's avatar Keun young Park
Browse files

add cancellation to background dexopt

- Completely refactored BackgroundDexOptimizationService to make it work
  under PackageManagerService : BackgroundDexOptJobService is added for
  JobService.
- Merged all post boot update code with idle opt code.
- added dump through adb shell dumpsys package dexopt
- cancel background dexopt when idle job is stopped.

Bug: 179094324
Bug: 156537504

TODO: add unit test as separate CL

Test: run idle job, stop it repeatedly and check cancellation
  $ adb shell cmd jobscheduler run android [800|801]
  $ adb shell cmd jobscheduler timeout android
  $ adb shell cmd jobscheduler run android [800|801]
  $ adb shell pm bg-dexopt-job
ex) $ adb shell cmd jobscheduler run android 801; sleep 1; adb shell cmd jobscheduler timeout android
ex) adb shell pm bg-dexopt-job, in a separate termainal: adb shell pm cancel-bg-dexopt-job
  $ adb shell dumpsys package dexopt

Change-Id: Ifa706fe44b0be76d393608646ea9e98169ea8916
parent bd4ea64e
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -598,12 +598,6 @@ interface IPackageManager {

    void forceDexOpt(String packageName);

    /**
     * Execute the background dexopt job immediately on packages in packageNames.
     * If null, then execute on all packages.
     */
    boolean runBackgroundDexoptJob(in List<String> packageNames);

    /**
     * Reconcile the information we have about the secondary dex files belonging to
     * {@code packagName} and the actual dex files. For all dex files that were
+1 −1
Original line number Diff line number Diff line
@@ -6291,7 +6291,7 @@
                 android:permission="android.permission.BIND_JOB_SERVICE" >
        </service>

        <service android:name="com.android.server.pm.BackgroundDexOptService"
        <service android:name="com.android.server.pm.BackgroundDexOptJobService"
                 android:exported="true"
                 android:permission="android.permission.BIND_JOB_SERVICE">
        </service>
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.pm;

import android.app.job.JobParameters;
import android.app.job.JobService;

/**
 * JobService to run background dex optimization. This is a thin wrapper and most logic exits in
 * {@link BackgroundDexOptService}.
 */
public final class BackgroundDexOptJobService extends JobService {

    @Override
    public boolean onStartJob(JobParameters params) {
        return BackgroundDexOptService.getService().onStartJob(this, params);
    }

    @Override
    public boolean onStopJob(JobParameters params) {
        return BackgroundDexOptService.getService().onStopJob(this, params);
    }
}
+617 −357

File changed.

Preview size limit exceeded, changes collapsed.

+6 −0
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ public class ComputerEngine implements Computer {
    private final PackageDexOptimizer mPackageDexOptimizer;
    private final DexManager mDexManager;
    private final CompilerStats mCompilerStats;
    private final BackgroundDexOptService mBackgroundDexOptService;

    // PackageManagerService attributes that are primitives are referenced through the
    // pms object directly.  Primitives are the only attributes so referenced.
@@ -228,6 +229,7 @@ public class ComputerEngine implements Computer {
        mPackageDexOptimizer = args.service.mPackageDexOptimizer;
        mDexManager = args.service.getDexManager();
        mCompilerStats = args.service.mCompilerStats;
        mBackgroundDexOptService = args.service.mBackgroundDexOptService;

        // Used to reference PMS attributes that are primitives and which are not
        // updated under control of the PMS lock.
@@ -2929,6 +2931,10 @@ public class ComputerEngine implements Computer {
                            mDexManager.getPackageUseInfoOrDefault(pkgName));
                    ipw.decreaseIndent();
                }
                ipw.println("BgDexopt state:");
                ipw.increaseIndent();
                mBackgroundDexOptService.dump(ipw);
                ipw.decreaseIndent();
                break;
            }

Loading