1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.exchange; 18 19 /** 20 * ActiveSync command error status definitions (EAS 14.0 and later); these are in addition to the 21 * command-specific errors defined for earlier protocol versions 22 */ 23 public class CommandStatusException extends EasException { 24 private static final long serialVersionUID = 1L; 25 26 // A status response to an EAS account. Responses < 16 correspond to command-specific errors as 27 // reported by EAS versions < 14.0; responses > 100 correspond to generic errors as reported 28 // by EAS versions 14.0 and greater 29 public final int mStatus; 30 // If the error refers to a specific data item, that item's id (as provided by the server) is 31 // stored here 32 public final String mItemId; 33 34 public static class CommandStatus { 35 36 public static final int STATUS_MAX = 177; 37 38 // Fatal user/provisioning issues (put on security hold) 39 public static final int USER_DISABLED_FOR_SYNC = 126; 40 public static final int USERS_DISABLED_FOR_SYNC = 127; 41 public static final int USER_ON_LEGACY_SERVER_CANT_SYNC = 128; 42 public static final int DEVICE_QUARANTINED = 129; 43 public static final int ACCESS_DENIED = 130; 44 public static final int USER_ACCOUNT_DISABLED = 131; 45 public static final int NOT_PROVISIONABLE_PARTIAL = 139; 46 public static final int NOT_PROVISIONABLE_LEGACY_DEVICE = 141; 47 public static final int TOO_MANY_PARTNERSHIPS = 177; 48 49 // Sync state problems (bad key, multiple client conflict, etc.) 50 public static final int SYNC_STATE_LOCKED = 133; 51 public static final int SYNC_STATE_CORRUPT = 134; 52 public static final int SYNC_STATE_EXISTS = 135; 53 public static final int SYNC_STATE_INVALID = 136; 54 55 // Soft provisioning errors, we need to send Provision command 56 public static final int NEEDS_PROVISIONING_WIPE = 140; 57 public static final int NEEDS_PROVISIONING = 142; 58 public static final int NEEDS_PROVISIONING_REFRESH = 143; 59 public static final int NEEDS_PROVISIONING_INVALID = 144; 60 61 // WTF issues (really shouldn't happen in our implementation) 62 public static final int WTF_INVALID_COMMAND = 137; 63 public static final int WTF_INVALID_PROTOCOL = 138; 64 public static final int WTF_DEVICE_CLAIMS_EXTERNAL_MANAGEMENT = 145; 65 public static final int WTF_UNKNOWN_ITEM_TYPE = 147; 66 public static final int WTF_REQUIRES_PROXY_WITHOUT_SSL = 148; 67 68 // For SmartReply/SmartForward 69 public static final int ITEM_NOT_FOUND = 150; 70 71 // Transient or possibly transient errors 72 public static final int SERVER_ERROR_RETRY = 111; 73 public static final int SYNC_STATE_NOT_FOUND = 132; 74 75 // String version of error status codes (for logging only) 76 private static final int STATUS_TEXT_START = 101; 77 private static final int STATUS_TEXT_END = 150; 78 private static final String[] STATUS_TEXT = { 79 "InvalidContent", "InvalidWBXML", "InvalidXML", "InvalidDateTime", "InvalidIDCombo", 80 "InvalidIDs", "InvalidMIME", "DeviceIdError", "DeviceTypeError", "ServerError", 81 "ServerErrorRetry", "ADAccessDenied", "Quota", "ServerOffline", "SendQuota", 82 "RecipientUnresolved", "ReplyNotAllowed", "SentPreviously", "NoRecipient", "SendFailed", 83 "ReplyFailed", "AttsTooLarge", "NoMailbox", "CantBeAnonymous", "UserNotFound", 84 "UserDisabled", "NewMailbox", "LegacyMailbox", "DeviceBlocked", "AccessDenied", 85 "AcctDisabled", "SyncStateNF", "SyncStateLocked", "SyncStateCorrupt", "SyncStateExists", 86 "SyncStateInvalid", "BadCommand", "BadVersion", "NotFullyProvisionable", "RemoteWipe", 87 "LegacyDevice", "NotProvisioned", "PolicyRefresh", "BadPolicyKey", "ExternallyManaged", 88 "NoRecurrence", "UnexpectedClass", "RemoteHasNoSSL", "InvalidRequest", "ItemNotFound" 89 }; 90 91 public static boolean isNeedsProvisioning(int status) { 92 return (status == CommandStatus.NEEDS_PROVISIONING || 93 status == CommandStatus.NEEDS_PROVISIONING_REFRESH || 94 status == CommandStatus.NEEDS_PROVISIONING_INVALID || 95 status == CommandStatus.NEEDS_PROVISIONING_WIPE); 96 } 97 98 public static boolean isBadSyncKey(int status) { 99 return (status == CommandStatus.SYNC_STATE_CORRUPT || 100 status == CommandStatus.SYNC_STATE_INVALID); 101 } 102 103 public static boolean isDeniedAccess(int status) { 104 return (status == CommandStatus.USER_DISABLED_FOR_SYNC || 105 status == CommandStatus.USERS_DISABLED_FOR_SYNC || 106 status == CommandStatus.USER_ON_LEGACY_SERVER_CANT_SYNC || 107 status == CommandStatus.DEVICE_QUARANTINED || 108 status == CommandStatus.ACCESS_DENIED || 109 status == CommandStatus.USER_ACCOUNT_DISABLED || 110 status == CommandStatus.NOT_PROVISIONABLE_LEGACY_DEVICE || 111 status == CommandStatus.NOT_PROVISIONABLE_PARTIAL || 112 status == CommandStatus.TOO_MANY_PARTNERSHIPS); 113 } 114 115 public static boolean isTransientError(int status) { 116 return status == CommandStatus.SYNC_STATE_NOT_FOUND || 117 status == CommandStatus.SERVER_ERROR_RETRY; 118 } 119 120 public static String toString(int status) { 121 StringBuilder sb = new StringBuilder(); 122 sb.append(status); 123 sb.append(" ("); 124 if (status < STATUS_TEXT_START || status > STATUS_TEXT_END) { 125 sb.append("unknown"); 126 } else { 127 int offset = status - STATUS_TEXT_START; 128 if (offset <= STATUS_TEXT.length) { 129 sb.append(STATUS_TEXT[offset]); 130 } 131 } 132 sb.append(")"); 133 return sb.toString(); 134 } 135 } 136 137 public CommandStatusException(int status) { 138 mStatus = status; 139 mItemId = null; 140 } 141 142 public CommandStatusException(int status, String itemId) { 143 mStatus = status; 144 mItemId = itemId; 145 } 146 } 147