Add per-account preference for bkgnd attachments

* Add flag to Account record
* Add checkbox to Account Settings (IMAP & EAS)
* Add checkbox to Account Setup (IMAP & EAS)
* Add flag to backup/restore logic
* Update Account & AccountSetupOptions unit tests

Bug: 3360873
Change-Id: I0c407776ede4110f33716644f6f027938f21130a
This commit is contained in:
Andy Stadler 2011-01-18 10:53:37 -08:00
parent f264ea638d
commit 946239e8a0
12 changed files with 153 additions and 28 deletions

View File

@ -149,4 +149,20 @@
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/account_setup_divider_color" />
<!-- Auto-download attachments - always show, unless POP3 -->
<CheckBox
android:id="@+id/account_background_attachments"
android:layout_below="@+id/account_sync_email_divider"
android:layout_marginTop="16dip"
android:layout_marginBottom="16dip"
android:layout_marginLeft="32dip"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/account_setup_options_background_attachments_label" />
<View
android:id="@+id/account_background_attachments_divider"
android:layout_below="@+id/account_sync_email"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/account_setup_divider_color" />
</RelativeLayout>

View File

@ -34,6 +34,10 @@
<string name="permission_access_provider_label"></string>
<!-- Do Not Translate. Unused string. -->
<string name="permission_access_provider_desc"></string>
<!-- Do Not Translate. Unused string. -->
<string name="general_preference_background_attachments_label"></string>
<!-- Do Not Translate. Unused string. -->
<string name="general_preference_background_attachments_summary"></string>
<!-- Name of application on Home screen -->
<string name="app_name">Email</string>
@ -632,6 +636,10 @@ save attachment.</string>
<!-- In Account setup options screen, check box to sync email -->
<string name="account_setup_options_sync_email_label">Sync email from this account.
</string>
<!-- In Account setup options screen, check box to auto-download attachments [CHAR LIMIT=none]
-->
<string name="account_setup_options_background_attachments_label">Auto-download attachments
when connected via Wi-Fi</string>
<!-- Dialog title when "setup" could not finish -->
<string name="account_setup_failed_dlg_title">Setup could not finish</string>
<!-- In Account setup options screen, label for email check frequency selector -->
@ -749,6 +757,12 @@ save attachment.</string>
<!-- Note, this should usually match the default account account setup checkbox string -->
<string name="account_settings_default_summary">Send email from this account by default</string>
<!-- On Settings screen, setting option name -->
<!-- Title of account preference for downloading attachments in background [CHAR LIMIT=32] -->
<string name="account_settings_background_attachments_label">
Auto-download attachments</string>
<!-- Summary of account preference for downloading attachments in background [CHAR LIMIT=64] -->
<string name="account_settings_background_attachments_summary">
Download files attached to recent messages when connected via Wi-Fi</string>
<string name="account_settings_notify_label">Email notifications</string>
<!-- On Settings screen, summary line when called via AccountManager for Exchange accounts
[CHAR LIMIT=50] -->
@ -974,15 +988,6 @@ save attachment.</string>
<!-- General preference: Text zoom. Value is "huge" (+2) [CHAR LIMIT=32] -->
<string name="general_preference_text_zoom_huge">Huge</string>
<!-- General preference: Allow downloading of attachments in background -->
<!-- Title of general preference for downloading attachments in background [CHAR LIMIT=32] -->
<string name="general_preference_background_attachments_label">
Automatically fetch attachments</string>
<!-- Summary of general preference for downloading attachments in background [CHAR LIMIT=64] -->
<string name="general_preference_background_attachments_summary">
Download attachments for Inbox messages. (Not available for POP3 accounts.)
</string>
<!-- Generic string for "current position" / "total number" [CHAR LIMIT=12] -->
<string name="position_of_count"><xliff:g example="1">%1$d</xliff:g> of <xliff:g
example="12">%2$s</xliff:g></string>

View File

@ -50,9 +50,16 @@
<!-- Reserve order#5 here for window size (if inserted) -->
<!-- (will hide on POP3 accounts) -->
<CheckBoxPreference
android:key="account_background_attachments"
android:order="6"
android:title="@string/account_settings_background_attachments_label"
android:summary="@string/account_settings_background_attachments_summary" />
<CheckBoxPreference
android:key="account_default"
android:order="6"
android:order="7"
android:title="@string/account_settings_default_label"
android:summary="@string/account_settings_default_summary" />

