AI 146331: Make the download window sizing adjustable on a per-store basis.

The default values are 25 (default) and 25 (increment).  This is fine
  for Stores that control downloads by # of messages, but won't work for
  stores that use other measurements - e.g. EAS windows the download in #
  of days.  So for this change:
  1.  Allow the StoreInfo to provide non-default values
  2.  Remove the hardcoded references to the default values
  3.  Use StoreInfo values everywhere
  4.  Set the values to 1,1 in EAS store info
  BUG=1789913

Automated import of CL 146331
This commit is contained in:
Andy Stadler 2009-04-15 10:58:59 -07:00 committed by The Android Open Source Project
parent 1464095f9f
commit 4836f3c289
7 changed files with 110 additions and 9 deletions

View File

@ -36,5 +36,5 @@
<!-- This is here for temporary demo purposes only. Do not ship with this. -->
<store scheme="eas" class="com.android.email.mail.exchange.ExchangeStoreExample"
push="true" />
push="true" visibleLimitDefault="1" visibleLimitIncrement="1" />
</stores>

View File

@ -99,10 +99,10 @@ public class Email extends Application {
* on each new folder and can be incremented with "Load more messages..." by the
* VISIBLE_LIMIT_INCREMENT
*/
public static final int DEFAULT_VISIBLE_LIMIT = 25;
public static final int VISIBLE_LIMIT_DEFAULT = 25;
/**
* Number of additioanl messages to load when a user selectes "Load more messages..."
* Number of additional messages to load when a user selects "Load more messages..."
*/
public static final int VISIBLE_LIMIT_INCREMENT = 25;

View File

@ -310,11 +310,16 @@ public class MessagingController implements Runnable {
public void loadMoreMessages(Account account, String folder, MessagingListener listener) {
try {
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(),
mApplication);
LocalStore localStore = (LocalStore) Store.getInstance(
account.getLocalStoreUri(), mApplication, null);
LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder);
localFolder.setVisibleLimit(localFolder.getVisibleLimit()
+ Email.VISIBLE_LIMIT_INCREMENT);
int oldLimit = localFolder.getVisibleLimit();
if (oldLimit <= 0) {
oldLimit = info.mVisibleLimitDefault;
}
localFolder.setVisibleLimit(oldLimit + info.mVisibleLimitIncrement);
synchronizeMailbox(account, folder, listener);
}
catch (MessagingException me) {
@ -325,9 +330,11 @@ public class MessagingController implements Runnable {
public void resetVisibleLimits(Account[] accounts) {
for (Account account : accounts) {
try {
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(),
mApplication);
LocalStore localStore =
(LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication, null);
localStore.resetVisibleLimits();
localStore.resetVisibleLimits(info.mVisibleLimitDefault);
}
catch (MessagingException e) {
Log.e(Email.LOG_TAG, "Unable to reset visible limits", e);
@ -453,6 +460,12 @@ public class MessagingController implements Runnable {
int remoteMessageCount = remoteFolder.getMessageCount();
int visibleLimit = localFolder.getVisibleLimit();
if (visibleLimit <= 0) {
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(account.getStoreUri(),
mApplication);
visibleLimit = info.mVisibleLimitDefault;
localFolder.setVisibleLimit(visibleLimit);
}
Message[] remoteMessages = new Message[0];
final ArrayList<Message> unsyncedMessages = new ArrayList<Message>();

View File

@ -93,7 +93,10 @@ public abstract class Store {
public String mScheme;
public String mClassName;
public boolean mPushSupported = false;
public int mVisibleLimitDefault;
public int mVisibleLimitIncrement;
// TODO cache result for performance - silly to keep reading the XML
public static StoreInfo getStoreInfo(String scheme, Context context) {
StoreInfo result = getStoreInfo(R.xml.stores_product, scheme, context);
if (result == null) {
@ -117,6 +120,10 @@ public abstract class Store {
result.mClassName = xml.getAttributeValue(null, "class");
result.mPushSupported = xml.getAttributeBooleanValue(
null, "push", false);
result.mVisibleLimitDefault = xml.getAttributeIntValue(
null, "visibleLimitDefault", Email.VISIBLE_LIMIT_DEFAULT);
result.mVisibleLimitIncrement = xml.getAttributeIntValue(
null, "visibleLimitIncrement", Email.VISIBLE_LIMIT_INCREMENT);
return result;
}
}

View File

@ -88,6 +88,7 @@ public class LocalStore extends Store {
private SQLiteDatabase mDb;
private File mAttachmentsDir;
private Context mContext;
private int mVisibleLimitDefault = -1;
/**
* Static named constructor.
@ -327,9 +328,19 @@ public class LocalStore extends Store {
}
}
public void resetVisibleLimits() {
/**
* Set the visible limit for all folders in a given store.
*
* NOTE: <b>Does Not</b> update cached values for any held Folder objects. This is
* intended only for use at startup time. To reset the value for any given folder, use
* {@link LocalFolder#setVisibleLimit(int)}.
*
* @param visibleLimit the value to write to all folders. -1 may also be used as a marker.
*/
public void resetVisibleLimits(int visibleLimit) {
mVisibleLimitDefault = visibleLimit; // used for future Folder.create ops
ContentValues cv = new ContentValues();
cv.put("visible_limit", Integer.toString(Email.DEFAULT_VISIBLE_LIMIT));
cv.put("visible_limit", Integer.toString(visibleLimit));
mDb.update("folders", cv, null, null);
}
@ -478,7 +489,7 @@ public class LocalStore extends Store {
}
mDb.execSQL("INSERT INTO folders (name, visible_limit) VALUES (?, ?)", new Object[] {
mName,
25
mVisibleLimitDefault
});
return true;
}

View File

@ -16,6 +16,8 @@
package com.android.email.mail;
import com.android.email.Email;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.MediumTest;
@ -36,6 +38,8 @@ public class StoreTests extends AndroidTestCase {
assertNotNull("scheme null", info.mScheme);
assertNotNull("classname null", info.mClassName);
assertFalse(info.mPushSupported);
assertEquals(Email.VISIBLE_LIMIT_DEFAULT, info.mVisibleLimitDefault);
assertEquals(Email.VISIBLE_LIMIT_INCREMENT, info.mVisibleLimitIncrement);
// This will throw MessagingException if the result would have been null
Store store = Store.getInstance(storeUri, getContext(), null);
@ -52,6 +56,8 @@ public class StoreTests extends AndroidTestCase {
assertNotNull("scheme null", info.mScheme);
assertNotNull("classname null", info.mClassName);
assertFalse(info.mPushSupported);
assertEquals(Email.VISIBLE_LIMIT_DEFAULT, info.mVisibleLimitDefault);
assertEquals(Email.VISIBLE_LIMIT_INCREMENT, info.mVisibleLimitIncrement);
// This will throw MessagingException if the result would have been null
Store store = Store.getInstance(storeUri, getContext(), null);
@ -68,6 +74,8 @@ public class StoreTests extends AndroidTestCase {
assertNotNull("scheme null", info.mScheme);
assertNotNull("classname null", info.mClassName);
assertTrue(info.mPushSupported);
assertEquals(1, info.mVisibleLimitDefault);
assertEquals(1, info.mVisibleLimitIncrement);
// This will throw MessagingException if the result would have been null
Store store = Store.getInstance(storeUri, getContext(), null);

View File

@ -16,6 +16,7 @@
package com.android.email.mail.store;
import com.android.email.Email;
import com.android.email.mail.Address;
import com.android.email.mail.Folder;
import com.android.email.mail.Message;
@ -250,6 +251,67 @@ public class LocalStoreUnitTests extends AndroidTestCase {
assertEquals("value-2-2b", callbacks2.getPersistentString("key2", null)); // changed
}
/**
* Test visible limits support
*/
public void testReadWriteVisibleLimits() throws MessagingException {
mFolder.open(OpenMode.READ_WRITE, null);
// set up a 2nd folder to confirm independent storage
LocalStore.LocalFolder folder2 = (LocalStore.LocalFolder) mStore.getFolder("FOLDER-2");
assertFalse(folder2.exists());
folder2.create(FolderType.HOLDS_MESSAGES);
folder2.open(OpenMode.READ_WRITE, null);
// read and write, look for independent storage
mFolder.setVisibleLimit(100);
folder2.setVisibleLimit(200);
mFolder.close(false);
folder2.close(false);
mFolder.open(OpenMode.READ_WRITE, null);
folder2.open(OpenMode.READ_WRITE, null);
assertEquals(100, mFolder.getVisibleLimit());
assertEquals(200, folder2.getVisibleLimit());
}
/**
* Test reset limits support
*/
public void testResetVisibleLimits() throws MessagingException {
mFolder.open(OpenMode.READ_WRITE, null);
// set up a 2nd folder to confirm independent storage
LocalStore.LocalFolder folder2 = (LocalStore.LocalFolder) mStore.getFolder("FOLDER-2");
assertFalse(folder2.exists());
folder2.create(FolderType.HOLDS_MESSAGES);
folder2.open(OpenMode.READ_WRITE, null);
// read and write, look for independent storage
mFolder.setVisibleLimit(100);
folder2.setVisibleLimit(200);
mFolder.close(false);
folder2.close(false);
mFolder.open(OpenMode.READ_WRITE, null);
folder2.open(OpenMode.READ_WRITE, null);
mStore.resetVisibleLimits(Email.VISIBLE_LIMIT_DEFAULT);
// NOTE: The open folders do not change, because resetVisibleLimits() resets the
// database only.
assertEquals(100, mFolder.getVisibleLimit());
assertEquals(200, folder2.getVisibleLimit());
mFolder.close(false);
folder2.close(false);
mFolder.open(OpenMode.READ_WRITE, null);
folder2.open(OpenMode.READ_WRITE, null);
assertEquals(Email.VISIBLE_LIMIT_DEFAULT, mFolder.getVisibleLimit());
assertEquals(Email.VISIBLE_LIMIT_DEFAULT, folder2.getVisibleLimit());
}
/**
* Tests for database version.
*/