From 265530723b8c008f6bc23b1723f4de706a3e9556 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Tue, 26 Apr 2011 12:54:33 -0700 Subject: [PATCH] Expose unsupported policies in the UI (account setup) Change-Id: I75b650af92c87bd990009e54072ac4b58ed0895b --- .../emailcommon/mail/MessagingException.java | 41 +++++++++++++++---- .../service/EmailServiceProxy.java | 2 + res/values/strings.xml | 3 +- .../setup/AccountCheckSettingsFragment.java | 31 +++++++++++--- 4 files changed, 61 insertions(+), 16 deletions(-) diff --git a/emailcommon/src/com/android/emailcommon/mail/MessagingException.java b/emailcommon/src/com/android/emailcommon/mail/MessagingException.java index 4a0530372..ce27e75ec 100644 --- a/emailcommon/src/com/android/emailcommon/mail/MessagingException.java +++ b/emailcommon/src/com/android/emailcommon/mail/MessagingException.java @@ -62,20 +62,17 @@ public class MessagingException extends Exception { public static final int ACCESS_DENIED = 14; protected int mExceptionType; - - public MessagingException(String message) { - super(message); - mExceptionType = UNSPECIFIED_EXCEPTION; - } + // Exception type-specific data + protected Object mExceptionData; public MessagingException(String message, Throwable throwable) { - super(message, throwable); - mExceptionType = UNSPECIFIED_EXCEPTION; + this(UNSPECIFIED_EXCEPTION, message, throwable); } public MessagingException(int exceptionType, String message, Throwable throwable) { super(message, throwable); mExceptionType = exceptionType; + mExceptionData = null; } /** @@ -83,8 +80,15 @@ public class MessagingException extends Exception { * @param exceptionType The exception type to set for this exception. */ public MessagingException(int exceptionType) { - super(); - mExceptionType = exceptionType; + this(exceptionType, null, null); + } + + /** + * Constructs a MessagingException with a message. + * @param message the message for this exception + */ + public MessagingException(String message) { + this(UNSPECIFIED_EXCEPTION, message, null); } /** @@ -92,8 +96,19 @@ public class MessagingException extends Exception { * @param exceptionType The exception type to set for this exception. */ public MessagingException(int exceptionType, String message) { + this(exceptionType, message, null); + } + + /** + * Constructs a MessagingException with an exceptionType, a message, and data + * @param exceptionType The exception type to set for this exception. + * @param message the message for the exception (or null) + * @param data exception-type specific data for the exception (or null) + */ + public MessagingException(int exceptionType, String message, Object data) { super(message); mExceptionType = exceptionType; + mExceptionData = data; } /** @@ -104,4 +119,12 @@ public class MessagingException extends Exception { public int getExceptionType() { return mExceptionType; } + /** + * Return the exception data. Will be null if not explicitly set. + * + * @return Returns the exception data. + */ + public Object getExceptionData() { + return mExceptionData; + } } \ No newline at end of file diff --git a/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java b/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java index aa26656d1..d04ad8917 100644 --- a/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java +++ b/emailcommon/src/com/android/emailcommon/service/EmailServiceProxy.java @@ -57,6 +57,8 @@ public class EmailServiceProxy extends ServiceProxy implements IEmailService { public static final String VALIDATE_BUNDLE_RESULT_CODE = "validate_result_code"; public static final String VALIDATE_BUNDLE_POLICY_SET = "validate_policy_set"; public static final String VALIDATE_BUNDLE_ERROR_MESSAGE = "validate_error_message"; + public static final String VALIDATE_BUNDLE_UNSUPPORTED_POLICIES = + "validate_unsupported_policies"; private final IEmailServiceCallback mCallback; private Object mReturn = null; diff --git a/res/values/strings.xml b/res/values/strings.xml index b2cdd878a..57fbff327 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -795,7 +795,8 @@ save attachment. - This server requires security features that your Android device does not support. + This server requires security features that your Android device does not support, + including: %s You can\'t change an account\'s username. To add an account with a different username, touch Add account. diff --git a/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java b/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java index f2f53d7d0..6de156211 100644 --- a/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java @@ -458,10 +458,12 @@ public class AccountCheckSettingsFragment extends Fragment { if (resultCode == MessagingException.SECURITY_POLICIES_REQUIRED) { SetupData.setPolicySet((PolicySet)bundle.getParcelable( EmailServiceProxy.VALIDATE_BUNDLE_POLICY_SET)); - return new MessagingException( - MessagingException.SECURITY_POLICIES_REQUIRED, mStoreHost); - } - if (resultCode != MessagingException.NO_ERROR) { + return new MessagingException(resultCode, mStoreHost); + } else if (resultCode == MessagingException.SECURITY_POLICIES_UNSUPPORTED) { + String[] data = bundle.getStringArray( + EmailServiceProxy.VALIDATE_BUNDLE_UNSUPPORTED_POLICIES); + return new MessagingException(resultCode, mStoreHost, data); + } else if (resultCode != MessagingException.NO_ERROR) { String errorMessage = bundle.getString(EmailServiceProxy.VALIDATE_BUNDLE_ERROR_MESSAGE); return new MessagingException(resultCode, errorMessage); @@ -519,8 +521,7 @@ public class AccountCheckSettingsFragment extends Fragment { if (DEBUG_FAKE_CHECK_ERR) { return new MessagingException(MessagingException.IOERROR); } else if (DEBUG_FORCE_SECURITY_REQUIRED) { - return new MessagingException( - MessagingException.SECURITY_POLICIES_REQUIRED); + return new MessagingException(MessagingException.SECURITY_POLICIES_REQUIRED); } } if (isCancelled()) return null; @@ -616,6 +617,24 @@ public class AccountCheckSettingsFragment extends Fragment { break; case MessagingException.SECURITY_POLICIES_UNSUPPORTED: id = R.string.account_setup_failed_security_policies_unsupported; + // Belt and suspenders here; there should always be a non-empty array here + String[] unsupportedPolicies = (String[])result.getExceptionData(); + if (unsupportedPolicies == null) { + Log.w(TAG, "No data for unsupported policies?"); + break; + } + // Build a string, concatenating policies we don't support + StringBuilder sb = new StringBuilder(); + boolean first = true; + for (String policyName: unsupportedPolicies) { + if (first) { + first = false; + } else { + sb.append(", "); + } + sb.append(policyName); + } + message = sb.toString(); break; case MessagingException.ACCESS_DENIED: id = R.string.account_setup_failed_access_denied;