1f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy/* 2f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * Copyright (C) 2012 The Android Open Source Project 3f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * 4f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * Licensed under the Apache License, Version 2.0 (the "License"); 5f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * you may not use this file except in compliance with the License. 6f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * You may obtain a copy of the License at 7f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * 8f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * http://www.apache.org/licenses/LICENSE-2.0 9f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * 10f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * Unless required by applicable law or agreed to in writing, software 11f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * distributed under the License is distributed on an "AS IS" BASIS, 12f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * See the License for the specific language governing permissions and 14f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * limitations under the License. 15f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy */ 16f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedypackage com.android.mail; 17f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy 18ddd17bc2963b67ba07dfd1e2d9b1f17abf8c8e4aAndrew Sappersteinimport android.net.Uri; 19259df5b9e11908c8ef7c91483924891dd96b3c27Scott Kennedy 2078324d6394baf31f05bf986f3f8e5fa0686011bdVikram Aggarwalimport com.android.mail.utils.StorageLowState; 2178324d6394baf31f05bf986f3f8e5fa0686011bdVikram Aggarwal 22f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedyimport android.app.IntentService; 23d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport android.content.Context; 24f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedyimport android.content.Intent; 25f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy 2623e2b8a59defe139c529fbd486afcb3b32272047Andy Huangimport com.android.mail.analytics.Analytics; 2723e2b8a59defe139c529fbd486afcb3b32272047Andy Huangimport com.android.mail.analytics.AnalyticsUtils; 28d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport com.android.mail.providers.Account; 29d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport com.android.mail.providers.Folder; 30259df5b9e11908c8ef7c91483924891dd96b3c27Scott Kennedyimport com.android.mail.utils.FolderUri; 31d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport com.android.mail.utils.LogTag; 32d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport com.android.mail.utils.LogUtils; 33d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport com.android.mail.utils.NotificationUtils; 3448cfe4613549cafdf36e2a524afba730522bf291Scott Kennedyimport com.android.mail.utils.Utils; 35d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 36f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy/** 37f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy * A service to handle various intents asynchronously. 38f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy */ 39f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedypublic class MailIntentService extends IntentService { 40d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private static final String LOG_TAG = LogTag.getLogTag(); 41d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 42f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy public static final String ACTION_RESEND_NOTIFICATIONS = 43f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy "com.android.mail.action.RESEND_NOTIFICATIONS"; 44f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy public static final String ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS = 45f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy "com.android.mail.action.CLEAR_NEW_MAIL_NOTIFICATIONS"; 46d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public static final String ACTION_BACKUP_DATA_CHANGED = 47d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy "com.android.mail.action.BACKUP_DATA_CHANGED"; 48f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy 49d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public static final String CONVERSATION_EXTRA = "conversation"; 50f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy 51f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy public MailIntentService() { 52f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy super("MailIntentService"); 53f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy } 54f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy 55f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy protected MailIntentService(final String name) { 56f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy super(name); 57f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy } 58f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy 59f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy @Override 60f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy protected void onHandleIntent(final Intent intent) { 61d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy // UnifiedEmail does not handle all Intents 62d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 63d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy LogUtils.v(LOG_TAG, "Handling intent %s", intent); 64d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 65d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final String action = intent.getAction(); 66d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 67d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { 6826b29ef558cce109c51584081c52781760a02dd9Scott Kennedy NotificationUtils.cancelAndResendNotifications(this); 69d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } else if (ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS.equals(action)) { 7048cfe4613549cafdf36e2a524afba730522bf291Scott Kennedy final Account account = intent.getParcelableExtra(Utils.EXTRA_ACCOUNT); 7148cfe4613549cafdf36e2a524afba730522bf291Scott Kennedy final Folder folder = intent.getParcelableExtra(Utils.EXTRA_FOLDER); 72d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 737f8aed6bea276d6069abbfbdb25263a9ec92a684Scott Kennedy NotificationUtils.clearFolderNotification(this, account, folder, true /* markSeen */); 7423e2b8a59defe139c529fbd486afcb3b32272047Andy Huang 7523e2b8a59defe139c529fbd486afcb3b32272047Andy Huang Analytics.getInstance().sendEvent("notification_dismiss", folder.getTypeDescription(), 7623e2b8a59defe139c529fbd486afcb3b32272047Andy Huang null, 0); 7723e2b8a59defe139c529fbd486afcb3b32272047Andy Huang 78d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } else if (ACTION_RESEND_NOTIFICATIONS.equals(action)) { 79ddd17bc2963b67ba07dfd1e2d9b1f17abf8c8e4aAndrew Sapperstein final Uri accountUri = intent.getParcelableExtra(Utils.EXTRA_ACCOUNT_URI); 80ddd17bc2963b67ba07dfd1e2d9b1f17abf8c8e4aAndrew Sapperstein final Uri folderUri = intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI); 81ddd17bc2963b67ba07dfd1e2d9b1f17abf8c8e4aAndrew Sapperstein 82259df5b9e11908c8ef7c91483924891dd96b3c27Scott Kennedy NotificationUtils.resendNotifications(this, false, accountUri, 83259df5b9e11908c8ef7c91483924891dd96b3c27Scott Kennedy new FolderUri(folderUri)); 8487bd7a21437b8308a2b7225475b586c5670c5befVikram Aggarwal } else if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(action)) { 8587bd7a21437b8308a2b7225475b586c5670c5befVikram Aggarwal // The storage_low state is recorded centrally even though 8687bd7a21437b8308a2b7225475b586c5670c5befVikram Aggarwal // no handler might be present to change application state 8787bd7a21437b8308a2b7225475b586c5670c5befVikram Aggarwal // based on state changes. 8878324d6394baf31f05bf986f3f8e5fa0686011bdVikram Aggarwal StorageLowState.setIsStorageLow(true); 8978324d6394baf31f05bf986f3f8e5fa0686011bdVikram Aggarwal } else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(action)) { 9078324d6394baf31f05bf986f3f8e5fa0686011bdVikram Aggarwal StorageLowState.setIsStorageLow(false); 91d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 92d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 93d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 94d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public static void broadcastBackupDataChanged(final Context context) { 95d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final Intent intent = new Intent(ACTION_BACKUP_DATA_CHANGED); 96d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy context.startService(intent); 97d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 98f2566a42b5dec4e846391ee0d7ecae0891356653Scott Kennedy} 99