DO NOT MERGE: Add static method to get temp dir in Email.
I need to be able to get the temp dir from anywhere without Context for the new IMAP parser. Backport of I3bf7d34059399a8253c0760ebc392804ea434412 Change-Id: Idf7f8dffe9d6dd040d1b2311d053d4fc292ba18e
This commit is contained in:
parent
550aa6163f
commit
7040017624
|
@ -174,6 +174,8 @@ public class Email extends Application {
|
|||
0x9d50a4,
|
||||
};
|
||||
|
||||
private static File sTempDirectory;
|
||||
|
||||
/* package for testing */ static int getColorIndexFromAccountId(long accountId) {
|
||||
// Account id is 1-based, so - 1.
|
||||
// Use abs so that it won't possibly return negative.
|
||||
|
@ -188,6 +190,13 @@ public class Email extends Application {
|
|||
return ACCOUNT_COLOR_CHIP_RGBS[getColorIndexFromAccountId(accountId)];
|
||||
}
|
||||
|
||||
public static File getTempDirectory() {
|
||||
if (sTempDirectory == null) {
|
||||
throw new RuntimeException("TempDirectory not set. Application hasn't started??");
|
||||
}
|
||||
return sTempDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called throughout the application when the number of accounts has changed. This method
|
||||
* enables or disables the Compose activity, the boot receiver and the service based on
|
||||
|
@ -256,16 +265,11 @@ public class Email extends Application {
|
|||
Preferences prefs = Preferences.getPreferences(this);
|
||||
DEBUG = prefs.getEnableDebugLogging();
|
||||
DEBUG_SENSITIVE = prefs.getEnableSensitiveLogging();
|
||||
sTempDirectory = getCacheDir();
|
||||
|
||||
// Reset all accounts to default visible window
|
||||
Controller.getInstance(this).resetVisibleLimits();
|
||||
|
||||
/*
|
||||
* We have to give MimeMessage a temp directory because File.createTempFile(String, String)
|
||||
* doesn't work in Android and MimeMessage does not have access to a Context.
|
||||
*/
|
||||
BinaryTempFileBody.setTempDirectory(getCacheDir());
|
||||
|
||||
// Enable logging in the EAS service, so it starts up as early as possible.
|
||||
Debug.updateLoggingFlags(this);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.android.email.mail.internet;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.mail.Body;
|
||||
import com.android.email.mail.MessagingException;
|
||||
|
||||
|
@ -39,21 +40,8 @@ import java.io.OutputStream;
|
|||
* getInputStream is closed the file is deleted and the Body should be considered disposed of.
|
||||
*/
|
||||
public class BinaryTempFileBody implements Body {
|
||||
private static File mTempDirectory;
|
||||
|
||||
private File mFile;
|
||||
|
||||
public static void setTempDirectory(File tempDirectory) {
|
||||
mTempDirectory = tempDirectory;
|
||||
}
|
||||
|
||||
public BinaryTempFileBody() throws IOException {
|
||||
if (mTempDirectory == null) {
|
||||
throw new
|
||||
RuntimeException("setTempDirectory has not been called on BinaryTempFileBody!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An alternate way to put data into a BinaryTempFileBody is to simply supply an already-
|
||||
* created file. Note that this file will be deleted after it is read.
|
||||
|
@ -64,7 +52,7 @@ public class BinaryTempFileBody implements Body {
|
|||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
mFile = File.createTempFile("body", null, mTempDirectory);
|
||||
mFile = File.createTempFile("body", null, Email.getTempDirectory());
|
||||
mFile.deleteOnExit();
|
||||
return new FileOutputStream(mFile);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package com.android.email.activity;
|
|||
import com.android.email.Email;
|
||||
import com.android.email.MessagingController;
|
||||
import com.android.email.R;
|
||||
import com.android.email.mail.internet.BinaryTempFileBody;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
@ -84,9 +83,6 @@ public class MessageViewTests
|
|||
mToView = (TextView) a.findViewById(R.id.to);
|
||||
mSubjectView = (TextView) a.findViewById(R.id.subject);
|
||||
mMessageContentView = (WebView) a.findViewById(R.id.message_content);
|
||||
|
||||
// This is needed for mime image bodypart.
|
||||
BinaryTempFileBody.setTempDirectory(getActivity().getCacheDir());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,9 +66,6 @@ public class EmailHtmlUtilTest extends AndroidTestCase {
|
|||
mCreatedAccountId = accountId;
|
||||
}
|
||||
Account.restoreAccountWithId(context, accountId);
|
||||
|
||||
// This is needed for mime image bodypart.
|
||||
BinaryTempFileBody.setTempDirectory(getContext().getCacheDir());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,7 +27,6 @@ import com.android.email.mail.Transport;
|
|||
import com.android.email.mail.Folder.FolderType;
|
||||
import com.android.email.mail.Folder.OpenMode;
|
||||
import com.android.email.mail.Message.RecipientType;
|
||||
import com.android.email.mail.internet.BinaryTempFileBody;
|
||||
import com.android.email.mail.internet.MimeUtility;
|
||||
import com.android.email.mail.internet.TextBody;
|
||||
import com.android.email.mail.store.ImapStore.ImapMessage;
|
||||
|
@ -71,9 +70,6 @@ public class ImapStoreUnitTests extends AndroidTestCase {
|
|||
mStore = (ImapStore) ImapStore.newInstance("imap://user:password@server:999",
|
||||
getContext(), null);
|
||||
mFolder = (ImapStore.ImapFolder) mStore.getFolder("INBOX");
|
||||
|
||||
// This is needed for parsing mime messages
|
||||
BinaryTempFileBody.setTempDirectory(this.getContext().getCacheDir());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,6 @@ import com.android.email.mail.Folder.FolderType;
|
|||
import com.android.email.mail.Folder.OpenMode;
|
||||
import com.android.email.mail.Message.RecipientType;
|
||||
import com.android.email.mail.MessageTestUtils.MultipartBuilder;
|
||||
import com.android.email.mail.internet.BinaryTempFileBody;
|
||||
import com.android.email.mail.internet.MimeMessage;
|
||||
import com.android.email.mail.internet.MimeUtility;
|
||||
import com.android.email.mail.internet.TextBody;
|
||||
|
@ -89,10 +88,6 @@ public class LocalStoreUnitTests extends AndroidTestCase {
|
|||
|
||||
mStore = (LocalStore) LocalStore.newInstance(mLocalStoreUri, getContext(), null);
|
||||
mFolder = (LocalStore.LocalFolder) mStore.getFolder(FOLDER_NAME);
|
||||
|
||||
// This is needed for parsing mime messages
|
||||
mCacheDir = getContext().getCacheDir();
|
||||
BinaryTempFileBody.setTempDirectory(mCacheDir);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,6 @@ import com.android.email.mail.Transport;
|
|||
import com.android.email.mail.Folder.FolderType;
|
||||
import com.android.email.mail.Folder.OpenMode;
|
||||
import com.android.email.mail.Message.RecipientType;
|
||||
import com.android.email.mail.internet.BinaryTempFileBody;
|
||||
import com.android.email.mail.internet.MimeMessage;
|
||||
import com.android.email.mail.transport.MockTransport;
|
||||
|
||||
|
@ -59,9 +58,6 @@ public class Pop3StoreUnitTests extends AndroidTestCase {
|
|||
mStore = (Pop3Store) Pop3Store.newInstance("pop3://user:password@server:999",
|
||||
getContext(), null);
|
||||
mFolder = (Pop3Store.Pop3Folder) mStore.getFolder("INBOX");
|
||||
|
||||
// This is needed for parsing mime messages
|
||||
BinaryTempFileBody.setTempDirectory(this.getContext().getCacheDir());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue