Duplicating FD in readClipboardFromVm

Bug: 349702327
Test: Interaction with ferrochrome
Change-Id: I97524775a5df708f918c5096d717f1d63699f867
diff --git a/vmlauncher_app/java/com/android/virtualization/vmlauncher/MainActivity.java b/vmlauncher_app/java/com/android/virtualization/vmlauncher/MainActivity.java
index cf83bff..3c62623 100644
--- a/vmlauncher_app/java/com/android/virtualization/vmlauncher/MainActivity.java
+++ b/vmlauncher_app/java/com/android/virtualization/vmlauncher/MainActivity.java
@@ -542,12 +542,17 @@
             Log.d(TAG, "file descriptor of ClipboardSharingServer is null");
             return false;
         }
-        try (OutputStream output = new AutoCloseOutputStream(pfd)) {
+        try (OutputStream output = new AutoCloseOutputStream(pfd.dup())) {
             output.write(request);
             output.flush();
             Log.d(TAG, "successfully send request to the VM for reading clipboard");
         } catch (IOException e) {
             Log.e(TAG, "failed to send request to the VM for read clipboard", e);
+            try {
+                pfd.close();
+            } catch (IOException err) {
+                Log.e(TAG, "failed to close file descriptor", err);
+            }
             return false;
         }