diff options
author | Raj Yengisetty <rajesh@cyngn.com> | 2015-06-09 10:38:04 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-18 13:52:56 -0700 |
commit | 0401cb56ea1105694a67d7569d56573c12947517 (patch) | |
tree | 5f4d85ca96bc93523c0076818c4d66809b041212 /src/com/android/calendar | |
parent | 46235341dc6c15a7bd2dbc89c8c258922876cca6 (diff) | |
download | android_packages_apps_Calendar-0401cb56ea1105694a67d7569d56573c12947517.tar.gz android_packages_apps_Calendar-0401cb56ea1105694a67d7569d56573c12947517.tar.bz2 android_packages_apps_Calendar-0401cb56ea1105694a67d7569d56573c12947517.zip |
Calendar: when sharing calendar events use File.createTempFile
Also handle ENAMETOOLONG when the event title is too long for the
file name.
Change-Id: I25dea55b3aa93b877d6b95404ef8b5f1cbeb9897
Diffstat (limited to 'src/com/android/calendar')
-rw-r--r-- | src/com/android/calendar/icalendar/IcalendarUtils.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/com/android/calendar/icalendar/IcalendarUtils.java b/src/com/android/calendar/icalendar/IcalendarUtils.java index efbb4583..ec96fc57 100644 --- a/src/com/android/calendar/icalendar/IcalendarUtils.java +++ b/src/com/android/calendar/icalendar/IcalendarUtils.java @@ -8,6 +8,8 @@ import android.content.ContentResolver; import android.content.Context; import android.net.Uri; import android.provider.CalendarContract; +import android.system.ErrnoException; +import android.system.OsConstants; import com.android.calendar.CalendarEventModel; import java.io.*; @@ -25,6 +27,8 @@ public class IcalendarUtils { public static int sPermittedLineLength = 75; // Line length mandated by iCalendar format private static final Random tempFileRandom = new Random(); + private static final String INVITE_FILE_NAME = "invite"; + public static String uncleanseString(CharSequence sequence) { if (sequence == null) return null; String input = sequence.toString(); @@ -94,11 +98,18 @@ public class IcalendarUtils { String tmpDir = System.getProperty("java.io.tmpdir", "."); tmpDirFile = new File(tmpDir); } - File result; - do { - result = new File(tmpDirFile, - prefix + tempFileRandom.nextInt(Integer.MAX_VALUE) + suffix); - } while (!result.createNewFile()); + File result = null; + try { + result = File.createTempFile(prefix, suffix, tmpDirFile); + } catch (IOException ioe) { + if (ioe.getCause() instanceof ErrnoException) { + if (((ErrnoException) ioe.getCause()).errno == OsConstants.ENAMETOOLONG) { + // This is a recoverable error the file name was too long, + // lets go for a smaller file name + result = File.createTempFile(INVITE_FILE_NAME, suffix, tmpDirFile); + } + } + } return result; } |