Fix clearing of mailbox notifications
Change-Id: Ieb98a8908ec067229dd449790da55085585ef17b
This commit is contained in:
parent
bf5caf97c5
commit
9a5e2a798e
|
@ -71,6 +71,17 @@ public abstract class EmailContent {
|
|||
|
||||
public static final Uri CONTENT_NOTIFIER_URI = Uri.parse("content://" + NOTIFIER_AUTHORITY);
|
||||
|
||||
public static final Uri MAILBOX_NOTIFICATION_URI =
|
||||
Uri.parse("content://" + EmailContent.AUTHORITY + "/mailboxNotification");
|
||||
public static final String[] NOTIFICATION_PROJECTION =
|
||||
new String[] {MailboxColumns.ID, MailboxColumns.UNREAD_COUNT, MailboxColumns.MESSAGE_COUNT};
|
||||
public static final int NOTIFICATION_MAILBOX_ID_COLUMN = 0;
|
||||
public static final int NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN = 1;
|
||||
public static final int NOTIFICATION_MAILBOX_MESSAGE_COUNT_COLUMN = 2;
|
||||
|
||||
public static final Uri MAILBOX_MOST_RECENT_MESSAGE_URI =
|
||||
Uri.parse("content://" + EmailContent.AUTHORITY + "/mailboxMostRecentMessage");
|
||||
|
||||
public static final String PROVIDER_PERMISSION = "com.android.email.permission.ACCESS_PROVIDER";
|
||||
|
||||
// All classes share this
|
||||
|
|
|
@ -52,7 +52,6 @@ import com.android.emailcommon.provider.EmailContent.AttachmentColumns;
|
|||
import com.android.emailcommon.provider.EmailContent.HostAuthColumns;
|
||||
import com.android.emailcommon.provider.EmailContent.MailboxColumns;
|
||||
import com.android.emailcommon.provider.EmailContent.Message;
|
||||
import com.android.emailcommon.provider.EmailContent.MessageColumns;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.android.emailcommon.provider.ProviderUnavailableException;
|
||||
|
@ -926,27 +925,26 @@ public class Utility {
|
|||
// need a point at which we can compare against in the future. By setting this
|
||||
// value, we are claiming that every message before this has potentially been
|
||||
// seen by the user.
|
||||
long messageId = Utility.getFirstRowLong(
|
||||
context,
|
||||
Message.CONTENT_URI,
|
||||
EmailContent.ID_PROJECTION,
|
||||
MessageColumns.MAILBOX_KEY + "=?",
|
||||
new String[] { Long.toString(mailbox.mId) },
|
||||
MessageColumns.ID + " DESC",
|
||||
EmailContent.ID_PROJECTION_COLUMN, 0L);
|
||||
long oldLastSeenMessageId = Utility.getFirstRowLong(
|
||||
context, ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailbox.mId),
|
||||
new String[] { MailboxColumns.LAST_NOTIFIED_MESSAGE_KEY },
|
||||
null, null, null, 0, 0L);
|
||||
long mostRecentMessageId = Utility.getFirstRowLong(context,
|
||||
ContentUris.withAppendedId(
|
||||
EmailContent.MAILBOX_MOST_RECENT_MESSAGE_URI, mailboxId),
|
||||
Message.ID_COLUMN_PROJECTION, null, null, null,
|
||||
Message.ID_MAILBOX_COLUMN_ID, -1L);
|
||||
long lastNotifiedMessageId = mailbox.mLastNotifiedMessageKey;
|
||||
// Only update the db if the value has changed
|
||||
if (messageId != oldLastSeenMessageId) {
|
||||
if (mostRecentMessageId != lastNotifiedMessageId) {
|
||||
Log.d(Logging.LOG_TAG, "Most recent = " + mostRecentMessageId +
|
||||
", last notified: " + lastNotifiedMessageId +
|
||||
"; updating last notified");
|
||||
ContentValues values = mailbox.toContentValues();
|
||||
values.put(MailboxColumns.LAST_NOTIFIED_MESSAGE_KEY, messageId);
|
||||
values.put(MailboxColumns.LAST_NOTIFIED_MESSAGE_KEY, mostRecentMessageId);
|
||||
resolver.update(
|
||||
Mailbox.CONTENT_URI,
|
||||
values,
|
||||
EmailContent.ID_SELECTION,
|
||||
new String[] { Long.toString(mailbox.mId) });
|
||||
} else {
|
||||
Log.d(Logging.LOG_TAG, "Most recent = last notified; no change");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ import com.android.email.activity.ContactStatusLoader;
|
|||
import com.android.email.activity.Welcome;
|
||||
import com.android.email.activity.setup.AccountSecurity;
|
||||
import com.android.email.activity.setup.AccountSettings;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.mail.Address;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
|
@ -286,6 +285,24 @@ public class NotificationController {
|
|||
if (suspend && mailboxId != Mailbox.NO_MAILBOX) {
|
||||
mSuspendMailboxId = mailboxId;
|
||||
}
|
||||
if (mailboxId == Mailbox.QUERY_ALL_INBOXES) {
|
||||
// Only go onto the notification handler if we really, absolutely need to
|
||||
ensureHandlerExists();
|
||||
sNotificationHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (long accountId: mNotificationMap.keySet()) {
|
||||
long mailboxId =
|
||||
Mailbox.findMailboxOfType(mContext, accountId, Mailbox.TYPE_INBOX);
|
||||
if (mailboxId != Mailbox.NO_MAILBOX) {
|
||||
mNotificationManager.cancel(getNewMessageNotificationId(mailboxId));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mNotificationManager.cancel(getNewMessageNotificationId(mailboxId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -695,21 +712,26 @@ public class NotificationController {
|
|||
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Cursor c = resolver.query(ContentUris.withAppendedId(
|
||||
EmailProvider.MAILBOX_NOTIFICATION_URI, mAccountId),
|
||||
EmailProvider.NOTIFICATION_PROJECTION, null, null, null);
|
||||
EmailContent.MAILBOX_NOTIFICATION_URI, mAccountId),
|
||||
EmailContent.NOTIFICATION_PROJECTION, null, null, null);
|
||||
try {
|
||||
while (c.moveToNext()) {
|
||||
long mailboxId = c.getLong(EmailProvider.NOTIFICATION_MAILBOX_ID_COLUMN);
|
||||
long mailboxId = c.getLong(EmailContent.NOTIFICATION_MAILBOX_ID_COLUMN);
|
||||
int messageCount =
|
||||
c.getInt(EmailProvider.NOTIFICATION_MAILBOX_MESSAGE_COUNT_COLUMN);
|
||||
c.getInt(EmailContent.NOTIFICATION_MAILBOX_MESSAGE_COUNT_COLUMN);
|
||||
int unreadCount =
|
||||
c.getInt(EmailProvider.NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN);
|
||||
System.err.println("Changes in " + c.getLong(0) + ", unread: " + unreadCount);
|
||||
c.getInt(EmailContent.NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN);
|
||||
|
||||
Mailbox m = Mailbox.restoreMailboxWithId(mContext, mailboxId);
|
||||
long newMessageId = Utility.getFirstRowLong(mContext,
|
||||
ContentUris.withAppendedId(
|
||||
EmailProvider.MAILBOX_MOST_RECENT_MESSAGE_URI, mailboxId),
|
||||
EmailContent.MAILBOX_MOST_RECENT_MESSAGE_URI, mailboxId),
|
||||
Message.ID_COLUMN_PROJECTION, null, null, null,
|
||||
Message.ID_MAILBOX_COLUMN_ID, -1L);
|
||||
// TODO: Remove debug logging
|
||||
Log.d(Logging.LOG_TAG, "Changes to " + account.mDisplayName + "/" +
|
||||
m.mDisplayName + ", count: " + messageCount + ", lastNotified: " +
|
||||
m.mLastNotifiedMessageKey + ", mostRecent: " + newMessageId);
|
||||
Notification n = sInstance.createNewMessageNotification(mailboxId, newMessageId,
|
||||
messageCount, unreadCount);
|
||||
if (n != null) {
|
||||
|
|
|
@ -69,7 +69,6 @@ import com.android.emailcommon.provider.Mailbox;
|
|||
import com.android.emailcommon.utility.EmailAsyncTask;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
@ -980,7 +979,7 @@ public class MessageListFragment extends ListFragment
|
|||
return;
|
||||
}
|
||||
|
||||
final HashMap<Long, Boolean> setValues = Maps.newHashMap();
|
||||
final HashMap<Long, Boolean> setValues = new HashMap<Long, Boolean>();
|
||||
boolean allWereSet = true;
|
||||
|
||||
c.moveToPosition(-1);
|
||||
|
|
|
@ -1143,11 +1143,14 @@ public class EmailProvider extends ContentProvider {
|
|||
c = uiQuery(match, uri, projection);
|
||||
return c;
|
||||
case UI_FOLDER_REFRESH:
|
||||
return uiFolderRefresh(uri, projection);
|
||||
c = uiFolderRefresh(uri, projection);
|
||||
return c;
|
||||
case MAILBOX_NOTIFICATION:
|
||||
return notificationQuery(uri);
|
||||
c = notificationQuery(uri);
|
||||
return c;
|
||||
case MAILBOX_MOST_RECENT_MESSAGE:
|
||||
return mostRecentMessageQuery(uri);
|
||||
c = mostRecentMessageQuery(uri);
|
||||
return c;
|
||||
case ACCOUNT_DEFAULT_ID:
|
||||
// Start with a snapshot of the cache
|
||||
Map<String, Cursor> accountCache = mCacheAccount.getSnapshot();
|
||||
|
@ -1808,17 +1811,6 @@ outer:
|
|||
mAttachmentService = (as == null) ? DEFAULT_ATTACHMENT_SERVICE : as;
|
||||
}
|
||||
|
||||
public static final String[] NOTIFICATION_PROJECTION =
|
||||
new String[] {MailboxColumns.ID, MailboxColumns.UNREAD_COUNT, MailboxColumns.MESSAGE_COUNT};
|
||||
public static final int NOTIFICATION_MAILBOX_ID_COLUMN = 0;
|
||||
public static final int NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN = 1;
|
||||
public static final int NOTIFICATION_MAILBOX_MESSAGE_COUNT_COLUMN = 2;
|
||||
|
||||
public static final Uri MAILBOX_NOTIFICATION_URI =
|
||||
Uri.parse("content://" + EmailContent.AUTHORITY + "/mailboxNotification");
|
||||
public static final Uri MAILBOX_MOST_RECENT_MESSAGE_URI =
|
||||
Uri.parse("content://" + EmailContent.AUTHORITY + "/mailboxMostRecentMessage");
|
||||
|
||||
// SELECT DISTINCT Boxes._id, Boxes.unreadCount from Message, (SELECT _id, unreadCount,
|
||||
// messageCount, lastNotifiedMessageCount, lastNotifiedMessageKey
|
||||
// FROM Mailbox WHERE accountKey=6 AND syncInterval!=0 AND syncInterval!=-1) AS Boxes
|
||||
|
|
Loading…
Reference in New Issue