Merge "Don't fall back to copy during rollback tests (5/n)" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-03-12 13:55:53 +00:00
committed by Android (Google) Code Review
5 changed files with 41 additions and 10 deletions

View File

@@ -24,6 +24,7 @@ import android.content.pm.VersionedPackage;
import android.content.rollback.PackageRollbackInfo;
import android.content.rollback.PackageRollbackInfo.RestoreInfo;
import android.content.rollback.RollbackInfo;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.system.ErrnoException;
import android.system.Os;
@@ -227,6 +228,15 @@ class RollbackStore {
packageSessionIds, extensionVersions);
}
private static boolean isLinkPossible(File oldFile, File newFile) {
try {
return Os.stat(oldFile.getAbsolutePath()).st_dev
== Os.stat(newFile.getAbsolutePath()).st_dev;
} catch (ErrnoException ignore) {
return false;
}
}
/**
* Creates a backup copy of an apk or apex for a package.
* For packages containing splits, this method should be called for each
@@ -239,16 +249,29 @@ class RollbackStore {
targetDir.mkdirs();
File targetFile = new File(targetDir, sourceFile.getName());
try {
// Create a hard link to avoid copy
// TODO(b/168562373)
// Linking between non-encrypted and encrypted is not supported and we have
// encrypted /data/rollback and non-encrypted /data/apex/active. For now this works
// because we happen to store encrypted files under /data/apex/active which is no
// longer the case when compressed apex rolls out. We have to handle this case in
// order not to fall back to copy.
Os.link(sourceFile.getAbsolutePath(), targetFile.getAbsolutePath());
} catch (ErrnoException ignore) {
boolean fallbackToCopy = !isLinkPossible(sourceFile, targetFile);
if (!fallbackToCopy) {
try {
// Create a hard link to avoid copy
// TODO(b/168562373)
// Linking between non-encrypted and encrypted is not supported and we have
// encrypted /data/rollback and non-encrypted /data/apex/active. For now this works
// because we happen to store encrypted files under /data/apex/active which is no
// longer the case when compressed apex rolls out. We have to handle this case in
// order not to fall back to copy.
Os.link(sourceFile.getAbsolutePath(), targetFile.getAbsolutePath());
} catch (ErrnoException e) {
boolean isRollbackTest =
SystemProperties.getBoolean("persist.rollback.is_test", false);
if (isRollbackTest) {
throw new IOException(e);
} else {
fallbackToCopy = true;
}
}
}
if (fallbackToCopy) {
// Fall back to copy if hardlink can't be created
Files.copy(sourceFile.toPath(), targetFile.toPath());
}

View File

@@ -20,6 +20,8 @@
<option name="run-command" value="pm uninstall com.android.cts.install.lib.testapp.B" />
<option name="teardown-command" value="pm uninstall com.android.cts.install.lib.testapp.A" />
<option name="teardown-command" value="pm uninstall com.android.cts.install.lib.testapp.B" />
<option name="run-command" value="setprop persist.rollback.is_test 1" />
<option name="teardown-command" value="setprop persist.rollback.is_test 0" />
</target_preparer>
<test class="com.android.tradefed.testtype.HostTest" >
<option name="class" value="com.android.tests.rollback.host.MultiUserRollbackTest" />

View File

@@ -24,6 +24,8 @@
<option name="run-command" value="am broadcast -a 'com.google.android.gms.phenotype.FLAG_OVERRIDE' --es package &quot;com.google.android.gms.platformconfigurator&quot; --es user '\\*' --esa flags &quot;ModuleConfig__versioned_immediate_commit_packages&quot; --esa types &quot;bytes&quot; --esa values &quot;Cm5vdGFwYWNrYWdlOgA=&quot; com.google.android.gms" />
<option name="teardown-command" value="am broadcast -a 'com.google.android.gms.phenotype.FLAG_OVERRIDE' --es action delete --es package &quot;com.google.android.gms.platformconfigurator&quot; --es user '\*' --esa flag &quot;ModuleConfig__immediate_commit_packages&quot; com.google.android.gms" />
<option name="teardown-command" value="am broadcast -a 'com.google.android.gms.phenotype.FLAG_OVERRIDE' --es action delete --es package &quot;com.google.android.gms.platformconfigurator&quot; --es user '\*' --esa flag &quot;ModuleConfig__versioned_immediate_commit_packages&quot; com.google.android.gms" />
<option name="run-command" value="setprop persist.rollback.is_test 1" />
<option name="teardown-command" value="setprop persist.rollback.is_test 0" />
</target_preparer>
<test class="com.android.tradefed.testtype.HostTest" >
<option name="class" value="com.android.tests.rollback.host.NetworkStagedRollbackTest" />

View File

@@ -27,6 +27,8 @@
<option name="run-command" value="pm uninstall com.android.cts.install.lib.testapp.B" />
<option name="teardown-command" value="pm uninstall com.android.cts.install.lib.testapp.A" />
<option name="teardown-command" value="pm uninstall com.android.cts.install.lib.testapp.B" />
<option name="run-command" value="setprop persist.rollback.is_test 1" />
<option name="teardown-command" value="setprop persist.rollback.is_test 0" />
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="com.android.tests.rollback" />

View File

@@ -24,6 +24,8 @@
<option name="run-command" value="pm uninstall com.android.cts.install.lib.testapp.B" />
<option name="teardown-command" value="pm uninstall com.android.cts.install.lib.testapp.A" />
<option name="teardown-command" value="pm uninstall com.android.cts.install.lib.testapp.B" />
<option name="run-command" value="setprop persist.rollback.is_test 1" />
<option name="teardown-command" value="setprop persist.rollback.is_test 0" />
</target_preparer>
<test class="com.android.tradefed.testtype.HostTest" >
<option name="class" value="com.android.tests.rollback.host.StagedRollbackTest" />