diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index 45961b627..858226854 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -421,9 +421,11 @@ public class MessagingController implements Runnable { try { Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(mContext), mContext); - LocalStore localStore = (LocalStore) Store.getInstance( - account.getLocalStoreUri(mContext), mContext, null); - localStore.resetVisibleLimits(info.mVisibleLimitDefault); + if (info != null) { + LocalStore localStore = (LocalStore) Store.getInstance( + account.getLocalStoreUri(mContext), mContext, null); + localStore.resetVisibleLimits(info.mVisibleLimitDefault); + } } catch (MessagingException e) { Log.e(Email.LOG_TAG, "Unable to reset visible limits", e); diff --git a/src/com/android/email/provider/EmailStore.java b/src/com/android/email/provider/EmailStore.java index df30e9d59..266f546b1 100644 --- a/src/com/android/email/provider/EmailStore.java +++ b/src/com/android/email/provider/EmailStore.java @@ -860,6 +860,7 @@ public class EmailStore { * * @param the new value */ + @Deprecated public void setStoreUri(Context context, String senderUri) { // reconstitute or create if necessary if (mHostAuthRecv == null) { @@ -880,6 +881,7 @@ public class EmailStore { * * @param the new value */ + @Deprecated public void setSenderUri(Context context, String senderUri) { // reconstitute or create if necessary if (mHostAuthSend == null) { @@ -1700,6 +1702,7 @@ public class EmailStore { /** * 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 */ @@ -1712,17 +1715,21 @@ public class EmailStore { } String userInfo = null; if ((mFlags & FLAG_AUTHENTICATE) != 0) { - userInfo = mLogin.trim() + ":" + mPassword.trim(); + String trimUser = (mLogin != null) ? mLogin.trim() : ""; + String trimPassword = (mPassword != null) ? mPassword.trim() : ""; + userInfo = trimUser + ":" + trimPassword; } + String address = (mAddress != null) ? mAddress.trim() : null; + String path = (mDomain != null) ? "/" + mDomain : null; URI uri; try { uri = new URI( mProtocol + security, userInfo, - mAddress.trim(), + address, mPort, - mDomain, // path + path, null, null); return uri.toString(); @@ -1736,6 +1743,7 @@ public class EmailStore { * * @param uriString a String containing a Uri */ + @Deprecated public void setStoreUri(String uriString) { try { URI uri = new URI(uriString); @@ -1745,9 +1753,9 @@ public class EmailStore { if (uri.getUserInfo() != null) { String[] userInfoParts = uri.getUserInfo().split(":", 2); mLogin = userInfoParts[0]; + mFlags |= FLAG_AUTHENTICATE; if (userInfoParts.length > 1) { mPassword = userInfoParts[1]; - mFlags |= FLAG_AUTHENTICATE; } } diff --git a/tests/src/com/android/email/activity/FolderMessageListUnitTests.java b/tests/src/com/android/email/activity/FolderMessageListUnitTests.java index b910466d1..20ea53719 100644 --- a/tests/src/com/android/email/activity/FolderMessageListUnitTests.java +++ b/tests/src/com/android/email/activity/FolderMessageListUnitTests.java @@ -42,13 +42,14 @@ public class FolderMessageListUnitTests extends AndroidTestCase { */ @Override protected void tearDown() throws Exception { - super.tearDown(); - if (mAccount != null) { Uri uri = ContentUris.withAppendedId( EmailStore.Account.CONTENT_URI, mAccountId); getContext().getContentResolver().delete(uri, null, null); } + + // must call last because it scrubs member variables + super.tearDown(); } /** diff --git a/tests/src/com/android/email/activity/setup/AccountSettingsTests.java b/tests/src/com/android/email/activity/setup/AccountSettingsTests.java index 2752f8757..68323a191 100644 --- a/tests/src/com/android/email/activity/setup/AccountSettingsTests.java +++ b/tests/src/com/android/email/activity/setup/AccountSettingsTests.java @@ -64,13 +64,14 @@ public class AccountSettingsTests extends ActivityInstrumentationTestCase2 { + // Borrowed from AccountSetupAccountType + private static final String EXTRA_ACCOUNT = "account"; + Context mContext; - private Preferences mPreferences; - private HashSet mAccounts = new HashSet(); + private HashSet mAccounts = new HashSet(); public AccountSetupAccountTypeUnitTests() { super(AccountSetupAccountType.class); @@ -50,7 +53,6 @@ public class AccountSetupAccountTypeUnitTests super.setUp(); mContext = this.getInstrumentation().getTargetContext(); - mPreferences = Preferences.getPreferences(mContext); } /** @@ -58,22 +60,23 @@ public class AccountSetupAccountTypeUnitTests */ @Override protected void tearDown() throws Exception { - super.tearDown(); - - if (mPreferences != null) { - for (Account account : mAccounts) { - account.delete(mPreferences); - } + for (EmailStore.Account account : mAccounts) { + Uri uri = ContentUris.withAppendedId( + EmailStore.Account.CONTENT_URI, account.mId); + mContext.getContentResolver().delete(uri, null, null); } + + // must call last because it scrubs member variables + super.tearDown(); } /** * Test store type limit enforcement */ public void testStoreTypeLimits() { - Account acct1 = createTestAccount("scheme1"); - Account acct2 = createTestAccount("scheme1"); - Account acct3 = createTestAccount("scheme2"); + EmailStore.Account acct1 = createTestAccount("scheme1"); + EmailStore.Account acct2 = createTestAccount("scheme1"); + EmailStore.Account acct3 = createTestAccount("scheme2"); AccountSetupAccountType activity = startActivity(getTestIntent(acct1), null, null); @@ -95,10 +98,10 @@ public class AccountSetupAccountTypeUnitTests /** * Create a dummy account with minimal fields */ - private Account createTestAccount(String scheme) { - Account account = new Account(mContext); - account.setStoreUri(scheme + "://user:pass@server.com:port"); - account.save(mPreferences); + private EmailStore.Account createTestAccount(String scheme) { + EmailStore.Account account = new EmailStore.Account(); + account.setStoreUri(mContext, scheme + "://user:pass@server.com:123"); + account.saveOrUpdate(mContext); mAccounts.add(account); return account; } @@ -106,9 +109,9 @@ public class AccountSetupAccountTypeUnitTests /** * Create an intent with the Account in it */ - private Intent getTestIntent(Account account) { + private Intent getTestIntent(EmailStore.Account account) { Intent i = new Intent(Intent.ACTION_MAIN); - i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account" + i.putExtra(EXTRA_ACCOUNT, account); return i; } diff --git a/tests/src/com/android/email/activity/setup/AccountSetupExchangeTests.java b/tests/src/com/android/email/activity/setup/AccountSetupExchangeTests.java index 419259963..8c1b05d2d 100644 --- a/tests/src/com/android/email/activity/setup/AccountSetupExchangeTests.java +++ b/tests/src/com/android/email/activity/setup/AccountSetupExchangeTests.java @@ -16,8 +16,8 @@ package com.android.email.activity.setup; -import com.android.email.Account; import com.android.email.R; +import com.android.email.provider.EmailStore; import android.content.Intent; import android.test.ActivityInstrumentationTestCase2; @@ -33,6 +33,9 @@ import android.widget.EditText; public class AccountSetupExchangeTests extends ActivityInstrumentationTestCase2 { + // borrowed from AccountSetupExchange + private static final String EXTRA_ACCOUNT = "account"; + private AccountSetupExchange mActivity; private EditText mServerView; private EditText mDomainView; @@ -171,10 +174,10 @@ public class AccountSetupExchangeTests extends * Create an intent with the Account in it */ private Intent getTestIntent(String storeUriString) { - Account account = new Account(this.getInstrumentation().getTargetContext()); - account.setStoreUri(storeUriString); + EmailStore.Account account = new EmailStore.Account(); + account.setStoreUri(getInstrumentation().getTargetContext(), storeUriString); Intent i = new Intent(Intent.ACTION_MAIN); - i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account" + i.putExtra(EXTRA_ACCOUNT, account); return i; } diff --git a/tests/src/com/android/email/activity/setup/AccountSetupIncomingTests.java b/tests/src/com/android/email/activity/setup/AccountSetupIncomingTests.java index ccb4bea8b..ebc98dfd6 100644 --- a/tests/src/com/android/email/activity/setup/AccountSetupIncomingTests.java +++ b/tests/src/com/android/email/activity/setup/AccountSetupIncomingTests.java @@ -16,8 +16,8 @@ package com.android.email.activity.setup; -import com.android.email.Account; import com.android.email.R; +import com.android.email.provider.EmailStore; import android.content.Intent; import android.test.ActivityInstrumentationTestCase2; @@ -32,6 +32,9 @@ import android.widget.EditText; @MediumTest public class AccountSetupIncomingTests extends ActivityInstrumentationTestCase2 { + + // borrowed from AccountSetupIncoming + private static final String EXTRA_ACCOUNT = "account"; private AccountSetupIncoming mActivity; private EditText mServerView; @@ -141,10 +144,10 @@ public class AccountSetupIncomingTests extends * Create an intent with the Account in it */ private Intent getTestIntent(String storeUriString) { - Account account = new Account(this.getInstrumentation().getTargetContext()); - account.setStoreUri(storeUriString); + EmailStore.Account account = new EmailStore.Account(); + account.setStoreUri(getInstrumentation().getTargetContext(), storeUriString); Intent i = new Intent(Intent.ACTION_MAIN); - i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account" + i.putExtra(EXTRA_ACCOUNT, account); return i; } diff --git a/tests/src/com/android/email/activity/setup/AccountSetupNamesTests.java b/tests/src/com/android/email/activity/setup/AccountSetupNamesTests.java index 630464d39..d5e808131 100644 --- a/tests/src/com/android/email/activity/setup/AccountSetupNamesTests.java +++ b/tests/src/com/android/email/activity/setup/AccountSetupNamesTests.java @@ -16,10 +16,13 @@ package com.android.email.activity.setup; -import com.android.email.Account; import com.android.email.R; +import com.android.email.provider.EmailStore; +import android.content.ContentUris; +import android.content.Context; import android.content.Intent; +import android.net.Uri; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.MediumTest; import android.widget.Button; @@ -30,6 +33,13 @@ import android.widget.Button; @MediumTest public class AccountSetupNamesTests extends ActivityInstrumentationTestCase2 { + // borrowed from AccountSetupNames + private static final String EXTRA_ACCOUNT_ID = "accountId"; + + private long mAccountId; + private EmailStore.Account mAccount; + + private Context mContext; private AccountSetupNames mActivity; private Button mDoneButton; @@ -37,6 +47,31 @@ public class AccountSetupNamesTests extends ActivityInstrumentationTestCase2 { + // borrowed from AccountSetupOptions + private static final String EXTRA_ACCOUNT = "account"; + private AccountSetupOptions mActivity; private Spinner mCheckFrequencyView; @@ -49,7 +52,7 @@ public class AccountSetupOptionsTests getActivityAndFields(); - boolean hasPush = frequencySpinnerHasValue(Account.CHECK_INTERVAL_PUSH); + boolean hasPush = frequencySpinnerHasValue(EmailStore.Account.CHECK_INTERVAL_PUSH); assertFalse(hasPush); } @@ -62,7 +65,7 @@ public class AccountSetupOptionsTests getActivityAndFields(); - boolean hasPush = frequencySpinnerHasValue(Account.CHECK_INTERVAL_PUSH); + boolean hasPush = frequencySpinnerHasValue(EmailStore.Account.CHECK_INTERVAL_PUSH); assertFalse(hasPush); } @@ -81,7 +84,7 @@ public class AccountSetupOptionsTests getActivityAndFields(); - boolean hasPush = frequencySpinnerHasValue(Account.CHECK_INTERVAL_PUSH); + boolean hasPush = frequencySpinnerHasValue(EmailStore.Account.CHECK_INTERVAL_PUSH); assertTrue(hasPush); } @@ -112,11 +115,11 @@ public class AccountSetupOptionsTests * Create an intent with the Account in it */ private Intent getTestIntent(String name, String storeUri) { - Account account = new Account(this.getInstrumentation().getTargetContext()); + EmailStore.Account account = new EmailStore.Account(); account.setName(name); - account.setStoreUri(storeUri); + account.setStoreUri(getInstrumentation().getTargetContext(), storeUri); Intent i = new Intent(Intent.ACTION_MAIN); - i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account" + i.putExtra(EXTRA_ACCOUNT, account); return i; } diff --git a/tests/src/com/android/email/activity/setup/AccountSetupOutgoingTests.java b/tests/src/com/android/email/activity/setup/AccountSetupOutgoingTests.java index 539391fcb..6e63b2066 100644 --- a/tests/src/com/android/email/activity/setup/AccountSetupOutgoingTests.java +++ b/tests/src/com/android/email/activity/setup/AccountSetupOutgoingTests.java @@ -16,8 +16,8 @@ package com.android.email.activity.setup; -import com.android.email.Account; import com.android.email.R; +import com.android.email.provider.EmailStore; import android.content.Intent; import android.test.ActivityInstrumentationTestCase2; @@ -138,8 +138,8 @@ public class AccountSetupOutgoingTests extends * Create an intent with the Account in it */ private Intent getTestIntent(String senderUriString) { - Account account = new Account(this.getInstrumentation().getTargetContext()); - account.setSenderUri(senderUriString); + EmailStore.Account account = new EmailStore.Account(); + account.setSenderUri(this.getInstrumentation().getTargetContext(), senderUriString); Intent i = new Intent(Intent.ACTION_MAIN); i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account" return i;