Merge "Forcibly kill the exchange process when an account is deleted" into jb-ub-mail-ur10
diff --git a/src/com/android/exchange/service/EmailSyncAdapterService.java b/src/com/android/exchange/service/EmailSyncAdapterService.java
index b60cd52..f391550 100644
--- a/src/com/android/exchange/service/EmailSyncAdapterService.java
+++ b/src/com/android/exchange/service/EmailSyncAdapterService.java
@@ -27,6 +27,7 @@
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.text.TextUtils;
 
 import com.android.emailcommon.Api;
 import com.android.emailcommon.TempDirectory;
@@ -38,6 +39,7 @@
 import com.android.emailcommon.service.IEmailService;
 import com.android.emailcommon.service.IEmailServiceCallback;
 import com.android.emailcommon.service.SearchParams;
+import com.android.emailcommon.service.ServiceProxy;
 import com.android.emailcommon.utility.Utility;
 import com.android.exchange.Eas;
 import com.android.exchange.adapter.PingParser;
@@ -474,6 +476,23 @@
     }
 
     @Override
+    public int onStartCommand(Intent intent, int flags, int startId) {
+        if (intent != null &&
+                TextUtils.equals(Eas.EXCHANGE_SERVICE_INTENT_ACTION, intent.getAction())) {
+            if (intent.getBooleanExtra(ServiceProxy.EXTRA_FORCE_SHUTDOWN, false)) {
+                // We've been asked to forcibly shutdown. This happens if email accounts are
+                // deleted, otherwise we can get errors if services are still running for
+                // accounts that are now gone.
+                // TODO: This is kind of a hack, it would be nicer if we could handle it correctly
+                // if accounts disappear out from under us.
+                LogUtils.d(TAG, "Forced shutdown, killing process");
+                System.exit(-1);
+            }
+        }
+        return super.onStartCommand(intent, flags, startId);
+    }
+
+    @Override
     protected AbstractThreadedSyncAdapter newSyncAdapter() {
         return new SyncAdapterImpl(this);
     }