AccountService.java revision 9dad9ad973ccf8255228a41acc0ee78af989a651
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.email.service; 18 19import com.android.email.Email; 20import com.android.email.ExchangeUtils; 21import com.android.email.NotificationController; 22import com.android.email.ResourceHelper; 23import com.android.email.VendorPolicyLoader; 24import com.android.emailcommon.Configuration; 25import com.android.emailcommon.Device; 26import com.android.emailcommon.service.IAccountService; 27import com.android.emailcommon.utility.EmailAsyncTask; 28 29import android.app.Service; 30import android.content.Context; 31import android.content.Intent; 32import android.os.Bundle; 33import android.os.IBinder; 34 35import java.io.IOException; 36 37public class AccountService extends Service { 38 39 // Save context 40 private Context mContext; 41 42 private final IAccountService.Stub mBinder = new IAccountService.Stub() { 43 44 @Override 45 public void notifyLoginFailed(long accountId) { 46 NotificationController.getInstance(mContext).showLoginFailedNotification(accountId); 47 } 48 49 @Override 50 public void notifyLoginSucceeded(long accountId) { 51 NotificationController.getInstance(mContext).cancelLoginFailedNotification(accountId); 52 } 53 54 @Override 55 public void restoreAccountsIfNeeded() { 56 // Obsolete -- this is done 100% transparently in EmailProvider. 57 // We leave the method because we don't want to change the service interface. 58 // (It may be okay to remove it, but we're not sure at this point.) 59 } 60 61 @Override 62 public void accountDeleted() { 63 MailService.accountDeleted(mContext); 64 } 65 66 @Override 67 public int getAccountColor(long accountId) { 68 return ResourceHelper.getInstance(mContext).getAccountColor(accountId); 69 } 70 71 @Override 72 public Bundle getConfigurationData(String accountType) { 73 Bundle bundle = new Bundle(); 74 bundle.putBoolean(Configuration.EXCHANGE_CONFIGURATION_USE_ALTERNATE_STRINGS, 75 VendorPolicyLoader.getInstance(mContext).useAlternateExchangeStrings()); 76 return bundle; 77 } 78 79 @Override 80 public String getDeviceId() { 81 try { 82 EmailAsyncTask.runAsyncSerial(new Runnable() { 83 @Override 84 public void run() { 85 // Make sure the service is properly running (re: lifecycle) 86 ExchangeUtils.startExchangeService(mContext); 87 // Send current logging flags 88 Email.updateLoggingFlags(mContext); 89 }}); 90 return Device.getDeviceId(mContext); 91 } catch (IOException e) { 92 return null; 93 } 94 } 95 }; 96 97 @Override 98 public IBinder onBind(Intent intent) { 99 if (mContext == null) { 100 mContext = this; 101 } 102 // Make sure we have a valid deviceId (just retrieves a static String except first time) 103 try { 104 Device.getDeviceId(this); 105 } catch (IOException e) { 106 } 107 return mBinder; 108 } 109}