Clean up handling of Exchange setup option

* Use concrete declarations, not the old sample code
* Remove unused "sample" code
* Create ExchangeSender.java
* Strip out the unused (old sample code) parts of ExchangeStore.java
* Unit test to make sure EAS is being offered
* Fix "account leak" in AccountSettingsTests

This was triggered by donut bug # 2092944 but the solution is
different because we support EAS here.
This commit is contained in:
Andrew Stadler 2009-09-01 17:50:46 -07:00
parent e99e2824dc
commit 91a5cd517f
10 changed files with 98 additions and 786 deletions

View File

@ -31,7 +31,5 @@
<senders>
<sender scheme="smtp" class="com.android.email.mail.transport.SmtpSender" />
<!-- This is here for temporary demo purposes only. Do not ship with this. -->
<sender scheme="eas" class="com.android.email.mail.exchange.ExchangeSenderExample" />
<sender scheme="eas" class="com.android.email.mail.transport.ExchangeSender" />
</senders>

View File

@ -33,8 +33,6 @@
<store scheme="local" class="com.android.email.mail.store.LocalStore" />
<store scheme="pop3" class="com.android.email.mail.store.Pop3Store" />
<store scheme="imap" class="com.android.email.mail.store.ImapStore" />
<!-- This is here for temporary demo purposes only. Do not ship with this. -->
<store scheme="eas" class="com.android.email.mail.store.ExchangeStore"
push="true" visibleLimitDefault="-1" visibleLimitIncrement="-1" />
</stores>

View File

