Merge "Use dev/null instead of tmp file"
diff --git a/core/java/android/os/BugreportManager.java b/core/java/android/os/BugreportManager.java
index e366fe0..32735aa 100644
--- a/core/java/android/os/BugreportManager.java
+++ b/core/java/android/os/BugreportManager.java
@@ -32,7 +32,7 @@
 import libcore.io.IoUtils;
 
 import java.io.File;
-import java.io.IOException;
+import java.io.FileNotFoundException;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.concurrent.Executor;
@@ -146,7 +146,6 @@
             @NonNull BugreportParams params,
             @NonNull @CallbackExecutor Executor executor,
             @NonNull BugreportCallback callback) {
-        File tmpScreenshotFile = null;
         try {
             Preconditions.checkNotNull(bugreportFd);
             Preconditions.checkNotNull(params);
@@ -155,13 +154,10 @@
 
             if (screenshotFd == null) {
                 // Binder needs a valid File Descriptor to be passed
-                tmpScreenshotFile = File.createTempFile("tmp", ".png");
-                screenshotFd = ParcelFileDescriptor.open(tmpScreenshotFile,
+                screenshotFd = ParcelFileDescriptor.open(new File("/dev/null"),
                         ParcelFileDescriptor.MODE_READ_ONLY);
             }
-            DumpstateListener dsListener = new DumpstateListener(executor,
-                    callback, tmpScreenshotFile);
-
+            DumpstateListener dsListener = new DumpstateListener(executor, callback);
             // Note: mBinder can get callingUid from the binder transaction.
             mBinder.startBugreport(-1 /* callingUid */,
                     mContext.getOpPackageName(),
@@ -169,13 +165,9 @@
                     screenshotFd.getFileDescriptor(),
                     params.getMode(), dsListener);
         } catch (RemoteException e) {
-            deleteFile(tmpScreenshotFile);
             throw e.rethrowFromSystemServer();
-        } catch (IOException e) {
-            // Need to delete the file if it was created but failed while trying to get fd
-            deleteFile(tmpScreenshotFile);
-            Log.e(TAG, "Not able to create/open temporary screenshot file ", e);
-            callback.onError(BugreportCallback.BUGREPORT_ERROR_RUNTIME);
+        } catch (FileNotFoundException e) {
+            Log.wtf(TAG, "Not able to find /dev/null file: ", e);
         } finally {
             // We can close the file descriptors here because binder would have duped them.
             IoUtils.closeQuietly(bugreportFd);
@@ -197,26 +189,13 @@
         }
     }
 
-    private void deleteFile(@Nullable File tmpScreenshotFile) {
-        try {
-            if (tmpScreenshotFile != null && tmpScreenshotFile.exists()) {
-                tmpScreenshotFile.delete();
-            }
-        } catch (SecurityException e) {
-            Log.e(TAG, "Not able to delete temporary screenshot file ", e);
-        }
-    }
-
     private final class DumpstateListener extends IDumpstateListener.Stub {
         private final Executor mExecutor;
         private final BugreportCallback mCallback;
-        private final File mTmpScreenshotFile;
 
-        DumpstateListener(Executor executor, BugreportCallback callback,
-                @Nullable File tmpScreenshotFile) {
+        DumpstateListener(Executor executor, BugreportCallback callback) {
             mExecutor = executor;
             mCallback = callback;
-            mTmpScreenshotFile = tmpScreenshotFile;
         }
 
         @Override
@@ -240,7 +219,6 @@
                 });
             } finally {
                 Binder.restoreCallingIdentity(identity);
-                deleteFile(mTmpScreenshotFile);
             }
         }
 
@@ -253,7 +231,6 @@
                 });
             } finally {
                 Binder.restoreCallingIdentity(identity);
-                deleteFile(mTmpScreenshotFile);
             }
         }