am d3dfc2b7: Merge branch \'eclair-plus-aosp\' of ssh://android-git.corp.google.com:29418/platform/packages/apps/Email into eclair-mr2-plus-aosp

Merge commit 'd3dfc2b7401c8559a5ae722d9f63d8d0d39f2132'

* commit 'd3dfc2b7401c8559a5ae722d9f63d8d0d39f2132':
  Email: exit AsyncTask.onPostExecute() if the result is null or isCancelled().
This commit is contained in:
Dima Zavin 2009-10-13 11:53:26 -07:00 committed by Android Git Automerger
commit 53fc90bd25
4 changed files with 63 additions and 11 deletions

View File

@ -102,6 +102,7 @@ public class MailboxList extends ListActivity implements OnItemClickListener, On
// DB access
private long mAccountId;
private LoadMailboxesTask mLoadMailboxesTask;
private AsyncTask mLoadAccountNameTask;
/**
* Open a specific account.
@ -147,7 +148,7 @@ public class MailboxList extends ListActivity implements OnItemClickListener, On
((TextView)findViewById(R.id.title_left_text)).setText(R.string.mailbox_list_title);
// Go to the database for the account name
new AsyncTask<Void, Void, String>() {
mLoadAccountNameTask = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
String result = null;
@ -166,6 +167,13 @@ public class MailboxList extends ListActivity implements OnItemClickListener, On
@Override
protected void onPostExecute(String result) {
/* doInBackground() returns null if the account name can't be retrieved from DB.
* so we can't use null test for cancellation, instead use isCancelled().
*/
if (isCancelled()) {
return;
}
// result is null if account name can't be retrieved or query exception
if (result == null) {
// something is wrong with this account
finish();
@ -199,6 +207,11 @@ public class MailboxList extends ListActivity implements OnItemClickListener, On
mLoadMailboxesTask.cancel(true);
mLoadMailboxesTask = null;
}
if (mLoadAccountNameTask != null &&
mLoadAccountNameTask.getStatus() != LoadMailboxesTask.Status.FINISHED) {
mLoadAccountNameTask.cancel(true);
mLoadAccountNameTask = null;
}
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@ -331,7 +344,7 @@ public class MailboxList extends ListActivity implements OnItemClickListener, On
@Override
protected void onPostExecute(Cursor cursor) {
if (cursor.isClosed()) {
if (cursor == null || cursor.isClosed()) {
return;
}
MailboxList.this.mListAdapter.changeCursor(cursor);

View File

@ -537,7 +537,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
protected Object[] doInBackground(Long... messageIds) {
Message message = Message.restoreMessageWithId(MessageCompose.this, messageIds[0]);
if (message == null) {
return null;
return new Object[] {null, null};
}
long accountId = message.mAccountKey;
Account account = Account.restoreAccountWithId(MessageCompose.this, accountId);
@ -561,7 +561,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
}
} catch (RuntimeException e) {
Log.d(Email.LOG_TAG, "Exception while loading message body: " + e);
return null;
return new Object[] {null, null};
}
return new Object[]{message, account};
}
@ -569,6 +569,12 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
@Override
protected void onPostExecute(Object[] messageAndAccount) {
if (messageAndAccount == null) {
return;
}
final Message message = (Message) messageAndAccount[0];
final Account account = (Account) messageAndAccount[1];
if (message == null && account == null) {
// Something unexpected happened:
// the message or the body couldn't be loaded by SQLite.
// Bail out.
@ -577,8 +583,6 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
finish();
return;
}
final Message message = (Message) messageAndAccount[0];
final Account account = (Account) messageAndAccount[1];
if (ACTION_EDIT_DRAFT.equals(mAction)) {
mDraft = message;
@ -590,10 +594,11 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
}
@Override
protected void onPostExecute(Attachment[] attachments) {
if (attachments != null) {
for (Attachment attachment : attachments) {
addAttachment(attachment);
}
if (attachments == null) {
return;
}
for (Attachment attachment : attachments) {
addAttachment(attachment);
}
}
}.execute(message.mId);
@ -831,6 +836,9 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
@Override
protected void onPostExecute(Void dummy) {
if (isCancelled()) {
return;
}
// Don't display the toast if the user is just changing the orientation
if (!send && (getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) {
Toast.makeText(MessageCompose.this, R.string.message_saved_toast,

View File

@ -909,6 +909,9 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
@Override
protected void onPostExecute(Integer listFooterMode) {
if (listFooterMode == null) {
return;
}
finishFooterView(listFooterMode);
}
}
@ -1016,6 +1019,9 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
@Override
protected void onPostExecute(Long mailboxId) {
if (mailboxId == null) {
return;
}
if (mailboxId != Mailbox.NO_MAILBOX) {
mMailboxId = mailboxId;
mSetTitleTask = new SetTitleTask(mMailboxId);
@ -1062,7 +1068,7 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
@Override
protected void onPostExecute(Cursor cursor) {
if (cursor.isClosed()) {
if (cursor == null || cursor.isClosed()) {
return;
}
MessageList.this.mListAdapter.changeCursor(cursor);
@ -1138,6 +1144,9 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
@Override
protected void onPostExecute(String[] names) {
if (names == null) {
return;
}
if (names[0] != null) {
mRightTitle.setText(names[0]);
}

View File

@ -982,6 +982,9 @@ public class MessageView extends Activity implements OnClickListener {
@Override
protected void onPostExecute(Integer icon) {
if (icon == null) {
return;
}
updateSenderPresence(icon);
}
}
@ -1055,6 +1058,9 @@ public class MessageView extends Activity implements OnClickListener {
@Override
protected void onPostExecute(Cursor cursor) {
if (cursor == null) {
return;
}
// remove the reference to ourselves so another one can be launched
MessageView.this.mLoadPrevNextTask = null;
@ -1097,6 +1103,19 @@ public class MessageView extends Activity implements OnClickListener {
@Override
protected void onPostExecute(Message message) {
/* doInBackground() may return null result (due to restoreMessageWithId())
* and in that situation we want to Activity.finish().
*
* OTOH we don't want to Activity.finish() for isCancelled() because this
* would introduce a surprise side-effect to task cancellation: every task
* cancelation would also result in finish().
*
* Right now LoadMesageTask is cancelled not only from onDestroy(),
* and it would be a bug to also finish() the activity in that situation.
*/
if (isCancelled()) {
return;
}
if (message == null) {
if (mId != Long.MIN_VALUE) {
finish();
@ -1166,6 +1185,9 @@ public class MessageView extends Activity implements OnClickListener {
@Override
protected void onPostExecute(Attachment[] attachments) {
if (attachments == null) {
return;
}
boolean htmlChanged = false;
for (Attachment attachment : attachments) {
if (mHtmlText != null && attachment.mContentId != null