Remove storeUri's except during auto-setup
* Remove per-store limitations * Use constants for VISIBLE_WINDOW, rather than having the potential for differences between Stores Change-Id: Idd5e0874bba6e3390e4f093bcb03f4b1bb399c11
This commit is contained in:
parent
0a5ed251f5
commit
85e4c101b0
|
@ -1392,46 +1392,6 @@ public abstract class EmailContent {
|
|||
return mCompatibilityUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* For compatibility while converting to provider model, generate a "store URI"
|
||||
*
|
||||
* @return a string in the form of a Uri, as used by the other parts of the email app
|
||||
*/
|
||||
public String getStoreUri(Context context) {
|
||||
// reconstitute if necessary
|
||||
if (mHostAuthRecv == null) {
|
||||
mHostAuthRecv = HostAuth.restoreHostAuthWithId(context, mHostAuthKeyRecv);
|
||||
}
|
||||
// convert if available
|
||||
if (mHostAuthRecv != null) {
|
||||
String storeUri = mHostAuthRecv.getStoreUri();
|
||||
if (storeUri != null) {
|
||||
return storeUri;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* For compatibility while converting to provider model, generate a "sender URI"
|
||||
*
|
||||
* @return a string in the form of a Uri, as used by the other parts of the email app
|
||||
*/
|
||||
public String getSenderUri(Context context) {
|
||||
// reconstitute if necessary
|
||||
if (mHostAuthSend == null) {
|
||||
mHostAuthSend = HostAuth.restoreHostAuthWithId(context, mHostAuthKeySend);
|
||||
}
|
||||
// convert if available
|
||||
if (mHostAuthSend != null) {
|
||||
String senderUri = mHostAuthSend.getStoreUri();
|
||||
if (senderUri != null) {
|
||||
return senderUri;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public HostAuth getOrCreateHostAuthSend(Context context) {
|
||||
if (mHostAuthSend == null) {
|
||||
if (mHostAuthKeySend != 0) {
|
||||
|
|
|
@ -195,66 +195,6 @@ public final class HostAuth extends EmailContent implements HostAuthColumns, Par
|
|||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* For compatibility while converting to provider model, generate a "store URI"
|
||||
* TODO cache this so we don't rebuild every time
|
||||
*
|
||||
* @return a string in the form of a Uri, as used by the other parts of the email app
|
||||
*/
|
||||
public String getStoreUri() {
|
||||
String userInfo = null;
|
||||
if ((mFlags & FLAG_AUTHENTICATE) != 0) {
|
||||
String trimUser = (mLogin != null) ? mLogin.trim() : "";
|
||||
String password = (mPassword != null) ? mPassword : "";
|
||||
userInfo = trimUser + ":" + password;
|
||||
}
|
||||
String scheme = getSchemeString(mProtocol, mFlags);
|
||||
String address = (mAddress != null) ? mAddress.trim() : null;
|
||||
String path = (mDomain != null) ? "/" + mDomain : null;
|
||||
|
||||
URI uri;
|
||||
try {
|
||||
uri = new URI(
|
||||
scheme,
|
||||
userInfo,
|
||||
address,
|
||||
mPort,
|
||||
path,
|
||||
null,
|
||||
null);
|
||||
return uri.toString();
|
||||
} catch (URISyntaxException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy URI parser. Used in one of three different scenarios:
|
||||
* 1. Backup / Restore of account
|
||||
* 2. Parsing template from provider.xml
|
||||
* 3. Forcefully creating URI for test
|
||||
* Example string:
|
||||
* "eas+ssl+trustallcerts://user:password@server/domain:123"
|
||||
*
|
||||
* Note that the use of client certificate is specified in the URI, a secure connection type
|
||||
* must be used.
|
||||
*/
|
||||
public static void setHostAuthFromString(HostAuth auth, String uriString)
|
||||
throws URISyntaxException {
|
||||
URI uri = new URI(uriString);
|
||||
String path = uri.getPath();
|
||||
String domain = null;
|
||||
if (!TextUtils.isEmpty(path)) {
|
||||
// Strip off the leading slash that begins the path.
|
||||
domain = path.substring(1);
|
||||
}
|
||||
auth.mDomain = domain;
|
||||
auth.setLogin(uri.getUserInfo());
|
||||
|
||||
String scheme = uri.getScheme();
|
||||
auth.setConnection(scheme, uri.getHost(), uri.getPort());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user name and password from URI user info string
|
||||
*/
|
||||
|
@ -298,27 +238,6 @@ public final class HostAuth extends EmailContent implements HostAuthColumns, Par
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the connection values of the auth structure per the given scheme, host and port.
|
||||
*/
|
||||
public void setConnection(String scheme, String host, int port) {
|
||||
String[] schemeParts = scheme.split("\\+");
|
||||
String protocol = schemeParts[0];
|
||||
String clientCertAlias = null;
|
||||
int flags = getSchemeFlags(scheme);
|
||||
|
||||
// Example scheme: "eas+ssl+trustallcerts" or "eas+tls+trustallcerts+client-cert-alias"
|
||||
if (schemeParts.length > 3) {
|
||||
clientCertAlias = schemeParts[3];
|
||||
} else if (schemeParts.length > 2) {
|
||||
if (!SCHEME_TRUST_ALL_CERTS.equals(schemeParts[2])) {
|
||||
mClientCertAlias = schemeParts[2];
|
||||
}
|
||||
}
|
||||
|
||||
setConnection(protocol, host, port, flags, clientCertAlias);
|
||||
}
|
||||
|
||||
public void setConnection(String protocol, String address, int port, int flags) {
|
||||
setConnection(protocol, address, port, flags, null);
|
||||
}
|
||||
|
@ -432,14 +351,6 @@ public final class HostAuth extends EmailContent implements HostAuthColumns, Par
|
|||
mClientCertAlias = in.readString();
|
||||
}
|
||||
|
||||
/**
|
||||
* For debugger support only - DO NOT use for code.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getStoreUri();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof HostAuth)) {
|
||||
|
@ -455,4 +366,50 @@ public final class HostAuth extends EmailContent implements HostAuthColumns, Par
|
|||
&& Utility.areStringsEqual(mDomain, that.mDomain)
|
||||
&& Utility.areStringsEqual(mClientCertAlias, that.mClientCertAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy URI parser. Used in parsing template from provider.xml
|
||||
* Example string:
|
||||
* "eas+ssl+trustallcerts://user:password@server/domain:123"
|
||||
*
|
||||
* Note that the use of client certificate is specified in the URI, a secure connection type
|
||||
* must be used.
|
||||
*/
|
||||
public static void setHostAuthFromString(HostAuth auth, String uriString)
|
||||
throws URISyntaxException {
|
||||
URI uri = new URI(uriString);
|
||||
String path = uri.getPath();
|
||||
String domain = null;
|
||||
if (!TextUtils.isEmpty(path)) {
|
||||
// Strip off the leading slash that begins the path.
|
||||
domain = path.substring(1);
|
||||
}
|
||||
auth.mDomain = domain;
|
||||
auth.setLogin(uri.getUserInfo());
|
||||
|
||||
String scheme = uri.getScheme();
|
||||
auth.setConnection(scheme, uri.getHost(), uri.getPort());
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy code for setting connection values from a "scheme" (see above)
|
||||
*/
|
||||
public void setConnection(String scheme, String host, int port) {
|
||||
String[] schemeParts = scheme.split("\\+");
|
||||
String protocol = schemeParts[0];
|
||||
String clientCertAlias = null;
|
||||
int flags = getSchemeFlags(scheme);
|
||||
|
||||
// Example scheme: "eas+ssl+trustallcerts" or "eas+tls+trustallcerts+client-cert-alias"
|
||||
if (schemeParts.length > 3) {
|
||||
clientCertAlias = schemeParts[3];
|
||||
} else if (schemeParts.length > 2) {
|
||||
if (!SCHEME_TRUST_ALL_CERTS.equals(schemeParts[2])) {
|
||||
mClientCertAlias = schemeParts[2];
|
||||
}
|
||||
}
|
||||
|
||||
setConnection(protocol, host, port, flags, clientCertAlias);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,21 @@
|
|||
|
||||
package com.android.email;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.email.mail.Store;
|
||||
import com.android.email.mail.store.Pop3Store.Pop3Message;
|
||||
import com.android.email.provider.AccountBackupRestore;
|
||||
|
@ -31,6 +46,7 @@ import com.android.emailcommon.provider.EmailContent.Body;
|
|||
import com.android.emailcommon.provider.EmailContent.MailboxColumns;
|
||||
import com.android.emailcommon.provider.EmailContent.Message;
|
||||
import com.android.emailcommon.provider.EmailContent.MessageColumns;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.android.emailcommon.service.EmailServiceStatus;
|
||||
import com.android.emailcommon.service.IEmailService;
|
||||
|
@ -41,21 +57,6 @@ import com.android.emailcommon.utility.EmailAsyncTask;
|
|||
import com.android.emailcommon.utility.Utility;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -642,18 +643,13 @@ public class Controller {
|
|||
null, null, null);
|
||||
while (c.moveToNext()) {
|
||||
long accountId = c.getLong(Account.ID_PROJECTION_COLUMN);
|
||||
Account account = Account.restoreAccountWithId(mProviderContext, accountId);
|
||||
if (account != null) {
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(
|
||||
account.getStoreUri(mProviderContext), mContext);
|
||||
if (info != null && info.mVisibleLimitDefault > 0) {
|
||||
int limit = info.mVisibleLimitDefault;
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(MailboxColumns.VISIBLE_LIMIT, limit);
|
||||
resolver.update(Mailbox.CONTENT_URI, cv,
|
||||
MailboxColumns.ACCOUNT_KEY + "=?",
|
||||
new String[] { Long.toString(accountId) });
|
||||
}
|
||||
String protocol = Account.getProtocol(mProviderContext, accountId);
|
||||
if (!HostAuth.SCHEME_EAS.equals(protocol)) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(MailboxColumns.VISIBLE_LIMIT, Email.VISIBLE_LIMIT_DEFAULT);
|
||||
resolver.update(Mailbox.CONTENT_URI, cv,
|
||||
MailboxColumns.ACCOUNT_KEY + "=?",
|
||||
new String[] { Long.toString(accountId) });
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
@ -683,19 +679,15 @@ public class Controller {
|
|||
if (account == null) {
|
||||
return;
|
||||
}
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(
|
||||
account.getStoreUri(mProviderContext), mContext);
|
||||
if (info != null && info.mVisibleLimitIncrement > 0) {
|
||||
// Use provider math to increment the field
|
||||
ContentValues cv = new ContentValues();;
|
||||
cv.put(EmailContent.FIELD_COLUMN_NAME, MailboxColumns.VISIBLE_LIMIT);
|
||||
cv.put(EmailContent.ADD_COLUMN_NAME, info.mVisibleLimitIncrement);
|
||||
Uri uri = ContentUris.withAppendedId(Mailbox.ADD_TO_FIELD_URI, mailboxId);
|
||||
mProviderContext.getContentResolver().update(uri, cv, null, null);
|
||||
// Trigger a refresh using the new, longer limit
|
||||
mailbox.mVisibleLimit += info.mVisibleLimitIncrement;
|
||||
mLegacyController.synchronizeMailbox(account, mailbox, mLegacyListener);
|
||||
}
|
||||
// Use provider math to increment the field
|
||||
ContentValues cv = new ContentValues();;
|
||||
cv.put(EmailContent.FIELD_COLUMN_NAME, MailboxColumns.VISIBLE_LIMIT);
|
||||
cv.put(EmailContent.ADD_COLUMN_NAME, Email.VISIBLE_LIMIT_INCREMENT);
|
||||
Uri uri = ContentUris.withAppendedId(Mailbox.ADD_TO_FIELD_URI, mailboxId);
|
||||
mProviderContext.getContentResolver().update(uri, cv, null, null);
|
||||
// Trigger a refresh using the new, longer limit
|
||||
mailbox.mVisibleLimit += Email.VISIBLE_LIMIT_INCREMENT;
|
||||
mLegacyController.synchronizeMailbox(account, mailbox, mLegacyListener);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -495,9 +495,7 @@ public class MessagingController implements Runnable {
|
|||
// 6. Determine the limit # of messages to download
|
||||
int visibleLimit = folder.mVisibleLimit;
|
||||
if (visibleLimit <= 0) {
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(mContext),
|
||||
mContext);
|
||||
visibleLimit = info.mVisibleLimitDefault;
|
||||
visibleLimit = Email.VISIBLE_LIMIT_DEFAULT;
|
||||
}
|
||||
|
||||
// 7. Create a list of messages to download
|
||||
|
|
|
@ -373,7 +373,4 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
* Respond to a click of the "Next" button. Concrete classes must implement.
|
||||
*/
|
||||
public abstract void onNext();
|
||||
|
||||
protected abstract URI getUri() throws URISyntaxException;
|
||||
|
||||
}
|
||||
|
|
|
@ -16,19 +16,6 @@
|
|||
|
||||
package com.android.email.activity.setup;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.R;
|
||||
import com.android.email.mail.Sender;
|
||||
import com.android.email.mail.Store;
|
||||
import com.android.emailcommon.AccountManagerTypes;
|
||||
import com.android.emailcommon.CalendarProviderStub;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
|
@ -47,7 +34,6 @@ import android.preference.CheckBoxPreference;
|
|||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.RingtonePreference;
|
||||
|
@ -55,6 +41,18 @@ import android.provider.ContactsContract;
|
|||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.R;
|
||||
import com.android.email.mail.Sender;
|
||||
import com.android.emailcommon.AccountManagerTypes;
|
||||
import com.android.emailcommon.CalendarProviderStub;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
|
||||
/**
|
||||
* Fragment containing the main logic for account settings. This also calls out to other
|
||||
* fragments for server settings.
|
||||
|
@ -419,10 +417,9 @@ public class AccountSettingsFragment extends PreferenceFragment {
|
|||
|
||||
mCheckFrequency = (ListPreference) findPreference(PREFERENCE_FREQUENCY);
|
||||
|
||||
// Before setting value, we may need to adjust the lists
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(mAccount.getStoreUri(mContext),
|
||||
mContext);
|
||||
if (info.mPushSupported) {
|
||||
// TODO Move protocol into Account to avoid retrieving the HostAuth (implicitly)
|
||||
String protocol = Account.getProtocol(mContext, mAccount.mId);
|
||||
if (HostAuth.SCHEME_EAS.equals(protocol)) {
|
||||
mCheckFrequency.setEntries(R.array.account_settings_check_frequency_entries_push);
|
||||
mCheckFrequency.setEntryValues(R.array.account_settings_check_frequency_values_push);
|
||||
}
|
||||
|
@ -442,7 +439,7 @@ public class AccountSettingsFragment extends PreferenceFragment {
|
|||
|
||||
// Add check window preference
|
||||
mSyncWindow = null;
|
||||
if (info.mVisibleLimitDefault == -1) {
|
||||
if (!HostAuth.SCHEME_EAS.equals(protocol)) {
|
||||
mSyncWindow = new ListPreference(mContext);
|
||||
mSyncWindow.setTitle(R.string.account_setup_options_mail_window_label);
|
||||
mSyncWindow.setEntries(R.array.account_settings_mail_window_entries);
|
||||
|
@ -466,7 +463,7 @@ public class AccountSettingsFragment extends PreferenceFragment {
|
|||
// Show "background attachments" for IMAP & EAS - hide it for POP3.
|
||||
mAccountBackgroundAttachments = (CheckBoxPreference)
|
||||
findPreference(PREFERENCE_BACKGROUND_ATTACHMENTS);
|
||||
if ("pop3".equals(mAccount.mHostAuthRecv.mProtocol)) {
|
||||
if (HostAuth.SCHEME_POP3.equals(mAccount.mHostAuthRecv.mProtocol)) {
|
||||
topCategory.removePreference(mAccountBackgroundAttachments);
|
||||
} else {
|
||||
mAccountBackgroundAttachments.setChecked(
|
||||
|
|
|
@ -16,24 +16,21 @@
|
|||
|
||||
package com.android.email.activity.setup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.email.ExchangeUtils;
|
||||
import com.android.email.R;
|
||||
import com.android.email.VendorPolicyLoader;
|
||||
import com.android.email.activity.ActivityHelper;
|
||||
import com.android.email.activity.UiUtilities;
|
||||
import com.android.email.mail.Store;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
|
||||
/**
|
||||
* Prompts the user to select an account type. The account type, along with the
|
||||
* passed in email address, password and makeDefault are then passed on to the
|
||||
|
@ -87,9 +84,10 @@ public class AccountSetupAccountType extends AccountSetupActivity implements OnC
|
|||
private void onPop() {
|
||||
Account account = SetupData.getAccount();
|
||||
HostAuth hostAuth = account.mHostAuthRecv;
|
||||
hostAuth.mProtocol = "pop3";
|
||||
hostAuth.mProtocol = HostAuth.SCHEME_POP3;
|
||||
hostAuth.mLogin = hostAuth.mLogin + "@" + hostAuth.mAddress;
|
||||
hostAuth.mAddress = AccountSettingsUtils.inferServerName(hostAuth.mAddress, "pop3", null);
|
||||
hostAuth.mAddress = AccountSettingsUtils.inferServerName(hostAuth.mAddress,
|
||||
HostAuth.SCHEME_POP3, null);
|
||||
SetupData.setCheckSettingsMode(SetupData.CHECK_INCOMING | SetupData.CHECK_OUTGOING);
|
||||
AccountSetupIncoming.actionIncomingSettings(this, SetupData.getFlowMode(), account);
|
||||
finish();
|
||||
|
@ -102,9 +100,10 @@ public class AccountSetupAccountType extends AccountSetupActivity implements OnC
|
|||
private void onImap() {
|
||||
Account account = SetupData.getAccount();
|
||||
HostAuth hostAuth = account.mHostAuthRecv;
|
||||
hostAuth.mProtocol = "imap";
|
||||
hostAuth.mProtocol = HostAuth.SCHEME_IMAP;
|
||||
hostAuth.mLogin = hostAuth.mLogin + "@" + hostAuth.mAddress;
|
||||
hostAuth.mAddress = AccountSettingsUtils.inferServerName(hostAuth.mAddress, "imap", null);
|
||||
hostAuth.mAddress = AccountSettingsUtils.inferServerName(hostAuth.mAddress,
|
||||
HostAuth.SCHEME_IMAP, null);
|
||||
// Delete policy must be set explicitly, because IMAP does not provide a UI selection
|
||||
// for it. This logic needs to be followed in the auto setup flow as well.
|
||||
account.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE);
|
||||
|
@ -120,11 +119,11 @@ public class AccountSetupAccountType extends AccountSetupActivity implements OnC
|
|||
private void onExchange() {
|
||||
Account account = SetupData.getAccount();
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
|
||||
recvAuth.setConnection(
|
||||
"eas", recvAuth.mAddress, recvAuth.mPort, recvAuth.mFlags | HostAuth.FLAG_SSL);
|
||||
recvAuth.setConnection(HostAuth.SCHEME_EAS, recvAuth.mAddress, recvAuth.mPort,
|
||||
recvAuth.mFlags | HostAuth.FLAG_SSL);
|
||||
HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
|
||||
sendAuth.setConnection(
|
||||
"eas", sendAuth.mAddress, sendAuth.mPort, sendAuth.mFlags | HostAuth.FLAG_SSL);
|
||||
sendAuth.setConnection(HostAuth.SCHEME_EAS, sendAuth.mAddress, sendAuth.mPort,
|
||||
sendAuth.mFlags | HostAuth.FLAG_SSL);
|
||||
// TODO: Confirm correct delete policy for exchange
|
||||
account.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE);
|
||||
account.setSyncInterval(Account.CHECK_INTERVAL_PUSH);
|
||||
|
@ -134,42 +133,6 @@ public class AccountSetupAccountType extends AccountSetupActivity implements OnC
|
|||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* If the optional store specifies a limit on the number of accounts, make sure that we
|
||||
* don't violate that limit.
|
||||
* @return true if OK to create another account, false if not OK (limit reached)
|
||||
*/
|
||||
/* package */ boolean checkAccountInstanceLimit(Store.StoreInfo storeInfo) {
|
||||
// return immediately if account defines no limit
|
||||
if (storeInfo.mAccountInstanceLimit < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// count existing accounts
|
||||
int currentAccountsCount = 0;
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = this.getContentResolver().query(
|
||||
Account.CONTENT_URI,
|
||||
Account.CONTENT_PROJECTION,
|
||||
null, null, null);
|
||||
while (c.moveToNext()) {
|
||||
Account account = EmailContent.getContent(c, Account.class);
|
||||
String storeUri = account.getStoreUri(this);
|
||||
if (storeUri != null && storeUri.startsWith(storeInfo.mScheme)) {
|
||||
currentAccountsCount++;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
// return true if we can accept another account
|
||||
return (currentAccountsCount < storeInfo.mAccountInstanceLimit);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.pop:
|
||||
|
|
|
@ -46,8 +46,6 @@ import android.widget.EditText;
|
|||
import android.widget.TextView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Provides generic setup for Exchange accounts.
|
||||
|
@ -267,7 +265,7 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
|
|||
|
||||
String protocol = hostAuth.mProtocol;
|
||||
if (protocol == null || !protocol.startsWith("eas")) {
|
||||
throw new Error("Unknown account type: " + account.getStoreUri(mContext));
|
||||
throw new Error("Unknown account type: " + protocol);
|
||||
}
|
||||
|
||||
if (hostAuth.mAddress != null) {
|
||||
|
@ -299,13 +297,6 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
|
|||
boolean enabled = usernameFieldValid(mUsernameView)
|
||||
&& Utility.isTextViewNotEmpty(mPasswordView)
|
||||
&& Utility.isTextViewNotEmpty(mServerView);
|
||||
if (enabled) {
|
||||
try {
|
||||
URI uri = getUri();
|
||||
} catch (URISyntaxException use) {
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
enableNextButton(enabled);
|
||||
|
||||
// Warn (but don't prevent) if password has leading/trailing spaces
|
||||
|
@ -363,41 +354,6 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
|
|||
return forceLoadSettings(account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to create a URI from the fields provided. Throws URISyntaxException if there's
|
||||
* a problem with the user input.
|
||||
* @return a URI built from the account setup fields
|
||||
*/
|
||||
@Override
|
||||
protected URI getUri() throws URISyntaxException {
|
||||
Account account = SetupData.getAccount();
|
||||
boolean sslRequired = mSslSecurityView.isChecked();
|
||||
boolean trustCertificates = mTrustCertificatesView.isChecked();
|
||||
String userName = mUsernameView.getText().toString().trim();
|
||||
// Remove a leading backslash, if there is one, since we now automatically put one at
|
||||
// the start of the username field
|
||||
if (userName.startsWith("\\")) {
|
||||
userName = userName.substring(1);
|
||||
}
|
||||
mCacheLoginCredential = userName;
|
||||
String userInfo = userName + ":" + mPasswordView.getText();
|
||||
String host = mServerView.getText().toString().trim();
|
||||
String path = null;
|
||||
int port = mSslSecurityView.isChecked() ? 443 : 80;
|
||||
// Ensure TLS is not set
|
||||
int flags = account.getOrCreateHostAuthRecv(mContext).mFlags & ~HostAuth.FLAG_TLS;
|
||||
|
||||
URI uri = new URI(
|
||||
HostAuth.getSchemeString(mBaseScheme, flags),
|
||||
userInfo,
|
||||
host,
|
||||
port,
|
||||
path,
|
||||
null,
|
||||
null);
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements AccountCheckSettingsFragment.Callbacks
|
||||
*/
|
||||
|
|
|
@ -42,9 +42,6 @@ import android.widget.EditText;
|
|||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Provides UI for IMAP/POP account settings.
|
||||
*
|
||||
|
@ -326,7 +323,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
|
|||
}
|
||||
} else if (!Store.STORE_SCHEME_POP3.equals(recvAuth.mProtocol)) {
|
||||
// Account must either be IMAP or POP3
|
||||
throw new Error("Unknown account type: " + account.getStoreUri(mContext));
|
||||
throw new Error("Unknown account type: " + recvAuth.mProtocol);
|
||||
}
|
||||
|
||||
// The delete policy is set for all legacy accounts. For POP3 accounts, the user sets
|
||||
|
@ -365,13 +362,6 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
|
|||
&& Utility.isTextViewNotEmpty(mPasswordView)
|
||||
&& Utility.isTextViewNotEmpty(mServerView)
|
||||
&& Utility.isPortFieldValid(mPortView);
|
||||
if (enabled) {
|
||||
try {
|
||||
URI uri = getUri();
|
||||
} catch (URISyntaxException use) {
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
enableNextButton(enabled);
|
||||
|
||||
// Warn (but don't prevent) if password has leading/trailing spaces
|
||||
|
@ -425,35 +415,6 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
|
|||
sendAuth.setConnection(sendAuth.mProtocol, hostName, sendAuth.mPort, sendAuth.mFlags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to create a URI from the fields provided. Throws URISyntaxException if there's
|
||||
* a problem with the user input.
|
||||
* @return a URI built from the account setup fields
|
||||
*/
|
||||
@Override
|
||||
protected URI getUri() throws URISyntaxException {
|
||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
String path = null;
|
||||
if (Store.STORE_SCHEME_IMAP.equals(mBaseScheme)) {
|
||||
path = "/" + mImapPathPrefixView.getText().toString().trim();
|
||||
}
|
||||
String userName = mUsernameView.getText().toString().trim();
|
||||
mCacheLoginCredential = userName;
|
||||
String userInfo = userName + ":" + mPasswordView.getText();
|
||||
String host = mServerView.getText().toString().trim();
|
||||
int port = Integer.parseInt(mPortView.getText().toString().trim());
|
||||
|
||||
URI uri = new URI(
|
||||
HostAuth.getSchemeString(mBaseScheme, securityType),
|
||||
userInfo,
|
||||
host,
|
||||
port,
|
||||
path, // path
|
||||
null, // query
|
||||
null);
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point from Activity, when "next" button is clicked
|
||||
*/
|
||||
|
|
|
@ -16,19 +16,6 @@
|
|||
|
||||
package com.android.email.activity.setup;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.ExchangeUtils;
|
||||
import com.android.email.R;
|
||||
import com.android.email.activity.ActivityHelper;
|
||||
import com.android.email.activity.UiUtilities;
|
||||
import com.android.email.mail.Store;
|
||||
import com.android.email.service.MailService;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.service.SyncWindow;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
|
||||
import android.accounts.AccountAuthenticatorResponse;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerCallback;
|
||||
|
@ -48,6 +35,19 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.CheckBox;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.ExchangeUtils;
|
||||
import com.android.email.R;
|
||||
import com.android.email.activity.ActivityHelper;
|
||||
import com.android.email.activity.UiUtilities;
|
||||
import com.android.email.service.MailService;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.service.SyncWindow;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
|
@ -102,8 +102,9 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
int frequencyValuesId;
|
||||
int frequencyEntriesId;
|
||||
Account account = SetupData.getAccount();
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(this), this);
|
||||
if (info.mPushSupported) {
|
||||
String protocol = account.mHostAuthRecv.mProtocol;
|
||||
boolean eas = HostAuth.SCHEME_EAS.equals(protocol);
|
||||
if (eas) {
|
||||
frequencyValuesId = R.array.account_settings_check_frequency_values_push;
|
||||
frequencyEntriesId = R.array.account_settings_check_frequency_entries_push;
|
||||
} else {
|
||||
|
@ -126,7 +127,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mCheckFrequencyView.setAdapter(checkFrequenciesAdapter);
|
||||
|
||||
if (info.mVisibleLimitDefault == -1) {
|
||||
if (eas) {
|
||||
enableEASSyncWindowSpinner();
|
||||
}
|
||||
|
||||
|
@ -140,7 +141,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
SpinnerOption.setSpinnerOptionValue(mCheckFrequencyView, account.getSyncInterval());
|
||||
|
||||
// Setup any additional items to support EAS & EAS flow mode
|
||||
if ("eas".equals(info.mScheme)) {
|
||||
if (eas) {
|
||||
// "also sync contacts" == "true"
|
||||
mSyncContactsView.setVisibility(View.VISIBLE);
|
||||
mSyncContactsView.setChecked(true);
|
||||
|
@ -152,7 +153,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
}
|
||||
|
||||
// If we are in POP3, hide the "Background Attachments" mode
|
||||
if ("pop3".equals(info.mScheme)) {
|
||||
if (HostAuth.SCHEME_POP3.equals(protocol)) {
|
||||
mBackgroundAttachmentsView.setVisibility(View.GONE);
|
||||
UiUtilities.setVisibilitySafe(this, R.id.account_background_attachments_divider,
|
||||
View.GONE);
|
||||
|
|
|
@ -16,16 +16,6 @@
|
|||
|
||||
package com.android.email.activity.setup;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.R;
|
||||
import com.android.email.activity.UiUtilities;
|
||||
import com.android.email.provider.AccountBackupRestore;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
@ -44,8 +34,15 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
|
|||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import com.android.email.Email;
|
||||
import com.android.email.R;
|
||||
import com.android.email.activity.UiUtilities;
|
||||
import com.android.email.provider.AccountBackupRestore;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
|
||||
/**
|
||||
* Provides UI for SMTP account settings (for IMAP/POP accounts).
|
||||
|
@ -86,7 +83,7 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
if (savedInstanceState != null) {
|
||||
mLoaded = savedInstanceState.getBoolean(STATE_KEY_LOADED, false);
|
||||
}
|
||||
mBaseScheme = "smtp";
|
||||
mBaseScheme = HostAuth.SCHEME_SMTP;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -299,16 +296,7 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
enabled = (Utility.isTextViewNotEmpty(mUsernameView)
|
||||
&& Utility.isTextViewNotEmpty(mPasswordView));
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
try {
|
||||
URI uri = getUri();
|
||||
} catch (URISyntaxException use) {
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
enableNextButton(enabled);
|
||||
|
||||
// Warn (but don't prevent) if password has leading/trailing spaces
|
||||
AccountSettingsUtils.checkPasswordSpaces(mContext, mPasswordView);
|
||||
}
|
||||
|
@ -354,33 +342,6 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
public void saveSettingsAfterSetup() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to create a URI from the fields provided. Throws URISyntaxException if there's
|
||||
* a problem with the user input.
|
||||
* @return a URI built from the account setup fields
|
||||
*/
|
||||
@Override
|
||||
protected URI getUri() throws URISyntaxException {
|
||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
String userInfo = null;
|
||||
if (mRequireLoginView.isChecked()) {
|
||||
userInfo = mUsernameView.getText().toString().trim() + ":" + mPasswordView.getText();
|
||||
}
|
||||
String host = mServerView.getText().toString().trim();
|
||||
String path = null;
|
||||
int port = Integer.parseInt(mPortView.getText().toString().trim());
|
||||
|
||||
URI uri = new URI(
|
||||
HostAuth.getSchemeString(mBaseScheme, securityType),
|
||||
userInfo,
|
||||
host,
|
||||
port,
|
||||
path,
|
||||
null,
|
||||
null);
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point from Activity, when "next" button is clicked
|
||||
*/
|
||||
|
|
|
@ -16,11 +16,17 @@
|
|||
|
||||
package com.android.email.mail;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.R;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.mail.Folder;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
|
@ -28,11 +34,6 @@ import com.google.common.annotations.VisibleForTesting;
|
|||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
@ -49,9 +50,9 @@ public abstract class Store {
|
|||
/**
|
||||
* String constants for known store schemes.
|
||||
*/
|
||||
public static final String STORE_SCHEME_IMAP = "imap";
|
||||
public static final String STORE_SCHEME_POP3 = "pop3";
|
||||
public static final String STORE_SCHEME_EAS = "eas";
|
||||
public static final String STORE_SCHEME_IMAP = HostAuth.SCHEME_IMAP;
|
||||
public static final String STORE_SCHEME_POP3 = HostAuth.SCHEME_POP3;
|
||||
public static final String STORE_SCHEME_EAS = HostAuth.SCHEME_EAS;
|
||||
public static final String STORE_SCHEME_LOCAL = "local";
|
||||
|
||||
public static final String STORE_SECURITY_SSL = "+ssl";
|
||||
|
@ -65,7 +66,7 @@ public abstract class Store {
|
|||
public static final int FETCH_BODY_SANE_SUGGESTED_SIZE = (50 * 1024);
|
||||
|
||||
@VisibleForTesting
|
||||
static final HashMap<String, Store> sStores = new HashMap<String, Store>();
|
||||
static final HashMap<Long, Store> sStores = new HashMap<Long, Store>();
|
||||
|
||||
protected Context mContext;
|
||||
protected Account mAccount;
|
||||
|
@ -162,23 +163,12 @@ public abstract class Store {
|
|||
}
|
||||
}
|
||||
|
||||
protected static String getStoreKey(Context context, Account account)
|
||||
throws MessagingException {
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(context);
|
||||
String key = recvAuth.getStoreUri();
|
||||
if (key == null) {
|
||||
throw new MessagingException("Could not find store for account: " +
|
||||
account.mDisplayName);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of a mail store for the given account. The account must be valid (i.e. has
|
||||
* at least an incoming server name).
|
||||
*
|
||||
* NOTE: The internal algorithm used to find a cached store depends upon the URI of the
|
||||
* account's HostAuth object. If this ever changes (e.g. such as the user updating the
|
||||
* NOTE: The internal algorithm used to find a cached store depends upon the id of the
|
||||
* account's HostAuth row. If this ever changes (e.g. such as the user updating the
|
||||
* host name or port), we will leak entries. This should not be typical, so, it is not
|
||||
* a critical problem. However, it is something we should consider fixing.
|
||||
*
|
||||
|
@ -188,17 +178,17 @@ public abstract class Store {
|
|||
*/
|
||||
public synchronized static Store getInstance(Account account, Context context,
|
||||
PersistentDataCallbacks callbacks) throws MessagingException {
|
||||
String storeKey = getStoreKey(context, account);
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(context);
|
||||
long storeKey = recvAuth.mId;
|
||||
Store store = sStores.get(storeKey);
|
||||
if (store == null) {
|
||||
Context appContext = context.getApplicationContext();
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(context);
|
||||
StoreInfo info = StoreInfo.getStoreInfo(recvAuth.mProtocol, context);
|
||||
if (info != null) {
|
||||
store = instantiateStore(info.mClassName, account, appContext, callbacks);
|
||||
}
|
||||
|
||||
if (store != null) {
|
||||
// Don't cache this unless it's we've got a saved HostAUth
|
||||
if (store != null && (storeKey != EmailContent.NOT_SAVED)) {
|
||||
sStores.put(storeKey, store);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.android.email.ExchangeUtils;
|
|||
import com.android.email.mail.Store;
|
||||
import com.android.emailcommon.mail.Folder;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.service.EmailServiceProxy;
|
||||
|
@ -102,19 +103,26 @@ public class ExchangeStore extends Store {
|
|||
private String mUsername;
|
||||
private String mPassword;
|
||||
|
||||
private static final HashMap<String, ExchangeTransport> sUriToInstanceMap =
|
||||
new HashMap<String, ExchangeTransport>();
|
||||
private static final HashMap<Long, ExchangeTransport> sHostAuthToInstanceMap =
|
||||
new HashMap<Long, ExchangeTransport>();
|
||||
|
||||
/**
|
||||
* Public factory. The transport should be a singleton (per Uri)
|
||||
* Public factory. The transport should be a singleton
|
||||
*/
|
||||
public synchronized static ExchangeTransport getInstance(Account account, Context context)
|
||||
throws MessagingException {
|
||||
final String storeKey = getStoreKey(context, account);
|
||||
ExchangeTransport transport = sUriToInstanceMap.get(storeKey);
|
||||
HostAuth hostAuth = HostAuth.restoreHostAuthWithId(context, account.mHostAuthKeyRecv);
|
||||
if (hostAuth == null) {
|
||||
hostAuth = new HostAuth();
|
||||
}
|
||||
final long storeKey = hostAuth.mId;
|
||||
ExchangeTransport transport = sHostAuthToInstanceMap.get(storeKey);
|
||||
if (transport == null) {
|
||||
transport = new ExchangeTransport(account, context);
|
||||
sUriToInstanceMap.put(storeKey, transport);
|
||||
// Only cache a saved HostAuth key
|
||||
if (storeKey != EmailContent.NOT_SAVED) {
|
||||
sHostAuthToInstanceMap.put(storeKey, transport);
|
||||
}
|
||||
}
|
||||
return transport;
|
||||
}
|
||||
|
|
|
@ -16,11 +16,6 @@
|
|||
|
||||
package com.android.email.activity.setup;
|
||||
|
||||
import com.android.email.R;
|
||||
import com.android.email.mail.Store;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -29,6 +24,10 @@ import android.test.ActivityUnitTestCase;
|
|||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.email.R;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
@ -68,37 +67,10 @@ public class AccountSetupAccountTypeTests
|
|||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test store type limit enforcement
|
||||
*/
|
||||
public void testStoreTypeLimits()
|
||||
throws URISyntaxException {
|
||||
createTestAccount("scheme1");
|
||||
createTestAccount("scheme1");
|
||||
createTestAccount("scheme2");
|
||||
|
||||
AccountSetupAccountType activity = startActivity(getTestIntent(), null, null);
|
||||
|
||||
// Test with no limit
|
||||
Store.StoreInfo info = new Store.StoreInfo();
|
||||
info.mAccountInstanceLimit = -1;
|
||||
info.mScheme = "scheme1";
|
||||
assertTrue("no limit", activity.checkAccountInstanceLimit(info));
|
||||
|
||||
// Test with limit, but not reached
|
||||
info.mAccountInstanceLimit = 3;
|
||||
assertTrue("limit, but not reached", activity.checkAccountInstanceLimit(info));
|
||||
|
||||
// Test with limit, reached
|
||||
info.mAccountInstanceLimit = 2;
|
||||
assertFalse("limit, reached", activity.checkAccountInstanceLimit(info));
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm that EAS is presented, when supported.
|
||||
*/
|
||||
public void testEasOffered()
|
||||
throws URISyntaxException {
|
||||
public void testEasOffered() throws URISyntaxException {
|
||||
createTestAccount("scheme1");
|
||||
AccountSetupAccountType activity = startActivity(getTestIntent(), null, null);
|
||||
View exchangeButton = activity.findViewById(R.id.exchange);
|
||||
|
@ -114,8 +86,7 @@ public class AccountSetupAccountTypeTests
|
|||
/**
|
||||
* Create a dummy account with minimal fields
|
||||
*/
|
||||
private Account createTestAccount(String scheme)
|
||||
throws URISyntaxException {
|
||||
private Account createTestAccount(String scheme) throws URISyntaxException {
|
||||
Account account = new Account();
|
||||
HostAuth auth = account.getOrCreateHostAuthRecv(mContext);
|
||||
HostAuth.setHostAuthFromString(auth, scheme + "://user:pass@server.com:123");
|
||||
|
|
|
@ -16,12 +16,6 @@
|
|||
|
||||
package com.android.email.activity.setup;
|
||||
|
||||
import com.android.email.R;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
@ -31,7 +25,12 @@ import android.view.View;
|
|||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.net.URI;
|
||||
import com.android.email.R;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
|
@ -74,8 +73,7 @@ public class AccountSetupExchangeTests extends
|
|||
/**
|
||||
* Test processing with a complete, good URI -> good fields
|
||||
*/
|
||||
public void testGoodUri()
|
||||
throws URISyntaxException {
|
||||
public void testGoodUri() throws URISyntaxException {
|
||||
Intent i = getTestIntent("eas://user:password@server.com");
|
||||
setActivityIntent(i);
|
||||
getActivityAndFields();
|
||||
|
@ -88,8 +86,7 @@ public class AccountSetupExchangeTests extends
|
|||
/**
|
||||
* No user is not OK - not enabled
|
||||
*/
|
||||
public void testBadUriNoUser()
|
||||
throws URISyntaxException {
|
||||
public void testBadUriNoUser() throws URISyntaxException {
|
||||
Intent i = getTestIntent("eas://:password@server.com");
|
||||
setActivityIntent(i);
|
||||
getActivityAndFields();
|
||||
|
@ -99,8 +96,7 @@ public class AccountSetupExchangeTests extends
|
|||
/**
|
||||
* No password is not OK - not enabled
|
||||
*/
|
||||
public void testBadUriNoPassword()
|
||||
throws URISyntaxException {
|
||||
public void testBadUriNoPassword() throws URISyntaxException {
|
||||
Intent i = getTestIntent("eas://user@server.com");
|
||||
setActivityIntent(i);
|
||||
getActivityAndFields();
|
||||
|
@ -138,7 +134,7 @@ public class AccountSetupExchangeTests extends
|
|||
* Test to confirm that passwords with leading or trailing spaces are accepted verbatim.
|
||||
*/
|
||||
@UiThreadTest
|
||||
public void testPasswordNoTrim() throws URISyntaxException {
|
||||
public void testPasswordNoTrim() {
|
||||
getActivityAndFields();
|
||||
|
||||
// Clear the password - should disable
|
||||
|
@ -158,14 +154,10 @@ public class AccountSetupExchangeTests extends
|
|||
* @param password the password to test with
|
||||
* @param expectNext true if expected that this password will enable the "next" button
|
||||
*/
|
||||
private void checkPassword(String password, boolean expectNext) throws URISyntaxException {
|
||||
private void checkPassword(String password, boolean expectNext) {
|
||||
mPasswordView.setText(password);
|
||||
if (expectNext) {
|
||||
assertTrue(mActivity.mNextButtonEnabled);
|
||||
URI uri = mFragment.getUri();
|
||||
String actualUserInfo = uri.getUserInfo();
|
||||
String actualPassword = actualUserInfo.split(":", 2)[1];
|
||||
assertEquals(password, actualPassword);
|
||||
} else {
|
||||
assertFalse(mActivity.mNextButtonEnabled);
|
||||
}
|
||||
|
@ -236,8 +228,7 @@ public class AccountSetupExchangeTests extends
|
|||
/**
|
||||
* Create an intent with the Account in it
|
||||
*/
|
||||
private Intent getTestIntent(String storeUriString)
|
||||
throws URISyntaxException {
|
||||
private Intent getTestIntent(String storeUriString) throws URISyntaxException {
|
||||
EmailContent.Account account = new EmailContent.Account();
|
||||
Context context = getInstrumentation().getTargetContext();
|
||||
HostAuth auth = account.getOrCreateHostAuthRecv(context);
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.test.UiThreadTest;
|
|||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
|
@ -162,10 +161,6 @@ public class AccountSetupIncomingTests extends
|
|||
mPasswordView.setText(password);
|
||||
if (expectNext) {
|
||||
assertTrue(mActivity.mNextButtonEnabled);
|
||||
URI uri = mFragment.getUri();
|
||||
String actualUserInfo = uri.getUserInfo();
|
||||
String actualPassword = actualUserInfo.split(":", 2)[1];
|
||||
assertEquals(password, actualPassword);
|
||||
} else {
|
||||
assertFalse(mActivity.mNextButtonEnabled);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.test.UiThreadTest;
|
|||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
|
@ -159,10 +158,6 @@ public class AccountSetupOutgoingTests extends
|
|||
mPasswordView.setText(password);
|
||||
if (expectNext) {
|
||||
assertTrue(mActivity.mNextButtonEnabled);
|
||||
URI uri = mFragment.getUri();
|
||||
String actualUserInfo = uri.getUserInfo();
|
||||
String actualPassword = actualUserInfo.split(":", 2)[1];
|
||||
assertEquals(password, actualPassword);
|
||||
} else {
|
||||
assertFalse(mActivity.mNextButtonEnabled);
|
||||
}
|
||||
|
|
|
@ -16,64 +16,42 @@
|
|||
|
||||
package com.android.email.mail;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.ProviderTestCase2;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.mail.Store.StoreInfo;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.Account;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
|
||||
/**
|
||||
* Tests of StoreInfo & Store lookup in the Store abstract class
|
||||
*
|
||||
* You can run this entire test case with:
|
||||
* runtest -c com.android.email.mail.store.StoreTests email
|
||||
*
|
||||
*/
|
||||
|
||||
@MediumTest
|
||||
public class StoreTests extends AndroidTestCase {
|
||||
public class StoreTests extends ProviderTestCase2<EmailProvider> {
|
||||
|
||||
private Context mMockContext;
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mMockContext = getMockContext();
|
||||
Store.sStores.clear();
|
||||
}
|
||||
|
||||
public void testGetStoreKey() throws MessagingException {
|
||||
HostAuth testAuth = new HostAuth();
|
||||
Account testAccount = new Account();
|
||||
String testKey;
|
||||
|
||||
// Make sure to set the host auth; otherwise we create entries in the hostauth db
|
||||
testAccount.mHostAuthRecv = testAuth;
|
||||
testAuth.mProtocol = "protocol";
|
||||
testAuth.mPort = 80;
|
||||
|
||||
// No address defined; throws an exception
|
||||
try {
|
||||
testKey = Store.getStoreKey(mContext, testAccount);
|
||||
fail("MesasginException not thrown for missing address");
|
||||
} catch (MessagingException expected) {
|
||||
}
|
||||
|
||||
// Empty address defined; throws an exception
|
||||
testAuth.mAddress = " \t ";
|
||||
try {
|
||||
testKey = Store.getStoreKey(mContext, testAccount);
|
||||
fail("MesasginException not thrown for empty address");
|
||||
} catch (MessagingException expected) {
|
||||
}
|
||||
|
||||
// Address defined, no login
|
||||
testAuth.mAddress = "a.valid.address.com";
|
||||
testKey = Store.getStoreKey(mContext, testAccount);
|
||||
assertEquals("protocol://a.valid.address.com:80", testKey);
|
||||
|
||||
// Address & login defined
|
||||
testAuth.mAddress = "address.org";
|
||||
testAuth.mFlags = HostAuth.FLAG_AUTHENTICATE;
|
||||
testAuth.mLogin = "auser";
|
||||
testAuth.mPassword = "password";
|
||||
testKey = Store.getStoreKey(mContext, testAccount);
|
||||
assertEquals("protocol://auser:password@address.org:80", testKey);
|
||||
public StoreTests(Class<EmailProvider> providerClass, String providerAuthority) {
|
||||
super(EmailProvider.class, EmailContent.AUTHORITY);
|
||||
}
|
||||
|
||||
public void testGetStoreInfo() {
|
||||
|
@ -103,42 +81,36 @@ public class StoreTests extends AndroidTestCase {
|
|||
}
|
||||
|
||||
public void testGetInstance() throws MessagingException {
|
||||
HostAuth testAuth = new HostAuth();
|
||||
Account testAccount = new Account();
|
||||
Store testStore;
|
||||
|
||||
// Make sure to set the host auth; otherwise we create entries in the hostauth db
|
||||
testAccount.mHostAuthRecv = testAuth;
|
||||
|
||||
// POP3
|
||||
Account testAccount = ProviderTestUtils.setupAccount("pop", false, mMockContext);
|
||||
HostAuth testAuth = new HostAuth();
|
||||
testAccount.mHostAuthRecv = testAuth;
|
||||
testAuth.mAddress = "pop3.google.com";
|
||||
testAuth.mProtocol = "pop3";
|
||||
testAccount.save(mMockContext);
|
||||
|
||||
testStore = Store.getInstance(testAccount, getContext(), null);
|
||||
assertEquals(1, Store.sStores.size());
|
||||
assertSame(testStore, Store.sStores.get(testAuth.getStoreUri()));
|
||||
assertSame(testStore, Store.sStores.get(testAccount.mId));
|
||||
Store.sStores.clear();
|
||||
|
||||
// IMAP
|
||||
testAccount = ProviderTestUtils.setupAccount("pop", false, mMockContext);
|
||||
testAuth = new HostAuth();
|
||||
testAccount.mHostAuthRecv = testAuth;
|
||||
testAuth.mAddress = "imap.google.com";
|
||||
testAuth.mProtocol = "imap";
|
||||
testAccount.save(mMockContext);
|
||||
testStore = Store.getInstance(testAccount, getContext(), null);
|
||||
assertEquals(1, Store.sStores.size());
|
||||
assertSame(testStore, Store.sStores.get(testAuth.getStoreUri()));
|
||||
Store.sStores.clear();
|
||||
|
||||
// IMAP; host auth changes
|
||||
testAuth.mAddress = "imap.google.com";
|
||||
testAuth.mProtocol = "imap";
|
||||
testStore = Store.getInstance(testAccount, getContext(), null); // cache first store
|
||||
assertEquals(1, Store.sStores.size());
|
||||
assertSame(testStore, Store.sStores.get(testAuth.getStoreUri()));
|
||||
testAuth.mAddress = "mail.google.com"; // change the auth hostname
|
||||
Store.getInstance(testAccount, getContext(), null); // cache second store
|
||||
assertEquals(2, Store.sStores.size()); // Now there are two entries ...
|
||||
assertNotSame(testStore, Store.sStores.get(testAuth.getStoreUri()));
|
||||
assertSame(testStore, Store.sStores.get(testAccount.mId));
|
||||
Store.sStores.clear();
|
||||
|
||||
// Unknown
|
||||
testAccount = ProviderTestUtils.setupAccount("unknown", false, mMockContext);
|
||||
testAuth = new HostAuth();
|
||||
testAuth.mAddress = "unknown.google.com";
|
||||
testAuth.mProtocol = "unknown";
|
||||
try {
|
||||
|
|
|
@ -16,145 +16,15 @@
|
|||
|
||||
package com.android.emailcommon.provider;
|
||||
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Unit tests for the HostAuth inner class.
|
||||
* These tests must be locally complete - no server(s) required.
|
||||
*/
|
||||
@SmallTest
|
||||
public class HostAuthTests extends AndroidTestCase {
|
||||
/**
|
||||
* Test the various combinations of SSL, TLS, and trust-certificates encoded as Uris
|
||||
*/
|
||||
public void testSecurityUri()
|
||||
throws URISyntaxException {
|
||||
HostAuth ha = ProviderTestUtils.setupHostAuth("uri-security", 1, false, mContext);
|
||||
|
||||
final int MASK =
|
||||
HostAuth.FLAG_SSL | HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL;
|
||||
|
||||
// Set various URIs and check the resulting flags
|
||||
HostAuth.setHostAuthFromString(ha, "protocol://user:password@server:123");
|
||||
assertEquals(0, ha.mFlags & MASK);
|
||||
HostAuth.setHostAuthFromString(ha, "protocol+ssl+://user:password@server:123");
|
||||
assertEquals(HostAuth.FLAG_SSL, ha.mFlags & MASK);
|
||||
HostAuth.setHostAuthFromString(ha, "protocol+ssl+trustallcerts://user:password@server:123");
|
||||
assertEquals(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, ha.mFlags & MASK);
|
||||
HostAuth.setHostAuthFromString(ha, "protocol+tls+://user:password@server:123");
|
||||
assertEquals(HostAuth.FLAG_TLS, ha.mFlags & MASK);
|
||||
HostAuth.setHostAuthFromString(ha, "protocol+tls+trustallcerts://user:password@server:123");
|
||||
assertEquals(HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL, ha.mFlags & MASK);
|
||||
|
||||
// Now check the retrival method (building URI from flags)
|
||||
ha.mFlags &= ~MASK;
|
||||
String uriString = ha.getStoreUri();
|
||||
assertTrue(uriString.startsWith("protocol://"));
|
||||
ha.mFlags |= HostAuth.FLAG_SSL;
|
||||
uriString = ha.getStoreUri();
|
||||
assertTrue(uriString.startsWith("protocol+ssl+://"));
|
||||
ha.mFlags |= HostAuth.FLAG_TRUST_ALL;
|
||||
uriString = ha.getStoreUri();
|
||||
assertTrue(uriString.startsWith("protocol+ssl+trustallcerts://"));
|
||||
ha.mFlags &= ~MASK;
|
||||
ha.mFlags |= HostAuth.FLAG_TLS;
|
||||
uriString = ha.getStoreUri();
|
||||
assertTrue(uriString.startsWith("protocol+tls+://"));
|
||||
ha.mFlags |= HostAuth.FLAG_TRUST_ALL;
|
||||
uriString = ha.getStoreUri();
|
||||
assertTrue(uriString.startsWith("protocol+tls+trustallcerts://"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test port assignments made from Uris
|
||||
*/
|
||||
public void testPortAssignments()
|
||||
throws URISyntaxException {
|
||||
HostAuth ha = ProviderTestUtils.setupHostAuth("uri-port", 1, false, mContext);
|
||||
|
||||
// Set various URIs and check the resulting flags
|
||||
// Hardwired port
|
||||
HostAuth.setHostAuthFromString(ha, "imap://user:password@server:123");
|
||||
assertEquals(123, ha.mPort);
|
||||
// Auto-assigned ports
|
||||
HostAuth.setHostAuthFromString(ha, "imap://user:password@server");
|
||||
assertEquals(143, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "imap+ssl://user:password@server");
|
||||
assertEquals(993, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "imap+ssl+trustallcerts://user:password@server");
|
||||
assertEquals(993, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "imap+tls://user:password@server");
|
||||
assertEquals(143, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "imap+tls+trustallcerts://user:password@server");
|
||||
assertEquals(143, ha.mPort);
|
||||
|
||||
// Hardwired port
|
||||
HostAuth.setHostAuthFromString(ha, "pop3://user:password@server:123");
|
||||
assertEquals(123, ha.mPort);
|
||||
// Auto-assigned ports
|
||||
HostAuth.setHostAuthFromString(ha, "pop3://user:password@server");
|
||||
assertEquals(110, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "pop3+ssl://user:password@server");
|
||||
assertEquals(995, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "pop3+ssl+trustallcerts://user:password@server");
|
||||
assertEquals(995, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "pop3+tls://user:password@server");
|
||||
assertEquals(110, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "pop3+tls+trustallcerts://user:password@server");
|
||||
assertEquals(110, ha.mPort);
|
||||
|
||||
// Hardwired port
|
||||
HostAuth.setHostAuthFromString(ha, "eas://user:password@server:123");
|
||||
assertEquals(123, ha.mPort);
|
||||
// Auto-assigned ports
|
||||
HostAuth.setHostAuthFromString(ha, "eas://user:password@server");
|
||||
assertEquals(80, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "eas+ssl://user:password@server");
|
||||
assertEquals(443, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "eas+ssl+trustallcerts://user:password@server");
|
||||
assertEquals(443, ha.mPort);
|
||||
|
||||
// Hardwired port
|
||||
HostAuth.setHostAuthFromString(ha, "smtp://user:password@server:123");
|
||||
assertEquals(123, ha.mPort);
|
||||
// Auto-assigned ports
|
||||
HostAuth.setHostAuthFromString(ha, "smtp://user:password@server");
|
||||
assertEquals(587, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "smtp+ssl://user:password@server");
|
||||
assertEquals(465, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "smtp+ssl+trustallcerts://user:password@server");
|
||||
assertEquals(465, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "smtp+tls://user:password@server");
|
||||
assertEquals(587, ha.mPort);
|
||||
HostAuth.setHostAuthFromString(ha, "smtp+tls+trustallcerts://user:password@server");
|
||||
assertEquals(587, ha.mPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test preservation of username & password in URI
|
||||
*/
|
||||
public void testGetStoreUri()
|
||||
throws URISyntaxException {
|
||||
HostAuth ha = new HostAuth();
|
||||
HostAuth.setHostAuthFromString(ha, "protocol://user:password@server:123");
|
||||
String getUri = ha.getStoreUri();
|
||||
assertEquals("protocol://user:password@server:123", getUri);
|
||||
|
||||
// Now put spaces in/around username (they are trimmed)
|
||||
HostAuth.setHostAuthFromString(ha, "protocol://%20us%20er%20:password@server:123");
|
||||
getUri = ha.getStoreUri();
|
||||
assertEquals("protocol://us%20er:password@server:123", getUri);
|
||||
|
||||
// Now put spaces around password (should not be trimmed)
|
||||
HostAuth.setHostAuthFromString(ha, "protocol://user:%20pass%20word%20@server:123");
|
||||
getUri = ha.getStoreUri();
|
||||
assertEquals("protocol://user:%20pass%20word%20@server:123", getUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user name and password are set correctly
|
||||
|
@ -227,122 +97,6 @@ public class HostAuthTests extends AndroidTestCase {
|
|||
assertEquals(~HostAuth.FLAG_AUTHENTICATE, ha.mFlags);
|
||||
}
|
||||
|
||||
public void testImapConnectionScheme() {
|
||||
HostAuth ha = new HostAuth();
|
||||
|
||||
// Set URIs for IMAP
|
||||
// Hardwired port
|
||||
ha.setConnection("imap", "server", 123);
|
||||
assertEquals(0, ha.mFlags);
|
||||
assertEquals(123, ha.mPort);
|
||||
|
||||
// Auto-assigned ports
|
||||
ha.setConnection("imap", "server", -1);
|
||||
assertEquals(0, ha.mFlags);
|
||||
assertEquals(143, ha.mPort);
|
||||
|
||||
ha.setConnection("imap+ssl", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_SSL, ha.mFlags);
|
||||
assertEquals(993, ha.mPort);
|
||||
|
||||
ha.setConnection("imap+ssl+trustallcerts", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_SSL|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
|
||||
assertEquals(993, ha.mPort);
|
||||
|
||||
ha.setConnection("imap+tls", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_TLS, ha.mFlags);
|
||||
assertEquals(143, ha.mPort);
|
||||
|
||||
ha.setConnection("imap+tls+trustallcerts", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_TLS|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
|
||||
assertEquals(143, ha.mPort);
|
||||
}
|
||||
|
||||
public void testPopConnectionScheme() {
|
||||
HostAuth ha = new HostAuth();
|
||||
|
||||
// Set URIs for POP3
|
||||
// Hardwired port
|
||||
ha.setConnection("pop3", "server", 123);
|
||||
assertEquals(0, ha.mFlags);
|
||||
assertEquals(123, ha.mPort);
|
||||
|
||||
// Auto-assigned ports
|
||||
ha.setConnection("pop3", "server", -1);
|
||||
assertEquals(0, ha.mFlags);
|
||||
assertEquals(110, ha.mPort);
|
||||
|
||||
ha.setConnection("pop3+ssl", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_SSL, ha.mFlags);
|
||||
assertEquals(995, ha.mPort);
|
||||
|
||||
ha.setConnection("pop3+ssl+trustallcerts", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_SSL|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
|
||||
assertEquals(995, ha.mPort);
|
||||
|
||||
ha.setConnection("pop3+tls", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_TLS, ha.mFlags);
|
||||
assertEquals(110, ha.mPort);
|
||||
|
||||
ha.setConnection("pop3+tls+trustallcerts", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_TLS|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
|
||||
assertEquals(110, ha.mPort);
|
||||
}
|
||||
|
||||
public void testEasConnectionScheme() {
|
||||
HostAuth ha = new HostAuth();
|
||||
|
||||
// Set URIs for Exchange
|
||||
// Hardwired port
|
||||
ha.setConnection("eas", "server", 123);
|
||||
assertEquals(0, ha.mFlags);
|
||||
assertEquals(123, ha.mPort);
|
||||
|
||||
// Auto-assigned ports
|
||||
ha.setConnection("eas", "server", -1);
|
||||
assertEquals(0, ha.mFlags);
|
||||
assertEquals(80, ha.mPort);
|
||||
|
||||
ha.setConnection("eas+ssl", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_SSL, ha.mFlags);
|
||||
assertEquals(443, ha.mPort);
|
||||
|
||||
ha.setConnection("eas+ssl+trustallcerts", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_SSL|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
|
||||
assertEquals(443, ha.mPort);
|
||||
}
|
||||
|
||||
public void testSmtpConnectionScheme() {
|
||||
HostAuth ha = new HostAuth();
|
||||
|
||||
// Set URIs for SMTP
|
||||
// Hardwired port
|
||||
ha.setConnection("smtp", "server", 123);
|
||||
assertEquals(0, ha.mFlags);
|
||||
assertEquals(123, ha.mPort);
|
||||
|
||||
// Auto-assigned ports
|
||||
ha.setConnection("smtp", "server", -1);
|
||||
assertEquals(0, ha.mFlags);
|
||||
assertEquals(587, ha.mPort);
|
||||
|
||||
ha.setConnection("smtp+ssl", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_SSL, ha.mFlags);
|
||||
assertEquals(465, ha.mPort);
|
||||
|
||||
ha.setConnection("smtp+ssl+trustallcerts", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_SSL|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
|
||||
assertEquals(465, ha.mPort);
|
||||
|
||||
ha.setConnection("smtp+tls", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_TLS, ha.mFlags);
|
||||
assertEquals(587, ha.mPort);
|
||||
|
||||
ha.setConnection("smtp+tls+trustallcerts", "server", -1);
|
||||
assertEquals(HostAuth.FLAG_TLS|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
|
||||
assertEquals(587, ha.mPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setting the connection using a protocol and flags
|
||||
*/
|
||||
|
@ -421,155 +175,5 @@ public class HostAuthTests extends AndroidTestCase {
|
|||
} catch (IllegalArgumentException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetSchemeString() {
|
||||
String scheme;
|
||||
|
||||
scheme = HostAuth.getSchemeString("foo", 0);
|
||||
assertEquals("foo", scheme);
|
||||
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_SSL);
|
||||
assertEquals("foo+ssl+", scheme);
|
||||
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL);
|
||||
assertEquals("foo+ssl+trustallcerts", scheme);
|
||||
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_TLS);
|
||||
assertEquals("foo+tls+", scheme);
|
||||
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL);
|
||||
assertEquals("foo+tls+trustallcerts", scheme);
|
||||
// error cases; no security string appended to protocol
|
||||
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_TRUST_ALL);
|
||||
assertEquals("foo", scheme);
|
||||
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_SSL | HostAuth.FLAG_TLS);
|
||||
assertEquals("foo", scheme);
|
||||
scheme = HostAuth.getSchemeString("foo",
|
||||
HostAuth.FLAG_SSL | HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL);
|
||||
scheme = HostAuth.getSchemeString("foo", 0xfffffff4);
|
||||
assertEquals("foo", scheme);
|
||||
// Use of custom client certs.
|
||||
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_SSL, "custom-client-cert-alias");
|
||||
assertEquals("foo+ssl+custom-client-cert-alias", scheme);
|
||||
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_TLS, "custom-client-cert-alias");
|
||||
assertEquals("foo+tls+custom-client-cert-alias", scheme);
|
||||
scheme = HostAuth.getSchemeString(
|
||||
"foo", HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, "custom-client-cert-alias");
|
||||
assertEquals("foo+ssl+trustallcerts+custom-client-cert-alias", scheme);
|
||||
scheme = HostAuth.getSchemeString(
|
||||
"foo", HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL, "custom-client-cert-alias");
|
||||
assertEquals("foo+tls+trustallcerts+custom-client-cert-alias", scheme);
|
||||
|
||||
try {
|
||||
scheme = HostAuth.getSchemeString(
|
||||
"foo", 0 /* no security flags */, "custom-client-cert-alias");
|
||||
fail("Should not be able to set a custom client cert on an insecure connection");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testGetSchemeFlags() {
|
||||
int flags;
|
||||
|
||||
flags = HostAuth.getSchemeFlags("");
|
||||
assertEquals(0, flags);
|
||||
flags = HostAuth.getSchemeFlags("+");
|
||||
assertEquals(0, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+");
|
||||
assertEquals(0, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+ssl");
|
||||
assertEquals(HostAuth.FLAG_SSL, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+ssl+");
|
||||
assertEquals(HostAuth.FLAG_SSL, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+ssl+trustallcerts");
|
||||
assertEquals(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+tls+");
|
||||
assertEquals(HostAuth.FLAG_TLS, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+tls+trustallcerts");
|
||||
assertEquals(HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+bogus");
|
||||
assertEquals(0, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+bogus+trustallcerts");
|
||||
assertEquals(HostAuth.FLAG_TRUST_ALL, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+ssl+bogus");
|
||||
assertEquals(HostAuth.FLAG_SSL, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+ssl+trustallcerts+bogus");
|
||||
assertEquals(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+bogus+bogus");
|
||||
assertEquals(0, flags);
|
||||
flags = HostAuth.getSchemeFlags("foo+bogus+bogus+bogus");
|
||||
assertEquals(0, flags);
|
||||
}
|
||||
|
||||
public void testEquals() throws URISyntaxException {
|
||||
HostAuth ha1;
|
||||
HostAuth ha2;
|
||||
|
||||
ha1 = new HostAuth();
|
||||
ha2 = new HostAuth();
|
||||
assertTrue(ha1.equals(ha2));
|
||||
assertTrue(ha2.equals(ha1));
|
||||
|
||||
HostAuth.setHostAuthFromString(ha1, "smtp+tls+://user:password@server/domain");
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://user:password@server/domain");
|
||||
assertTrue(ha1.equals(ha2));
|
||||
assertTrue(ha2.equals(ha1));
|
||||
|
||||
// Different protocol
|
||||
HostAuth.setHostAuthFromString(ha2, "imap+tls+://user:password@server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Different domain
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://user:password@server/domain2");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Missing server
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://user:password/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Missing domain
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://user:password@server");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Different server
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://user:password@server2/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Different password
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://user:password2@server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Different user name
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://user2:password@server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Missing password
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://user@server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Missing user name
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://password@server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Missing user name & password
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+://server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Added "trustallcerts"
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+tls+trustallcerts://user:password@server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Different authentication
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+ssl+://user:password@server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Missing authentication
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+://user:password@server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
// Use of custom certificate
|
||||
HostAuth.setHostAuthFromString(ha2, "smtp+ssl+clientcert://user:password@server/domain");
|
||||
assertFalse(ha1.equals(ha2));
|
||||
assertFalse(ha2.equals(ha1));
|
||||
ha2 = null;
|
||||
assertFalse(ha1.equals(ha2));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue