Fix for #511200 - run widget updater in the background. Also tweaked auto-synchronization in background. Hopefully that doesn't break :|

pull/14/head
Tim Su 16 years ago
parent 0857f9c1d3
commit e2f9d652aa

@ -375,9 +375,8 @@ Thanks for using Astrid!\n
It looks like you are using a task killer application! Please add Astrid to It looks like you are using a task killer application! Please add Astrid to
the exclusion list for your task killer. Otherwise, if Astrid gets killed, the exclusion list for your task killer. Otherwise, if Astrid gets killed,
it will not let you know when your tasks are due.\n it will not let you know when your tasks are due.\n
\n
In other words: don\'t kill Astrid!
</string> </string>
<string name="task_killer_help_ok">I Won\'t Kill Astrid!</string>
<!-- Locale Plugin --> <!-- Locale Plugin -->
<skip /> <skip />

@ -84,8 +84,8 @@ public class SynchronizationService extends BroadcastReceiver {
offset = Math.max(offset, AUTO_SYNC_MIN_OFFSET); offset = Math.max(offset, AUTO_SYNC_MIN_OFFSET);
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, PendingIntent pendingIntent = PendingIntent.getService(context, 0,
createAlarmIntent(context), 0); createAlarmIntent(context), PendingIntent.FLAG_UPDATE_CURRENT);
if (Constants.DEBUG) if (Constants.DEBUG)
Log.e("Astrid", "Autosync set for " + offset / 1000 Log.e("Astrid", "Autosync set for " + offset / 1000
@ -95,7 +95,7 @@ public class SynchronizationService extends BroadcastReceiver {
am.cancel(pendingIntent); am.cancel(pendingIntent);
// schedule new // schedule new
am.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + offset, am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + offset,
interval, pendingIntent); interval, pendingIntent);
} }
@ -105,8 +105,8 @@ public class SynchronizationService extends BroadcastReceiver {
*/ */
public static void unscheduleService(Context context) { public static void unscheduleService(Context context) {
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, PendingIntent pendingIntent = PendingIntent.getService(context, 0,
createAlarmIntent(context), 0); createAlarmIntent(context), PendingIntent.FLAG_UPDATE_CURRENT);
am.cancel(pendingIntent); am.cancel(pendingIntent);
} }

@ -13,7 +13,9 @@ public class Constants {
/** Flurry API KEy */ /** Flurry API KEy */
public static final String FLURRY_KEY = "T3JAY9TV2JFMJR4YTG16"; public static final String FLURRY_KEY = "T3JAY9TV2JFMJR4YTG16";
public static final boolean DEBUG = true; public static final boolean DEBUG = false;
public static final long WIDGET_UPDATE_INTERVAL = 30 * 60 * 1000L;
// result codes // result codes

@ -3,6 +3,9 @@ package com.timsu.astrid.utilities;
import java.util.List; import java.util.List;
import android.Manifest; import android.Manifest;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -66,25 +69,30 @@ public class StartupReceiver extends BroadcastReceiver {
} }
// schedule alarms in background every time Astrid is run // perform startup activities in a background thread
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {
// schedule alarms
Notifications.scheduleAllAlarms(context); Notifications.scheduleAllAlarms(context);
// start widget updating alarm
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, UpdateService.class);
PendingIntent pendingIntent = PendingIntent.getService(context,
0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setInexactRepeating(AlarmManager.RTC, 0,
Constants.WIDGET_UPDATE_INTERVAL, pendingIntent);
} }
}).start(); }).start();
Preferences.setPreferenceDefaults(context); Preferences.setPreferenceDefaults(context);
// start synchronization service
SynchronizationService.scheduleService(context);
// update widget
Intent intent = new Intent(context, UpdateService.class);
context.startService(intent);
// check for task killers // check for task killers
showTaskKillerHelp(context); showTaskKillerHelp(context);
// start synchronization service
SynchronizationService.scheduleService(context);
hasStartedUp = true; hasStartedUp = true;
} }
@ -93,31 +101,37 @@ public class StartupReceiver extends BroadcastReceiver {
return; return;
// search for task killers. if they exist, show the help! // search for task killers. if they exist, show the help!
new Thread(new Runnable() { PackageManager pm = context.getPackageManager();
@Override List<PackageInfo> apps = pm
public void run() { .getInstalledPackages(PackageManager.GET_PERMISSIONS);
PackageManager pm = context.getPackageManager(); outer: for (PackageInfo app : apps) {
List<PackageInfo> apps = pm if(app == null || app.requestedPermissions == null)
.getInstalledPackages(PackageManager.GET_PERMISSIONS); continue;
for (PackageInfo app : apps) { if(app.packageName.startsWith("com.android"))
for (String permission : app.requestedPermissions) { continue;
if (Manifest.permission.RESTART_PACKAGES for (String permission : app.requestedPermissions) {
.equals(permission)) { if (Manifest.permission.RESTART_PACKAGES.equals(permission)) {
DialogUtilities.okDialog(context, context Log.e("astrid", "found task killer: " + app.packageName);
.getString(R.string.task_killer_help),
new OnClickListener() { OnClickListener listener = new OnClickListener() {
@Override @Override
public void onClick( public void onClick(DialogInterface arg0,
DialogInterface arg0, int arg1) { int arg1) {
Preferences Preferences.setShouldShowTaskKillerHelp(
.setShouldShowTaskKillerHelp( context, true);
context, true);
}
});
} }
} };
new AlertDialog.Builder(context)
.setTitle(R.string.information_title)
.setMessage(R.string.task_killer_help)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.task_killer_help_ok, listener)
.show();
break outer;
} }
} }
}).start(); }
} }
} }

Loading…
Cancel
Save