Ignore "android.net.ipsec.ike" <uses-library> tag

"android.net.ipsec.ike" is converted from a shared library to a jar
in boot classpath since S. This CL makes package manager to ignore
<uses-library name="android.net.ipsec.ike"> to avoid loading the
jar again from the app class loader.

Bug: 177266501
Test: build, flash, boot
Test: AndroidNetIpSecIkeUpdaterTest, PackageBackwardCompatibilityTest
Change-Id: I05c8c46f102b01945724077830dc9871ab407c1d
Merged-In: I05c8c46f102b01945724077830dc9871ab407c1d
This commit is contained in:
Yan Yan
2021-02-03 16:12:28 -08:00
parent f8b973c3f6
commit e4fc06b9db
4 changed files with 145 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2021 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 com.android.server.pm.parsing.library;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.pm.parsing.pkg.ParsedPackage;
/**
* Updates a package to remove dependency on android.net.ipsec.ike library.
*
* @hide
*/
@VisibleForTesting
public class AndroidNetIpSecIkeUpdater extends PackageSharedLibraryUpdater {
private static final String LIBRARY_NAME = "android.net.ipsec.ike";
@Override
public void updatePackage(ParsedPackage parsedPackage, boolean isUpdatedSystemApp) {
removeLibrary(parsedPackage, LIBRARY_NAME);
}
}

View File

@@ -45,6 +45,9 @@ public class PackageBackwardCompatibility extends PackageSharedLibraryUpdater {
static {
final List<PackageSharedLibraryUpdater> packageUpdaters = new ArrayList<>();
// Remove android.net.ipsec.ike library, it is added to boot classpath since Android S.
packageUpdaters.add(new AndroidNetIpSecIkeUpdater());
// Remove com.google.android.maps library.
packageUpdaters.add(new ComGoogleAndroidMapsUpdater());

View File

@@ -0,0 +1,90 @@
/*
* Copyright (C) 2021 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 com.android.server.pm.parsing.library;
import android.os.Build;
import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.PackageImpl;
import com.android.server.pm.parsing.pkg.ParsedPackage;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Test for {@link AndroidNetIpSecIkeUpdater}
*/
@Presubmit
@SmallTest
@RunWith(JUnit4.class)
public class AndroidNetIpSecIkeUpdaterTest extends PackageSharedLibraryUpdaterTest {
@Test
public void otherUsesLibraries() {
ParsedPackage before = ((ParsedPackage) PackageImpl.forTesting(PACKAGE_NAME)
.setTargetSdkVersion(Build.VERSION_CODES.O)
.addUsesLibrary("other")
.addUsesOptionalLibrary("optional")
.addUsesLibrary("android.net.ipsec.ike")
.hideAsParsed());
AndroidPackage after = ((ParsedPackage) PackageImpl.forTesting(PACKAGE_NAME)
.setTargetSdkVersion(Build.VERSION_CODES.O)
.addUsesLibrary("other")
.addUsesOptionalLibrary("optional")
.hideAsParsed())
.hideAsFinal();
checkBackwardsCompatibility(before, after);
}
@Test
public void in_usesLibraries() {
ParsedPackage before = ((ParsedPackage) PackageImpl.forTesting(PACKAGE_NAME)
.setTargetSdkVersion(Build.VERSION_CODES.CUR_DEVELOPMENT)
.addUsesLibrary("android.net.ipsec.ike")
.hideAsParsed());
AndroidPackage after = ((ParsedPackage) PackageImpl.forTesting(PACKAGE_NAME)
.setTargetSdkVersion(Build.VERSION_CODES.CUR_DEVELOPMENT)
.hideAsParsed())
.hideAsFinal();
checkBackwardsCompatibility(before, after);
}
@Test
public void in_usesOptionalLibraries() {
ParsedPackage before = ((ParsedPackage) PackageImpl.forTesting(PACKAGE_NAME)
.setTargetSdkVersion(Build.VERSION_CODES.CUR_DEVELOPMENT)
.addUsesOptionalLibrary("android.net.ipsec.ike")
.hideAsParsed());
AndroidPackage after = ((ParsedPackage) PackageImpl.forTesting(PACKAGE_NAME)
.setTargetSdkVersion(Build.VERSION_CODES.CUR_DEVELOPMENT)
.hideAsParsed())
.hideAsFinal();
checkBackwardsCompatibility(before, after);
}
private void checkBackwardsCompatibility(ParsedPackage before, AndroidPackage after) {
checkBackwardsCompatibility(before, after, AndroidNetIpSecIkeUpdater::new);
}
}

View File

@@ -165,6 +165,23 @@ public class PackageBackwardCompatibilityTest extends PackageSharedLibraryUpdate
checkBackwardsCompatibility(before, ((ParsedPackage) after.hideAsParsed()).hideAsFinal());
}
/**
* Ensures that the {@link PackageBackwardCompatibility} uses a
* {@link AndroidNetIpSecIkeUpdater}.
*/
@Test
public void android_net_ipsec_ike_in_usesLibraries() {
ParsedPackage before = ((ParsedPackage) PackageImpl.forTesting(PACKAGE_NAME)
.setTargetSdkVersion(Build.VERSION_CODES.CUR_DEVELOPMENT)
.addUsesLibrary("android.net.ipsec.ike")
.hideAsParsed());
ParsingPackage after = PackageImpl.forTesting(PACKAGE_NAME)
.setTargetSdkVersion(Build.VERSION_CODES.CUR_DEVELOPMENT);
checkBackwardsCompatibility(before, ((ParsedPackage) after.hideAsParsed()).hideAsFinal());
}
private void checkBackwardsCompatibility(ParsedPackage before, AndroidPackage after) {
checkBackwardsCompatibility(before, after, PackageBackwardCompatibility::getInstance);
}