Handle downgrade install for rebootless apexes correctly (1/n)
1. ApexManager::checkDowngrade() doesn't handle the downgrade flag. 2. Downgrade install is already handled by PMS. 3. This change is required for rollback to work. Bug: 195517333 Test: atest ApexManagerTest StagedInstallInternalTest Change-Id: I86e49f26fc72df18291a8a65c43091d4be9b9e05
This commit is contained in:
@@ -1035,17 +1035,6 @@ public abstract class ApexManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDowngrade(PackageInfo existingApexPkg, PackageInfo newApexPkg)
|
||||
throws PackageManagerException {
|
||||
final long currentVersionCode = existingApexPkg.applicationInfo.longVersionCode;
|
||||
final long newVersionCode = newApexPkg.applicationInfo.longVersionCode;
|
||||
if (currentVersionCode > newVersionCode) {
|
||||
throw new PackageManagerException(PackageManager.INSTALL_FAILED_VERSION_DOWNGRADE,
|
||||
"Downgrade of APEX package " + newApexPkg.packageName
|
||||
+ " is not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void installPackage(File apexFile, PackageParser2 packageParser)
|
||||
throws PackageManagerException {
|
||||
@@ -1069,7 +1058,6 @@ public abstract class ApexManager {
|
||||
"It is forbidden to install new APEX packages");
|
||||
}
|
||||
checkApexSignature(existingApexPkg, newApexPkg);
|
||||
checkDowngrade(existingApexPkg, newApexPkg);
|
||||
ApexInfo apexInfo = waitForApexService().installAndActivatePackage(
|
||||
apexFile.getAbsolutePath());
|
||||
final ParsedPackage parsedPackage2 = packageParser.parsePackage(
|
||||
|
||||
@@ -347,24 +347,6 @@ public class ApexManagerTest {
|
||||
assertThat(e).hasMessageThat().contains("It is forbidden to install new APEX packages");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstallPackageDowngrade() throws Exception {
|
||||
File activeApex = extractResource("test.apex_rebootless_v2",
|
||||
"test.rebootless_apex_v2.apex");
|
||||
ApexInfo activeApexInfo = createApexInfo("test.apex_rebootless", 2, /* isActive= */ true,
|
||||
/* isFactory= */ false, activeApex);
|
||||
when(mApexService.getAllPackages()).thenReturn(new ApexInfo[]{activeApexInfo});
|
||||
mApexManager.scanApexPackagesTraced(mPackageParser2,
|
||||
ParallelPackageParser.makeExecutorService());
|
||||
|
||||
File installedApex = extractResource("test.apex_rebootless_v1",
|
||||
"test.rebootless_apex_v1.apex");
|
||||
PackageManagerException e = expectThrows(PackageManagerException.class,
|
||||
() -> mApexManager.installPackage(installedApex, mPackageParser2));
|
||||
assertThat(e).hasMessageThat().contains(
|
||||
"Downgrade of APEX package test.apex.rebootless is not allowed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstallPackage_activeOnSystem() throws Exception {
|
||||
ApexInfo activeApexInfo = createApexInfo("test.apex_rebootless", 1, /* isActive= */ true,
|
||||
|
||||
@@ -59,6 +59,7 @@ java_test_host {
|
||||
":StagedInstallTestApexV2_WrongSha",
|
||||
":TestAppAv1",
|
||||
":test.rebootless_apex_v1",
|
||||
":test.rebootless_apex_v2",
|
||||
],
|
||||
test_suites: ["general-tests"],
|
||||
test_config: "StagedInstallInternalTest.xml",
|
||||
|
||||
@@ -476,6 +476,18 @@ public class StagedInstallInternalTest {
|
||||
assertThat(captor.getValue().stagedApexModuleNames).hasLength(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRebootlessDowngrade() throws Exception {
|
||||
final String packageName = "test.apex.rebootless";
|
||||
assertThat(InstallUtils.getInstalledVersion(packageName)).isEqualTo(2);
|
||||
TestApp apex1 = new TestApp("TestRebootlessApexV1", packageName, 1,
|
||||
/* isApex= */ true, "test.rebootless_apex_v1.apex");
|
||||
InstallUtils.commitExpectingFailure(AssertionError.class,
|
||||
"INSTALL_FAILED_VERSION_DOWNGRADE", Install.single(apex1));
|
||||
Install.single(apex1).setRequestDowngrade().commit();
|
||||
assertThat(InstallUtils.getInstalledVersion(packageName)).isEqualTo(1);
|
||||
}
|
||||
|
||||
private IPackageManagerNative getPackageManagerNative() {
|
||||
IBinder binder = ServiceManager.waitForService("package_native");
|
||||
assertThat(binder).isNotNull();
|
||||
|
||||
@@ -91,7 +91,7 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
|
||||
deleteFiles("/system/apex/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex",
|
||||
"/data/apex/active/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex",
|
||||
"/data/apex/active/" + SHIM_APEX_PACKAGE_NAME + "*.apex",
|
||||
"/system/apex/test.rebootless_apex_v1.apex",
|
||||
"/system/apex/test.rebootless_apex_v*.apex",
|
||||
"/data/apex/active/test.apex.rebootless*.apex",
|
||||
TEST_VENDOR_APEX_ALLOW_LIST);
|
||||
}
|
||||
@@ -493,6 +493,13 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
|
||||
runPhase("testStagedApexObserver");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRebootlessDowngrade() throws Exception {
|
||||
pushTestApex("test.rebootless_apex_v2.apex");
|
||||
getDevice().reboot();
|
||||
runPhase("testRebootlessDowngrade");
|
||||
}
|
||||
|
||||
private List<String> getStagingDirectories() throws DeviceNotAvailableException {
|
||||
String baseDir = "/data/app-staging";
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user