Merge changes Id7dcf0b8,Ia8749923

* changes:
  Add VM memory config to Java API.
  Use Java style field names in AIDL.
diff --git a/javalib/src/android/system/virtualmachine/VirtualMachineConfig.java b/javalib/src/android/system/virtualmachine/VirtualMachineConfig.java
index 21e1a46..7a10a96 100644
--- a/javalib/src/android/system/virtualmachine/VirtualMachineConfig.java
+++ b/javalib/src/android/system/virtualmachine/VirtualMachineConfig.java
@@ -51,12 +51,17 @@
     private static final String KEY_IDSIGPATH = "idsigPath";
     private static final String KEY_PAYLOADCONFIGPATH = "payloadConfigPath";
     private static final String KEY_DEBUGMODE = "debugMode";
+    private static final String KEY_MEMORY_MIB = "memoryMib";
 
     // Paths to the APK and its idsig file of this application.
     private final @NonNull String mApkPath;
     private final @NonNull Signature[] mCerts;
     private final @NonNull String mIdsigPath;
     private final boolean mDebugMode;
+    /**
+     * The amount of RAM to give the VM, in MiB. If this is 0 or negative the default will be used.
+     */
+    private final int mMemoryMib;
 
     /**
      * Path within the APK to the payload config file that defines software aspects of this config.
@@ -70,12 +75,14 @@
             @NonNull Signature[] certs,
             @NonNull String idsigPath,
             @NonNull String payloadConfigPath,
-            boolean debugMode) {
+            boolean debugMode,
+            int memoryMib) {
         mApkPath = apkPath;
         mCerts = certs;
         mIdsigPath = idsigPath;
         mPayloadConfigPath = payloadConfigPath;
         mDebugMode = debugMode;
+        mMemoryMib = memoryMib;
     }
 
     /** Loads a config from a stream, for example a file. */
@@ -108,7 +115,9 @@
             throw new VirtualMachineException("No payloadConfigPath");
         }
         final boolean debugMode = b.getBoolean(KEY_DEBUGMODE);
-        return new VirtualMachineConfig(apkPath, certs, idsigPath, payloadConfigPath, debugMode);
+        final int memoryMib = b.getInt(KEY_MEMORY_MIB);
+        return new VirtualMachineConfig(
+                apkPath, certs, idsigPath, payloadConfigPath, debugMode, memoryMib);
     }
 
     /** Persists this config to a stream, for example a file. */
@@ -125,6 +134,9 @@
         b.putString(KEY_IDSIGPATH, mIdsigPath);
         b.putString(KEY_PAYLOADCONFIGPATH, mPayloadConfigPath);
         b.putBoolean(KEY_DEBUGMODE, mDebugMode);
+        if (mMemoryMib > 0) {
+            b.putInt(KEY_MEMORY_MIB, mMemoryMib);
+        }
         b.writeToStream(output);
     }
 
@@ -162,6 +174,7 @@
         parcel.idsig = ParcelFileDescriptor.open(new File(mIdsigPath), MODE_READ_ONLY);
         parcel.configPath = mPayloadConfigPath;
         parcel.debug = mDebugMode;
+        parcel.memoryMib = mMemoryMib;
         return parcel;
     }
 
@@ -170,6 +183,7 @@
         private Context mContext;
         private String mPayloadConfigPath;
         private boolean mDebugMode;
+        private int mMemoryMib;
         private String mIdsigPath; // TODO(jiyong): remove this
         // TODO(jiyong): add more items like # of cpu, size of ram, debuggability, etc.
 
@@ -186,6 +200,15 @@
             return this;
         }
 
+        /**
+         * Sets the amount of RAM to give the VM. If this is zero or negative then the default will
+         * be used.
+         */
+        public Builder memoryMib(int memoryMib) {
+            mMemoryMib = memoryMib;
+            return this;
+        }
+
         // TODO(jiyong): remove this. Apps shouldn't need to set the path to the idsig file. It
         // should be automatically found or created on demand.
         /** Set the path to the idsig file for the current application. */
@@ -212,7 +235,7 @@
             }
 
             return new VirtualMachineConfig(
-                    apkPath, certs, mIdsigPath, mPayloadConfigPath, mDebugMode);
+                    apkPath, certs, mIdsigPath, mPayloadConfigPath, mDebugMode, mMemoryMib);
         }
     }
 }
