Merge "Gather common exchange related methods into one place"

This commit is contained in:
Makoto Onuki 2010-02-02 13:48:04 -08:00 committed by Android (Google) Code Review
commit 130988e49d
9 changed files with 72 additions and 32 deletions

View File

@ -23,7 +23,6 @@ import com.android.exchange.Eas;
import android.accounts.AccountManagerFuture;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Calendar;
@ -66,8 +65,7 @@ public class AccountBackupRestore {
// after restoring accounts, register services appropriately
Log.w(Email.LOG_TAG, "Register services after restoring accounts");
Email.setServicesEnabled(context);
context.startService(new Intent(context.getApplicationContext(),
com.android.exchange.SyncManager.class));
ExchangeUtils.startExchangeService(context);
}
}

View File

@ -27,11 +27,9 @@ import com.android.email.provider.EmailContent.Mailbox;
import com.android.email.provider.EmailContent.MailboxColumns;
import com.android.email.provider.EmailContent.Message;
import com.android.email.provider.EmailContent.MessageColumns;
import com.android.email.service.EmailServiceProxy;
import com.android.email.service.EmailServiceStatus;
import com.android.email.service.IEmailService;
import com.android.email.service.IEmailServiceCallback;
import com.android.exchange.SyncManager;
import android.content.ContentResolver;
import android.content.ContentUris;
@ -136,8 +134,7 @@ public class Controller {
* Generally this should be called by anybody who changes Email.DEBUG
*/
public void serviceLogging(int debugEnabled) {
IEmailService service =
new EmailServiceProxy(mContext, SyncManager.class, mServiceCallback);
IEmailService service = ExchangeUtils.getExchangeEmailService(mContext, mServiceCallback);
try {
service.setLogging(debugEnabled);
} catch (RemoteException e) {
@ -787,7 +784,7 @@ public class Controller {
if (account == null || isMessagingController(account)) {
return null;
} else {
return new EmailServiceProxy(mContext, SyncManager.class, mServiceCallback);
return ExchangeUtils.getExchangeEmailService(mContext, mServiceCallback);
}
}

View File

@ -0,0 +1,50 @@
/*
* 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.
*/
package com.android.email;
import com.android.email.service.EmailServiceProxy;
import com.android.email.service.IEmailService;
import com.android.email.service.IEmailServiceCallback;
import com.android.exchange.SyncManager;
import android.content.Context;
import android.content.Intent;
/**
* Utility functions for Exchange support.
*/
public class ExchangeUtils {
/**
* Starts the service for Exchange, if supported.
*/
public static void startExchangeService(Context context) {
context.startService(new Intent(context, SyncManager.class));
}
/**
* Returns an {@link IEmailService} for the Exchange service, if supported. Otherwise it'll
* return an empty {@link IEmailService} implementation.
*
* @param context
* @param callback Object to get callback, or can be null
*/
public static IEmailService getExchangeEmailService(Context context,
IEmailServiceCallback callback) {
// TODO Return an empty IEmailService impl if exchange support is removed
return new EmailServiceProxy(context, SyncManager.class, callback);
}
}

View File

@ -17,10 +17,10 @@
package com.android.email.activity;
import com.android.email.AccountBackupRestore;
import com.android.email.ExchangeUtils;
import com.android.email.activity.setup.AccountSetupBasics;
import com.android.email.provider.EmailContent.Account;
import com.android.email.provider.EmailContent.Mailbox;
import com.android.exchange.SyncManager;
import android.app.Activity;
import android.content.Intent;
@ -59,7 +59,7 @@ public class Welcome extends Activity {
// SyncManager gets a chance to start. There is no harm to starting it if it has already
// been started
// TODO More completely separate SyncManager from Email app
startService(new Intent(this, SyncManager.class));
ExchangeUtils.startExchangeService(this);
// Find out how many accounts we have, and if there's just one, go directly to it
Cursor c = null;

View File

@ -17,13 +17,12 @@
package com.android.email.activity.setup;
import com.android.email.AccountBackupRestore;
import com.android.email.ExchangeUtils;
import com.android.email.R;
import com.android.email.Utility;
import com.android.email.provider.EmailContent;
import com.android.email.provider.EmailContent.Account;
import com.android.email.provider.EmailContent.HostAuth;
import com.android.email.service.EmailServiceProxy;
import com.android.exchange.SyncManager;
import android.app.Activity;
import android.app.AlertDialog;
@ -308,7 +307,7 @@ public class AccountSetupExchange extends Activity implements OnClickListener,
if (mAccount.mHostAuthRecv.mProtocol.equals("eas")) {
// For EAS, notify SyncManager that the password has changed
try {
new EmailServiceProxy(this, SyncManager.class)
ExchangeUtils.getExchangeEmailService(this, null)
.hostChanged(mAccount.mId);
} catch (RemoteException e) {
// Nothing to be done if this fails

View File

@ -17,6 +17,7 @@
package com.android.email.activity.setup;
import com.android.email.Email;
import com.android.email.ExchangeUtils;
import com.android.email.R;
import com.android.email.mail.Store;
import com.android.email.mail.store.ExchangeStore;
@ -186,7 +187,7 @@ public class AccountSetupOptions extends Activity implements OnClickListener {
Email.setServicesEnabled(this);
AccountSetupNames.actionSetNames(this, mAccount.mId, mEasFlowMode);
// Start up SyncManager (if it isn't already running)
startService(new Intent(getApplicationContext(), com.android.exchange.SyncManager.class));
ExchangeUtils.startExchangeService(this);
finish();
}

View File

@ -17,6 +17,7 @@
package com.android.email.mail.store;
import com.android.email.Email;
import com.android.email.ExchangeUtils;
import com.android.email.mail.AuthenticationFailedException;
import com.android.email.mail.Folder;
import com.android.email.mail.MessagingException;
@ -24,9 +25,7 @@ import com.android.email.mail.Store;
import com.android.email.mail.StoreSynchronizer;
import com.android.email.provider.EmailContent.Account;
import com.android.email.service.EasAuthenticatorService;
import com.android.email.service.EmailServiceProxy;
import com.android.exchange.Eas;
import com.android.exchange.SyncManager;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
@ -240,7 +239,7 @@ public class ExchangeStore extends Store {
boolean tssl = uri.getScheme().contains("+trustallcerts");
try {
int port = ssl ? 443 : 80;
int result = new EmailServiceProxy(mContext, SyncManager.class)
int result = ExchangeUtils.getExchangeEmailService(mContext, null)
.validate("eas", mHost, mUsername, mPassword, port, ssl, tssl);
if (result != MessagingException.NO_ERROR) {
if (result == MessagingException.AUTHENTICATION_FAILED) {
@ -263,11 +262,10 @@ public class ExchangeStore extends Store {
public Bundle autoDiscover(Context context, String username, String password)
throws MessagingException {
try {
return new EmailServiceProxy(context, SyncManager.class)
return ExchangeUtils.getExchangeEmailService(context, null)
.autoDiscover(username, password);
} catch (RemoteException e) {
return null;
}
}
}

View File

@ -50,9 +50,9 @@ public class EmailServiceProxy implements IEmailService {
public static final String AUTO_DISCOVER_BUNDLE_ERROR_CODE = "autodiscover_error_code";
public static final String AUTO_DISCOVER_BUNDLE_HOST_AUTH = "autodiscover_host_auth";
private Context mContext;
private Class<?> mClass;
private IEmailServiceCallback mCallback;
private final Context mContext;
private final Class<?> mClass;
private final IEmailServiceCallback mCallback;
private Runnable mRunnable;
private ServiceConnection mSyncManagerConnection = new EmailServiceConnection ();
private IEmailService mService = null;
@ -61,21 +61,16 @@ public class EmailServiceProxy implements IEmailService {
private boolean mDead = false;
public EmailServiceProxy(Context _context, Class<?> _class) {
mContext = _context;
mClass = _class;
// Proxy calls have a timeout, and this can cause failures while debugging due to the
// far slower execution speed. In particular, validate calls fail regularly with ssl
// connections at the default timeout (30 seconds)
if (Debug.isDebuggerConnected()) {
mTimeout <<= 2;
}
this(_context, _class, null);
}
public EmailServiceProxy(Context _context, Class<?> _class, IEmailServiceCallback _callback) {
mContext = _context;
mClass = _class;
mCallback = _callback;
// See comment above
// Proxy calls have a timeout, and this can cause failures while debugging due to the
// far slower execution speed. In particular, validate calls fail regularly with ssl
// connections at the default timeout (30 seconds)
if (Debug.isDebuggerConnected()) {
mTimeout <<= 2;
}

View File

@ -16,6 +16,8 @@
package com.android.exchange;
import com.android.email.ExchangeUtils;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -25,6 +27,6 @@ public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("Exchange", "BootReceiver onReceive");
context.startService(new Intent(context, SyncManager.class));
ExchangeUtils.startExchangeService(context);
}
}