Pass HostAuth when validating an account.
Since HostAuth is fully Parcelable, no sense passing the individual fields. Change-Id: I4d8fd2bbe7b47e8f1e2ff00c8c0cad8429eec159
This commit is contained in:
parent
cad633bc1d
commit
22409fcffa
|
@ -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;
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Long, ExchangeTransport> sHostAuthToInstanceMap =
|
||||
new HashMap<Long, ExchangeTransport>();
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue