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

Commit 71b3eee7 authored by Jackal Guo's avatar Jackal Guo Committed by Android (Google) Code Review
Browse files

Merge "Remove unused compile command --compile-layouts"

parents 7daf8a17 51fdab00
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -975,11 +975,6 @@ public abstract class PackageManagerInternal {
     */
    public abstract void setEnableRollbackCode(int token, int enableRollbackCode);

    /**
     * Ask the package manager to compile layouts in the given package.
     */
    public abstract boolean compileLayouts(String packageName);

    /*
     * Inform the package manager that the pending package install identified by
     * {@code token} can be completed.
+0 −15
Original line number Diff line number Diff line
@@ -6309,21 +6309,6 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            }
        }

        /**
         * Ask the package manager to compile layouts in the given package.
         */
        @Override
        public boolean compileLayouts(String packageName) {
            AndroidPackage pkg;
            synchronized (mLock) {
                pkg = mPackages.get(packageName);
                if (pkg == null) {
                    return false;
                }
            }
            return mArtManagerService.compileLayouts(pkg);
        }

        @Nullable
        @Override
        public String removeLegacyDefaultBrowserPackageName(int userId) {
+10 −20
Original line number Diff line number Diff line
@@ -1792,7 +1792,6 @@ class PackageManagerShellCommand extends ShellCommand {
        String checkProfilesRaw = null;
        boolean secondaryDex = false;
        String split = null;
        boolean compileLayouts = false;

        String opt;
        while ((opt = getNextOption()) != null) {
@@ -1812,9 +1811,6 @@ class PackageManagerShellCommand extends ShellCommand {
                case "-r":
                    compilationReason = getNextArgRequired();
                    break;
                case "--compile-layouts":
                    compileLayouts = true;
                    break;
                case "--check-prof":
                    checkProfilesRaw = getNextArgRequired();
                    break;
@@ -1848,14 +1844,15 @@ class PackageManagerShellCommand extends ShellCommand {

        final boolean compilerFilterGiven = compilerFilter != null;
        final boolean compilationReasonGiven = compilationReason != null;
        // Make sure exactly one of -m, -r, or --compile-layouts is given.
        if ((!compilerFilterGiven && !compilationReasonGiven && !compileLayouts)
            || (!compilerFilterGiven && compilationReasonGiven && compileLayouts)
            || (compilerFilterGiven && !compilationReasonGiven && compileLayouts)
            || (compilerFilterGiven && compilationReasonGiven && !compileLayouts)
            || (compilerFilterGiven && compilationReasonGiven && compileLayouts)) {
            pw.println("Must specify exactly one of compilation filter (\"-m\"), compilation " +
                    "reason (\"-r\"), or compile layouts (\"--compile-layouts\")");
        // Make sure exactly one of -m, or -r is given.
        if (compilerFilterGiven && compilationReasonGiven) {
            pw.println("Cannot use compilation filter (\"-m\") and compilation reason (\"-r\") "
                    + "at the same time");
            return 1;
        }
        if (!compilerFilterGiven && !compilationReasonGiven) {
            pw.println("Cannot run without any of compilation filter (\"-m\") and compilation "
                    + "reason (\"-r\")");
            return 1;
        }

@@ -1920,19 +1917,12 @@ class PackageManagerShellCommand extends ShellCommand {
                pw.flush();
            }

            boolean result = true;
            if (compileLayouts) {
                PackageManagerInternal internal = LocalServices.getService(
                        PackageManagerInternal.class);
                result = internal.compileLayouts(packageName);
            } else {
                result = secondaryDex
            final boolean result = secondaryDex
                    ? mInterface.performDexOptSecondary(packageName,
                            targetCompilerFilter, forceCompilation)
                    : mInterface.performDexOptMode(packageName,
                            checkProfiles, targetCompilerFilter, forceCompilation,
                            true /* bootComplete */, split);
            }
            if (!result) {
                failedPackages.add(packageName);
            }
+0 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ genrule {
android_test {
    name: "dex-builder-test",
    srcs: [
        "src/android/startop/test/ApkLayoutCompilerTest.java",
        "src/android/startop/test/DexBuilderTest.java",
        "src/android/startop/test/LayoutCompilerTest.java",
        "src/android/startop/test/TestClass.java",
+0 −57
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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 android.startop.test;

import android.content.Context;
import androidx.test.InstrumentationRegistry;
import android.view.View;
import dalvik.system.PathClassLoader;
import java.lang.reflect.Method;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class ApkLayoutCompilerTest {
    static ClassLoader loadDexFile() throws Exception {
        Context context = InstrumentationRegistry.getTargetContext();
        return new PathClassLoader(context.getCodeCacheDir() + "/compiled_view.dex",
                ClassLoader.getSystemClassLoader());
    }

    @BeforeClass
    public static void setup() throws Exception {
        // ensure PackageManager has compiled the layouts.
        Process pm = Runtime.getRuntime().exec("pm compile --compile-layouts android.startop.test");
        pm.waitFor();
    }

    @Test
    public void loadAndInflateLayout1() throws Exception {
        ClassLoader dex_file = loadDexFile();
        Class compiled_view = dex_file.loadClass("android.startop.test.CompiledView");
        Method layout1 = compiled_view.getMethod("layout1", Context.class, int.class);
        Context context = InstrumentationRegistry.getTargetContext();
        layout1.invoke(null, context, R.layout.layout1);
    }

    @Test
    public void loadAndInflateLayout2() throws Exception {
        ClassLoader dex_file = loadDexFile();
        Class compiled_view = dex_file.loadClass("android.startop.test.CompiledView");
        Method layout2 = compiled_view.getMethod("layout2", Context.class, int.class);
        Context context = InstrumentationRegistry.getTargetContext();
        layout2.invoke(null, context, R.layout.layout2);
    }
}