Automatically create QCoW2 images as needed on startup

Snapshots in QEMU 2 work only as long as images in QCoW2
format are used. It is a copy-on-write format that stores diffs
to a backing image.
This change makes it so that the emulator creates the necessary
QCoW2 images (backed by the raw images specified in AVD config)
automatically.
The QCoW2 images are re-created (and snapshots obliterated) if
the user wipes AVD's data or it is detected that the system image
has been updated to another version.

Change-Id: I6b863ad07733c72fc4653cdf9aa6d7ca2b4c292c
diff --git a/android-qemu2-glue/main.cpp b/android-qemu2-glue/main.cpp
index de5a0e4..e370bfa 100644
--- a/android-qemu2-glue/main.cpp
+++ b/android-qemu2-glue/main.cpp
@@ -208,7 +208,7 @@
 
 static void makePartitionCmd(const char** args, int* argsPosition, int* driveIndex,
                              AndroidHwConfig* hw, ImageType type, bool writable,
-                             int apiLevel) {
+                             int apiLevel, const char* avdContentPath) {
     int n   = *argsPosition;
     int idx = *driveIndex;
 
@@ -219,12 +219,12 @@
     std::string driveParam;
 #endif
     std::string deviceParam;
-
     switch (type) {
         case IMAGE_TYPE_SYSTEM:
-            driveParam += StringFormat("index=%d,id=system,file=%s,format=raw",
+            driveParam += StringFormat("index=%d,id=system,file=%s"
+                                       PATH_SEP "system.img.qcow2",
                                         idx++,
-                                        hw->disk_systemPartition_initPath);
+                                        avdContentPath);
             // API 15 and under images need a read+write
             // system image.
             if (apiLevel > 15) {
@@ -238,14 +238,14 @@
                                        kTarget.storageDeviceType);
             break;
         case IMAGE_TYPE_CACHE:
-            driveParam += StringFormat("index=%d,id=cache,file=%s,format=raw",
+            driveParam += StringFormat("index=%d,id=cache,file=%s.qcow2",
                                       idx++,
                                       hw->disk_cachePartition_path);
             deviceParam = StringFormat("%s,drive=cache",
                                        kTarget.storageDeviceType);
             break;
         case IMAGE_TYPE_USER_DATA:
-            driveParam += StringFormat("index=%d,id=userdata,file=%s,format=raw",
+            driveParam += StringFormat("index=%d,id=userdata,file=%s.qcow2",
                                       idx++,
                                       hw->disk_dataPartition_path);
             deviceParam = StringFormat("%s,drive=userdata",
@@ -253,7 +253,7 @@
             break;
         case IMAGE_TYPE_SD_CARD:
             if (hw->hw_sdCard_path != NULL && strcmp(hw->hw_sdCard_path, "")) {
-               driveParam += StringFormat("index=%d,id=sdcard,file=%s,format=raw",
+               driveParam += StringFormat("index=%d,id=sdcard,file=%s.qcow2",
                                          idx++, hw->hw_sdCard_path);
                deviceParam = StringFormat("%s,drive=sdcard",
                                           kTarget.storageDeviceType);
@@ -801,7 +801,8 @@
         bool writable = (kTarget.imagePartitionTypes[s] == IMAGE_TYPE_SYSTEM) ?
                     android_op_writable_system : true;
         makePartitionCmd(args, &n, &drvIndex, hw,
-                         kTarget.imagePartitionTypes[s], writable, apiLevel);
+                         kTarget.imagePartitionTypes[s], writable, apiLevel,
+                         avdInfo_getContentPath(avd));
     }
 
     // Network