2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.service;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-01-03 19:47:11 -05:00
|
|
|
import java.util.Date;
|
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2009-10-21 20:41:06 -04:00
|
|
|
import android.net.ConnectivityManager;
|
2009-11-22 12:01:04 -05:00
|
|
|
import android.net.Uri;
|
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
|
|
|
import android.util.Log;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-01-03 19:47:11 -05:00
|
|
|
import com.fsck.k9.K9;
|
2009-12-09 22:16:42 -05:00
|
|
|
|
2010-01-03 19:47:11 -05:00
|
|
|
public class BootReceiver extends CoreReceiver
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
public static String FIRE_INTENT = "com.fsck.k9.service.BroadcastReceiver.fireIntent";
|
|
|
|
public static String SCHEDULE_INTENT = "com.fsck.k9.service.BroadcastReceiver.scheduleIntent";
|
|
|
|
public static String CANCEL_INTENT = "com.fsck.k9.service.BroadcastReceiver.cancelIntent";
|
2009-11-22 12:01:04 -05:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
public static String ALARMED_INTENT = "com.fsck.k9.service.BroadcastReceiver.pendingIntent";
|
|
|
|
public static String AT_TIME = "com.fsck.k9.service.BroadcastReceiver.atTime";
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2010-01-03 19:47:11 -05:00
|
|
|
public Integer receive(Context context, Intent intent, Integer tmpWakeLockId)
|
2009-11-22 12:01:04 -05:00
|
|
|
{
|
2010-01-03 19:47:11 -05:00
|
|
|
if (K9.DEBUG)
|
|
|
|
Log.i(K9.LOG_TAG, "BootReceiver.onReceive" + intent);
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2010-01-03 19:47:11 -05:00
|
|
|
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
|
2009-11-22 12:01:04 -05:00
|
|
|
{
|
2010-01-03 19:47:11 -05:00
|
|
|
//K9.setServicesEnabled(context, tmpWakeLockId);
|
|
|
|
//tmpWakeLockId = null;
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
2010-01-03 19:47:11 -05:00
|
|
|
else if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(intent.getAction()))
|
|
|
|
{
|
|
|
|
MailService.actionCancel(context, tmpWakeLockId);
|
|
|
|
tmpWakeLockId = null;
|
|
|
|
}
|
|
|
|
else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(intent.getAction()))
|
|
|
|
{
|
|
|
|
MailService.actionReschedule(context, tmpWakeLockId);
|
|
|
|
tmpWakeLockId = null;
|
|
|
|
}
|
|
|
|
else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction()))
|
|
|
|
{
|
|
|
|
boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
|
|
|
|
MailService.connectivityChange(context, !noConnectivity, tmpWakeLockId);
|
|
|
|
tmpWakeLockId = null;
|
|
|
|
}
|
|
|
|
else if (ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED.equals(intent.getAction()))
|
|
|
|
{
|
|
|
|
MailService.backgroundDataChanged(context, tmpWakeLockId);
|
|
|
|
tmpWakeLockId = null;
|
|
|
|
}
|
|
|
|
else if (FIRE_INTENT.equals(intent.getAction()))
|
2009-11-22 12:01:04 -05:00
|
|
|
{
|
2010-01-03 19:47:11 -05:00
|
|
|
Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
|
|
|
|
String alarmedAction = alarmedIntent.getAction();
|
2010-01-02 20:50:32 -05:00
|
|
|
if (K9.DEBUG)
|
2010-01-03 19:47:11 -05:00
|
|
|
Log.i(K9.LOG_TAG, "BootReceiver Got alarm to fire alarmedIntent " + alarmedAction);
|
|
|
|
alarmedIntent.putExtra(WAKE_LOCK_ID, tmpWakeLockId);
|
|
|
|
tmpWakeLockId = null;
|
|
|
|
if (alarmedIntent != null)
|
2009-11-22 12:01:04 -05:00
|
|
|
{
|
2010-01-03 19:47:11 -05:00
|
|
|
context.startService(alarmedIntent);
|
2009-11-22 12:01:04 -05:00
|
|
|
}
|
2010-01-03 19:47:11 -05:00
|
|
|
}
|
|
|
|
else if (SCHEDULE_INTENT.equals(intent.getAction()))
|
|
|
|
{
|
|
|
|
long atTime = intent.getLongExtra(AT_TIME, -1);
|
|
|
|
Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
|
|
|
|
if (K9.DEBUG)
|
|
|
|
Log.i(K9.LOG_TAG,"BootReceiver Scheduling intent " + alarmedIntent + " for " + new Date(atTime));
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2010-01-03 19:47:11 -05:00
|
|
|
PendingIntent pi = buildPendingIntent(context, intent);
|
|
|
|
AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2010-01-03 19:47:11 -05:00
|
|
|
alarmMgr.set(AlarmManager.RTC_WAKEUP, atTime, pi);
|
2009-10-21 20:41:06 -04:00
|
|
|
}
|
2010-01-03 19:47:11 -05:00
|
|
|
else if (CANCEL_INTENT.equals(intent.getAction()))
|
2009-11-22 12:01:04 -05:00
|
|
|
{
|
2010-01-03 19:47:11 -05:00
|
|
|
Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
|
|
|
|
if (K9.DEBUG)
|
|
|
|
Log.i(K9.LOG_TAG, "BootReceiver Canceling alarmedIntent " + alarmedIntent);
|
|
|
|
|
|
|
|
PendingIntent pi = buildPendingIntent(context, intent);
|
|
|
|
|
|
|
|
AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
|
|
|
alarmMgr.cancel(pi);
|
2009-10-31 14:51:59 -04:00
|
|
|
}
|
2010-01-03 19:47:11 -05:00
|
|
|
|
|
|
|
|
|
|
|
return tmpWakeLockId;
|
2009-11-22 12:01:04 -05:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
private PendingIntent buildPendingIntent(Context context, Intent intent)
|
|
|
|
{
|
|
|
|
Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
|
|
|
|
String alarmedAction = alarmedIntent.getAction();
|
|
|
|
|
|
|
|
Intent i = new Intent(context, BootReceiver.class);
|
|
|
|
i.setAction(FIRE_INTENT);
|
|
|
|
i.putExtra(ALARMED_INTENT, alarmedIntent);
|
|
|
|
Uri uri = Uri.parse("action://" + alarmedAction);
|
|
|
|
i.setData(uri);
|
|
|
|
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
|
|
|
|
return pi;
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
public static void scheduleIntent(Context context, long atTime, Intent alarmedIntent)
|
|
|
|
{
|
2010-01-02 20:50:32 -05:00
|
|
|
if (K9.DEBUG)
|
|
|
|
Log.i(K9.LOG_TAG, "BootReceiver Got request to schedule alarmedIntent " + alarmedIntent.getAction());
|
2009-11-22 12:01:04 -05:00
|
|
|
Intent i = new Intent();
|
|
|
|
i.setClass(context, BootReceiver.class);
|
|
|
|
i.setAction(SCHEDULE_INTENT);
|
|
|
|
i.putExtra(ALARMED_INTENT, alarmedIntent);
|
|
|
|
i.putExtra(AT_TIME, atTime);
|
|
|
|
context.sendBroadcast(i);
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
public static void cancelIntent(Context context, Intent alarmedIntent)
|
|
|
|
{
|
2010-01-02 20:50:32 -05:00
|
|
|
if (K9.DEBUG)
|
|
|
|
Log.i(K9.LOG_TAG, "BootReceiver Got request to cancel alarmedIntent " + alarmedIntent.getAction());
|
2009-11-22 12:01:04 -05:00
|
|
|
Intent i = new Intent();
|
|
|
|
i.setClass(context, BootReceiver.class);
|
|
|
|
i.setAction(CANCEL_INTENT);
|
|
|
|
i.putExtra(ALARMED_INTENT, alarmedIntent);
|
|
|
|
context.sendBroadcast(i);
|
|
|
|
}
|
2010-01-03 19:47:11 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|