diff --git a/tests/vsock_test.cc b/tests/vsock_test.cc
index d9b8f21..c5643ec 100644
--- a/tests/vsock_test.cc
+++ b/tests/vsock_test.cc
@@ -88,7 +88,7 @@
     raw_config.kernel = ParcelFileDescriptor(unique_fd(open(kVmKernelPath, O_RDONLY | O_CLOEXEC)));
     raw_config.initrd = ParcelFileDescriptor(unique_fd(open(kVmInitrdPath, O_RDONLY | O_CLOEXEC)));
     raw_config.params = kVmParams;
-    raw_config.protected_vm = protected_vm;
+    raw_config.protectedVm = protected_vm;
 
     VirtualMachineConfig config(std::move(raw_config));
     sp<IVirtualMachine> vm;
diff --git a/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineAppConfig.aidl b/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineAppConfig.aidl
index 9339f82..a522dee 100644
--- a/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineAppConfig.aidl
+++ b/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineAppConfig.aidl
@@ -36,5 +36,5 @@
      * The amount of RAM to give the VM, in MiB. If this is 0 or negative then it will default to
      * the value in microdroid.json, if any, or the crosvm default.
      */
-    int memory_mib;
+    int memoryMib;
 }
diff --git a/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineRawConfig.aidl b/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineRawConfig.aidl
index 612c498..c62117e 100644
--- a/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineRawConfig.aidl
+++ b/virtualizationservice/aidl/android/system/virtualizationservice/VirtualMachineRawConfig.aidl
@@ -41,8 +41,8 @@
     DiskImage[] disks;
 
     /** Whether the VM should be a protected VM. */
-    boolean protected_vm;
+    boolean protectedVm;
 
     /** The amount of RAM to give the VM, in MiB. 0 or negative to use the default. */
-    int memory_mib;
+    int memoryMib;
 }
diff --git a/virtualizationservice/src/aidl.rs b/virtualizationservice/src/aidl.rs
index 389dd23..64d3913 100644
--- a/virtualizationservice/src/aidl.rs
+++ b/virtualizationservice/src/aidl.rs
@@ -160,8 +160,8 @@
             initrd: as_asref(&config.initrd),
             disks,
             params: config.params.to_owned(),
-            protected: config.protected_vm,
-            memory_mib: config.memory_mib.try_into().ok().and_then(NonZeroU32::new),
+            protected: config.protectedVm,
+            memory_mib: config.memoryMib.try_into().ok().and_then(NonZeroU32::new),
         };
         let composite_disk_fds: Vec<_> =
             indirect_files.iter().map(|file| file.as_raw_fd()).collect();
@@ -382,8 +382,8 @@
     let vm_config_file = File::open(vm_config_path)?;
     let mut vm_config = VmConfig::load(&vm_config_file)?.to_parcelable()?;
 
-    if config.memory_mib > 0 {
-        vm_config.memory_mib = config.memory_mib;
+    if config.memoryMib > 0 {
+        vm_config.memoryMib = config.memoryMib;
     }
 
     // Microdroid requires an additional payload disk image and the bootconfig partition.
diff --git a/vm/src/run.rs b/vm/src/run.rs
index 1b1d5a3..5b3f193 100644
--- a/vm/src/run.rs
+++ b/vm/src/run.rs
@@ -63,7 +63,7 @@
         configPath: config_path.to_owned(),
         debug,
         // Use the default.
-        memory_mib: 0,
+        memoryMib: 0,
     });
     run(service, &config, &format!("{:?}!{:?}", apk, config_path), daemonize, log_path)
 }
diff --git a/vmconfig/src/lib.rs b/vmconfig/src/lib.rs
index 890051e..7739e36 100644
--- a/vmconfig/src/lib.rs
+++ b/vmconfig/src/lib.rs
@@ -93,8 +93,8 @@
             params: self.params.clone(),
             bootloader: maybe_open_parcel_file(&self.bootloader, false)?,
             disks: self.disks.iter().map(DiskImage::to_parcelable).collect::<Result<_, Error>>()?,
-            protected_vm: self.protected,
-            memory_mib,
+            protectedVm: self.protected,
+            memoryMib: memory_mib,
         })
     }
 }