Expose unsupported policies in the UI (account setup)

Change-Id: I75b650af92c87bd990009e54072ac4b58ed0895b
This commit is contained in:
Marc Blank 2011-04-26 12:54:33 -07:00
parent 27cf8b5ffe
commit 265530723b
4 changed files with 61 additions and 16 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -795,7 +795,8 @@ save attachment.</string>
<!-- Additional diagnostic text when validation failed due to required provisioning not
being supported [CHAR LIMIT=none] -->
<string name="account_setup_failed_security_policies_unsupported">
This server requires security features that your Android device does not support.</string>
This server requires security features that your Android device does not support,
including: <xliff:g id="error">%s</xliff:g></string>
<!-- The user name can only be changed during initial account setup. [CHAR LIMIT=none] -->
<string name="account_setup_username_uneditable_error">You can\'t change an account\'s username.
To add an account with a different username, touch Add account.</string>

View File

@ -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;