Remove MailService.

Change-Id: Ibffd0c9fb0eed4822dff28d1577fb455736cffd1
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4ed1a82..70cf03a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -456,12 +456,6 @@
         </receiver>
 
         <service
-            android:name=".service.MailService"
-            android:enabled="true"
-            >
-        </service>
-
-        <service
             android:name=".service.AttachmentDownloadService"
             android:enabled="false"
             >
diff --git a/src/com/android/email/activity/setup/AccountSetupOptions.java b/src/com/android/email/activity/setup/AccountSetupOptions.java
index 62f1cbe..ee6eb15 100644
--- a/src/com/android/email/activity/setup/AccountSetupOptions.java
+++ b/src/com/android/email/activity/setup/AccountSetupOptions.java
@@ -41,7 +41,6 @@
 import com.android.email.activity.UiUtilities;
 import com.android.email.service.EmailServiceUtils;
 import com.android.email.service.EmailServiceUtils.EmailServiceInfo;
-import com.android.email.service.MailService;
 import com.android.email2.ui.MailActivityEmail;
 import com.android.emailcommon.Logging;
 import com.android.emailcommon.provider.Account;
@@ -254,7 +253,7 @@
             public void run() {
                 Context context = AccountSetupOptions.this;
                 AccountSettingsUtils.commitSettings(context, account);
-                MailService.setupAccountManagerAccount(context, account,
+                EmailServiceUtils.setupAccountManagerAccount(context, account,
                         email2, calendar2, contacts2, mAccountManagerCallback);
 
                 // We can move the notification setting to the inbox FolderPreferences later, once
diff --git a/src/com/android/email/service/EmailServiceUtils.java b/src/com/android/email/service/EmailServiceUtils.java
index f20498d..ce95a18 100644
--- a/src/com/android/email/service/EmailServiceUtils.java
+++ b/src/com/android/email/service/EmailServiceUtils.java
@@ -17,6 +17,7 @@
 package com.android.email.service;
 
 import android.accounts.AccountManager;
+import android.accounts.AccountManagerCallback;
 import android.accounts.AccountManagerFuture;
 import android.accounts.AuthenticatorException;
 import android.accounts.OperationCanceledException;
@@ -250,6 +251,36 @@
         }
     }
 
+    /**
+     * Add an account to the AccountManager.
+     * @param context Our {@link Context}.
+     * @param account The {@link Account} we're adding.
+     * @param email Whether the user wants to sync email on this account.
+     * @param calendar Whether the user wants to sync calendar on this account.
+     * @param contacts Whether the user wants to sync contacts on this account.
+     * @param callback A callback for when the AccountManager is done.
+     * @return The result of {@link AccountManager#addAccount}.
+     */
+    public static AccountManagerFuture<Bundle> setupAccountManagerAccount(final Context context,
+            final Account account, final boolean email, final boolean calendar,
+            final boolean contacts, final AccountManagerCallback<Bundle> callback) {
+        final Bundle options = new Bundle(5);
+        final HostAuth hostAuthRecv =
+                HostAuth.restoreHostAuthWithId(context, account.mHostAuthKeyRecv);
+        if (hostAuthRecv == null) {
+            return null;
+        }
+        // Set up username/password
+        options.putString(EasAuthenticatorService.OPTIONS_USERNAME, account.mEmailAddress);
+        options.putString(EasAuthenticatorService.OPTIONS_PASSWORD, hostAuthRecv.mPassword);
+        options.putBoolean(EasAuthenticatorService.OPTIONS_CONTACTS_SYNC_ENABLED, contacts);
+        options.putBoolean(EasAuthenticatorService.OPTIONS_CALENDAR_SYNC_ENABLED, calendar);
+        options.putBoolean(EasAuthenticatorService.OPTIONS_EMAIL_SYNC_ENABLED, email);
+        final EmailServiceInfo info = getServiceInfo(context, hostAuthRecv.mProtocol);
+        return AccountManager.get(context).addAccount(info.accountType, null, null, options, null,
+                callback, null);
+    }
+
     public static void updateAccountManagerType(Context context,
             android.accounts.Account amAccount, final HashMap<String, String> protocolMap) {
         final ContentResolver resolver = context.getContentResolver();
@@ -347,8 +378,8 @@
                     }
 
                     // Set up a new AccountManager account with new type and old settings
