Change the concept of a default account

The user no longer has control over this. Now, the "default" account
(which is only used for prepopulating the name of new accounts is
either the last used account (to be defined), or the first account in
the database.

This removes a setting, and simplifies a lot of code.

We may also want to auto-select the default account when entering the
compose screen from the combined view, but we do not currently have
an easy way to do that.

Bug: 7442992
Change-Id: Iff5bb36d8cbd327334211b670fa4851cbda6b9a0
This commit is contained in:
Scott Kennedy 2013-06-26 15:49:12 -07:00
parent cf5dc6ba4f
commit 229c070b0b
14 changed files with 74 additions and 270 deletions

View File

@ -99,13 +99,11 @@ public final class Account extends EmailContent implements AccountColumns, Parce
public static Uri CONTENT_URI;
public static Uri RESET_NEW_MESSAGE_COUNT_URI;
public static Uri NOTIFIER_URI;
public static Uri DEFAULT_ACCOUNT_ID_URI;
public static void initAccount() {
CONTENT_URI = Uri.parse(EmailContent.CONTENT_URI + "/account");
RESET_NEW_MESSAGE_COUNT_URI = Uri.parse(EmailContent.CONTENT_URI + "/resetNewMessageCount");
NOTIFIER_URI = Uri.parse(EmailContent.CONTENT_NOTIFIER_URI + "/account");
DEFAULT_ACCOUNT_ID_URI = Uri.parse(EmailContent.CONTENT_URI + "/account/default");
}
public String mDisplayName;
@ -116,7 +114,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
public long mHostAuthKeyRecv;
public long mHostAuthKeySend;
public int mFlags;
public boolean mIsDefault; // note: callers should use getDefaultAccountId()
public String mCompatibilityUuid;
public String mSenderName;
public String mProtocolVersion;
@ -141,20 +138,19 @@ public final class Account extends EmailContent implements AccountColumns, Parce
public static final int CONTENT_HOST_AUTH_KEY_RECV_COLUMN = 6;
public static final int CONTENT_HOST_AUTH_KEY_SEND_COLUMN = 7;
public static final int CONTENT_FLAGS_COLUMN = 8;
public static final int CONTENT_IS_DEFAULT_COLUMN = 9;
public static final int CONTENT_COMPATIBILITY_UUID_COLUMN = 10;
public static final int CONTENT_SENDER_NAME_COLUMN = 11;
public static final int CONTENT_PROTOCOL_VERSION_COLUMN = 12;
public static final int CONTENT_NEW_MESSAGE_COUNT_COLUMN = 13;
public static final int CONTENT_SECURITY_SYNC_KEY_COLUMN = 14;
public static final int CONTENT_SIGNATURE_COLUMN = 15;
public static final int CONTENT_POLICY_KEY = 16;
public static final int CONTENT_COMPATIBILITY_UUID_COLUMN = 9;
public static final int CONTENT_SENDER_NAME_COLUMN = 10;
public static final int CONTENT_PROTOCOL_VERSION_COLUMN = 11;
public static final int CONTENT_NEW_MESSAGE_COUNT_COLUMN = 12;
public static final int CONTENT_SECURITY_SYNC_KEY_COLUMN = 13;
public static final int CONTENT_SIGNATURE_COLUMN = 14;
public static final int CONTENT_POLICY_KEY = 15;
public static final String[] CONTENT_PROJECTION = new String[] {
RECORD_ID, AccountColumns.DISPLAY_NAME,
AccountColumns.EMAIL_ADDRESS, AccountColumns.SYNC_KEY, AccountColumns.SYNC_LOOKBACK,
AccountColumns.SYNC_INTERVAL, AccountColumns.HOST_AUTH_KEY_RECV,
AccountColumns.HOST_AUTH_KEY_SEND, AccountColumns.FLAGS, AccountColumns.IS_DEFAULT,
AccountColumns.HOST_AUTH_KEY_SEND, AccountColumns.FLAGS,
AccountColumns.COMPATIBILITY_UUID, AccountColumns.SENDER_NAME,
AccountColumns.PROTOCOL_VERSION,
AccountColumns.NEW_MESSAGE_COUNT, AccountColumns.SECURITY_SYNC_KEY,
@ -175,12 +171,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
public static final String[] ACCOUNT_FLAGS_PROJECTION = new String[] {
AccountColumns.ID, AccountColumns.FLAGS};
public static final int ACCOUNT_IS_DEFAULT_COLUMN_ID = 0;
public static final int ACCOUNT_IS_DEFAULT_COLUMN_IS_DEFAULT = 1;
public static final String[] ACCOUNT_IS_DEFAULT_PROJECTION = new String[] {
AccountColumns.ID, AccountColumns.IS_DEFAULT
};
public static final String MAILBOX_SELECTION =
MessageColumns.MAILBOX_KEY + " =?";
@ -252,7 +242,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
mHostAuthKeyRecv = cursor.getLong(CONTENT_HOST_AUTH_KEY_RECV_COLUMN);
mHostAuthKeySend = cursor.getLong(CONTENT_HOST_AUTH_KEY_SEND_COLUMN);
mFlags = cursor.getInt(CONTENT_FLAGS_COLUMN);
mIsDefault = cursor.getInt(CONTENT_IS_DEFAULT_COLUMN) == 1;
mCompatibilityUuid = cursor.getString(CONTENT_COMPATIBILITY_UUID_COLUMN);
mSenderName = cursor.getString(CONTENT_SENDER_NAME_COLUMN);
mProtocolVersion = cursor.getString(CONTENT_PROTOCOL_VERSION_COLUMN);
@ -435,15 +424,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
return (account.mFlags & Account.FLAGS_SUPPORTS_SEARCH) != 0;
}
/**
* Set the account to be the default account. If this is set to "true", when the account
* is saved, all other accounts will have the same value set to "false".
* @param newDefaultState the new default state - if true, others will be cleared.
*/
public void setDefaultAccount(boolean newDefaultState) {
mIsDefault = newDefaultState;
}
/**
* @return {@link Uri} to this {@link Account} in the
* {@code content://com.android.email.provider/account/UUID} format, which is safe to use
@ -509,24 +489,39 @@ public final class Account extends EmailContent implements AccountColumns, Parce
}
/**
* Return the id of the default account. If one hasn't been explicitly specified, return
* the first one in the database (the logic is provided within EmailProvider)
* Return the id of the default account. If one hasn't been explicitly specified, return the
* first one in the database. If no account exists, returns {@link #NO_ACCOUNT}.
*
* @param context the caller's context
* @return the id of the default account, or Account.NO_ACCOUNT if there are no accounts
* @param lastUsedAccountId the last used account id, which is the basis of the default account
*/
static public long getDefaultAccountId(Context context) {
final Cursor c = context.getContentResolver().query(
Account.DEFAULT_ACCOUNT_ID_URI, Account.ID_PROJECTION, null, null, null);
public static long getDefaultAccountId(final Context context, final long lastUsedAccountId) {
final Cursor cursor = context.getContentResolver().query(
CONTENT_URI, ID_PROJECTION, null, null, null);
long firstAccount = NO_ACCOUNT;
try {
if (c != null && c.moveToFirst()) {
return c.getLong(Account.ID_PROJECTION_COLUMN);
if (cursor != null && cursor.moveToFirst()) {
do {
final long accountId = cursor.getLong(Account.ID_PROJECTION_COLUMN);
if (accountId == lastUsedAccountId) {
return accountId;
}
if (firstAccount == NO_ACCOUNT) {
firstAccount = accountId;
}
} while (cursor.moveToNext());
}
} finally {
if (c != null) {
c.close();
if (cursor != null) {
cursor.close();
}
}
return Account.NO_ACCOUNT;
return firstAccount;
}
/**
@ -664,35 +659,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
return policy.mRequireManualSyncWhenRoaming;
}
/**
* Override update to enforce a single default account, and do it atomically
*/
@Override
public int update(Context context, ContentValues cv) {
if (cv.containsKey(AccountColumns.IS_DEFAULT) &&
cv.getAsBoolean(AccountColumns.IS_DEFAULT)) {
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ContentValues cv1 = new ContentValues();
cv1.put(AccountColumns.IS_DEFAULT, false);
// Clear the default flag in all accounts
ops.add(ContentProviderOperation.newUpdate(CONTENT_URI).withValues(cv1).build());
// Update this account
ops.add(ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(CONTENT_URI, mId))
.withValues(cv).build());
try {
context.getContentResolver().applyBatch(EmailContent.AUTHORITY, ops);
return 1;
} catch (RemoteException e) {
// There is nothing to be done here; fail by returning 0
} catch (OperationApplicationException e) {
// There is nothing to be done here; fail by returning 0
}
return 0;
}
return super.update(context, cv);
}
/*
* Override this so that we can store the HostAuth's first and link them to the Account
* (non-Javadoc)
@ -706,8 +672,7 @@ public final class Account extends EmailContent implements AccountColumns, Parce
// This logic is in place so I can (a) short circuit the expensive stuff when
// possible, and (b) override (and throw) if anyone tries to call save() or update()
// directly for Account, which are unsupported.
if (mHostAuthRecv == null && mHostAuthSend == null && mIsDefault == false &&
mPolicy != null) {
if (mHostAuthRecv == null && mHostAuthSend == null && mPolicy != null) {
return super.save(context);
}
@ -731,15 +696,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
.build());
}
// Create operations for making this the only default account
// Note, these are always updates because they change existing accounts
if (mIsDefault) {
index++;
ContentValues cv1 = new ContentValues();
cv1.put(AccountColumns.IS_DEFAULT, 0);
ops.add(ContentProviderOperation.newUpdate(CONTENT_URI).withValues(cv1).build());
}
// Now do the Account
ContentValues cv = null;
if (recvIndex >= 0 || sendIndex >= 0) {
@ -795,7 +751,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
values.put(AccountColumns.HOST_AUTH_KEY_RECV, mHostAuthKeyRecv);
values.put(AccountColumns.HOST_AUTH_KEY_SEND, mHostAuthKeySend);
values.put(AccountColumns.FLAGS, mFlags);
values.put(AccountColumns.IS_DEFAULT, mIsDefault);
values.put(AccountColumns.COMPATIBILITY_UUID, mCompatibilityUuid);
values.put(AccountColumns.SENDER_NAME, mSenderName);
values.put(AccountColumns.PROTOCOL_VERSION, mProtocolVersion);
@ -845,7 +800,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
dest.writeLong(mHostAuthKeyRecv);
dest.writeLong(mHostAuthKeySend);
dest.writeInt(mFlags);
dest.writeByte(mIsDefault ? (byte)1 : (byte)0);
dest.writeString(mCompatibilityUuid);
dest.writeString(mSenderName);
dest.writeString(mProtocolVersion);
@ -883,7 +837,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
mHostAuthKeyRecv = in.readLong();
mHostAuthKeySend = in.readLong();
mFlags = in.readInt();
mIsDefault = in.readByte() == 1;
mCompatibilityUuid = in.readString();
mSenderName = in.readString();
mProtocolVersion = in.readString();

View File

@ -1552,7 +1552,13 @@ public abstract class EmailContent {
public static final String HOST_AUTH_KEY_SEND = "hostAuthKeySend";
// Flags
public static final String FLAGS = "flags";
// Default account
/**
* Default account
*
* @deprecated This should never be used any more, as default accounts are handled
* differently now
*/
@Deprecated
public static final String IS_DEFAULT = "isDefault";
// Old-Style UUID for compatibility with previous versions
public static final String COMPATIBILITY_UUID = "compatibilityUuid";

View File

@ -71,32 +71,4 @@
android:nextFocusDown="@+id/next" />
</TableRow>
</TableLayout>
<!-- Note, the next three items should be shown/hidden as a group -->
<View
android:id="@+id/account_default_divider_1"
android:layout_below="@+id/email_password_table"
android:layout_marginTop="48dip"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/account_setup_divider_color"
android:visibility="gone" />
<CheckBox
android:id="@+id/account_default"
android:layout_below="@+id/account_default_divider_1"
android:layout_marginTop="16dip"
android:layout_marginBottom="16dip"
android:layout_marginLeft="32dip"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/account_setup_basics_default_label"
android:textAppearance="@style/accountSetupInfoText"
android:visibility="gone" />
<View
android:id="@+id/account_default_divider_2"
android:layout_below="@+id/account_default"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/account_setup_divider_color"
android:visibility="gone" />
</RelativeLayout>

View File

@ -60,31 +60,9 @@
android:layout_width="match_parent" />
</TableRow>
</TableLayout>
<View
android:id="@+id/account_default_divider_upper"
android:layout_below="@+id/spinners_table"
android:layout_marginTop="32dip"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/account_setup_divider_color" />
<CheckBox
android:id="@+id/account_default"
android:layout_below="@+id/account_default_divider_upper"
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_default_label" />
<View
android:id="@+id/account_default_divider"
android:layout_below="@+id/account_default"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/account_setup_divider_color" />
<CheckBox
android:id="@+id/account_notify"
android:layout_below="@+id/account_default_divider"
android:layout_below="@+id/spinners_table"
android:layout_marginTop="16dip"
android:layout_marginBottom="16dip"
android:layout_marginLeft="32dip"

View File

@ -50,11 +50,4 @@
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:nextFocusDown="@+id/next" />
<CheckBox
android:id="@+id/account_default"
android:layout_below="@+id/account_password"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/account_setup_basics_default_label"
android:visibility="gone" />
</RelativeLayout>

View File

@ -59,11 +59,6 @@
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout>
<CheckBox
android:id="@+id/account_default"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/account_setup_options_default_label" />
<CheckBox
android:id="@+id/account_notify"
android:layout_height="wrap_content"

View File

@ -711,9 +711,6 @@ as <xliff:g id="filename">%s</xliff:g>.</string>
<string name="account_setup_options_mail_check_frequency_30min">Every 30 minutes</string>
<!-- In Account setup options & Account Settings screens, email check frequency option -->
<string name="account_setup_options_mail_check_frequency_1hour">Every hour</string>
<!-- Check box label on "Set up email" screen to make this the default account -->
<!-- Note, this should usually match the default account summary preference string -->
<string name="account_setup_options_default_label">Send email from this account by default</string>
<!-- In Account setup options & Account Settings screens, check box for new-mail notification -->
<string name="account_setup_options_notify_label">Notify me when email arrives</string>
<!-- In Account setup options screen, optional check box to also sync contacts -->
@ -909,11 +906,6 @@ as <xliff:g id="filename">%s</xliff:g>.</string>
Your login to <xliff:g id="account">%s</xliff:g> failed; the server said: <xliff:g id="reason">%s</xliff:g>
Do you want to update your username and/or password?</string>
<!-- On Settings screen, setting option name -->
<string name="account_settings_default_label">Default account</string>
<!-- Check box "summary" label on "Account options" screen to make this the default account -->
<!-- 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">

View File

@ -41,11 +41,6 @@
android:title="@string/account_settings_edit_quick_responses_label"
android:summary="@string/account_settings_edit_quick_responses_summary" />
<CheckBoxPreference
android:key="account_default"
android:title="@string/account_settings_default_label"
android:summary="@string/account_settings_default_summary" />
<PreferenceCategory
android:key="data_usage"
android:title="@string/account_settings_data_usage">

View File

@ -88,7 +88,6 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
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_DATA_USAGE = "data_usage";
private static final String PREFERENCE_CATEGORY_NOTIFICATIONS = "account_notifications";
private static final String PREFERENCE_CATEGORY_SERVER = "account_servers";
@ -115,7 +114,6 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
private ListPreference mCheckFrequency;
private ListPreference mSyncWindow;
private CheckBoxPreference mAccountBackgroundAttachments;
private CheckBoxPreference mAccountDefault;
private CheckBoxPreference mInboxNotify;
private CheckBoxPreference mInboxVibrate;
private Preference mInboxRingtone;
@ -127,7 +125,6 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
private Context mContext;
private Account mAccount;
private boolean mAccountDirty;
private long mDefaultAccountId;
private Callback mCallback = EmptyCallback.INSTANCE;
private boolean mStarted;
private boolean mLoaded;
@ -440,9 +437,9 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
/**
* Async task to load account in order to view/edit it
*/
private class LoadAccountTask extends AsyncTask<Long, Void, Object[]> {
private class LoadAccountTask extends AsyncTask<Long, Void, Account> {
@Override
protected Object[] doInBackground(Long... params) {
protected Account doInBackground(Long... params) {
long accountId = params[0];
Account account = Account.restoreAccountWithId(mContext, accountId);
if (account != null) {
@ -454,20 +451,17 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
account = null;
}
}
long defaultAccountId = Account.getDefaultAccountId(mContext);
return new Object[] { account, Long.valueOf(defaultAccountId) };
return account;
}
@Override
protected void onPostExecute(Object[] results) {
if (results != null && !isCancelled()) {
Account account = (Account) results[0];
protected void onPostExecute(Account account) {
if (!isCancelled()) {
if (account == null) {
mSaveOnExit = false;
mCallback.abandonEdit();
} else {
mAccount = account;
mDefaultAccountId = (Long) results[1];
if (mStarted && !mLoaded) {
loadSettings();
}
@ -727,10 +721,6 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
mAccountBackgroundAttachments.setOnPreferenceChangeListener(this);
}
mAccountDefault = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT);
mAccountDefault.setChecked(mAccount.mId == mDefaultAccountId);
mAccountDefault.setOnPreferenceChangeListener(this);
mInboxNotify = (CheckBoxPreference) findPreference(
FolderPreferences.PreferenceKeys.NOTIFICATIONS_ENABLED);
mInboxNotify.setOnPreferenceChangeListener(this);
@ -874,7 +864,6 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
newFlags |= mAccountBackgroundAttachments.isChecked() ?
Account.FLAGS_BACKGROUND_ATTACHMENTS : 0;
mAccount.setDefaultAccount(mAccountDefault.isChecked());
// If the display name has been cleared, we'll reset it to the default value (email addr)
mAccount.setDisplayName(mAccountDescription.getText().trim());
// The sender name must never be empty (this is enforced by the preference editor)

View File

@ -84,7 +84,6 @@ public class AccountSettingsUtils {
*/
public static ContentValues getAccountContentValues(Account account) {
ContentValues cv = new ContentValues();
cv.put(AccountColumns.IS_DEFAULT, account.mIsDefault);
cv.put(AccountColumns.DISPLAY_NAME, account.getDisplayName());
cv.put(AccountColumns.SENDER_NAME, account.getSenderName());
cv.put(AccountColumns.SIGNATURE, account.getSignature());

View File

@ -35,11 +35,11 @@ import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import com.android.email.EmailAddressValidator;
import com.android.email.Preferences;
import com.android.email.R;
import com.android.email.activity.ActivityHelper;
import com.android.email.activity.UiUtilities;
@ -110,7 +110,6 @@ public class AccountSetupBasics extends AccountSetupActivity
// Support for UI
private EditText mEmailView;
private EditText mPasswordView;
private CheckBox mDefaultView;
private final EmailAddressValidator mEmailValidator = new EmailAddressValidator();
private Provider mProvider;
private Button mManualButton;
@ -242,15 +241,10 @@ public class AccountSetupBasics extends AccountSetupActivity
mEmailView = (EditText) UiUtilities.getView(this, R.id.account_email);
mPasswordView = (EditText) UiUtilities.getView(this, R.id.account_password);
mDefaultView = (CheckBox) UiUtilities.getView(this, R.id.account_default);
mEmailView.addTextChangedListener(this);
mPasswordView.addTextChangedListener(this);
// If there are one or more accounts already in existence, then display
// the "use as default" checkbox (it defaults to hidden).
new DisplayCheckboxTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
boolean manualButtonDisplayed = true;
// Configure buttons
@ -432,16 +426,20 @@ public class AccountSetupBasics extends AccountSetupActivity
private final Callable<String> mOwnerLookupCallable = new Callable<String>() {
@Override
public String call() {
Context context = AccountSetupBasics.this;
String name = null;
long defaultId = Account.getDefaultAccountId(context);
final Context context = AccountSetupBasics.this;
final long lastUsedAccountId =
Preferences.getPreferences(context).getLastUsedAccountId();
final long defaultId = Account.getDefaultAccountId(context, lastUsedAccountId);
if (defaultId != -1) {
Account account = Account.restoreAccountWithId(context, defaultId);
final Account account = Account.restoreAccountWithId(context, defaultId);
if (account != null) {
name = account.getSenderName();
return account.getSenderName();
}
}
return name;
return null;
}
};
@ -469,7 +467,7 @@ public class AccountSetupBasics extends AccountSetupActivity
sendAuth.setLogin(mProvider.outgoingUsername, password);
// Populate the setup data, assuming that the duplicate account check will succeed
populateSetupData(getOwnerName(), email, mDefaultView.isChecked());
populateSetupData(getOwnerName(), email);
// Stop here if the login credentials duplicate an existing account
// Launch an Async task to do the work
@ -590,7 +588,7 @@ public class AccountSetupBasics extends AccountSetupActivity
sendAuth.setLogin(user, password);
sendAuth.setConnection(null, domain, HostAuth.PORT_UNKNOWN, HostAuth.FLAG_NONE);
populateSetupData(getOwnerName(), email, mDefaultView.isChecked());
populateSetupData(getOwnerName(), email);
SetupData.setAllowAutodiscover(allowAutoDiscover);
AccountSetupType.actionSelectAccountType(this);
@ -616,7 +614,7 @@ public class AccountSetupBasics extends AccountSetupActivity
HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
HostAuth.setHostAuthFromString(sendAuth, outgoing);
populateSetupData(user, email, false);
populateSetupData(user, email);
} catch (URISyntaxException e) {
// If we can't set up the URL, don't continue - account setup pages will fail too
Toast.makeText(
@ -638,13 +636,11 @@ public class AccountSetupBasics extends AccountSetupActivity
/**
* Populate SetupData's account with complete setup info.
*/
private void populateSetupData(String senderName, String senderEmail, boolean isDefault) {
private void populateSetupData(String senderName, String senderEmail) {
Account account = SetupData.getAccount();
account.setSenderName(senderName);
account.setEmailAddress(senderEmail);
account.setDisplayName(senderEmail);
account.setDefaultAccount(isDefault);
SetupData.setDefault(isDefault); // TODO - why duplicated, if already set in account
setDefaultsForProtocol(this, account);
}
@ -674,28 +670,6 @@ public class AccountSetupBasics extends AccountSetupActivity
throw new IllegalStateException();
}
/**
* AsyncTask checks count of accounts and displays "use this account as default" checkbox
* if there are more than one.
*/
private class DisplayCheckboxTask extends AsyncTask<Void, Void, Integer> {
@Override
protected Integer doInBackground(Void... params) {
return EmailContent.count(AccountSetupBasics.this, Account.CONTENT_URI);
}
@Override
protected void onPostExecute(Integer numAccounts) {
if (numAccounts > 0) {
Activity a = AccountSetupBasics.this;
UiUtilities.setVisibilitySafe(mDefaultView, View.VISIBLE);
UiUtilities.setVisibilitySafe(a, R.id.account_default_divider_1, View.VISIBLE);
UiUtilities.setVisibilitySafe(a, R.id.account_default_divider_2, View.VISIBLE);
}
}
}
private void onEnableProceedButtons(boolean enabled) {
mManualButton.setEnabled(enabled);
mNextButton.setEnabled(enabled);

View File

@ -57,7 +57,6 @@ import java.io.IOException;
public class AccountSetupOptions extends AccountSetupActivity implements OnClickListener {
private Spinner mCheckFrequencyView;
private Spinner mSyncWindowView;
private CheckBox mDefaultView;
private CheckBox mNotifyView;
private CheckBox mSyncContactsView;
private CheckBox mSyncCalendarView;
@ -86,7 +85,6 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
mCheckFrequencyView = (Spinner) UiUtilities.getView(this, R.id.account_check_frequency);
mSyncWindowView = (Spinner) UiUtilities.getView(this, R.id.account_sync_window);
mDefaultView = (CheckBox) UiUtilities.getView(this, R.id.account_default);
mNotifyView = (CheckBox) UiUtilities.getView(this, R.id.account_notify);
mSyncContactsView = (CheckBox) UiUtilities.getView(this, R.id.account_sync_contacts);
mSyncCalendarView = (CheckBox) UiUtilities.getView(this, R.id.account_sync_calendar);
@ -121,12 +119,6 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
enableLookbackSpinner();
}
// Note: It is OK to use mAccount.mIsDefault here *only* because the account
// has not been written to the DB yet. Ordinarily, call Account.getDefaultAccountId().
if (account.mIsDefault || SetupData.isDefault()) {
mDefaultView.setChecked(true);
}
mNotifyView.setChecked(true); // By default, we want notifications on
SpinnerOption.setSpinnerOptionValue(mCheckFrequencyView, account.getSyncInterval());
@ -221,7 +213,6 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
int window = (Integer)((SpinnerOption)mSyncWindowView.getSelectedItem()).value;
account.setSyncLookback(window);
}
account.setDefaultAccount(mDefaultView.isChecked());
if (account.mHostAuthRecv == null) {
throw new IllegalStateException("in AccountSetupOptions with null mHostAuthRecv");

View File

@ -57,7 +57,6 @@ public class SetupData implements Parcelable {
private boolean mAllowAutodiscover = true;
private Policy mPolicy;
private boolean mAutoSetup = false;
private boolean mDefault = false;
private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null;
// We only have one instance of SetupData; if/when the process is destroyed, this data will be
@ -151,14 +150,6 @@ public class SetupData implements Parcelable {
getInstance().mAutoSetup = autoSetup;
}
static public boolean isDefault() {
return getInstance().mDefault;
}
static public void setDefault(boolean _default) {
getInstance().mDefault = _default;
}
static public AccountAuthenticatorResponse getAccountAuthenticatorResponse() {
return getInstance().mAccountAuthenticatorResponse;
}
@ -197,7 +188,6 @@ public class SetupData implements Parcelable {
mAllowAutodiscover = true;
mCheckSettingsMode = 0;
mAccount = new Account();
mDefault = false;
mUsername = null;
mPassword = null;
mAccountAuthenticatorResponse = null;
@ -232,7 +222,6 @@ public class SetupData implements Parcelable {
dest.writeInt(mAllowAutodiscover ? 1 : 0);
dest.writeParcelable(mPolicy, 0);
dest.writeInt(mAutoSetup ? 1 : 0);
dest.writeInt(mDefault ? 1 : 0);
dest.writeParcelable(mAccountAuthenticatorResponse, 0);
}
@ -246,7 +235,6 @@ public class SetupData implements Parcelable {
mAllowAutodiscover = in.readInt() == 1;
mPolicy = in.readParcelable(loader);
mAutoSetup = in.readInt() == 1;
mDefault = in.readInt() == 1;
mAccountAuthenticatorResponse = in.readParcelable(loader);
}
@ -276,7 +264,6 @@ public class SetupData implements Parcelable {
}
sb.append(":a/d=" + data.mAllowAutodiscover);
sb.append(":auto=" + data.mAutoSetup);
sb.append(":default=" + data.mDefault);
sb.append(":check=");
if (SetupData.isCheckIncoming()) sb.append("in+");
if (SetupData.isCheckOutgoing()) sb.append("out+");

View File

@ -166,10 +166,9 @@ public class EmailProvider extends ContentProvider {
private static final int ACCOUNT_ID = ACCOUNT_BASE + 1;
private static final int ACCOUNT_RESET_NEW_COUNT = ACCOUNT_BASE + 2;
private static final int ACCOUNT_RESET_NEW_COUNT_ID = ACCOUNT_BASE + 3;
private static final int ACCOUNT_DEFAULT_ID = ACCOUNT_BASE + 4;
private static final int ACCOUNT_CHECK = ACCOUNT_BASE + 5;
private static final int ACCOUNT_PICK_TRASH_FOLDER = ACCOUNT_BASE + 6;
private static final int ACCOUNT_PICK_SENT_FOLDER = ACCOUNT_BASE + 7;
private static final int ACCOUNT_CHECK = ACCOUNT_BASE + 4;
private static final int ACCOUNT_PICK_TRASH_FOLDER = ACCOUNT_BASE + 5;
private static final int ACCOUNT_PICK_SENT_FOLDER = ACCOUNT_BASE + 6;
private static final int MAILBOX_BASE = 0x1000;
private static final int MAILBOX = MAILBOX_BASE;
@ -856,7 +855,6 @@ public class EmailProvider extends ContentProvider {
// A specific account
// insert into this URI causes a mailbox to be added to the account
matcher.addURI(EmailContent.AUTHORITY, "account/#", ACCOUNT_ID);
matcher.addURI(EmailContent.AUTHORITY, "account/default", ACCOUNT_DEFAULT_ID);
matcher.addURI(EmailContent.AUTHORITY, "accountCheck/#", ACCOUNT_CHECK);
// Special URI to reset the new message count. Only update works, and values
@ -1096,31 +1094,6 @@ public class EmailProvider extends ContentProvider {
case MAILBOX_MESSAGE_COUNT:
c = getMailboxMessageCount(uri);
return c;
case ACCOUNT_DEFAULT_ID:
// We want either the row which has isDefault set, or we want the lowest valued
// account id if none are isDefault. I don't think there's a way to express this
// simply in sql so we get all account ids and loop through them manually.
final Cursor accounts = db.query(Account.TABLE_NAME,
Account.ACCOUNT_IS_DEFAULT_PROJECTION,
null, null, null, null, null, null);
long defaultAccountId = Account.NO_ACCOUNT;
while (accounts.moveToNext()) {
final long accountId =
accounts.getLong(Account.ACCOUNT_IS_DEFAULT_COLUMN_ID);
if (accounts.getInt(Account.ACCOUNT_IS_DEFAULT_COLUMN_IS_DEFAULT) == 1) {
defaultAccountId = accountId;
break;
} else if (defaultAccountId == Account.NO_ACCOUNT ||
accountId < defaultAccountId) {
defaultAccountId = accountId;
}
}
// Return a cursor with an id projection
final MatrixCursor mc =
new MatrixCursorWithCachedColumns(EmailContent.ID_PROJECTION, 1);
mc.addRow(new Object[] {defaultAccountId});
c = mc;
break;
case BODY:
case MESSAGE:
case UPDATED_MESSAGE:
@ -1617,8 +1590,13 @@ public class EmailProvider extends ContentProvider {
Uri messageUri = null;
if (TextUtils.equals(method, UIProvider.AccountCallMethods.SEND_MESSAGE)) {
messageUri = uiSendDraftMessage(accountId, extras);
Preferences.getPreferences(getContext()).setLastUsedAccountId(accountId);
} else if (TextUtils.equals(method, UIProvider.AccountCallMethods.SAVE_MESSAGE)) {
messageUri = uiSaveDraftMessage(accountId, extras);
} else if (TextUtils.equals(method, UIProvider.AccountCallMethods.SET_CURRENT_ACCOUNT)) {
LogUtils.d(TAG, "Unhandled (but expected) Content provider method: %s", method);
} else {
LogUtils.wtf(TAG, "Unexpected Content provider method: %s", method);
}
final Bundle result;
@ -2759,7 +2737,9 @@ public class EmailProvider extends ContentProvider {
}
private void addCombinedAccountRow(MatrixCursor mc) {
final long id = Account.getDefaultAccountId(getContext());
final long lastUsedAccountId =
Preferences.getPreferences(getContext()).getLastUsedAccountId();
final long id = Account.getDefaultAccountId(getContext(), lastUsedAccountId);
if (id == Account.NO_ACCOUNT) return;
// Build a map of the requested columns to the appropriate positions