Remove unused compile command --compile-layouts

The 'pm compile --compile-layouts' is deprecated, and it leaves the
possibility that malicious apps could do a side channel attack. Re-
move related entry to mitigate this.

Bug: 241233589
Test: atest dex-builder-test
Test: manually using the PoC in the buganizer to ensure the symptom
      no longer exists.
Change-Id: Ibd11425e6ee1468149fabe201983f95bfd69349c
This commit is contained in:
Jackal Guo
2022-08-10 15:34:19 +08:00
parent e609a5f25a
commit 51fdab007e
5 changed files with 10 additions and 98 deletions

View File

@@ -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.

View File

@@ -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) {

View File

@@ -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);
}

View File

@@ -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",

View File

@@ -1,57 +0,0 @@
/*
* 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);
}
}