Make AccountBackupRestore/"delete account" robust.
Fix for crashes caused by an incomplete account which typically a crashed unit test leaves behind. - "Delete account" now works for incomplete accounts - AccountBackupRestore won't crash. Change-Id: Ie235aa15cf9b970fd184c60f14406aa7353c6f00
This commit is contained in:
parent
d632426c0a
commit
6d8bfa67c4
@ -107,7 +107,7 @@ public class AccountBackupRestore {
|
||||
Account toAccount = LegacyConversions.makeLegacyAccount(context, fromAccount);
|
||||
|
||||
// Determine if contacts are also synced, and if so, record that
|
||||
if (fromAccount.mHostAuthRecv.mProtocol.equals("eas")) {
|
||||
if (fromAccount.isEasAccount()) {
|
||||
android.accounts.Account acct = new android.accounts.Account(
|
||||
fromAccount.mEmailAddress, Email.EXCHANGE_ACCOUNT_MANAGER_TYPE);
|
||||
boolean syncContacts = ContentResolver.getSyncAutomatically(acct,
|
||||
@ -188,7 +188,7 @@ public class AccountBackupRestore {
|
||||
boolean contacts = false;
|
||||
boolean calendar = false;
|
||||
// Handle system account first, then save in provider
|
||||
if (toAccount.mHostAuthRecv.mProtocol.equals("eas")) {
|
||||
if (toAccount.isEasAccount()) {
|
||||
contacts = (backupAccount.mBackupFlags & Account.BACKUP_FLAGS_SYNC_CONTACTS) != 0;
|
||||
calendar = (backupAccount.mBackupFlags & Account.BACKUP_FLAGS_SYNC_CALENDAR) != 0;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.RemoteException;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
@ -965,13 +966,15 @@ public class Controller {
|
||||
if (account == null) {
|
||||
return; // Already deleted?
|
||||
}
|
||||
|
||||
final String accountUri = account.getStoreUri(mContext);
|
||||
|
||||
// Delete Remote store at first.
|
||||
Store.getInstance(accountUri, mContext, null).delete();
|
||||
if (!TextUtils.isEmpty(accountUri)) {
|
||||
Store.getInstance(accountUri, mContext, null).delete();
|
||||
// Remove the Store instance from cache.
|
||||
Store.removeInstance(accountUri);
|
||||
}
|
||||
|
||||
// Remove the Store instance from cache.
|
||||
Store.removeInstance(accountUri);
|
||||
Uri uri = ContentUris.withAppendedId(
|
||||
EmailContent.Account.CONTENT_URI, accountId);
|
||||
mContext.getContentResolver().delete(uri, null, null);
|
||||
@ -984,7 +987,7 @@ public class Controller {
|
||||
|
||||
Email.setServicesEnabled(mContext);
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
Log.w(Email.LOG_TAG, "Exception while deleting account", e);
|
||||
} finally {
|
||||
synchronized (mListeners) {
|
||||
for (Result l : mListeners) {
|
||||
|
@ -1255,6 +1255,16 @@ public abstract class EmailContent {
|
||||
return "local://localhost/" + context.getDatabasePath(getUuid() + ".db");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the instance is of an EAS account.
|
||||
*/
|
||||
public boolean isEasAccount() {
|
||||
if (mHostAuthRecv == null) {
|
||||
return false;
|
||||
}
|
||||
return "eas".equals(mHostAuthRecv.mProtocol);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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".
|
||||
|
@ -1942,4 +1942,21 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
|
||||
return ProviderTestUtils.setupMessage("1", b.mAccountKey, b.mId, true, true, c, starred,
|
||||
read);
|
||||
}
|
||||
|
||||
public static void testAccountIsEasAccount() {
|
||||
Account account = new Account();
|
||||
assertFalse(account.isEasAccount());
|
||||
|
||||
account.mHostAuthRecv = new HostAuth();
|
||||
assertFalse(account.isEasAccount());
|
||||
|
||||
account.mHostAuthRecv.mProtocol = "";
|
||||
assertFalse(account.isEasAccount());
|
||||
|
||||
account.mHostAuthRecv.mProtocol = "x";
|
||||
assertFalse(account.isEasAccount());
|
||||
|
||||
account.mHostAuthRecv.mProtocol = "eas";
|
||||
assertTrue(account.isEasAccount());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user