From 22409fcffae4c6e551fb3e6ead4cdc92e33fded1 Mon Sep 17 00:00:00 2001 From: Ben Komalo Date: Mon, 13 Jun 2011 18:48:05 -0700 Subject: [PATCH] Pass HostAuth when validating an account. Since HostAuth is fully Parcelable, no sense passing the individual fields. Change-Id: I4d8fd2bbe7b47e8f1e2ff00c8c0cad8429eec159 --- .../emailcommon/provider/HostAuth.aidl | 18 ++++++++++++ .../emailcommon/provider/HostAuth.java | 10 +++++++ .../service/EmailServiceProxy.java | 16 ++-------- .../emailcommon/service/IEmailService.aidl | 6 ++-- src/com/android/email/Controller.java | 3 +- src/com/android/email/ExchangeUtils.java | 4 +-- .../email/mail/store/ExchangeStore.java | 29 ++++++------------- 7 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 emailcommon/src/com/android/emailcommon/provider/HostAuth.aidl diff --git a/emailcommon/src/com/android/emailcommon/provider/HostAuth.aidl b/emailcommon/src/com/android/emailcommon/provider/HostAuth.aidl new file mode 100644 index 000000000..88eb88fe0 --- /dev/null +++ b/emailcommon/src/com/android/emailcommon/provider/HostAuth.aidl @@ -0,0 +1,18 @@ +/* Copyright (C) 2011 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.emailcommon.provider; + +parcelable HostAuth; \ No newline at end of file diff --git a/emailcommon/src/com/android/emailcommon/provider/HostAuth.java b/emailcommon/src/com/android/emailcommon/provider/HostAuth.java index 22a9bd058..6bd77a749 100644 --- a/emailcommon/src/com/android/emailcommon/provider/HostAuth.java +++ b/emailcommon/src/com/android/emailcommon/provider/HostAuth.java @@ -294,6 +294,16 @@ public final class HostAuth extends EmailContent implements HostAuthColumns, Par return SCHEME_EAS.equals(mProtocol); } + /** Convenience method to determine if SSL is used. */ + public boolean useSsl() { + return (mFlags & FLAG_SSL) != 0; + } + + /** Convenience method to determine if all server certs should be used. */ + public boolean trustAllServerCerts() { + return (mFlags & FLAG_TRUST_ALL) != 0; + } + /** * Supports Parcelable */ diff --git a/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java b/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java index 76477db1e..a44734368 100644 --- a/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java +++ b/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java @@ -186,24 +186,14 @@ public class EmailServiceProxy extends ServiceProxy implements IEmailService { * address that serves the specified protocol and credentials sufficient to be authorized * by the server to do so. * - * @param protocol the protocol used by the account (e.g. "imap", "pop3", or "eas) - * @param host the address of the host server (in the form x.y.z) - * @param userName the username credential for the account - * @param password the password credential for the account - * @param port the port used to connect to the host server - * @param ssl whether or not a secure (SSL) socket should be used for the connection - * @param trustCertificates whether or not self-signed or otherwise unverified server - * certificates should be allowed when connecting to the host + * @param hostAuth the hostauth object to validate * @return a Bundle as described above */ - public Bundle validate(final String protocol, final String host, final String userName, - final String password, final int port, final boolean ssl, - final boolean trustCertificates) throws RemoteException { + public Bundle validate(final HostAuth hostAuth) throws RemoteException { setTask(new ProxyTask() { public void run() throws RemoteException{ if (mCallback != null) mService.setCallback(mCallback); - mReturn = mService.validate(protocol, host, userName, password, port, ssl, - trustCertificates); + mReturn = mService.validate(hostAuth); } }, "validate"); waitForCompletion(); diff --git a/emailcommon/src/com/android/emailcommon/service/IEmailService.aidl b/emailcommon/src/com/android/emailcommon/service/IEmailService.aidl index dc5fbf62a..1c3d85946 100644 --- a/emailcommon/src/com/android/emailcommon/service/IEmailService.aidl +++ b/emailcommon/src/com/android/emailcommon/service/IEmailService.aidl @@ -17,13 +17,13 @@ package com.android.emailcommon.service; +import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.service.IEmailServiceCallback; import com.android.emailcommon.service.SearchParams; import android.os.Bundle; interface IEmailService { - Bundle validate(in String protocol, in String host, in String userName, in String password, - int port, boolean ssl, boolean trustCertificates) ; + Bundle validate(in HostAuth hostauth); oneway void startSync(long mailboxId, boolean userRequest); oneway void stopSync(long mailboxId); @@ -57,4 +57,4 @@ interface IEmailService { // API level 2 int searchMessages(long accountId, in SearchParams params, long destMailboxId); -} \ No newline at end of file +} diff --git a/src/com/android/email/Controller.java b/src/com/android/email/Controller.java index 98b6f33c9..2d5fa331a 100644 --- a/src/com/android/email/Controller.java +++ b/src/com/android/email/Controller.java @@ -1682,8 +1682,7 @@ public class Controller { */ private final IEmailService.Stub mBinder = new IEmailService.Stub() { - public Bundle validate(String protocol, String host, String userName, String password, - int port, boolean ssl, boolean trustCertificates) { + public Bundle validate(HostAuth hostAuth) { return null; } diff --git a/src/com/android/email/ExchangeUtils.java b/src/com/android/email/ExchangeUtils.java index 57180e8d1..e5494d888 100644 --- a/src/com/android/email/ExchangeUtils.java +++ b/src/com/android/email/ExchangeUtils.java @@ -17,6 +17,7 @@ package com.android.email; import com.android.emailcommon.Api; +import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.service.EmailServiceProxy; import com.android.emailcommon.service.IEmailService; import com.android.emailcommon.service.IEmailServiceCallback; @@ -130,8 +131,7 @@ public class ExchangeUtils { public void updateFolderList(long accountId) throws RemoteException { } - public Bundle validate(String protocol, String host, String userName, String password, - int port, boolean ssl, boolean trustCertificates) throws RemoteException { + public Bundle validate(HostAuth hostAuth) throws RemoteException { return null; } diff --git a/src/com/android/email/mail/store/ExchangeStore.java b/src/com/android/email/mail/store/ExchangeStore.java index d34c7d746..6f0c3a835 100644 --- a/src/com/android/email/mail/store/ExchangeStore.java +++ b/src/com/android/email/mail/store/ExchangeStore.java @@ -95,13 +95,7 @@ public class ExchangeStore extends Store { public static class ExchangeTransport { private final Context mContext; - private String mHost; - private String mDomain; - private int mPort; - private boolean mSsl; - private boolean mTSsl; - private String mUsername; - private String mPassword; + private HostAuth mHostAuth; private static final HashMap sHostAuthToInstanceMap = new HashMap(); @@ -140,31 +134,26 @@ public class ExchangeStore extends Store { if (recvAuth == null || !STORE_SCHEME_EAS.equalsIgnoreCase(recvAuth.mProtocol)) { throw new MessagingException("Unsupported protocol"); } - mHost = recvAuth.mAddress; - if (mHost == null) { + if (recvAuth.mAddress == null) { throw new MessagingException("host not specified"); } - mDomain = recvAuth.mDomain; - if (!TextUtils.isEmpty(mDomain)) { - mDomain = mDomain.substring(1); + if (!TextUtils.isEmpty(recvAuth.mDomain)) { + recvAuth.mDomain = recvAuth.mDomain.substring(1); } - mPort = 80; + recvAuth.mPort = 80; if ((recvAuth.mFlags & HostAuth.FLAG_SSL) != 0) { - mPort = 443; - mSsl = true; + recvAuth.mPort = 443; } - mTSsl = ((recvAuth.mFlags & HostAuth.FLAG_TRUST_ALL) != 0); String[] userInfoParts = recvAuth.getLogin(); if (userInfoParts != null) { - mUsername = userInfoParts[0]; - mPassword = userInfoParts[1]; - if (TextUtils.isEmpty(mPassword)) { + if (TextUtils.isEmpty(userInfoParts[0]) || TextUtils.isEmpty(userInfoParts[1])) { throw new MessagingException("user name and password not specified"); } } else { throw new MessagingException("user information not specifed"); } + mHostAuth = recvAuth; } /** @@ -179,7 +168,7 @@ public class ExchangeStore extends Store { if (svc instanceof EmailServiceProxy) { ((EmailServiceProxy)svc).setTimeout(90); } - return svc.validate("eas", mHost, mUsername, mPassword, mPort, mSsl, mTSsl); + return svc.validate(mHostAuth); } catch (RemoteException e) { throw new MessagingException("Call to validate generated an exception", e); }