summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jackal Guo <jackalguo@google.com> 2022-08-10 15:34:19 +0800
committer Jackal Guo <jackalguo@google.com> 2022-08-16 11:14:12 +0800
commit51fdab007e78f8067753c3017065738965218cfd (patch)
treeaafd6a4a2064a4daa20fca334b6a5c685b5370be
parente609a5f25a102bb71065fd1cff0e447d894cbb62 (diff)
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
-rw-r--r--services/core/java/android/content/pm/PackageManagerInternal.java5
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerService.java15
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerShellCommand.java30
-rw-r--r--startop/view_compiler/dex_builder_test/Android.bp1
-rw-r--r--startop/view_compiler/dex_builder_test/src/android/startop/test/ApkLayoutCompilerTest.java57
5 files changed, 10 insertions, 98 deletions
diff --git a/services/core/java/android/content/pm/PackageManagerInternal.java b/services/core/java/android/content/pm/PackageManagerInternal.java
index dac23a775d56..3d8dc148b7e2 100644
--- a/services/core/java/android/content/pm/PackageManagerInternal.java
+++ b/services/core/java/android/content/pm/PackageManagerInternal.java
@@ -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.
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 72f3850891ad..e9637ec30302 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -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) {
diff --git a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
index dba7dcd21721..da89b9e7a599 100644
--- a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
+++ b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
@@ -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);
}
diff --git a/startop/view_compiler/dex_builder_test/Android.bp b/startop/view_compiler/dex_builder_test/Android.bp
index 2048964f4af2..bcba2febdcdc 100644
--- a/startop/view_compiler/dex_builder_test/Android.bp
+++ b/startop/view_compiler/dex_builder_test/Android.bp
@@ -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",
diff --git a/startop/view_compiler/dex_builder_test/src/android/startop/test/ApkLayoutCompilerTest.java b/startop/view_compiler/dex_builder_test/src/android/startop/test/ApkLayoutCompilerTest.java
deleted file mode 100644
index 230e8df1e687..000000000000
--- a/startop/view_compiler/dex_builder_test/src/android/startop/test/ApkLayoutCompilerTest.java
+++ /dev/null
@@ -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);
- }
-}