1328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu/* 2328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * Copyright (C) 2013 The Android Open Source Project 3328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * 4328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * Licensed under the Apache License, Version 2.0 (the "License"); 5328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * you may not use this file except in compliance with the License. 6328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * You may obtain a copy of the License at 7328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * 8328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * http://www.apache.org/licenses/LICENSE-2.0 9328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * 10328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * Unless required by applicable law or agreed to in writing, software 11328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * distributed under the License is distributed on an "AS IS" BASIS, 12328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * See the License for the specific language governing permissions and 14328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * limitations under the License. 15328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu */ 16328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 17328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hupackage com.android.exchange.eas; 18328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 19328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport android.content.Context; 20328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport android.os.Bundle; 21328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 22b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Huimport com.android.emailcommon.mail.MessagingException; 23328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport com.android.emailcommon.provider.Account; 24328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport com.android.emailcommon.provider.HostAuth; 25b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Huimport com.android.emailcommon.provider.Policy; 26b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Huimport com.android.emailcommon.service.EmailServiceProxy; 27328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport com.android.exchange.CommandStatusException; 28328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport com.android.exchange.EasResponse; 29328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport com.android.exchange.adapter.FolderSyncParser; 30328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport com.android.exchange.adapter.Serializer; 31328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport com.android.exchange.adapter.Tags; 326c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Huimport com.android.exchange.service.EasService; 33328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport com.android.mail.utils.LogUtils; 34328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 35328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport org.apache.http.HttpEntity; 36328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 37328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Huimport java.io.IOException; 38328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 39328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu/** 40328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * Implements the EAS FolderSync command. We use this both to actually do a folder sync, and also 41328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * during account adding flow as a convenient command to validate the account settings (e.g. since 42328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * it needs to login and will tell us about provisioning requirements). 43328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * TODO: Doing validation here is kind of wonky. There must be a better way. 44b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu * TODO: Add the use of the Settings command during validation. 45328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * 46328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * See http://msdn.microsoft.com/en-us/library/ee237648(v=exchg.80).aspx for more details. 47328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu */ 48328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hupublic class EasFolderSync extends EasOperation { 49328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 50328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu /** Result code indicating the sync completed correctly. */ 51328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu public static final int RESULT_OK = 1; 52328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu /** 53328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * Result code indicating that this object was constructed for sync and was asked to validate, 54328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * or vice versa. 55328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu */ 56328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu public static final int RESULT_WRONG_OPERATION = 2; 57328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 58328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu /** Indicates whether this object is for validation rather than sync. */ 59328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu private final boolean mStatusOnly; 60328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 61b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu /** During validation, this holds the policy we must enforce. */ 62b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu private Policy mPolicy; 63b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu 646c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu /** During validation, this holds the result. */ 656c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu private Bundle mValidationResult; 666c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu 676c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu /** 686c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu * Constructor for use with {@link EasService} when performing an actual sync. 696c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu * @param context 706c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu * @param accountId 716c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu */ 726c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu public EasFolderSync(final Context context, final long accountId) { 736c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu super(context, accountId); 746c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu mStatusOnly = false; 756c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu mPolicy = null; 766c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu } 776c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu 78328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu /** 79328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * Constructor for actually doing folder sync. 80328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * @param context 81328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * @param account 82328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu */ 83328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu public EasFolderSync(final Context context, final Account account) { 84328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu super(context, account); 85328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu mStatusOnly = false; 86b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu mPolicy = null; 87328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu } 88328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 89328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu /** 90328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * Constructor for account validation. 91328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * @param context 92328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu * @param hostAuth 93328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu */ 94328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu public EasFolderSync(final Context context, final HostAuth hostAuth) { 956c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu super(context, -1); 966c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu setDummyAccount(hostAuth); 976c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu mStatusOnly = true; 98328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu } 99328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 1006c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu @Override 1018c95506ad96f5990d5e4d4ca86b05ec95dd4b1d6Yu Ping Hu public int performOperation() { 1026c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu if (mStatusOnly) { 1036c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu return validate(); 1046c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu } else { 1056c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu LogUtils.d(LOG_TAG, "Performing FolderSync for account %d", getAccountId()); 1068c95506ad96f5990d5e4d4ca86b05ec95dd4b1d6Yu Ping Hu return super.performOperation(); 1076c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu } 1086c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu } 1096c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu 1106c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu /** 1116c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu * Returns the validation results after this operation has been performed. 1126c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu * @return The validation results. 1136c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu */ 1146c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu public Bundle getValidationResult() { 1156c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu return mValidationResult; 116328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu } 117328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 118328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu /** 1196c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu * Helper function for {@link #performOperation} -- do some initial checks and, if they pass, 1206c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu * perform a folder sync to verify that we can. This sets {@link #mValidationResult} as a side 1216c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu * effect which holds the result details needed by the UI. 1226c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu * @return A result code, either from above or from the base class. 123328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu */ 1246c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu private int validate() { 1256c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu mValidationResult = new Bundle(3); 126b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu if (!mStatusOnly) { 1276c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu writeResultCode(mValidationResult, RESULT_OTHER_FAILURE); 1286c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu return RESULT_OTHER_FAILURE; 129328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu } 1303eef378426c7c88608f53f5a268baed40259ccf6Alon Albert LogUtils.d(LOG_TAG, "Performing validation"); 131b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu 132b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu if (!registerClientCert()) { 1336c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu mValidationResult.putInt(EmailServiceProxy.VALIDATE_BUNDLE_RESULT_CODE, 134b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu MessagingException.CLIENT_CERTIFICATE_ERROR); 1356c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu return RESULT_CLIENT_CERTIFICATE_REQUIRED; 136b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu } 137b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu 138b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu if (shouldGetProtocolVersion()) { 139b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu final EasOptions options = new EasOptions(this); 1408c95506ad96f5990d5e4d4ca86b05ec95dd4b1d6Yu Ping Hu final int result = options.getProtocolVersionFromServer(); 141b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu if (result != EasOptions.RESULT_OK) { 1426c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu writeResultCode(mValidationResult, result); 1436c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu return result; 144b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu } 145b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu final String protocolVersion = options.getProtocolVersionString(); 146b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu setProtocolVersion(protocolVersion); 1476c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu mValidationResult.putString(EmailServiceProxy.VALIDATE_BUNDLE_PROTOCOL_VERSION, 1486c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu protocolVersion); 149b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu } 150b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu 1516c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu // This is intentionally a call to super.performOperation. This is a helper function for 1526c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu // our version of perfomOperation so calling that function would infinite loop. 1538c95506ad96f5990d5e4d4ca86b05ec95dd4b1d6Yu Ping Hu final int result = super.performOperation(); 1546c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu writeResultCode(mValidationResult, result); 1556c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu return result; 1566c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu } 1576c4254903d2f42836c5b74a934e54441ccee6dbeYu Ping Hu 158328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu @Override 159328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu protected String getCommand() { 160328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu return "FolderSync"; 161328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu } 162328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 163328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu @Override 164328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu protected HttpEntity getRequestEntity() throws IOException { 165328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu final String syncKey = mAccount.mSyncKey != null ? mAccount.mSyncKey : "0"; 166328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu final Serializer s = new Serializer(); 167328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu s.start(Tags.FOLDER_FOLDER_SYNC).start(Tags.FOLDER_SYNC_KEY).text(syncKey) 168328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu .end().end().done(); 169328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu return makeEntity(s); 170328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu } 171328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 172328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu @Override 1738c95506ad96f5990d5e4d4ca86b05ec95dd4b1d6Yu Ping Hu protected int handleResponse(final EasResponse response) 1747f0b7b0d66b40ec3004fbc329dbd34a801608b92Yu Ping Hu throws IOException, CommandStatusException { 175328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu if (!response.isEmpty()) { 1767f0b7b0d66b40ec3004fbc329dbd34a801608b92Yu Ping Hu new FolderSyncParser(mContext, mContext.getContentResolver(), 1777f0b7b0d66b40ec3004fbc329dbd34a801608b92Yu Ping Hu response.getInputStream(), mAccount, mStatusOnly).parse(); 178328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu } 179328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu return RESULT_OK; 180328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu } 181328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu 182328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu @Override 183328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu protected boolean handleForbidden() { 184328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu return mStatusOnly; 185328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu } 186b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu 187b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu @Override 1888c95506ad96f5990d5e4d4ca86b05ec95dd4b1d6Yu Ping Hu protected boolean handleProvisionError() { 189b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu if (mStatusOnly) { 190b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu final EasProvision provisionOperation = new EasProvision(this); 191b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu mPolicy = provisionOperation.test(); 192b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu // Regardless of whether the policy is supported, we return false because there's 193b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu // no need to re-run the operation. 194b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu return false; 195b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu } 1968c95506ad96f5990d5e4d4ca86b05ec95dd4b1d6Yu Ping Hu return super.handleProvisionError(); 197b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu } 198b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu 199b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu /** 200b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu * Translate {@link EasOperation} result codes to the values needed by the RPC, and write 201b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu * them to the {@link Bundle}. 202b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu * @param bundle The {@link Bundle} to return to the RPC. 203b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu * @param resultCode The result code for this operation. 204b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu */ 205b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu private void writeResultCode(final Bundle bundle, final int resultCode) { 206b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu final int messagingExceptionCode; 207b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu switch (resultCode) { 208b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_ABORT: 209b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.IOERROR; 210b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 211b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_RESTART: 212b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.IOERROR; 213b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 214b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_TOO_MANY_REDIRECTS: 215b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.UNSPECIFIED_EXCEPTION; 216b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 21761ebb38e67421fd122c81f046bf11778b61a2113Martin Hibdon case RESULT_NETWORK_PROBLEM: 218b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.IOERROR; 219b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 220b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_FORBIDDEN: 221b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.ACCESS_DENIED; 222b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 223b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_PROVISIONING_ERROR: 224b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu if (mPolicy == null) { 225be22ff8b8b3aa6057de165b76da433cabad4dcfdYu Ping Hu messagingExceptionCode = MessagingException.UNSPECIFIED_EXCEPTION; 226b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu } else { 227be22ff8b8b3aa6057de165b76da433cabad4dcfdYu Ping Hu bundle.putParcelable(EmailServiceProxy.VALIDATE_BUNDLE_POLICY_SET, mPolicy); 228be22ff8b8b3aa6057de165b76da433cabad4dcfdYu Ping Hu messagingExceptionCode = mPolicy.mProtocolPoliciesUnsupported == null ? 229be22ff8b8b3aa6057de165b76da433cabad4dcfdYu Ping Hu MessagingException.SECURITY_POLICIES_REQUIRED : 230be22ff8b8b3aa6057de165b76da433cabad4dcfdYu Ping Hu MessagingException.SECURITY_POLICIES_UNSUPPORTED; 231b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu } 232b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 233b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_AUTHENTICATION_ERROR: 234b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.AUTHENTICATION_FAILED; 235b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 236b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_CLIENT_CERTIFICATE_REQUIRED: 237b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.CLIENT_CERTIFICATE_REQUIRED; 238b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 239b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_PROTOCOL_VERSION_UNSUPPORTED: 240b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.PROTOCOL_VERSION_UNSUPPORTED; 241b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 242b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_OTHER_FAILURE: 243b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.UNSPECIFIED_EXCEPTION; 244b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 245b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu case RESULT_OK: 246b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.NO_ERROR; 247b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 248b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu default: 249b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu messagingExceptionCode = MessagingException.UNSPECIFIED_EXCEPTION; 250b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu break; 251b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu } 252b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu bundle.putInt(EmailServiceProxy.VALIDATE_BUNDLE_RESULT_CODE, messagingExceptionCode); 253b6ef78e8c4112d47d965b5b274d52fe8885f58faYu Ping Hu } 254328ca0d959f7e729e96f19538c8f3af8fe782a09Yu Ping Hu} 255