summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2019-03-06 09:39:27 -0800
committer Steven Moreland <smoreland@google.com> 2019-03-12 21:44:22 +0000
commit2410821b670bdc76c2089124b152f14a0eeed218 (patch)
treeb00ed972382db176d5c8fee50684fe8f6fabc287
parentb28b7960b2bd2d33cbccd88d2d4d3c05e09f2770 (diff)
pm: AndroidHidlUpdater: system only
Backwards compatibility takes a slight performance hit. Only apply this rule to outdated system apps as they are the only ones that use these libraries. Bug: 86259915 Test: boot Pixel 2 Test: boot Pixel 3 and systrace app startup Test: atest android.content.pm.AndroidHidlUpdaterTest Change-Id: I2d2e2ca79266a92ba0e4efcf25e31d15daee87a1
-rw-r--r--core/java/android/content/pm/AndroidHidlUpdater.java8
-rw-r--r--core/tests/coretests/src/android/content/pm/AndroidHidlUpdaterTest.java46
-rw-r--r--core/tests/coretests/src/android/content/pm/PackageBuilder.java8
3 files changed, 53 insertions, 9 deletions
diff --git a/core/java/android/content/pm/AndroidHidlUpdater.java b/core/java/android/content/pm/AndroidHidlUpdater.java
index b7ae8f4a1291..d0657e5eb8ec 100644
--- a/core/java/android/content/pm/AndroidHidlUpdater.java
+++ b/core/java/android/content/pm/AndroidHidlUpdater.java
@@ -34,8 +34,14 @@ public class AndroidHidlUpdater extends PackageSharedLibraryUpdater {
@Override
public void updatePackage(Package pkg) {
+ ApplicationInfo info = pkg.applicationInfo;
+
// This was the default <= P and is maintained for backwards compatibility.
- if (pkg.applicationInfo.targetSdkVersion <= Build.VERSION_CODES.P) {
+ boolean isLegacy = info.targetSdkVersion <= Build.VERSION_CODES.P;
+ // Only system apps use these libraries
+ boolean isSystem = info.isSystemApp() || info.isUpdatedSystemApp();
+
+ if (isLegacy && isSystem) {
prefixRequiredLibrary(pkg, ANDROID_HIDL_BASE);
prefixRequiredLibrary(pkg, ANDROID_HIDL_MANAGER);
} else {
diff --git a/core/tests/coretests/src/android/content/pm/AndroidHidlUpdaterTest.java b/core/tests/coretests/src/android/content/pm/AndroidHidlUpdaterTest.java
index 2acb08da4ef0..f557ef9835da 100644
--- a/core/tests/coretests/src/android/content/pm/AndroidHidlUpdaterTest.java
+++ b/core/tests/coretests/src/android/content/pm/AndroidHidlUpdaterTest.java
@@ -40,8 +40,17 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
PackageBuilder before = builder()
.targetSdkVersion(Build.VERSION_CODES.P);
+ // no change, not system
+ checkBackwardsCompatibility(before, before);
+ }
+
+ @Test
+ public void targeted_at_P_system() {
+ PackageBuilder before = builder().asSystemApp()
+ .targetSdkVersion(Build.VERSION_CODES.P);
+
// Should add both HIDL libraries
- PackageBuilder after = builder()
+ PackageBuilder after = builder().asSystemApp()
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE);
@@ -54,9 +63,19 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(OTHER_LIBRARY);
+ // no change, not system
+ checkBackwardsCompatibility(before, before);
+ }
+
+ @Test
+ public void targeted_at_P_not_empty_usesLibraries_system() {
+ PackageBuilder before = builder().asSystemApp()
+ .targetSdkVersion(Build.VERSION_CODES.P)
+ .requiredLibraries(OTHER_LIBRARY);
+
// The hidl jars should be added at the start of the list because it
// is not on the bootclasspath and the package targets pre-P.
- PackageBuilder after = builder()
+ PackageBuilder after = builder().asSystemApp()
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE, OTHER_LIBRARY);
@@ -69,8 +88,21 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
.targetSdkVersion(Build.VERSION_CODES.P)
.requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE);
- // No change is required because although the HIDL libraries has been removed from
- // the bootclasspath the package explicitly requests it.
+ PackageBuilder after = builder()
+ .targetSdkVersion(Build.VERSION_CODES.P);
+
+ // Libraries are removed because they are not available for non-system apps
+ checkBackwardsCompatibility(before, after);
+ }
+
+ @Test
+ public void targeted_at_P_in_usesLibraries_system() {
+ PackageBuilder before = builder().asSystemApp()
+ .targetSdkVersion(Build.VERSION_CODES.P)
+ .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE);
+
+ // No change is required because the package explicitly requests the HIDL libraries
+ // and is targeted at the current version so does not need backwards compatibility.
checkBackwardsCompatibility(before, before);
}
@@ -81,8 +113,7 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
// Dependency is removed, it is not available.
PackageBuilder after = builder();
- // No change is required because the package explicitly requests the HIDL libraries
- // and is targeted at the current version so does not need backwards compatibility.
+ // Libraries are removed because they are not available for apps targetting Q+
checkBackwardsCompatibility(before, after);
}
@@ -93,8 +124,7 @@ public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest {
// Dependency is removed, it is not available.
PackageBuilder after = builder();
- // No change is required because the package explicitly requests the HIDL libraries
- // and is targeted at the current version so does not need backwards compatibility.
+ // Libraries are removed because they are not available for apps targetting Q+
checkBackwardsCompatibility(before, after);
}
diff --git a/core/tests/coretests/src/android/content/pm/PackageBuilder.java b/core/tests/coretests/src/android/content/pm/PackageBuilder.java
index 4ceed834aab7..f5be3f79191a 100644
--- a/core/tests/coretests/src/android/content/pm/PackageBuilder.java
+++ b/core/tests/coretests/src/android/content/pm/PackageBuilder.java
@@ -30,6 +30,8 @@ class PackageBuilder {
private int mTargetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
+ private int mFlags = 0;
+
private ArrayList<String> mRequiredLibraries;
private ArrayList<String> mOptionalLibraries;
@@ -41,6 +43,7 @@ class PackageBuilder {
public PackageParser.Package build() {
PackageParser.Package pkg = new PackageParser.Package("org.package.name");
pkg.applicationInfo.targetSdkVersion = mTargetSdkVersion;
+ pkg.applicationInfo.flags = mFlags;
pkg.usesLibraries = mRequiredLibraries;
pkg.usesOptionalLibraries = mOptionalLibraries;
return pkg;
@@ -51,6 +54,11 @@ class PackageBuilder {
return this;
}
+ PackageBuilder asSystemApp() {
+ this.mFlags |= ApplicationInfo.FLAG_SYSTEM;
+ return this;
+ }
+
PackageBuilder requiredLibraries(String... names) {
this.mRequiredLibraries = arrayListOrNull(names);
return this;