@ -1,172 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.email.mail.exchange;
import com.android.email.mail.FetchProfile;
import com.android.email.mail.Flag;
import com.android.email.mail.Folder;
import com.android.email.mail.Message;
import com.android.email.mail.MessageRetrievalListener;
import com.android.email.mail.MessagingException;
/**
* Sample code for implementing a new server folder. See also ExchangeStoreExample,
* ExchangeSenderExample, and ExchangeTransportExample.
*/
public class ExchangeFolderExample extends Folder {
private final ExchangeTransportExample mTransport;
private final ExchangeStoreExample mStore;
private final String mName;
private PersistentDataCallbacks mPersistenceCallbacks;
public ExchangeFolderExample(ExchangeStoreExample store, String name)
throws MessagingException {
mStore = store;
mTransport = store.getTransport();
mName = name;
if (!mTransport.isFolderAvailable(name)) {
throw new MessagingException("folder not supported: " + name);
}
}
@Override
public void appendMessages(Message[] messages) throws MessagingException {
// TODO Implement this function
}
@Override
public void close(boolean expunge) throws MessagingException {
mPersistenceCallbacks = null;
// TODO Implement this function
}
@Override
public void copyMessages(Message[] msgs, Folder folder, MessageUpdateCallbacks callbacks)
throws MessagingException {
// TODO Implement this function
}
@Override
public boolean create(FolderType type) throws MessagingException {
// TODO Implement this function
return false;
}
@Override
public void delete(boolean recurse) throws MessagingException {
// TODO Implement this function
}
@Override
public boolean exists() throws MessagingException {
// TODO Implement this function
return false;
}
@Override
public Message[] expunge() throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public void fetch(Message[] messages, FetchProfile fp, MessageRetrievalListener listener)
throws MessagingException {
// TODO Implement this function
}
@Override
public Message getMessage(String uid) throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public int getMessageCount() throws MessagingException {
// TODO Implement this function
return 0;
}
@Override
public Message[] getMessages(int start, int end, MessageRetrievalListener listener)
throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public Message[] getMessages(MessageRetrievalListener listener) throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public Message[] getMessages(String[] uids, MessageRetrievalListener listener)
throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public OpenMode getMode() throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public String getName() {
// TODO Implement this function
return null;
}
@Override
public Flag[] getPermanentFlags() throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public int getUnreadMessageCount() throws MessagingException {
// TODO Implement this function
return 0;
}
@Override
public boolean isOpen() {
// TODO Implement this function
return false;
}
@Override
public void open(OpenMode mode, PersistentDataCallbacks callbacks) throws MessagingException {
mPersistenceCallbacks = callbacks;
// TODO Implement this function
}
@Override
public void setFlags(Message[] messages, Flag[] flags, boolean value) throws MessagingException {
// TODO Implement this function
}
@Override
public Message createMessage(String uid) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,99 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.email.mail.exchange;
import com.android.email.mail.Message;
import com.android.email.mail.MessagingException;
import com.android.email.mail.Sender;
import android.content.Context;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Sample code for implementing a new Sender. See also ExchangeSenderExample,
* ExchangeFolderExample, and ExchangeTransportExample.
*
* To enable this placeholder, please add:
* <sender scheme="eas" class="com.android.email.mail.exchange.ExchangeSenderExample" />
* to res/xml/senders.xml
*/
public class ExchangeSenderExample extends Sender {
private final Context mContext;
private final ExchangeTransportExample mTransport;
/**
* Factory method.
*/
public static Sender newInstance(Context context, String uri) throws MessagingException {
return new ExchangeSenderExample(context, uri);
}
private ExchangeSenderExample(Context context, String _uri) throws MessagingException {
mContext = context;
URI uri = null;
try {
uri = new URI(_uri);
} catch (URISyntaxException e) {
throw new MessagingException("Invalid uri for ExchangeSenderExample");
}
String scheme = uri.getScheme();
int connectionSecurity;
if (scheme.equals("eas")) {
connectionSecurity = ExchangeTransportExample.CONNECTION_SECURITY_NONE;
} else if (scheme.equals("eas+ssl+")) {
connectionSecurity = ExchangeTransportExample.CONNECTION_SECURITY_SSL_REQUIRED;
} else {
throw new MessagingException("Unsupported protocol");
}
mTransport = ExchangeTransportExample.getInstance(uri, context);
}
@Override
public void close() throws MessagingException {
// TODO Auto-generated method stub
}
@Override
public void open() throws MessagingException {
// TODO Auto-generated method stub
}
@Override
public void sendMessage(long messageId) throws MessagingException {
// TODO Auto-generated method stub
}
/**
* Get class of SettingActivity for this Sender class.
* @return Activity class that has class method actionEditOutgoingSettings(), or null if
* outgoing settings should not be presented (e.g. they're handled by the incoming settings
* screen).
*/
@Override
public Class<? extends android.app.Activity> getSettingActivityClass() {
return null;
}
}

View File

@ -1,163 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.email.mail.exchange;
import com.android.email.Email;
import com.android.email.mail.Folder;
import com.android.email.mail.MessagingException;
import com.android.email.mail.Store;
import com.android.email.mail.StoreSynchronizer;
import android.content.Context;
import android.util.Config;
import android.util.Log;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
/**
* This is a placeholder for use in Exchange implementations. It is based on the notion of
* lightweight adapter classes for Store, Folder, and Sender, and a common facade for the common
* Transport code.
*
* To enable this placeholder, please add:
* <store scheme="eas" class="com.android.email.mail.exchange.ExchangeStoreExample" />
* to res/xml/stores.xml
*/
public class ExchangeStoreExample extends Store {
public static final String LOG_TAG = "ExchangeStoreExample";
private final Context mContext;
private URI mUri;
private PersistentDataCallbacks mCallbacks;
private final ExchangeTransportExample mTransport;
private final HashMap<String, Folder> mFolders = new HashMap<String, Folder>();
/**
* Factory method.
*/
public static Store newInstance(String uri, Context context, PersistentDataCallbacks callbacks)
throws MessagingException {
return new ExchangeStoreExample(uri, context, callbacks);
}
/**
* eas://user:password@server/domain
*
* @param _uri
* @param application
* @throws MessagingException
*/
private ExchangeStoreExample(String _uri, Context context, PersistentDataCallbacks callbacks)
throws MessagingException {
mContext = context;
try {
mUri = new URI(_uri);
} catch (URISyntaxException e) {
throw new MessagingException("Invalid uri for ExchangeStoreExample");
}
mCallbacks = callbacks;
String scheme = mUri.getScheme();
int connectionSecurity;
if (scheme.equals("eas")) {
connectionSecurity = ExchangeTransportExample.CONNECTION_SECURITY_NONE;
} else if (scheme.equals("eas+ssl+")) {
connectionSecurity = ExchangeTransportExample.CONNECTION_SECURITY_SSL_REQUIRED;
} else {
throw new MessagingException("Unsupported protocol");
}
mTransport = ExchangeTransportExample.getInstance(mUri, context);
}
/**
* Retrieve the underlying transport. Used primarily for testing.
* @return
*/
/* package */ ExchangeTransportExample getTransport() {
return mTransport;
}
@Override
public void checkSettings() throws MessagingException {
mTransport.checkSettings(mUri);
}
@Override
public Folder getFolder(String name) throws MessagingException {
synchronized (mFolders) {
Folder folder = mFolders.get(name);
if (folder == null) {
folder = new ExchangeFolderExample(this, name);
mFolders.put(folder.getName(), folder);
}
return folder;
}
}
@Override
public Folder[] getPersonalNamespaces() throws MessagingException {
return new Folder[] {
getFolder(ExchangeTransportExample.FOLDER_INBOX),
};
}
/**
* Get class of SettingActivity for this Store class.
* @return Activity class that has class method actionEditIncomingSettings().
*/
@Override
public Class<? extends android.app.Activity> getSettingActivityClass() {
return com.android.email.activity.setup.AccountSetupExchange.class;
}
/**
* Get class of sync'er for this Store class. Because exchange Sync rules are so different
* than IMAP or POP3, it's likely that an Exchange implementation will need its own sync
* controller. If so, this function must return a non-null value.
*
* @return Message Sync controller, or null to use default
*/
@Override
public StoreSynchronizer getMessageSynchronizer() {
return null;
}
/**
* Inform MessagingController that this store requires message structures to be prefetched
* before it can fetch message bodies (this is due to EAS protocol restrictions.)
* @return always true for EAS
*/
@Override
public boolean requireStructurePrefetch() {
return true;
}
/**
* Inform MessagingController that messages sent via EAS will be placed in the Sent folder
* automatically (server-side) and don't need to be uploaded.
* @return always false for EAS (assuming server-side copy is supported)
*/
@Override
public boolean requireCopyMessageToSentFolder() {
return false;
}
}

View File

@ -1,121 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.email.mail.exchange;
import com.android.email.Email;
import com.android.email.mail.MessagingException;
import android.content.Context;
import android.text.TextUtils;
import java.net.URI;
import java.util.HashMap;
/**
* Sample code for implementing a new server transport. See also ExchangeStoreExample,
* ExchangeFolderExample, and ExchangeSenderExample.
*/
public class ExchangeTransportExample {
public static final int CONNECTION_SECURITY_NONE = 0;
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 1;
public static final String FOLDER_INBOX = Email.INBOX;
private static final String TAG = "ExchangeTransportExample";
private final Context mContext;
private String mHost;
private String mDomain;
private String mUsername;
private String mPassword;
private static HashMap<String, ExchangeTransportExample> sUriToInstanceMap =
new HashMap<String, ExchangeTransportExample>();
private static final HashMap<String, Integer> sFolderMap = new HashMap<String, Integer>();
/**
* Public factory. The transport should be a singleton (per Uri)
*/
public synchronized static ExchangeTransportExample getInstance(URI uri, Context context)
throws MessagingException {
if (!uri.getScheme().equals("eas") && !uri.getScheme().equals("eas+ssl+")) {
throw new MessagingException("Invalid scheme");
}
final String key = uri.toString();
ExchangeTransportExample transport = sUriToInstanceMap.get(key);
if (transport == null) {
transport = new ExchangeTransportExample(uri, context);
sUriToInstanceMap.put(key, transport);
}
return transport;
}
/**
* Private constructor - use public factory.
*/
private ExchangeTransportExample(URI uri, Context context) throws MessagingException {
mContext = context;
setUri(uri);
}
/**
* Use the Uri to set up a newly-constructed transport
* @param uri
* @throws MessagingException
*/
private void setUri(final URI uri) throws MessagingException {
mHost = uri.getHost();
if (mHost == null) {
throw new MessagingException("host not specified");
}
mDomain = uri.getPath();
if (!TextUtils.isEmpty(mDomain)) {
mDomain = mDomain.substring(1);
}
final String userInfo = uri.getUserInfo();
if (userInfo == null) {
throw new MessagingException("user information not specifed");
}
final String[] uinfo = userInfo.split(":", 2);
if (uinfo.length != 2) {
throw new MessagingException("user name and password not specified");
}
mUsername = uinfo[0];
mPassword = uinfo[1];
}
/**
* Blocking call that checks for a useable server connection, credentials, etc.
* @param uri the server/account to try and connect to
* @throws MessagingException thrown if the connection, server, account are not useable
*/
public void checkSettings(URI uri) throws MessagingException {
setUri(uri);
}
/**
* Typical helper function: Return existence of a given folder
*/
public boolean isFolderAvailable(final String folder) {
return sFolderMap.containsKey(folder);
}
}

View File

@ -16,13 +16,8 @@
package com.android.email.mail.store;
import com.android.email.Email;
import com.android.email.mail.AuthenticationFailedException;
import com.android.email.mail.FetchProfile;
import com.android.email.mail.Flag;
import com.android.email.mail.Folder;
import com.android.email.mail.Message;
import com.android.email.mail.MessageRetrievalListener;
import com.android.email.mail.MessagingException;
import com.android.email.mail.Store;
import com.android.email.mail.StoreSynchronizer;
@ -44,25 +39,22 @@ import java.net.URISyntaxException;
import java.util.HashMap;
/**
* This is a placeholder for use in Exchange implementations. It is based on the notion of
* lightweight adapter classes for Store, Folder, and Sender, and a common facade for the common
* Transport code.
* Our Exchange service does not use the sender/store model. This class exists for exactly two
* purposes, (1) to provide a hook for checking account connections, and (2) to return
* "AccountSetupExchange.class" for getSettingActivityClass().
*/
public class ExchangeStore extends Store {
public static final String LOG_TAG = "ExchangeStore";
private final Context mContext;
private Context mContext;
private URI mUri;
private PersistentDataCallbacks mCallbacks;
private final ExchangeTransport mTransport;
private final HashMap<String, Folder> mFolders = new HashMap<String, Folder>();
/**
* Factory method.
*/
public static Store newInstance(String uri, Context context, PersistentDataCallbacks callbacks)
throws MessagingException {
throws MessagingException {
return new ExchangeStore(uri, context, callbacks);
}
@ -71,7 +63,6 @@ public class ExchangeStore extends Store {
*
* @param _uri
* @param application
* @throws MessagingException
*/
private ExchangeStore(String _uri, Context context, PersistentDataCallbacks callbacks)
throws MessagingException {
@ -81,29 +72,10 @@ public class ExchangeStore extends Store {
} catch (URISyntaxException e) {
throw new MessagingException("Invalid uri for ExchangeStore");
}
mCallbacks = callbacks;
String scheme = mUri.getScheme();
int connectionSecurity;
if (scheme.equals("eas")) {
connectionSecurity = ExchangeTransport.CONNECTION_SECURITY_NONE;
} else if (scheme.equals("eas+ssl+")) {
connectionSecurity = ExchangeTransport.CONNECTION_SECURITY_SSL_REQUIRED;
} else {
throw new MessagingException("Unsupported protocol");
}
mTransport = ExchangeTransport.getInstance(mUri, context);
}
/**
* Retrieve the underlying transport. Used primarily for testing.
* @return
*/
/* package */ ExchangeTransport getTransport() {
return mTransport;
}
@Override
public void checkSettings() throws MessagingException {
mTransport.checkSettings(mUri);
@ -125,22 +97,13 @@ public class ExchangeStore extends Store {
}
@Override
public Folder getFolder(String name) throws MessagingException {
synchronized (mFolders) {
Folder folder = mFolders.get(name);
if (folder == null) {
folder = new ExchangeFolder(this, name);
mFolders.put(folder.getName(), folder);
}
return folder;
}
public Folder getFolder(String name) {
return null;
}
@Override
public Folder[] getPersonalNamespaces() throws MessagingException {
return new Folder[] {
getFolder(ExchangeTransport.FOLDER_INBOX),
};
public Folder[] getPersonalNamespaces() {
return null;
}
/**
@ -185,12 +148,6 @@ public class ExchangeStore extends Store {
}
public static class ExchangeTransport {
public static final int CONNECTION_SECURITY_NONE = 0;
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 1;
public static final String FOLDER_INBOX = Email.INBOX;
private static final String TAG = "ExchangeTransport";
private final Context mContext;
private String mHost;
@ -278,164 +235,6 @@ public class ExchangeStore extends Store {
throw new MessagingException("Call to validate generated an exception", e);
}
}
/**
* Typical helper function: Return existence of a given folder
*/
public boolean isFolderAvailable(final String folder) {
return sFolderMap.containsKey(folder);
}
}
public static class ExchangeFolder extends Folder {
private final ExchangeTransport mTransport;
@SuppressWarnings("unused")
private final ExchangeStore mStore;
@SuppressWarnings("unused")
private final String mName;
@SuppressWarnings("unused")
private PersistentDataCallbacks mPersistenceCallbacks;
public ExchangeFolder(ExchangeStore store, String name)
throws MessagingException {
mStore = store;
mTransport = store.getTransport();
mName = name;
if (!mTransport.isFolderAvailable(name)) {
throw new MessagingException("folder not supported: " + name);
}
}
@Override
public void appendMessages(Message[] messages) throws MessagingException {
// TODO Implement this function
}
@Override
public void close(boolean expunge) throws MessagingException {
mPersistenceCallbacks = null;
// TODO Implement this function
}
@Override
public void copyMessages(Message[] msgs, Folder folder, MessageUpdateCallbacks callbacks)
throws MessagingException {
// TODO Implement this function
}
@Override
public boolean create(FolderType type) throws MessagingException {
// TODO Implement this function
return false;
}
@Override
public void delete(boolean recurse) throws MessagingException {
// TODO Implement this function
}
@Override
public boolean exists() throws MessagingException {
// TODO Implement this function
return false;
}
@Override
public Message[] expunge() throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public void fetch(Message[] messages, FetchProfile fp, MessageRetrievalListener listener)
throws MessagingException {
// TODO Implement this function
}
@Override
public Message getMessage(String uid) throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public int getMessageCount() throws MessagingException {
// TODO Implement this function
return 0;
}
@Override
public Message[] getMessages(int start, int end, MessageRetrievalListener listener)
throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public Message[] getMessages(MessageRetrievalListener listener) throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public Message[] getMessages(String[] uids, MessageRetrievalListener listener)
throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public OpenMode getMode() throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public String getName() {
// TODO Implement this function
return null;
}
@Override
public Flag[] getPermanentFlags() throws MessagingException {
// TODO Implement this function
return null;
}
@Override
public int getUnreadMessageCount() throws MessagingException {
// TODO Implement this function
return 0;
}
@Override
public boolean isOpen() {
// TODO Implement this function
return false;
}
@Override
public void open(OpenMode mode, PersistentDataCallbacks callbacks)
throws MessagingException {
mPersistenceCallbacks = callbacks;
// TODO Implement this function
}
@Override
public void setFlags(Message[] messages, Flag[] flags, boolean value)
throws MessagingException {
// TODO Implement this function
}
@Override
public Message createMessage(String uid) {
// TODO Auto-generated method stub
return null;
}
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.email.mail.transport;
import com.android.email.mail.Sender;
import android.content.Context;
/**
* Our Exchange service does not use the sender/store model. This class exists for exactly one
* purpose, which is to return "null" for getSettingActivityClass().
*/
public class ExchangeSender extends Sender {
/**
* Factory method.
*/
public static Sender newInstance(Context context, String uri) {
return new ExchangeSender(context, uri);
}
private ExchangeSender(Context context, String _uri) {
}
@Override
public void close() {
}
@Override
public void open() {
}
@Override
public void sendMessage(long messageId) {
}
/**
* Get class of SettingActivity for this Sender class.
* @return Activity class that has class method actionEditOutgoingSettings(), or null if
* outgoing settings should not be presented (e.g. they're handled by the incoming settings
* screen).
*/
@Override
public Class<? extends android.app.Activity> getSettingActivityClass() {
return null;
}
}

View File

@ -18,6 +18,7 @@ package com.android.email.activity.setup;
import com.android.email.mail.Store;
import com.android.email.provider.EmailContent;
import com.android.email.provider.EmailContent.Account;
import android.content.ContentUris;
import android.content.Context;
@ -37,7 +38,7 @@ public class AccountSettingsTests extends ActivityInstrumentationTestCase2<Accou
private static final String EXTRA_ACCOUNT_ID = "account_id";
private long mAccountId;
private EmailContent.Account mAccount;
private Account mAccount;
private Context mContext;
private AccountSettings mActivity;
@ -65,8 +66,7 @@ public class AccountSettingsTests extends ActivityInstrumentationTestCase2<Accou
@Override
protected void tearDown() throws Exception {
if (mAccount != null) {
Uri uri = ContentUris.withAppendedId(
EmailContent.Account.CONTENT_URI, mAccountId);
Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, mAccountId);
mContext.getContentResolver().delete(uri, null, null);
}
@ -84,7 +84,7 @@ public class AccountSettingsTests extends ActivityInstrumentationTestCase2<Accou
getActivityAndFields();
boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
boolean hasPush = frequencySpinnerHasValue(Account.CHECK_INTERVAL_PUSH);
assertFalse(hasPush);
}
@ -98,7 +98,7 @@ public class AccountSettingsTests extends ActivityInstrumentationTestCase2<Accou
getActivityAndFields();
boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
boolean hasPush = frequencySpinnerHasValue(Account.CHECK_INTERVAL_PUSH);
assertFalse(hasPush);
}
@ -118,7 +118,7 @@ public class AccountSettingsTests extends ActivityInstrumentationTestCase2<Accou
getActivityAndFields();
boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
boolean hasPush = frequencySpinnerHasValue(Account.CHECK_INTERVAL_PUSH);
assertTrue(hasPush);
}
@ -147,7 +147,7 @@ public class AccountSettingsTests extends ActivityInstrumentationTestCase2<Accou
* Create an intent with the Account in it
*/
private Intent getTestIntent(String name, String storeUri, String senderUri) {
EmailContent.Account mAccount = new EmailContent.Account();
mAccount = new Account();
mAccount.setSenderName(name);
// For EAS, at least, email address is required
mAccount.mEmailAddress = "user@server.com";

View File

@ -16,8 +16,10 @@
package com.android.email.activity.setup;
import com.android.email.R;
import com.android.email.mail.Store;
import com.android.email.provider.EmailContent;
import com.android.email.provider.EmailContent.Account;
import android.content.ContentUris;
import android.content.Context;
@ -25,13 +27,12 @@ import android.content.Intent;
import android.net.Uri;
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.View;
import java.util.HashSet;
/**
* This is a series of unit tests for the AccountSetupAccountType class.
*
* This is just unit tests of simple calls - the activity is not instantiated
*/
@SmallTest
public class AccountSetupAccountTypeUnitTests
@ -42,7 +43,7 @@ public class AccountSetupAccountTypeUnitTests
Context mContext;
private HashSet<EmailContent.Account> mAccounts = new HashSet<EmailContent.Account>();
private HashSet<Account> mAccounts = new HashSet<Account>();
public AccountSetupAccountTypeUnitTests() {
super(AccountSetupAccountType.class);
@ -60,9 +61,8 @@ public class AccountSetupAccountTypeUnitTests
*/
@Override
protected void tearDown() throws Exception {
for (EmailContent.Account account : mAccounts) {
Uri uri = ContentUris.withAppendedId(
EmailContent.Account.CONTENT_URI, account.mId);
for (Account account : mAccounts) {
Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, account.mId);
mContext.getContentResolver().delete(uri, null, null);
}
@ -94,12 +94,22 @@ public class AccountSetupAccountTypeUnitTests
info.mAccountInstanceLimit = 2;
assertFalse("limit, reached", activity.checkAccountInstanceLimit(info));
}
/**
* Confirm that EAS is presented (supported in this release)
*/
public void testEasOffered() {
Account acct1 = createTestAccount("scheme1");
AccountSetupAccountType activity = startActivity(getTestIntent(acct1), null, null);
View exchangeButton = activity.findViewById(R.id.exchange);
assertEquals(View.VISIBLE, exchangeButton.getVisibility());
}
/**
* Create a dummy account with minimal fields
*/
private EmailContent.Account createTestAccount(String scheme) {
EmailContent.Account account = new EmailContent.Account();
private Account createTestAccount(String scheme) {
Account account = new Account();
account.setStoreUri(mContext, scheme + "://user:pass@server.com:123");
account.save(mContext);
mAccounts.add(account);