AccountService.java revision dc78a769fce18d259eccc602c4623fa74cdf5319
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.AccountBackupRestore; 20import com.android.email.NotificationController; 21import com.android.email.ResourceHelper; 22import com.android.email.VendorPolicyLoader; 23import com.android.emailcommon.Configuration; 24import com.android.emailcommon.Device; 25import com.android.emailcommon.service.IAccountService; 26 27import android.app.Service; 28import android.content.Context; 29import android.content.Intent; 30import android.os.Bundle; 31import android.os.IBinder; 32import android.os.RemoteException; 33 34import java.io.IOException; 35 36public class AccountService extends Service { 37 38 // Save context 39 private Context mContext; 40 41 private final IAccountService.Stub mBinder = new IAccountService.Stub() { 42 43 @Override 44 public void notifyLoginFailed(long accountId) throws RemoteException { 45 NotificationController.getInstance(mContext).showLoginFailedNotification(accountId); 46 } 47 48 @Override 49 public void notifyLoginSucceeded(long accountId) throws RemoteException { 50 NotificationController.getInstance(mContext).cancelLoginFailedNotification(accountId); 51 } 52 53 @Override 54 public void notifyNewMessages(long accountId) throws RemoteException { 55 MailService.actionNotifyNewMessages(mContext, accountId); 56 } 57 58 @Override 59 public void restoreAccountsIfNeeded() throws RemoteException { 60 AccountBackupRestore.restoreAccountsIfNeeded(mContext); 61 } 62 63 @Override 64 public void accountDeleted() throws RemoteException { 65 MailService.accountDeleted(mContext); 66 } 67 68 @Override 69 public int getAccountColor(long accountId) throws RemoteException { 70 return ResourceHelper.getInstance(mContext).getAccountColor(accountId); 71 } 72 73 @Override 74 public Bundle getConfigurationData(String accountType) throws RemoteException { 75 Bundle bundle = new Bundle(); 76 bundle.putBoolean(Configuration.EXCHANGE_CONFIGURATION_USE_ALTERNATE_STRINGS, 77 VendorPolicyLoader.getInstance(mContext).useAlternateExchangeStrings()); 78 return bundle; 79 } 80 81 @Override 82 public String getDeviceId() throws RemoteException { 83 try { 84 return Device.getDeviceId(mContext); 85 } catch (IOException e) { 86 return null; 87 } 88 } 89 }; 90 91 @Override 92 public IBinder onBind(Intent intent) { 93 if (mContext == null) { 94 mContext = this; 95 } 96 // Make sure we have a valid deviceId (just retrieves a static String except first time) 97 try { 98 Device.getDeviceId(this); 99 } catch (IOException e) { 100 } 101 return mBinder; 102 } 103}