am e7e1ca43: Change AccountManager username for Exchange to the user\'s login credential

Merge commit 'e7e1ca432e1aace5b7f11a3f1684a4abc503e6b2' into eclair-plus-aosp

* commit 'e7e1ca432e1aace5b7f11a3f1684a4abc503e6b2':
  Change AccountManager username for Exchange to the user's login credential
This commit is contained in:
Marc Blank 2009-09-17 10:23:05 -07:00 committed by Android Git Automerger
commit 2aa9724ea0
5 changed files with 49 additions and 30 deletions

View File

@ -83,7 +83,7 @@ public class ExchangeStore extends Store {
AccountManagerCallback<Bundle> callback) { AccountManagerCallback<Bundle> callback) {
// Create a description of the new account // Create a description of the new account
Bundle options = new Bundle(); Bundle options = new Bundle();
options.putString(EasAuthenticatorService.OPTIONS_USERNAME, acct.mEmailAddress); options.putString(EasAuthenticatorService.OPTIONS_USERNAME, acct.mHostAuthRecv.mLogin);
options.putString(EasAuthenticatorService.OPTIONS_PASSWORD, acct.mHostAuthRecv.mPassword); options.putString(EasAuthenticatorService.OPTIONS_PASSWORD, acct.mHostAuthRecv.mPassword);
options.putBoolean(EasAuthenticatorService.OPTIONS_CONTACTS_SYNC_ENABLED, syncContacts); options.putBoolean(EasAuthenticatorService.OPTIONS_CONTACTS_SYNC_ENABLED, syncContacts);

View File

@ -30,7 +30,9 @@ import com.android.email.provider.EmailContent.MailboxColumns;
import com.android.email.provider.EmailContent.Message; import com.android.email.provider.EmailContent.Message;
import com.android.email.provider.EmailContent.MessageColumns; import com.android.email.provider.EmailContent.MessageColumns;
import com.android.email.provider.EmailContent.SyncColumns; import com.android.email.provider.EmailContent.SyncColumns;
import com.android.exchange.Eas;
import android.accounts.AccountManager;
import android.content.ContentProvider; import android.content.ContentProvider;
import android.content.ContentProviderOperation; import android.content.ContentProviderOperation;
import android.content.ContentProviderResult; import android.content.ContentProviderResult;
@ -57,12 +59,14 @@ public class EmailProvider extends ContentProvider {
// Any changes to the database format *must* include update-in-place code. // Any changes to the database format *must* include update-in-place code.
// Original version: 3 // Original version: 3
public static final int DATABASE_VERSION = 3; // Version 4: Database wipe required; changing AccountManager interface w/Exchange
public static final int DATABASE_VERSION = 4;
// Any changes to the database format *must* include update-in-place code. // Any changes to the database format *must* include update-in-place code.
// Original version: 2 // Original version: 2
// Version 3: Add "sourceKey" column // Version 3: Add "sourceKey" column
public static final int BODY_DATABASE_VERSION = 3; // Version 4: Database wipe required; changing AccountManager interface w/Exchange
public static final int BODY_DATABASE_VERSION = 4;
public static final String EMAIL_AUTHORITY = "com.android.email.provider"; public static final String EMAIL_AUTHORITY = "com.android.email.provider";
@ -348,7 +352,7 @@ public class EmailProvider extends ContentProvider {
"; end"); "; end");
} }
static void upgradeMessageTable(SQLiteDatabase db, int oldVersion, int newVersion) { static void resetMessageTable(SQLiteDatabase db, int oldVersion, int newVersion) {
try { try {
db.execSQL("drop table " + Message.TABLE_NAME); db.execSQL("drop table " + Message.TABLE_NAME);
db.execSQL("drop table " + Message.UPDATED_TABLE_NAME); db.execSQL("drop table " + Message.UPDATED_TABLE_NAME);
@ -387,7 +391,7 @@ public class EmailProvider extends ContentProvider {
"; end"); "; end");
} }
static void upgradeAccountTable(SQLiteDatabase db, int oldVersion, int newVersion) { static void resetAccountTable(SQLiteDatabase db, int oldVersion, int newVersion) {
try { try {
db.execSQL("drop table " + Account.TABLE_NAME); db.execSQL("drop table " + Account.TABLE_NAME);
} catch (SQLException e) { } catch (SQLException e) {
@ -409,7 +413,7 @@ public class EmailProvider extends ContentProvider {
db.execSQL("create table " + HostAuth.TABLE_NAME + s); db.execSQL("create table " + HostAuth.TABLE_NAME + s);
} }
static void upgradeHostAuthTable(SQLiteDatabase db, int oldVersion, int newVersion) { static void resetHostAuthTable(SQLiteDatabase db, int oldVersion, int newVersion) {
try { try {
db.execSQL("drop table " + HostAuth.TABLE_NAME); db.execSQL("drop table " + HostAuth.TABLE_NAME);
} catch (SQLException e) { } catch (SQLException e) {
@ -447,7 +451,7 @@ public class EmailProvider extends ContentProvider {
"; end"); "; end");
} }
static void upgradeMailboxTable(SQLiteDatabase db, int oldVersion, int newVersion) { static void resetMailboxTable(SQLiteDatabase db, int oldVersion, int newVersion) {
try { try {
db.execSQL("drop table " + Mailbox.TABLE_NAME); db.execSQL("drop table " + Mailbox.TABLE_NAME);
} catch (SQLException e) { } catch (SQLException e) {
@ -470,7 +474,7 @@ public class EmailProvider extends ContentProvider {
db.execSQL(createIndex(Attachment.TABLE_NAME, AttachmentColumns.MESSAGE_KEY)); db.execSQL(createIndex(Attachment.TABLE_NAME, AttachmentColumns.MESSAGE_KEY));
} }
static void upgradeAttachmentTable(SQLiteDatabase db, int oldVersion, int newVersion) { static void resetAttachmentTable(SQLiteDatabase db, int oldVersion, int newVersion) {
try { try {
db.execSQL("drop table " + Attachment.TABLE_NAME); db.execSQL("drop table " + Attachment.TABLE_NAME);
} catch (SQLException e) { } catch (SQLException e) {
@ -492,18 +496,13 @@ public class EmailProvider extends ContentProvider {
} }
static void upgradeBodyTable(SQLiteDatabase db, int oldVersion, int newVersion) { static void upgradeBodyTable(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < 2) { if (oldVersion < 4) {
// Versions earlier than 2 require a wipe of the database
try { try {
db.execSQL("drop table " + Body.TABLE_NAME); db.execSQL("drop table " + Body.TABLE_NAME);
createBodyTable(db); createBodyTable(db);
} catch (SQLException e) { } catch (SQLException e) {
} }
} else if (oldVersion == 2) { }
Log.d(TAG, "Upgrading Body from v2 to v3");
db.execSQL("alter table " + Body.TABLE_NAME +
" add " + Body.SOURCE_MESSAGE_KEY + " integer");
}
} }
private final int mDatabaseVersion = DATABASE_VERSION; private final int mDatabaseVersion = DATABASE_VERSION;
@ -554,8 +553,11 @@ public class EmailProvider extends ContentProvider {
} }
private class DatabaseHelper extends SQLiteOpenHelper { private class DatabaseHelper extends SQLiteOpenHelper {
Context mContext;
DatabaseHelper(Context context, String name) { DatabaseHelper(Context context, String name) {
super(context, name, null, mDatabaseVersion); super(context, name, null, mDatabaseVersion);
mContext = context;
} }
@Override @Override
@ -570,11 +572,20 @@ public class EmailProvider extends ContentProvider {
@Override @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
upgradeMessageTable(db, oldVersion, newVersion); // For versions prior to 4, delete all data
upgradeAttachmentTable(db, oldVersion, newVersion); // Versions >= 4 require that data be preserved!
upgradeMailboxTable(db, oldVersion, newVersion); if (oldVersion < 4) {
upgradeHostAuthTable(db, oldVersion, newVersion); android.accounts.Account[] accounts =
upgradeAccountTable(db, oldVersion, newVersion); AccountManager.get(mContext).getAccountsByType(Eas.ACCOUNT_MANAGER_TYPE);
for (android.accounts.Account account: accounts) {
AccountManager.get(mContext).removeAccount(account, null, null);
}
resetMessageTable(db, oldVersion, newVersion);
resetAttachmentTable(db, oldVersion, newVersion);
resetMailboxTable(db, oldVersion, newVersion);
resetHostAuthTable(db, oldVersion, newVersion);
resetAccountTable(db, oldVersion, newVersion);
}
} }
@Override @Override

View File

@ -133,6 +133,7 @@ public class EasSyncService extends AbstractSyncService {
private boolean mSsl = true; private boolean mSsl = true;
private boolean mTrustSsl = false; private boolean mTrustSsl = false;
public ContentResolver mContentResolver; public ContentResolver mContentResolver;
public String mHostLogin;
private String[] mBindArguments = new String[2]; private String[] mBindArguments = new String[2];
private ArrayList<String> mPingChangeList; private ArrayList<String> mPingChangeList;
private HttpPost mPendingPost = null; private HttpPost mPendingPost = null;
@ -147,6 +148,7 @@ public class EasSyncService extends AbstractSyncService {
super(_context, _mailbox); super(_context, _mailbox);
mContentResolver = _context.getContentResolver(); mContentResolver = _context.getContentResolver();
HostAuth ha = HostAuth.restoreHostAuthWithId(_context, mAccount.mHostAuthKeyRecv); HostAuth ha = HostAuth.restoreHostAuthWithId(_context, mAccount.mHostAuthKeyRecv);
mHostLogin = ha.mLogin;
mSsl = (ha.mFlags & HostAuth.FLAG_SSL) != 0; mSsl = (ha.mFlags & HostAuth.FLAG_SSL) != 0;
mTrustSsl = (ha.mFlags & HostAuth.FLAG_TRUST_ALL_CERTIFICATES) != 0; mTrustSsl = (ha.mFlags & HostAuth.FLAG_TRUST_ALL_CERTIFICATES) != 0;
} }
@ -1039,7 +1041,6 @@ public class EasSyncService extends AbstractSyncService {
runAccountMailbox(); runAccountMailbox();
} else { } else {
AbstractSyncAdapter target; AbstractSyncAdapter target;
mAccount = Account.restoreAccountWithId(mContext, mAccount.mId);
mProtocolVersion = mAccount.mProtocolVersion; mProtocolVersion = mAccount.mProtocolVersion;
mProtocolVersionDouble = Double.parseDouble(mProtocolVersion); mProtocolVersionDouble = Double.parseDouble(mProtocolVersion);
if (mMailbox.mType == Mailbox.TYPE_CONTACTS) { if (mMailbox.mType == Mailbox.TYPE_CONTACTS) {

View File

@ -443,7 +443,7 @@ public class SyncManager extends Service implements Runnable {
stopAccountSyncs(account.mId, true); stopAccountSyncs(account.mId, true);
// Delete this from AccountManager... // Delete this from AccountManager...
android.accounts.Account acct = android.accounts.Account acct =
new android.accounts.Account(account.mEmailAddress, new android.accounts.Account(account.mHostAuthRecv.mLogin,
Eas.ACCOUNT_MANAGER_TYPE); Eas.ACCOUNT_MANAGER_TYPE);
AccountManager.get(SyncManager.this).removeAccount(acct, null, null); AccountManager.get(SyncManager.this).removeAccount(acct, null, null);
mAccountKeyList = null; mAccountKeyList = null;
@ -471,6 +471,10 @@ public class SyncManager extends Service implements Runnable {
if (!mAccounts.contains(account.mId)) { if (!mAccounts.contains(account.mId)) {
// This is an addition; create our magic hidden mailbox... // This is an addition; create our magic hidden mailbox...
addAccountMailbox(account.mId); addAccountMailbox(account.mId);
// Don't forget to cache the HostAuth
HostAuth ha =
HostAuth.restoreHostAuthWithId(getContext(), account.mHostAuthKeyRecv);
account.mHostAuthRecv = ha;
mAccounts.add(account); mAccounts.add(account);
mAccountKeyList = null; mAccountKeyList = null;
} }
@ -493,7 +497,10 @@ public class SyncManager extends Service implements Runnable {
if (hostAuthId > 0) { if (hostAuthId > 0) {
HostAuth ha = HostAuth.restoreHostAuthWithId(context, hostAuthId); HostAuth ha = HostAuth.restoreHostAuthWithId(context, hostAuthId);
if (ha != null && ha.mProtocol.equals("eas")) { if (ha != null && ha.mProtocol.equals("eas")) {
accounts.add(new Account().restore(c)); Account account = new Account().restore(c);
// Cache the HostAuth
account.mHostAuthRecv = ha;
accounts.add(account);
} }
} }
} }
@ -1030,7 +1037,7 @@ public class SyncManager extends Service implements Runnable {
if (contactsId != Mailbox.NO_MAILBOX) { if (contactsId != Mailbox.NO_MAILBOX) {
// Create an AccountManager style Account // Create an AccountManager style Account
android.accounts.Account acct = android.accounts.Account acct =
new android.accounts.Account(easAccount.mEmailAddress, new android.accounts.Account(easAccount.mHostAuthRecv.mLogin,
Eas.ACCOUNT_MANAGER_TYPE); Eas.ACCOUNT_MANAGER_TYPE);
// Get the Contacts mailbox; this happens rarely so it's ok to get it all // Get the Contacts mailbox; this happens rarely so it's ok to get it all
Mailbox contacts = Mailbox.restoreMailboxWithId(this, contactsId); Mailbox contacts = Mailbox.restoreMailboxWithId(this, contactsId);
@ -1069,7 +1076,7 @@ public class SyncManager extends Service implements Runnable {
AccountManager.get(this).getAccountsByType(Eas.ACCOUNT_MANAGER_TYPE); AccountManager.get(this).getAccountsByType(Eas.ACCOUNT_MANAGER_TYPE);
List<Account> easAccounts = getAccountList(); List<Account> easAccounts = getAccountList();
for (Account easAccount: easAccounts) { for (Account easAccount: easAccounts) {
String accountName = easAccount.mEmailAddress; String accountName = easAccount.mHostAuthRecv.mLogin;
boolean found = false; boolean found = false;
for (android.accounts.Account acct: accts) { for (android.accounts.Account acct: accts) {
if (acct.name.equalsIgnoreCase(accountName)) { if (acct.name.equalsIgnoreCase(accountName)) {
@ -1400,7 +1407,7 @@ public class SyncManager extends Service implements Runnable {
getAccountById(c.getInt(Mailbox.CONTENT_ACCOUNT_KEY_COLUMN)); getAccountById(c.getInt(Mailbox.CONTENT_ACCOUNT_KEY_COLUMN));
if (account != null) { if (account != null) {
android.accounts.Account a = android.accounts.Account a =
new android.accounts.Account(account.mEmailAddress, new android.accounts.Account(account.mHostAuthRecv.mLogin,
Eas.ACCOUNT_MANAGER_TYPE); Eas.ACCOUNT_MANAGER_TYPE);
if (!ContentResolver.getSyncAutomatically(a, if (!ContentResolver.getSyncAutomatically(a,
ContactsContract.AUTHORITY)) { ContactsContract.AUTHORITY)) {

View File

@ -151,7 +151,7 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
setSyncKey("0", false); setSyncKey("0", false);
// Make sure ungrouped contacts for Exchange are defaultly visible // Make sure ungrouped contacts for Exchange are defaultly visible
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put(Groups.ACCOUNT_NAME, mAccount.mEmailAddress); cv.put(Groups.ACCOUNT_NAME, mService.mHostLogin);
cv.put(Groups.ACCOUNT_TYPE, Eas.ACCOUNT_MANAGER_TYPE); cv.put(Groups.ACCOUNT_TYPE, Eas.ACCOUNT_MANAGER_TYPE);
cv.put(Settings.UNGROUPED_VISIBLE, true); cv.put(Settings.UNGROUPED_VISIBLE, true);
client.insert(Settings.CONTENT_URI, cv); client.insert(Settings.CONTENT_URI, cv);
@ -190,7 +190,7 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
public android.accounts.Account getAccountManagerAccount() { public android.accounts.Account getAccountManagerAccount() {
if (mAccountManagerAccount == null) { if (mAccountManagerAccount == null) {
mAccountManagerAccount = mAccountManagerAccount =
new android.accounts.Account(mAccount.mEmailAddress, Eas.ACCOUNT_MANAGER_TYPE); new android.accounts.Account(mService.mHostLogin, Eas.ACCOUNT_MANAGER_TYPE);
} }
return mAccountManagerAccount; return mAccountManagerAccount;
} }
@ -877,7 +877,7 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
private Uri uriWithAccountAndIsSyncAdapter(Uri uri) { private Uri uriWithAccountAndIsSyncAdapter(Uri uri) {
return uri.buildUpon() return uri.buildUpon()
.appendQueryParameter(RawContacts.ACCOUNT_NAME, mAccount.mEmailAddress) .appendQueryParameter(RawContacts.ACCOUNT_NAME, mService.mHostLogin)
.appendQueryParameter(RawContacts.ACCOUNT_TYPE, Eas.ACCOUNT_MANAGER_TYPE) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, Eas.ACCOUNT_MANAGER_TYPE)
.appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true") .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
.build(); .build();
@ -1713,7 +1713,7 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
// First, let's find Contacts that have changed. // First, let's find Contacts that have changed.
ContentResolver cr = mService.mContentResolver; ContentResolver cr = mService.mContentResolver;
Uri uri = RawContacts.CONTENT_URI.buildUpon() Uri uri = RawContacts.CONTENT_URI.buildUpon()
.appendQueryParameter(RawContacts.ACCOUNT_NAME, mAccount.mEmailAddress) .appendQueryParameter(RawContacts.ACCOUNT_NAME, mService.mHostLogin)
.appendQueryParameter(RawContacts.ACCOUNT_TYPE, Eas.ACCOUNT_MANAGER_TYPE) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, Eas.ACCOUNT_MANAGER_TYPE)
.build(); .build();