Make sure we call setServicesEnabled in the BootReceiver

* Otherwise, there's a chance that various activities will be
  disabled (like MessageCompose), even if there are existing
  accounts.
* Enable BootReceiver by default

Change-Id: Id4669c41a846545d8bac5ad85736e1508074864a
This commit is contained in:
Marc Blank 2009-09-23 15:06:19 -07:00
parent 3e1c871f04
commit 5fed934083
3 changed files with 10 additions and 9 deletions

View File

@ -181,9 +181,7 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name=".service.BootReceiver" <receiver android:name=".service.BootReceiver" android:enabled="true">
android:enabled="false"
>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>

View File

@ -140,9 +140,9 @@ public class Email extends Application {
/** /**
* Called throughout the application when the number of accounts has changed. This method * Called throughout the application when the number of accounts has changed. This method
* enables or disables the Compose activity, the boot receiver and the service based on * enables or disables the Compose activity, the boot receiver and the service based on
* whether any accounts are configured. * whether any accounts are configured. Returns true if there are any accounts configured.
*/ */
public static void setServicesEnabled(Context context) { public static boolean setServicesEnabled(Context context) {
Cursor c = null; Cursor c = null;
try { try {
c = context.getContentResolver().query( c = context.getContentResolver().query(
@ -151,6 +151,7 @@ public class Email extends Application {
null, null, null); null, null, null);
boolean enable = c.getCount() > 0; boolean enable = c.getCount() > 0;
setServicesEnabled(context, enable); setServicesEnabled(context, enable);
return enable;
} finally { } finally {
if (c != null) { if (c != null) {
c.close(); c.close();

View File

@ -16,18 +16,20 @@
package com.android.email.service; package com.android.email.service;
import com.android.exchange.SyncManager; import com.android.email.Email;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
public class BootReceiver extends BroadcastReceiver { public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
MailService.actionReschedule(context); // Returns true if there are any accounts
// TODO Remove when Exchange is running on its own if (Email.setServicesEnabled(context)) {
context.startService(new Intent(context, SyncManager.class)); MailService.actionReschedule(context);
}
} }
else if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(intent.getAction())) { else if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(intent.getAction())) {
MailService.actionCancel(context); MailService.actionCancel(context);