Use update notification intent to trigger notifications
This ensures the SuppressNotificationReceiver object quiesces the notification while we're viewing the folder b/11789666 Change-Id: I98f388844b29458e7ea7deee398f7d8536b1919c
This commit is contained in:
parent
6b9c648105
commit
8196f82ce2
|
@ -682,6 +682,11 @@
|
||||||
<action android:name="com.android.mail.action.CLEAR_NEW_MAIL_NOTIFICATIONS" />
|
<action android:name="com.android.mail.action.CLEAR_NEW_MAIL_NOTIFICATIONS" />
|
||||||
<data android:scheme="content" />
|
<data android:scheme="content" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="com.android.mail.action.update_notification"
|
||||||
|
android:priority="-10"/>
|
||||||
|
<data android:mimeType="@string/application_mime_type" />
|
||||||
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service android:name="com.android.mail.NotificationActionIntentService"
|
<service android:name="com.android.mail.NotificationActionIntentService"
|
||||||
|
|
|
@ -18,6 +18,7 @@ package com.android.email;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import com.android.mail.MailIntentService;
|
import com.android.mail.MailIntentService;
|
||||||
|
import com.android.mail.providers.UIProvider;
|
||||||
import com.android.mail.utils.LogTag;
|
import com.android.mail.utils.LogTag;
|
||||||
import com.android.mail.utils.LogUtils;
|
import com.android.mail.utils.LogUtils;
|
||||||
|
|
||||||
|
@ -35,6 +36,10 @@ public class EmailIntentService extends MailIntentService {
|
||||||
protected void onHandleIntent(final Intent intent) {
|
protected void onHandleIntent(final Intent intent) {
|
||||||
super.onHandleIntent(intent);
|
super.onHandleIntent(intent);
|
||||||
|
|
||||||
|
if (UIProvider.ACTION_UPDATE_NOTIFICATION.equals(intent.getAction())) {
|
||||||
|
NotificationController.handleUpdateNotificationIntent(this, intent);
|
||||||
|
}
|
||||||
|
|
||||||
LogUtils.v(LOG_TAG, "Handling intent %s", intent);
|
LogUtils.v(LOG_TAG, "Handling intent %s", intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -592,14 +592,73 @@ public class NotificationController {
|
||||||
|
|
||||||
private static void refreshNotificationsForAccountInternal(final Context context,
|
private static void refreshNotificationsForAccountInternal(final Context context,
|
||||||
final long accountId) {
|
final long accountId) {
|
||||||
|
final Uri accountUri = EmailProvider.uiUri("uiaccount", accountId);
|
||||||
|
|
||||||
final ContentResolver contentResolver = context.getContentResolver();
|
final ContentResolver contentResolver = context.getContentResolver();
|
||||||
|
|
||||||
final Cursor accountCursor = contentResolver.query(
|
final Cursor mailboxCursor = contentResolver.query(
|
||||||
EmailProvider.uiUri("uiaccount", accountId), UIProvider.ACCOUNTS_PROJECTION,
|
ContentUris.withAppendedId(EmailContent.MAILBOX_NOTIFICATION_URI, accountId),
|
||||||
null, null, null);
|
null, null, null, null);
|
||||||
|
try {
|
||||||
|
while (mailboxCursor.moveToNext()) {
|
||||||
|
final long mailboxId =
|
||||||
|
mailboxCursor.getLong(EmailContent.NOTIFICATION_MAILBOX_ID_COLUMN);
|
||||||
|
if (mailboxId == 0) continue;
|
||||||
|
|
||||||
|
final int unseenCount = mailboxCursor.getInt(
|
||||||
|
EmailContent.NOTIFICATION_MAILBOX_UNSEEN_COUNT_COLUMN);
|
||||||
|
|
||||||
|
final int unreadCount;
|
||||||
|
// If nothing is unseen, clear the notification
|
||||||
|
if (unseenCount == 0) {
|
||||||
|
unreadCount = 0;
|
||||||
|
} else {
|
||||||
|
unreadCount = mailboxCursor.getInt(
|
||||||
|
EmailContent.NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Uri folderUri = EmailProvider.uiUri("uifolder", mailboxId);
|
||||||
|
|
||||||
|
|
||||||
|
LogUtils.d(LOG_TAG, "Changes to account " + accountId + ", folder: "
|
||||||
|
+ mailboxId + ", unreadCount: " + unreadCount + ", unseenCount: "
|
||||||
|
+ unseenCount);
|
||||||
|
|
||||||
|
final Intent intent = new Intent(UIProvider.ACTION_UPDATE_NOTIFICATION);
|
||||||
|
intent.setPackage(context.getPackageName());
|
||||||
|
intent.setType(EmailProvider.EMAIL_APP_MIME_TYPE);
|
||||||
|
|
||||||
|
intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_ACCOUNT, accountUri);
|
||||||
|
intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_FOLDER, folderUri);
|
||||||
|
intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNREAD_COUNT,
|
||||||
|
unreadCount);
|
||||||
|
intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNSEEN_COUNT,
|
||||||
|
unseenCount);
|
||||||
|
|
||||||
|
context.sendOrderedBroadcast(intent, null);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
mailboxCursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handleUpdateNotificationIntent(Context context, Intent intent) {
|
||||||
|
final Uri accountUri =
|
||||||
|
intent.getParcelableExtra(UIProvider.UpdateNotificationExtras.EXTRA_ACCOUNT);
|
||||||
|
final Uri folderUri =
|
||||||
|
intent.getParcelableExtra(UIProvider.UpdateNotificationExtras.EXTRA_FOLDER);
|
||||||
|
final int unreadCount = intent.getIntExtra(
|
||||||
|
UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNREAD_COUNT, 0);
|
||||||
|
final int unseenCount = intent.getIntExtra(
|
||||||
|
UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNSEEN_COUNT, 0);
|
||||||
|
|
||||||
|
final ContentResolver contentResolver = context.getContentResolver();
|
||||||
|
|
||||||
|
final Cursor accountCursor = contentResolver.query(accountUri,
|
||||||
|
UIProvider.ACCOUNTS_PROJECTION, null, null, null);
|
||||||
|
|
||||||
if (accountCursor == null) {
|
if (accountCursor == null) {
|
||||||
LogUtils.e(LOG_TAG, "Null account cursor for account id %d", accountId);
|
LogUtils.e(LOG_TAG, "Null account cursor for account " + accountUri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,58 +672,37 @@ public class NotificationController {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
LogUtils.d(LOG_TAG, "Tried to create a notification for a missing account %d",
|
LogUtils.d(LOG_TAG, "Tried to create a notification for a missing account "
|
||||||
accountId);
|
+ accountUri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Cursor mailboxCursor = contentResolver.query(
|
final Cursor folderCursor = contentResolver.query(folderUri, UIProvider.FOLDERS_PROJECTION,
|
||||||
ContentUris.withAppendedId(EmailContent.MAILBOX_NOTIFICATION_URI, accountId),
|
null, null, null);
|
||||||
null, null, null, null);
|
|
||||||
|
if (folderCursor == null) {
|
||||||
|
LogUtils.e(LOG_TAG, "Null folder cursor for account " + accountUri + ", mailbox "
|
||||||
|
+ folderUri);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Folder folder = null;
|
||||||
try {
|
try {
|
||||||
while (mailboxCursor.moveToNext()) {
|
if (folderCursor.moveToFirst()) {
|
||||||
final long mailboxId =
|
folder = new Folder(folderCursor);
|
||||||
mailboxCursor.getLong(EmailContent.NOTIFICATION_MAILBOX_ID_COLUMN);
|
} else {
|
||||||
if (mailboxId == 0) continue;
|
LogUtils.e(LOG_TAG, "Empty folder cursor for account " + accountUri + ", mailbox "
|
||||||
|
+ folderUri);
|
||||||
final int unreadCount = mailboxCursor.getInt(
|
return;
|
||||||
EmailContent.NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN);
|
|
||||||
final int unseenCount = mailboxCursor.getInt(
|
|
||||||
EmailContent.NOTIFICATION_MAILBOX_UNSEEN_COUNT_COLUMN);
|
|
||||||
|
|
||||||
final Cursor folderCursor = contentResolver.query(
|
|
||||||
EmailProvider.uiUri("uifolder", mailboxId),
|
|
||||||
UIProvider.FOLDERS_PROJECTION, null, null, null);
|
|
||||||
|
|
||||||
if (folderCursor == null) {
|
|
||||||
LogUtils.e(LOG_TAG, "Null folder cursor for account %d, mailbox %d",
|
|
||||||
accountId, mailboxId);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Folder folder = null;
|
|
||||||
try {
|
|
||||||
if (folderCursor.moveToFirst()) {
|
|
||||||
folder = new Folder(folderCursor);
|
|
||||||
} else {
|
|
||||||
LogUtils.e(LOG_TAG, "Empty folder cursor for account %d, mailbox %d",
|
|
||||||
accountId, mailboxId);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
folderCursor.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
LogUtils.d(LOG_TAG, "Changes to account " + account.name + ", folder: "
|
|
||||||
+ folder.name + ", unreadCount: " + unreadCount + ", unseenCount: "
|
|
||||||
+ unseenCount);
|
|
||||||
|
|
||||||
NotificationUtils.setNewEmailIndicator(context, unreadCount, unseenCount,
|
|
||||||
account, folder, true);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
mailboxCursor.close();
|
folderCursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: we don't always want getAttention to be true, but we don't necessarily have a
|
||||||
|
// good heuristic for when it should or shouldn't be.
|
||||||
|
NotificationUtils.setNewEmailIndicator(context, unreadCount, unseenCount, account, folder,
|
||||||
|
true /* getAttention */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void refreshAllNotifications(final Context context) {
|
private static void refreshAllNotifications(final Context context) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import android.provider.ContactsContract;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
|
|
||||||
|
import com.android.email.EmailIntentService;
|
||||||
import com.android.email.Preferences;
|
import com.android.email.Preferences;
|
||||||
import com.android.email.R;
|
import com.android.email.R;
|
||||||
import com.android.email.SecurityPolicy;
|
import com.android.email.SecurityPolicy;
|
||||||
|
@ -45,6 +46,7 @@ import com.android.emailcommon.provider.Account;
|
||||||
import com.android.emailcommon.provider.EmailContent;
|
import com.android.emailcommon.provider.EmailContent;
|
||||||
import com.android.emailcommon.provider.EmailContent.AccountColumns;
|
import com.android.emailcommon.provider.EmailContent.AccountColumns;
|
||||||
import com.android.emailcommon.provider.HostAuth;
|
import com.android.emailcommon.provider.HostAuth;
|
||||||
|
import com.android.mail.providers.UIProvider;
|
||||||
import com.android.mail.utils.LogUtils;
|
import com.android.mail.utils.LogUtils;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
@ -136,6 +138,9 @@ public class EmailBroadcastProcessorService extends IntentService {
|
||||||
AccountSettings.actionSettingsWithDebug(this);
|
AccountSettings.actionSettingsWithDebug(this);
|
||||||
} else if (AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(broadcastAction)) {
|
} else if (AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(broadcastAction)) {
|
||||||
onSystemAccountChanged();
|
onSystemAccountChanged();
|
||||||
|
} else if (UIProvider.ACTION_UPDATE_NOTIFICATION.equals((broadcastAction))) {
|
||||||
|
broadcastIntent.setClass(this, EmailIntentService.class);
|
||||||
|
startService(broadcastIntent);
|
||||||
}
|
}
|
||||||
} else if (ACTION_DEVICE_POLICY_ADMIN.equals(action)) {
|
} else if (ACTION_DEVICE_POLICY_ADMIN.equals(action)) {
|
||||||
int message = intent.getIntExtra(EXTRA_DEVICE_POLICY_ADMIN, -1);
|
int message = intent.getIntExtra(EXTRA_DEVICE_POLICY_ADMIN, -1);
|
||||||
|
|
Loading…
Reference in New Issue