-                    AccountManagerFuture<?> amFuture = MailService.setupAccountManagerAccount(
-                            context, account, email, calendar, contacts, null);
+                    AccountManagerFuture<?> amFuture = setupAccountManagerAccount(context, account,
+                            email, calendar, contacts, null);
                     finishAccountManagerBlocker(amFuture);
                     LogUtils.w(Logging.LOG_TAG, "Created new AccountManager account");
 
diff --git a/src/com/android/email/service/MailService.java b/src/com/android/email/service/MailService.java
deleted file mode 100644
index e626cc6..0000000
--- a/src/com/android/email/service/MailService.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.email.service;
-
-import android.accounts.AccountManager;
-import android.accounts.AccountManagerCallback;
-import android.accounts.AccountManagerFuture;
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.IBinder;
-
-import com.android.email.provider.AccountReconciler;
-import com.android.email.service.EmailServiceUtils.EmailServiceInfo;
-import com.android.email2.ui.MailActivityEmail;
-import com.android.emailcommon.provider.Account;
-import com.android.emailcommon.provider.HostAuth;
-
-/**
- * Legacy service, now used mainly for account reconciliation
- * TODO: Eliminate this service, since it doesn't actually do anything.
- */
-public class MailService extends Service {
-
-    @Override
-    public int onStartCommand(final Intent intent, int flags, final int startId) {
-        super.onStartCommand(intent, flags, startId);
-        AccountReconciler.reconcileAccounts(this);
-        // Make sure our services are running, if necessary
-        MailActivityEmail.setServicesEnabledAsync(this);
-        return START_STICKY;
-    }
-
-    @Override
-    public IBinder onBind(Intent intent) {
-        return null;
-    }
-
-    public static AccountManagerFuture<Bundle> setupAccountManagerAccount(Context context,
-            Account account, boolean email, boolean calendar, boolean contacts,
-            AccountManagerCallback<Bundle> callback) {
-        Bundle options = new Bundle();
-        HostAuth hostAuthRecv = HostAuth.restoreHostAuthWithId(context, account.mHostAuthKeyRecv);
-        if (hostAuthRecv == null) {
-            return null;
-        }
-        // Set up username/password
-        options.putString(EasAuthenticatorService.OPTIONS_USERNAME, account.mEmailAddress);
-        options.putString(EasAuthenticatorService.OPTIONS_PASSWORD, hostAuthRecv.mPassword);
-        options.putBoolean(EasAuthenticatorService.OPTIONS_CONTACTS_SYNC_ENABLED, contacts);
-        options.putBoolean(EasAuthenticatorService.OPTIONS_CALENDAR_SYNC_ENABLED, calendar);
-        options.putBoolean(EasAuthenticatorService.OPTIONS_EMAIL_SYNC_ENABLED, email);
-        EmailServiceInfo info = EmailServiceUtils.getServiceInfo(context, hostAuthRecv.mProtocol);
-        return AccountManager.get(context).addAccount(info.accountType, null, null, options, null,
-                callback, null);
-    }
-}
diff --git a/src/com/android/email2/ui/MailActivityEmail.java b/src/com/android/email2/ui/MailActivityEmail.java
index 107528c..4f2d9e9 100644
--- a/src/com/android/email2/ui/MailActivityEmail.java
+++ b/src/com/android/email2/ui/MailActivityEmail.java
@@ -20,8 +20,8 @@
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.PackageManager;
 import android.content.UriMatcher;
+import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
@@ -32,7 +32,6 @@
 import com.android.email.provider.EmailProvider;
 import com.android.email.service.AttachmentDownloadService;
 import com.android.email.service.EmailServiceUtils;
-import com.android.email.service.MailService;
 import com.android.emailcommon.Logging;
 import com.android.emailcommon.TempDirectory;
 import com.android.emailcommon.provider.Account;
@@ -143,11 +142,6 @@
     private static void setServicesEnabled(Context context, boolean enabled) {
         PackageManager pm = context.getPackageManager();
         pm.setComponentEnabledSetting(
-                new ComponentName(context, MailService.class),
-                enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
-                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
-                PackageManager.DONT_KILL_APP);
-        pm.setComponentEnabledSetting(
                 new ComponentName(context, AttachmentDownloadService.class),
                 enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
                     PackageManager.COMPONENT_ENABLED_STATE_DISABLED,