EmailServiceUtils.java revision c84467afe1b5e0a657ed7d6a9fa1e3fe1ff259a0
1/* 2 * Copyright (C) 2010 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 android.app.Service; 20import android.content.Context; 21import android.content.Intent; 22import android.os.Bundle; 23import android.os.IBinder; 24import android.os.RemoteException; 25 26import com.android.emailcommon.Api; 27import com.android.emailcommon.provider.HostAuth; 28import com.android.emailcommon.service.EmailServiceProxy; 29import com.android.emailcommon.service.IEmailService; 30import com.android.emailcommon.service.IEmailServiceCallback; 31import com.android.emailcommon.service.SearchParams; 32 33/** 34 * Utility functions for EmailService support. 35 */ 36public class EmailServiceUtils { 37 /** 38 * Starts an EmailService by name 39 */ 40 public static void startService(Context context, String intentAction) { 41 context.startService(new Intent(intentAction)); 42 } 43 44 /** 45 * Returns an {@link IEmailService} for the service; otherwise returns an empty 46 * {@link IEmailService} implementation. 47 * 48 * @param context 49 * @param callback Object to get callback, or can be null 50 */ 51 public static EmailServiceProxy getService(Context context, String intentAction, 52 IEmailServiceCallback callback) { 53 return new EmailServiceProxy(context, intentAction, callback); 54 } 55 56 /** 57 * Determine if the EmailService is available 58 */ 59 public static boolean isServiceAvailable(Context context, String intentAction) { 60 return new EmailServiceProxy(context, intentAction, null).test(); 61 } 62 63 public static void startExchangeService(Context context) { 64 startService(context, EmailServiceProxy.EXCHANGE_INTENT); 65 } 66 67 public static EmailServiceProxy getExchangeService(Context context, 68 IEmailServiceCallback callback) { 69 return getService(context, EmailServiceProxy.EXCHANGE_INTENT, callback); 70 } 71 72 public static EmailServiceProxy getImapService(Context context, 73 IEmailServiceCallback callback) { 74 return new EmailServiceProxy(context, ImapService.class, callback); 75 } 76 77 public static boolean isExchangeAvailable(Context context) { 78 return isServiceAvailable(context, EmailServiceProxy.EXCHANGE_INTENT); 79 } 80 81 /** 82 * An empty {@link IEmailService} implementation which is used instead of 83 * {@link com.android.exchange.ExchangeService} on the build with no exchange support. 84 * 85 * <p>In theory, the service in question isn't used on the no-exchange-support build, 86 * because we won't have any exchange accounts in that case, so we wouldn't have to have this 87 * class. However, there are a few places we do use the service even if there's no exchange 88 * accounts (e.g. setLogging), so this class is added for safety and simplicity. 89 */ 90 public static class NullEmailService extends Service implements IEmailService { 91 public static final NullEmailService INSTANCE = new NullEmailService(); 92 93 @Override 94 public int getApiLevel() { 95 return Api.LEVEL; 96 } 97 98 @Override 99 public Bundle autoDiscover(String userName, String password) throws RemoteException { 100 return Bundle.EMPTY; 101 } 102 103 @Override 104 public boolean createFolder(long accountId, String name) throws RemoteException { 105 return false; 106 } 107 108 @Override 109 public boolean deleteFolder(long accountId, String name) throws RemoteException { 110 return false; 111 } 112 113 @Override 114 public void hostChanged(long accountId) throws RemoteException { 115 } 116 117 @Override 118 public void loadAttachment(long attachmentId, boolean background) throws RemoteException { 119 } 120 121 @Override 122 public void loadMore(long messageId) throws RemoteException { 123 } 124 125 @Override 126 public boolean renameFolder(long accountId, String oldName, String newName) 127 throws RemoteException { 128 return false; 129 } 130 131 @Override 132 public void sendMeetingResponse(long messageId, int response) throws RemoteException { 133 } 134 135 @Override 136 public void setCallback(IEmailServiceCallback cb) throws RemoteException { 137 } 138 139 @Override 140 public void setLogging(int flags) throws RemoteException { 141 } 142 143 @Override 144 public void startSync(long mailboxId, boolean userRequest) throws RemoteException { 145 } 146 147 @Override 148 public void stopSync(long mailboxId) throws RemoteException { 149 } 150 151 @Override 152 public void updateFolderList(long accountId) throws RemoteException { 153 } 154 155 @Override 156 public Bundle validate(HostAuth hostAuth) throws RemoteException { 157 return null; 158 } 159 160 @Override 161 public void deleteAccountPIMData(long accountId) throws RemoteException { 162 } 163 164 @Override 165 public int searchMessages(long accountId, SearchParams searchParams, long destMailboxId) { 166 return 0; 167 } 168 169 @Override 170 public IBinder asBinder() { 171 return null; 172 } 173 174 @Override 175 public IBinder onBind(Intent intent) { 176 return null; 177 } 178 } 179} 180