Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd856bf8 authored by Raj Yengisetty's avatar Raj Yengisetty Committed by Jochen Sprickerhof
Browse files

Calendar: Use FIle.createTempFIle when sharing calendar events

Also handle ENAMETOOLONG when the event title is too long for the
file name.

Change-Id: I25dea55b3aa93b877d6b95404ef8b5f1cbeb9897
(cherry picked from commit 79c84ff)
parent 64088419
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -20,6 +20,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.*;
@@ -37,6 +39,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();
@@ -106,11 +110,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;
    }