Merge "Add tests for creating VM with CE/DE contexts"
This commit is contained in:
commit
13c17be4dd
|
@ -1,6 +1,10 @@
|
|||
// Signature format: 2.0
|
||||
package android.system.virtualmachine {
|
||||
|
||||
public class VirtualMachine implements java.lang.AutoCloseable {
|
||||
method @NonNull public java.io.File getRootDir();
|
||||
}
|
||||
|
||||
public final class VirtualMachineConfig {
|
||||
method @Nullable public String getPayloadConfigPath();
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ import android.annotation.NonNull;
|
|||
import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.content.ComponentCallbacks2;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
|
@ -983,6 +984,18 @@ public class VirtualMachine implements AutoCloseable {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root directory where all files related to this {@link VirtualMachine} (e.g.
|
||||
* {@code instance.img}, {@code apk.idsig}, etc) are stored.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@NonNull
|
||||
public File getRootDir() {
|
||||
return mVmRootPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures the current state of the VM in a {@link VirtualMachineDescriptor} instance. The VM
|
||||
* needs to be stopped to avoid inconsistency in its state representation.
|
||||
|
|
|
@ -324,6 +324,52 @@ public class MicrodroidTests extends MicrodroidDeviceTestBase {
|
|||
assertThat(getVirtualMachineManager().get("vm_name")).isSameInstanceAs(vm);
|
||||
}
|
||||
|
||||
@Test
|
||||
@CddTest(requirements = {"9.17/C-1-1"})
|
||||
public void vmFilesStoredInDeDirWhenCreatedFromDEContext() throws Exception {
|
||||
final Context ctx = getContext().createDeviceProtectedStorageContext();
|
||||
final int userId = ctx.getUserId();
|
||||
final VirtualMachineManager vmm = ctx.getSystemService(VirtualMachineManager.class);
|
||||
VirtualMachineConfig config =
|
||||
newVmConfigBuilder().setPayloadBinaryPath("binary/path").build();
|
||||
try {
|
||||
VirtualMachine vm = vmm.create("vm-name", config);
|
||||
// TODO(b/261430346): what about non-primary user?
|
||||
assertThat(vm.getRootDir().getAbsolutePath())
|
||||
.isEqualTo(
|
||||
"/data/user_de/" + userId + "/com.android.microdroid.test/vm/vm-name");
|
||||
} finally {
|
||||
vmm.delete("vm-name");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@CddTest(requirements = {"9.17/C-1-1"})
|
||||
public void vmFilesStoredInCeDirWhenCreatedFromCEContext() throws Exception {
|
||||
final Context ctx = getContext().createCredentialProtectedStorageContext();
|
||||
final int userId = ctx.getUserId();
|
||||
final VirtualMachineManager vmm = ctx.getSystemService(VirtualMachineManager.class);
|
||||
VirtualMachineConfig config =
|
||||
newVmConfigBuilder().setPayloadBinaryPath("binary/path").build();
|
||||
try {
|
||||
VirtualMachine vm = vmm.create("vm-name", config);
|
||||
// TODO(b/261430346): what about non-primary user?
|
||||
assertThat(vm.getRootDir().getAbsolutePath())
|
||||
.isEqualTo("/data/user/" + userId + "/com.android.microdroid.test/vm/vm-name");
|
||||
} finally {
|
||||
vmm.delete("vm-name");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@CddTest(requirements = {"9.17/C-1-1"})
|
||||
public void differentManagersForDifferentContexts() throws Exception {
|
||||
final Context ceCtx = getContext().createCredentialProtectedStorageContext();
|
||||
final Context deCtx = getContext().createDeviceProtectedStorageContext();
|
||||
assertThat(ceCtx.getSystemService(VirtualMachineManager.class))
|
||||
.isNotSameInstanceAs(deCtx.getSystemService(VirtualMachineManager.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@CddTest(requirements = {
|
||||
"9.17/C-1-1",
|
||||
|
|
Loading…
Reference in New Issue