View File

@ -36,10 +36,5 @@
android:entryValues="@array/general_preference_text_zoom_values"
android:dialogTitle="@string/general_preference_text_zoom_dialog_title" />
<CheckBoxPreference
android:key="background_attachments"
android:title="@string/general_preference_background_attachments_label"
android:summary="@string/general_preference_background_attachments_summary" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -53,6 +53,7 @@ public class Account {
// Since email sync has always been "on" prior to the creation of this flag, it's sense is
// reversed to avoid legacy issues.
public static final int BACKUP_FLAGS_DONT_SYNC_EMAIL = 16;
public static final int BACKUP_FLAGS_BACKGROUND_ATTACHMENTS = 32;
// serialized values
String mUuid;

View File

@ -135,6 +135,11 @@ public class AccountBackupRestore {
}
}
// Attachment downloading
if ((fromAccount.mFlags & EmailContent.Account.FLAGS_BACKGROUND_ATTACHMENTS) != 0) {
toAccount.mBackupFlags |= Account.BACKUP_FLAGS_BACKGROUND_ATTACHMENTS;
}
// If this is the default account, mark it as such
if (fromAccount.mId == defaultAccountId) {
toAccount.mBackupFlags |= Account.BACKUP_FLAGS_IS_DEFAULT;
@ -190,6 +195,11 @@ public class AccountBackupRestore {
toAccount.setDefaultAccount(true);
}
// Restore attachment flag
if (0 != (backupAccount.mBackupFlags & Account.BACKUP_FLAGS_BACKGROUND_ATTACHMENTS)) {
toAccount.mFlags |= EmailContent.Account.FLAGS_BACKGROUND_ATTACHMENTS;
}
// Note that the sense of the email flag is opposite that of contacts/calendar flags
boolean email =
(backupAccount.mBackupFlags & Account.BACKUP_FLAGS_DONT_SYNC_EMAIL) == 0;

View File

@ -69,6 +69,8 @@ public class AccountSettingsFragment extends PreferenceFragment {
private static final String PREFERENCE_NAME = "account_name";
private static final String PREFERENCE_SIGNATURE = "account_signature";
private static final String PREFERENCE_FREQUENCY = "account_check_frequency";
private static final String PREFERENCE_BACKGROUND_ATTACHMENTS =
"account_background_attachments";
private static final String PREFERENCE_DEFAULT = "account_default";
private static final String PREFERENCE_CATEGORY_NOTIFICATIONS = "account_notifications";
private static final String PREFERENCE_NOTIFY = "account_notify";
@ -92,6 +94,7 @@ public class AccountSettingsFragment extends PreferenceFragment {
private EditTextPreference mAccountSignature;
private ListPreference mCheckFrequency;
private ListPreference mSyncWindow;
private CheckBoxPreference mAccountBackgroundAttachments;
private CheckBoxPreference mAccountDefault;
private CheckBoxPreference mAccountNotify;
private ListPreference mAccountVibrateWhen;
@ -446,6 +449,17 @@ public class AccountSettingsFragment extends PreferenceFragment {
topCategory.addPreference(mSyncWindow);
}
// Show "background attachments" for IMAP & EAS - hide it for POP3.
mAccountBackgroundAttachments = (CheckBoxPreference)
findPreference(PREFERENCE_BACKGROUND_ATTACHMENTS);
if ("pop3".equals(mAccount.mHostAuthRecv.mProtocol)) {
topCategory.removePreference(mAccountBackgroundAttachments);
} else {
mAccountBackgroundAttachments.setChecked(
0 != (mAccount.getFlags() & Account.FLAGS_BACKGROUND_ATTACHMENTS));
mAccountBackgroundAttachments.setOnPreferenceChangeListener(mPreferenceChangeListener);
}
mAccountDefault = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT);
mAccountDefault.setChecked(mAccount.mId == mDefaultAccountId);
mAccountDefault.setOnPreferenceChangeListener(mPreferenceChangeListener);
@ -578,10 +592,14 @@ public class AccountSettingsFragment extends PreferenceFragment {
* committed before we might be killed.
*/
private void saveSettings() {
// Turn off all controlled flags - will turn them back on while checking UI elements
int newFlags = mAccount.getFlags() &
~(Account.FLAGS_NOTIFY_NEW_MAIL |
Account.FLAGS_VIBRATE_ALWAYS | Account.FLAGS_VIBRATE_WHEN_SILENT);
Account.FLAGS_VIBRATE_ALWAYS | Account.FLAGS_VIBRATE_WHEN_SILENT |
Account.FLAGS_BACKGROUND_ATTACHMENTS);
newFlags |= mAccountBackgroundAttachments.isChecked() ?
Account.FLAGS_BACKGROUND_ATTACHMENTS : 0;
mAccount.setDefaultAccount(mAccountDefault.isChecked());
mAccount.setDisplayName(mAccountDescription.getText());
mAccount.setSenderName(mAccountName.getText());

View File

@ -58,6 +58,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
private CheckBox mSyncContactsView;
private CheckBox mSyncCalendarView;
private CheckBox mSyncEmailView;
private CheckBox mBackgroundAttachmentsView;
private boolean mDonePressed = false;
public static final int REQUEST_CODE_ACCEPT_POLICIES = 1;
@ -83,6 +84,8 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
mSyncCalendarView = (CheckBox) findViewById(R.id.account_sync_calendar);
mSyncEmailView = (CheckBox) findViewById(R.id.account_sync_email);
mSyncEmailView.setChecked(true);
mBackgroundAttachmentsView = (CheckBox) findViewById(R.id.account_background_attachments);
mBackgroundAttachmentsView.setChecked(true);
findViewById(R.id.previous).setOnClickListener(this);
findViewById(R.id.next).setOnClickListener(this);
@ -139,6 +142,12 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
findViewById(R.id.account_sync_calendar_divider).setVisibility(View.VISIBLE);
}
// If we are in POP3, hide the "Background Attachments" mode
if ("pop3".equals(info.mScheme)) {
mBackgroundAttachmentsView.setVisibility(View.GONE);
findViewById(R.id.account_background_attachments_divider).setVisibility(View.GONE);
}
// If we are just visiting here to fill in details, exit immediately
if (SetupData.isAutoSetup() ||
SetupData.getFlowMode() == SetupData.FLOW_MODE_FORCE_CREATE) {
@ -176,9 +185,13 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
private void onDone() {
final Account account = SetupData.getAccount();
account.setDisplayName(account.getEmailAddress());
int newFlags = account.getFlags() & ~(EmailContent.Account.FLAGS_NOTIFY_NEW_MAIL);
int newFlags = account.getFlags() &
~(Account.FLAGS_NOTIFY_NEW_MAIL | Account.FLAGS_BACKGROUND_ATTACHMENTS);
if (mNotifyView.isChecked()) {
newFlags |= EmailContent.Account.FLAGS_NOTIFY_NEW_MAIL;
newFlags |= Account.FLAGS_NOTIFY_NEW_MAIL;
}
if (mBackgroundAttachmentsView.isChecked()) {
newFlags |= Account.FLAGS_BACKGROUND_ATTACHMENTS;
}
account.setFlags(newFlags);
account.setSyncInterval((Integer)((SpinnerOption)mCheckFrequencyView

View File

@ -30,12 +30,10 @@ public class GeneralPreferences extends PreferenceFragment implements OnPreferen
private static final String PREFERENCE_KEY_AUTO_ADVANCE = "auto_advance";
private static final String PREFERENCE_KEY_TEXT_ZOOM = "text_zoom";
private static final String PREFERENCE_KEY_BACKGROUND_ATTACHMENTS = "background_attachments";
private Preferences mPreferences;
private ListPreference mAutoAdvance;
private ListPreference mTextZoom;
private CheckBoxPreference mBackgroundAttachments;
CharSequence[] mSizeSummaries;
@ -64,9 +62,6 @@ public class GeneralPreferences extends PreferenceFragment implements OnPreferen
mPreferences.setTextZoom(mTextZoom.findIndexOfValue((String) newValue));
reloadDynamicSummaries();
return true;
} else if (PREFERENCE_KEY_BACKGROUND_ATTACHMENTS.equals(key)) {
mPreferences.setBackgroundAttachments((Boolean) newValue);
return true;
}
return false;
}
@ -81,10 +76,6 @@ public class GeneralPreferences extends PreferenceFragment implements OnPreferen
mTextZoom.setValueIndex(mPreferences.getTextZoom());
mTextZoom.setOnPreferenceChangeListener(this);
mBackgroundAttachments = (CheckBoxPreference)
findPreference(PREFERENCE_KEY_BACKGROUND_ATTACHMENTS);
mBackgroundAttachments.setChecked(mPreferences.getBackgroundAttachments());
mBackgroundAttachments.setOnPreferenceChangeListener(this);
reloadDynamicSummaries();
}

View File

@ -967,6 +967,7 @@ public abstract class EmailContent {
public static final int FLAGS_SECURITY_HOLD = 32;
public static final int FLAGS_VIBRATE_WHEN_SILENT = 64;
public static final int FLAGS_SUPPORTS_SMART_FORWARD = 128;
public static final int FLAGS_BACKGROUND_ATTACHMENTS = 256;
public static final int DELETE_POLICY_NEVER = 0;
public static final int DELETE_POLICY_7DAYS = 1; // not supported

View File

@ -163,6 +163,24 @@ public class AccountUnitTests extends AndroidTestCase {
mAccount.mBackupFlags = -1;
mAccount.refresh(mPreferences);
assertEquals(Account.BACKUP_FLAGS_IS_DEFAULT, mAccount.mBackupFlags);
mAccount.mBackupFlags = Account.BACKUP_FLAGS_SYNC_CALENDAR;
mAccount.save(mPreferences);
mAccount.mBackupFlags = -1;
mAccount.refresh(mPreferences);
assertEquals(Account.BACKUP_FLAGS_SYNC_CALENDAR, mAccount.mBackupFlags);
mAccount.mBackupFlags = Account.BACKUP_FLAGS_DONT_SYNC_EMAIL;
mAccount.save(mPreferences);
mAccount.mBackupFlags = -1;
mAccount.refresh(mPreferences);
assertEquals(Account.BACKUP_FLAGS_DONT_SYNC_EMAIL, mAccount.mBackupFlags);
mAccount.mBackupFlags = Account.BACKUP_FLAGS_BACKGROUND_ATTACHMENTS;
mAccount.save(mPreferences);
mAccount.mBackupFlags = -1;
mAccount.refresh(mPreferences);
assertEquals(Account.BACKUP_FLAGS_BACKGROUND_ATTACHMENTS, mAccount.mBackupFlags);
}
/**

View File

@ -23,6 +23,8 @@ import com.android.email.provider.EmailContent;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
@ -37,6 +39,7 @@ public class AccountSetupOptionsTests
private AccountSetupOptions mActivity;
private Spinner mCheckFrequencyView;
private CheckBox mBackgroundAttachmentsView;
public AccountSetupOptionsTests() {
super(AccountSetupOptions.class);
@ -86,13 +89,60 @@ public class AccountSetupOptionsTests
boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
assertTrue(hasPush);
}
/**
* Test that POP3 accounts don't have a "background attachments" checkbox
*/
public void testBackgroundAttachmentsPop() {
checkBackgroundAttachments("pop3://user:password@server.com", false);
}
/**
* Test that IMAP accounts have a "background attachments" checkbox
*/
public void testBackgroundAttachmentsImap() {
checkBackgroundAttachments("imap://user:password@server.com", true);
}
/**
* Test that EAS accounts have a "background attachments" checkbox
*/
public void testBackgroundAttachmentsEas() {
// This test should only be run if EAS is supported
if (Store.StoreInfo.getStoreInfo("eas", this.getInstrumentation().getTargetContext())
== null) {
return;
}
checkBackgroundAttachments("eas://user:password@server.com", true);
}
/**
* Common code to check that the "background attachments" checkbox is shown/hidden properly
*/
private void checkBackgroundAttachments(String storeUri, boolean expectVisible) {
Intent i = getTestIntent("Name", storeUri);
this.setActivityIntent(i);
getActivityAndFields();
boolean isNull = mBackgroundAttachmentsView == null;
boolean isVisible = !isNull && (mBackgroundAttachmentsView.getVisibility() == View.VISIBLE);
if (!expectVisible) {
assertTrue(!isVisible);
} else {
assertTrue(!isNull);
assertTrue(isVisible);
}
}
/**
* Get the activity (which causes it to be started, using our intent) and get the UI fields
*/
private void getActivityAndFields() {
mActivity = getActivity();
mCheckFrequencyView = (Spinner) mActivity.findViewById(R.id.account_check_frequency);
mBackgroundAttachmentsView = (CheckBox) mActivity.findViewById(
R.id.account_background_attachments);
}
/**