claimInstance is last step while moving vm bw apps
In case of any failure in other steps, this ensures the record with
central VS indicates the VM is owned by the transferor, which can retry
transferring the app or otherwise, still use it if the transfer fails.
Test: Builds
Bug: 294177871
Change-Id: I49fe6ca2a15b3d898f6e6070b0d033bd67d010a2
diff --git a/java/framework/src/android/system/virtualmachine/VirtualMachine.java b/java/framework/src/android/system/virtualmachine/VirtualMachine.java
index d746c7c..cc126eb 100644
--- a/java/framework/src/android/system/virtualmachine/VirtualMachine.java
+++ b/java/framework/src/android/system/virtualmachine/VirtualMachine.java
@@ -431,11 +431,6 @@
VirtualMachineConfig config = VirtualMachineConfig.from(vmDescriptor.getConfigFd());
vm = new VirtualMachine(context, name, config, VirtualizationService.getInstance());
config.serialize(vm.mConfigFilePath);
- if (vm.mInstanceIdPath != null) {
- vm.importInstanceIdFrom(vmDescriptor.getInstanceIdFd());
- vm.claimInstance();
- }
-
try {
vm.mInstanceFilePath.createNewFile();
} catch (IOException e) {
@@ -452,12 +447,16 @@
}
vm.importEncryptedStoreFrom(vmDescriptor.getEncryptedStoreFd());
}
+ if (vm.mInstanceIdPath != null) {
+ vm.importInstanceIdFrom(vmDescriptor.getInstanceIdFd());
+ vm.claimInstance();
+ }
}
return vm;
} catch (VirtualMachineException | RuntimeException e) {
// If anything goes wrong, delete any files created so far and the VM's directory
try {
- vmInstanceCleanup(context, name);
+ deleteRecursively(vmDir);
} catch (Exception innerException) {
e.addSuppressed(innerException);
}