dexopt: Restore old files when cancelled

- out_oat, out_vdex, out_image will be first updated upon
  temporary work file. When dex2oat is completed, this temp
  file is committed and renamed into regular file.
- For whatever reason, if renaming fails, guarantee three states:
  all files committed to new version
  all files kept with original version
  all three files removed
- reference_profile is kept for cancellation or successful run
  while removed for dexopt failure.
- Added RestorableFile to handle usage for out_* files.
- Added unit test.
- Also fixed wrong returning of completed state for cancellation.

Bug: 203689833
Bug: 32230521
Test: atest installd_unique_file_test installd_dexopt_test
Change-Id: Ib6804fb311596dfd9180c1d6083cd2e9a661b621
7 files changed