diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2015-04-19 22:41:21 +0200 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-18 15:54:18 -0700 |
commit | f8e74526038ec8e86bb37e7f4634237760b6fb29 (patch) | |
tree | ca23d8f2327bc2cd5a2222de8e18ab3a83fe048b | |
parent | e1cc6ccc675fdd38e3e8f7695a22a2296d7b78a0 (diff) | |
download | android_packages_apps_Exchange-f8e74526038ec8e86bb37e7f4634237760b6fb29.tar.gz android_packages_apps_Exchange-f8e74526038ec8e86bb37e7f4634237760b6fb29.tar.bz2 android_packages_apps_Exchange-f8e74526038ec8e86bb37e7f4634237760b6fb29.zip |
exchange: fix eas autodiscover
Change-Id: If368396d608b0bec63bc794d70d1b4ba9b7b5d8e
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r-- | src/com/android/exchange/eas/EasAutoDiscover.java | 12 | ||||
-rw-r--r-- | src/com/android/exchange/service/EasService.java | 11 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/com/android/exchange/eas/EasAutoDiscover.java b/src/com/android/exchange/eas/EasAutoDiscover.java index 4cd963c8..ea7198cb 100644 --- a/src/com/android/exchange/eas/EasAutoDiscover.java +++ b/src/com/android/exchange/eas/EasAutoDiscover.java @@ -5,6 +5,7 @@ import android.net.Uri; import android.os.Bundle; import android.util.Xml; +import com.android.emailcommon.mail.MessagingException; import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.service.EmailServiceProxy; @@ -411,4 +412,15 @@ public class EasAutoDiscover extends EasOperation { } return null; } + + public static int translateToMessagingException(int easDiscoveryResultCode) { + switch (easDiscoveryResultCode) { + case RESULT_SC_UNAUTHORIZED: + return MessagingException.AUTODISCOVER_AUTHENTICATION_FAILED; + case RESULT_OK: + return MessagingException.AUTODISCOVER_AUTHENTICATION_RESULT; + default: + return MessagingException.UNSPECIFIED_EXCEPTION; + } + } } diff --git a/src/com/android/exchange/service/EasService.java b/src/com/android/exchange/service/EasService.java index b809632b..f9287446 100644 --- a/src/com/android/exchange/service/EasService.java +++ b/src/com/android/exchange/service/EasService.java @@ -203,6 +203,12 @@ public class EasService extends Service { Bundle result = autoDiscoverInternal(uri, attempt, username, password, true); int resultCode = result.getInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE); if (resultCode != EasAutoDiscover.RESULT_BAD_RESPONSE) { + // To fix autodiscover setup we need to fill the bundle with the appropriate + // MessagingException to code, which can be interpreted by our Email app. + // We leave untouched the original extra so it can be used by Gmail and other + // email clients. + result.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_MESSAGING_ERROR_CODE, + EasAutoDiscover.translateToMessagingException(resultCode)); return result; } else { LogUtils.d(TAG, "got BAD_RESPONSE"); @@ -221,7 +227,8 @@ public class EasService extends Service { // Try again recursively with the new uri. TODO we should limit the number of redirects. final String redirectUri = op.getRedirectUri(); return autoDiscoverInternal(redirectUri, attempt, username, password, canRetry); - } else if (result == EasAutoDiscover.RESULT_SC_UNAUTHORIZED) { + } else if (result == EasAutoDiscover.RESULT_SC_UNAUTHORIZED || + result == EasAutoDiscover.RESULT_AUTHENTICATION_ERROR) { if (canRetry && username.contains("@")) { // Try again using the bare user name final int atSignIndex = username.indexOf('@'); @@ -234,7 +241,7 @@ public class EasService extends Service { // to begin with. Either way, failure. final Bundle bundle = new Bundle(1); bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE, - EasAutoDiscover.RESULT_OTHER_FAILURE); + EasAutoDiscover.RESULT_SC_UNAUTHORIZED); return bundle; } } else if (result != EasAutoDiscover.RESULT_OK) { |