Merge "Use staged APEXes for compilation"
diff --git a/apkverify/src/sigutil.rs b/apkverify/src/sigutil.rs
index fc92898..23dd91e 100644
--- a/apkverify/src/sigutil.rs
+++ b/apkverify/src/sigutil.rs
@@ -104,8 +104,8 @@
             let mut data = data(self)?;
             while data.limit() > 0 {
                 let chunk_size = min(CHUNK_SIZE_BYTES, data.limit());
-                let mut slice = &mut chunk[..(chunk_size as usize)];
-                data.read_exact(&mut slice)?;
+                let slice = &mut chunk[..(chunk_size as usize)];
+                data.read_exact(slice)?;
                 digests_of_chunks.put_slice(
                     digester.digest(slice, CHUNK_HEADER_MID, chunk_size as u32).as_ref(),
                 );
diff --git a/authfs/fd_server/src/aidl.rs b/authfs/fd_server/src/aidl.rs
index 92be504..ddac2bc 100644
--- a/authfs/fd_server/src/aidl.rs
+++ b/authfs/fd_server/src/aidl.rs
@@ -110,8 +110,8 @@
         F: FnOnce(&mut FdConfig) -> BinderResult<(i32, FdConfig)>,
     {
         let mut fd_pool = self.fd_pool.lock().unwrap();
-        let mut fd_config = fd_pool.get_mut(&fd).ok_or_else(|| new_errno_error(Errno::EBADF))?;
-        let (new_fd, new_fd_config) = create_fn(&mut fd_config)?;
+        let fd_config = fd_pool.get_mut(&fd).ok_or_else(|| new_errno_error(Errno::EBADF))?;
+        let (new_fd, new_fd_config) = create_fn(fd_config)?;
         if let btree_map::Entry::Vacant(entry) = fd_pool.entry(new_fd) {
             entry.insert(new_fd_config);
             Ok(new_fd)
diff --git a/authfs/src/fusefs.rs b/authfs/src/fusefs.rs
index 89bac45..549df1e 100644
--- a/authfs/src/fusefs.rs
+++ b/authfs/src/fusefs.rs
@@ -215,13 +215,13 @@
         F: FnOnce(&mut AuthFsEntry, &Path, Inode) -> io::Result<AuthFsEntry>,
     {
         let mut inode_table = self.inode_table.lock().unwrap();
-        let mut parent_entry = inode_table
+        let parent_entry = inode_table
             .get_mut(&parent_inode)
             .ok_or_else(|| io::Error::from_raw_os_error(libc::ENOENT))?;
 
         let new_inode = self.next_inode.fetch_add(1, Ordering::Relaxed);
         let basename: &Path = cstr_to_path(name);
-        let new_file_entry = create_fn(&mut parent_entry, basename, new_inode)?;
+        let new_file_entry = create_fn(parent_entry, basename, new_inode)?;
         if let btree_map::Entry::Vacant(entry) = inode_table.entry(new_inode) {
             entry.insert(new_file_entry);
             Ok(new_inode)
diff --git a/compos/common/compos_client.rs b/compos/common/compos_client.rs
index 73554bb..6c16bb0 100644
--- a/compos/common/compos_client.rs
+++ b/compos/common/compos_client.rs
@@ -202,18 +202,12 @@
     }
 }
 
-#[derive(Debug)]
+#[derive(Debug, Default)]
 struct VmState {
     has_died: bool,
     cid: Option<i32>,
 }
 
-impl Default for VmState {
-    fn default() -> Self {
-        Self { has_died: false, cid: None }
-    }
-}
-
 #[derive(Debug)]
 struct VmStateMonitor {
     mutex: Mutex<VmState>,
diff --git a/compos/compos_key_cmd/compos_key_cmd.cpp b/compos/compos_key_cmd/compos_key_cmd.cpp
index e4d1cf2..76ff06f 100644
--- a/compos/compos_key_cmd/compos_key_cmd.cpp
+++ b/compos/compos_key_cmd/compos_key_cmd.cpp
@@ -102,6 +102,10 @@
 
 void copyToLog(unique_fd&& fd) {
     FILE* source = Fdopen(std::move(fd), "r");
+    if (source == nullptr) {
+        LOG(INFO) << "Can't log VM output";
+        return;
+    }
     size_t size = 0;
     char* line = nullptr;
 
@@ -239,7 +243,7 @@
         }
 
         ScopedFileDescriptor instanceFd(
-                TEMP_FAILURE_RETRY(open(mInstanceImageFile.c_str(), O_RDONLY | O_CLOEXEC)));
+                TEMP_FAILURE_RETRY(open(mInstanceImageFile.c_str(), O_RDWR | O_CLOEXEC)));
         if (instanceFd.get() == -1) {
             return ErrnoError() << "Failed to open instance image file";
         }
diff --git a/compos/service/Android.bp b/compos/service/Android.bp
index 6270c9a..336ae9b 100644
--- a/compos/service/Android.bp
+++ b/compos/service/Android.bp
@@ -12,6 +12,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
 java_library {
     name: "service-compos",
     srcs: [
diff --git a/virtualizationservice/src/aidl.rs b/virtualizationservice/src/aidl.rs
index af420f6..e6210e2 100644
--- a/virtualizationservice/src/aidl.rs
+++ b/virtualizationservice/src/aidl.rs
@@ -644,6 +644,7 @@
 struct VirtualMachine {
     instance: Arc<VmInstance>,
     /// Keeps our service process running as long as this VM instance exists.
+    #[allow(dead_code)]
     lazy_service_guard: LazyServiceGuard,
 }
 
@@ -775,7 +776,7 @@
 
 /// The mutable state of the VirtualizationService. There should only be one instance of this
 /// struct.
-#[derive(Debug)]
+#[derive(Debug, Default)]
 struct State {
     /// The VMs which have been started. When VMs are started a weak reference is added to this list
     /// while a strong reference is returned to the caller over Binder. Once all copies of the
@@ -822,12 +823,6 @@
     }
 }
 
-impl Default for State {
-    fn default() -> Self {
-        State { vms: vec![], debug_held_vms: vec![] }
-    }
-}
-
 /// Get the next available CID, or an error if we have run out. The last CID used is stored in
 /// a system property so that restart of virtualizationservice doesn't reuse CID while the host
 /// Android is up.