Add android.permission.WRITE_EXTERNAL_STORAGE

Add unit test to verify writeable to sdcard.

Fixed bug http://b/issue?id=1883487
This commit is contained in:
Andrew Stadler 2009-06-04 15:16:43 -07:00
parent a15503a4a6
commit a392e070bc
3 changed files with 31 additions and 13 deletions

View File

@ -22,6 +22,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Only required if a store implements push mail and needs to keep network open -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>

View File

@ -541,7 +541,7 @@ public class MessageView extends Activity
* @param filename
* @return a new File object, or null if one could not be created
*/
private File createUniqueFile(File directory, String filename) {
/* package */ static File createUniqueFile(File directory, String filename) {
File file = new File(directory, filename);
if (!file.exists()) {
return file;

View File

@ -21,30 +21,23 @@ import com.android.email.Email;
import com.android.email.MessagingController;
import com.android.email.Preferences;
import com.android.email.R;
import com.android.email.mail.MessageTestUtils;
import com.android.email.mail.Message;
import com.android.email.mail.MessagingException;
import com.android.email.mail.MessageTestUtils.MessageBuilder;
import com.android.email.mail.MessageTestUtils.MultipartBuilder;
import com.android.email.mail.MessageTestUtils.TextBuilder;
import com.android.email.mail.internet.BinaryTempFileBody;
import com.android.email.mail.internet.EmailHtmlUtil;
import com.android.email.mail.store.LocalStore;
import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Environment;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.Suppress;
import android.util.Log;
import android.webkit.WebView;
import android.widget.TextView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
@ -134,6 +127,30 @@ public class MessageViewTests
assertNotNull(mMessageContentView);
}
/**
* Test that we have the necessary permissions to write to external storage.
*/
public void testAttachmentWritePermissions() throws FileNotFoundException, IOException {
File file = null;
try {
file = MessageView.createUniqueFile(Environment.getExternalStorageDirectory(),
"write-test");
OutputStream out = new FileOutputStream(file);
out.write(1);
out.close();
} finally {
try {
if (file != null) {
if (file.exists()) {
file.delete();
}
}
} catch (Exception e) {
// ignore cleanup error - it still throws the original
}
}
}
/**
* Tests that various UI calls can be made safely even before the messaging controller
* has completed loading the message. This catches various race conditions.