From bb6d38615ef43ab4cb985293005165a43f7ab45f Mon Sep 17 00:00:00 2001 From: Jin Seok Park Date: Mon, 27 Jul 2020 11:23:14 +0900 Subject: DO NOT MERGE: Rename temp file to use a valid image file extension MediaProvider added a restriction in R for apps targeting SDK 30 to not allow .tmp files in image file directories such as "Pictures" and "DCIM". This CL renames the temp file to avoid this restriction. Also added test to check for writing to FileDescriptor instances. Bug: 160874777 Test: atest CtsMediaTestCases:android.media.cts.ExifInterfaceTest Also tested with an image file inside /Pictures Change-Id: Iedb548651c0048b0aecc4b34e9c94f778cf5d1e0 (cherry picked from commit 5abacddfc3355905a3d15a3561d321f5ea62dcc2) --- media/java/android/media/ExifInterface.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java index ed566a50ec58..533f6950fb89 100644 --- a/media/java/android/media/ExifInterface.java +++ b/media/java/android/media/ExifInterface.java @@ -68,6 +68,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TimeZone; +import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.CRC32; @@ -2079,7 +2080,10 @@ public class ExifInterface { try { // Move the original file to temporary file. if (mFilename != null) { - tempFile = new File(mFilename + ".tmp"); + String parent = originalFile.getParent(); + String name = originalFile.getName(); + String tempPrefix = UUID.randomUUID().toString() + "_"; + tempFile = new File(parent, tempPrefix + name); if (!originalFile.renameTo(tempFile)) { throw new IOException("Couldn't rename to " + tempFile.getAbsolutePath()); } -- cgit v1.2.3-59-g8ed1b