Loading core/java/android/content/pm/AndroidHidlUpdater.java 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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.content.pm; import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_BASE; import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_MANAGER; import android.content.pm.PackageParser.Package; import android.os.Build; import com.android.internal.annotations.VisibleForTesting; /** * Updates a package to ensure that if it targets <= P that the android.hidl.base-V1.0-java * and android.hidl.manager-V1.0-java libraries are included by default. * * @hide */ @VisibleForTesting public class AndroidHidlUpdater extends PackageSharedLibraryUpdater { @Override public void updatePackage(Package pkg) { // This was the default <= P and is maintained for backwards compatibility. if (pkg.applicationInfo.targetSdkVersion <= Build.VERSION_CODES.P) { prefixRequiredLibrary(pkg, ANDROID_HIDL_BASE); prefixRequiredLibrary(pkg, ANDROID_HIDL_MANAGER); } } } core/java/android/content/pm/PackageBackwardCompatibility.java +2 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,8 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { "android.content.pm.OrgApacheHttpLegacyUpdater", RemoveUnnecessaryOrgApacheHttpLegacyLibrary::new); packageUpdaters.add(new AndroidHidlUpdater()); // Add this before adding AndroidTestBaseUpdater so that android.test.base comes before // android.test.mock. packageUpdaters.add(new AndroidTestRunnerSplitUpdater()); Loading core/java/android/content/pm/SharedLibraryNames.java +4 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ package android.content.pm; */ public class SharedLibraryNames { static final String ANDROID_HIDL_BASE = "android.hidl.base-V1.0-java"; static final String ANDROID_HIDL_MANAGER = "android.hidl.manager-V1.0-java"; static final String ANDROID_TEST_BASE = "android.test.base"; static final String ANDROID_TEST_MOCK = "android.test.mock"; Loading core/tests/coretests/src/android/content/pm/AndroidHidlUpdaterTest.java 0 → 100644 +98 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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.content.pm; import static android.content.pm.PackageBuilder.builder; import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_BASE; import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_MANAGER; import android.os.Build; import android.support.test.filters.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Test for {@link AndroidHidlUpdater} */ @SmallTest @RunWith(JUnit4.class) public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest { private static final String OTHER_LIBRARY = "other.library"; @Test public void targeted_at_O() { PackageBuilder before = builder() .targetSdkVersion(Build.VERSION_CODES.O); // Should add both HIDL libraries PackageBuilder after = builder() .targetSdkVersion(Build.VERSION_CODES.O) .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE); checkBackwardsCompatibility(before, after); } @Test public void targeted_at_O_not_empty_usesLibraries() { PackageBuilder before = builder() .targetSdkVersion(Build.VERSION_CODES.O) .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() .targetSdkVersion(Build.VERSION_CODES.O) .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE, OTHER_LIBRARY); checkBackwardsCompatibility(before, after); } @Test public void targeted_at_O_in_usesLibraries() { PackageBuilder before = builder() .targetSdkVersion(Build.VERSION_CODES.O) .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. checkBackwardsCompatibility(before, before); } @Test public void in_usesLibraries() { PackageBuilder before = builder().requiredLibraries(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); } @Test public void in_usesOptionalLibraries() { PackageBuilder before = builder().optionalLibraries(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); } private void checkBackwardsCompatibility(PackageBuilder before, PackageBuilder after) { checkBackwardsCompatibility(before, after, AndroidHidlUpdater::new); } } data/etc/platform.xml +6 −0 Original line number Diff line number Diff line Loading @@ -188,6 +188,12 @@ <library name="android.test.runner" file="/system/framework/android.test.runner.impl.jar" /> <!-- In BOOT_JARS historically, and now added to legacy applications. --> <library name="android.hidl.base-V1.0-java" file="/system/framework/android.hidl.base-V1.0-java.jar" /> <library name="android.hidl.manager-V1.0-java" file="/system/framework/android.hidl.manager-V1.0-java.jar" /> <!-- These are the standard packages that are white-listed to always have internet access while in power save mode, even if they aren't in the foreground. --> <allow-in-power-save package="com.android.providers.downloads" /> Loading Loading
core/java/android/content/pm/AndroidHidlUpdater.java 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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.content.pm; import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_BASE; import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_MANAGER; import android.content.pm.PackageParser.Package; import android.os.Build; import com.android.internal.annotations.VisibleForTesting; /** * Updates a package to ensure that if it targets <= P that the android.hidl.base-V1.0-java * and android.hidl.manager-V1.0-java libraries are included by default. * * @hide */ @VisibleForTesting public class AndroidHidlUpdater extends PackageSharedLibraryUpdater { @Override public void updatePackage(Package pkg) { // This was the default <= P and is maintained for backwards compatibility. if (pkg.applicationInfo.targetSdkVersion <= Build.VERSION_CODES.P) { prefixRequiredLibrary(pkg, ANDROID_HIDL_BASE); prefixRequiredLibrary(pkg, ANDROID_HIDL_MANAGER); } } }
core/java/android/content/pm/PackageBackwardCompatibility.java +2 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,8 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater { "android.content.pm.OrgApacheHttpLegacyUpdater", RemoveUnnecessaryOrgApacheHttpLegacyLibrary::new); packageUpdaters.add(new AndroidHidlUpdater()); // Add this before adding AndroidTestBaseUpdater so that android.test.base comes before // android.test.mock. packageUpdaters.add(new AndroidTestRunnerSplitUpdater()); Loading
core/java/android/content/pm/SharedLibraryNames.java +4 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ package android.content.pm; */ public class SharedLibraryNames { static final String ANDROID_HIDL_BASE = "android.hidl.base-V1.0-java"; static final String ANDROID_HIDL_MANAGER = "android.hidl.manager-V1.0-java"; static final String ANDROID_TEST_BASE = "android.test.base"; static final String ANDROID_TEST_MOCK = "android.test.mock"; Loading
core/tests/coretests/src/android/content/pm/AndroidHidlUpdaterTest.java 0 → 100644 +98 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 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.content.pm; import static android.content.pm.PackageBuilder.builder; import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_BASE; import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_MANAGER; import android.os.Build; import android.support.test.filters.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Test for {@link AndroidHidlUpdater} */ @SmallTest @RunWith(JUnit4.class) public class AndroidHidlUpdaterTest extends PackageSharedLibraryUpdaterTest { private static final String OTHER_LIBRARY = "other.library"; @Test public void targeted_at_O() { PackageBuilder before = builder() .targetSdkVersion(Build.VERSION_CODES.O); // Should add both HIDL libraries PackageBuilder after = builder() .targetSdkVersion(Build.VERSION_CODES.O) .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE); checkBackwardsCompatibility(before, after); } @Test public void targeted_at_O_not_empty_usesLibraries() { PackageBuilder before = builder() .targetSdkVersion(Build.VERSION_CODES.O) .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() .targetSdkVersion(Build.VERSION_CODES.O) .requiredLibraries(ANDROID_HIDL_MANAGER, ANDROID_HIDL_BASE, OTHER_LIBRARY); checkBackwardsCompatibility(before, after); } @Test public void targeted_at_O_in_usesLibraries() { PackageBuilder before = builder() .targetSdkVersion(Build.VERSION_CODES.O) .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. checkBackwardsCompatibility(before, before); } @Test public void in_usesLibraries() { PackageBuilder before = builder().requiredLibraries(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); } @Test public void in_usesOptionalLibraries() { PackageBuilder before = builder().optionalLibraries(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); } private void checkBackwardsCompatibility(PackageBuilder before, PackageBuilder after) { checkBackwardsCompatibility(before, after, AndroidHidlUpdater::new); } }
data/etc/platform.xml +6 −0 Original line number Diff line number Diff line Loading @@ -188,6 +188,12 @@ <library name="android.test.runner" file="/system/framework/android.test.runner.impl.jar" /> <!-- In BOOT_JARS historically, and now added to legacy applications. --> <library name="android.hidl.base-V1.0-java" file="/system/framework/android.hidl.base-V1.0-java.jar" /> <library name="android.hidl.manager-V1.0-java" file="/system/framework/android.hidl.manager-V1.0-java.jar" /> <!-- These are the standard packages that are white-listed to always have internet access while in power save mode, even if they aren't in the foreground. --> <allow-in-power-save package="com.android.providers.downloads" /> Loading