2010-02-02 19:17:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 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.
|
|
|
|
*/
|
|
|
|
|
2011-06-27 19:12:41 +00:00
|
|
|
package com.android.email.service;
|
2010-02-02 19:17:48 +00:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2012-02-14 18:55:45 +00:00
|
|
|
import com.android.emailcommon.provider.Account;
|
2011-06-27 19:12:41 +00:00
|
|
|
import com.android.emailcommon.provider.HostAuth;
|
|
|
|
import com.android.emailcommon.service.EmailServiceProxy;
|
|
|
|
import com.android.emailcommon.service.IEmailService;
|
|
|
|
import com.android.emailcommon.service.IEmailServiceCallback;
|
|
|
|
|
2010-02-02 19:17:48 +00:00
|
|
|
/**
|
2011-06-27 19:12:41 +00:00
|
|
|
* Utility functions for EmailService support.
|
2010-02-02 19:17:48 +00:00
|
|
|
*/
|
2011-06-27 19:12:41 +00:00
|
|
|
public class EmailServiceUtils {
|
2010-02-02 19:17:48 +00:00
|
|
|
/**
|
2011-06-27 19:12:41 +00:00
|
|
|
* Starts an EmailService by name
|
2010-02-02 19:17:48 +00:00
|
|
|
*/
|
2011-06-27 19:12:41 +00:00
|
|
|
public static void startService(Context context, String intentAction) {
|
|
|
|
context.startService(new Intent(intentAction));
|
2010-02-02 19:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-27 19:12:41 +00:00
|
|
|
* Returns an {@link IEmailService} for the service; otherwise returns an empty
|
|
|
|
* {@link IEmailService} implementation.
|
2010-02-02 19:17:48 +00:00
|
|
|
*
|
|
|
|
* @param context
|
|
|
|
* @param callback Object to get callback, or can be null
|
|
|
|
*/
|
2012-02-09 00:29:08 +00:00
|
|
|
public static EmailServiceProxy getService(Context context, String intentAction,
|
2010-02-02 19:17:48 +00:00
|
|
|
IEmailServiceCallback callback) {
|
2011-06-27 19:12:41 +00:00
|
|
|
return new EmailServiceProxy(context, intentAction, callback);
|
2011-02-13 02:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-27 19:12:41 +00:00
|
|
|
* Determine if the EmailService is available
|
2011-02-13 02:56:09 +00:00
|
|
|
*/
|
2011-06-27 19:12:41 +00:00
|
|
|
public static boolean isServiceAvailable(Context context, String intentAction) {
|
|
|
|
return new EmailServiceProxy(context, intentAction, null).test();
|
2010-02-02 23:06:52 +00:00
|
|
|
}
|
|
|
|
|
2011-06-27 19:12:41 +00:00
|
|
|
public static void startExchangeService(Context context) {
|
|
|
|
startService(context, EmailServiceProxy.EXCHANGE_INTENT);
|
|
|
|
}
|
|
|
|
|
2012-02-09 00:29:08 +00:00
|
|
|
public static EmailServiceProxy getExchangeService(Context context,
|
2011-06-27 19:12:41 +00:00
|
|
|
IEmailServiceCallback callback) {
|
|
|
|
return getService(context, EmailServiceProxy.EXCHANGE_INTENT, callback);
|
|
|
|
}
|
|
|
|
|
2012-02-09 00:29:08 +00:00
|
|
|
public static EmailServiceProxy getImapService(Context context,
|
|
|
|
IEmailServiceCallback callback) {
|
|
|
|
return new EmailServiceProxy(context, ImapService.class, callback);
|
|
|
|
}
|
|
|
|
|
2012-02-14 18:55:45 +00:00
|
|
|
public static EmailServiceProxy getPop3Service(Context context,
|
|
|
|
IEmailServiceCallback callback) {
|
|
|
|
return new EmailServiceProxy(context, Pop3Service.class, callback);
|
|
|
|
}
|
|
|
|
|
2011-06-27 19:12:41 +00:00
|
|
|
public static boolean isExchangeAvailable(Context context) {
|
|
|
|
return isServiceAvailable(context, EmailServiceProxy.EXCHANGE_INTENT);
|
2010-02-24 19:51:59 +00:00
|
|
|
}
|
|
|
|
|
2010-02-02 23:06:52 +00:00
|
|
|
/**
|
2012-02-14 18:55:45 +00:00
|
|
|
* For a given account id, return a service proxy if applicable, or null.
|
2010-02-02 23:06:52 +00:00
|
|
|
*
|
2012-02-14 18:55:45 +00:00
|
|
|
* @param accountId the message of interest
|
|
|
|
* @result service proxy, or null if n/a
|
2010-02-02 23:06:52 +00:00
|
|
|
*/
|
2012-02-14 18:55:45 +00:00
|
|
|
public static EmailServiceProxy getServiceForAccount(Context context,
|
|
|
|
IEmailServiceCallback callback, long accountId) {
|
|
|
|
String protocol = Account.getProtocol(context, accountId);
|
|
|
|
if (protocol.equals(HostAuth.SCHEME_IMAP)) {
|
|
|
|
return getImapService(context, callback);
|
|
|
|
} else if (protocol.equals(HostAuth.SCHEME_POP3)) {
|
|
|
|
return getPop3Service(context, callback);
|
|
|
|
} else if (protocol.equals(HostAuth.SCHEME_EAS)) {
|
|
|
|
return getExchangeService(context, callback);
|
|
|
|
} else {
|
|
|
|
throw new IllegalArgumentException("Account with unknown protocol: " + accountId);
|
2010-08-20 16:53:46 +00:00
|
|
|
}
|
2010-02-02 19:17:48 +00:00
|
|
|
}
|
|
|
|
}
|