1 /* 2 * Copyright (C) 2010 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.ddmlib; 18 19 import java.io.IOException; 20 21 /** 22 * Exception thrown when a transfer using {@link SyncService} doesn't complete. 23 * <p/>This is different from an {@link IOException} because it's not the underlying connection 24 * that triggered the error, but the adb transfer protocol that didn't work somehow, or that the 25 * targets (local and/or remote) were wrong. 26 */ 27 public class SyncException extends CanceledException { 28 private static final long serialVersionUID = 1L; 29 30 public enum SyncError { 31 /** canceled transfer */ 32 CANCELED("Operation was canceled by the user."), 33 /** Transfer error */ 34 TRANSFER_PROTOCOL_ERROR("Adb Transfer Protocol Error."), 35 /** unknown remote object during a pull */ 36 NO_REMOTE_OBJECT("Remote object doesn't exist!"), 37 /** Result code when attempting to pull multiple files into a file */ 38 TARGET_IS_FILE("Target object is a file."), 39 /** Result code when attempting to pull multiple into a directory that does not exist. */ 40 NO_DIR_TARGET("Target directory doesn't exist."), 41 /** wrong encoding on the remote path. */ 42 REMOTE_PATH_ENCODING("Remote Path encoding is not supported."), 43 /** remote path that is too long. */ 44 REMOTE_PATH_LENGTH("Remote path is too long."), 45 /** error while reading local file. */ 46 FILE_READ_ERROR("Reading local file failed!"), 47 /** error while writing local file. */ 48 FILE_WRITE_ERROR("Writing local file failed!"), 49 /** attempting to push a directory. */ 50 LOCAL_IS_DIRECTORY("Local path is a directory."), 51 /** attempting to push a non-existent file. */ 52 NO_LOCAL_FILE("Local path doesn't exist."), 53 /** when the target path of a multi file push is a file. */ 54 REMOTE_IS_FILE("Remote path is a file."), 55 /** receiving too much data from the remove device at once */ 56 BUFFER_OVERRUN("Receiving too much data."); 57 58 private final String mMessage; 59 SyncError(String message)60 private SyncError(String message) { 61 mMessage = message; 62 } 63 getMessage()64 public String getMessage() { 65 return mMessage; 66 } 67 } 68 69 private final SyncError mError; 70 SyncException(SyncError error)71 public SyncException(SyncError error) { 72 super(error.getMessage()); 73 mError = error; 74 } 75 SyncException(SyncError error, String message)76 public SyncException(SyncError error, String message) { 77 super(message); 78 mError = error; 79 } 80 SyncException(SyncError error, Throwable cause)81 public SyncException(SyncError error, Throwable cause) { 82 super(error.getMessage(), cause); 83 mError = error; 84 } 85 getErrorCode()86 public SyncError getErrorCode() { 87 return mError; 88 } 89 90 /** 91 * Returns true if the sync was canceled by user input. 92 */ 93 @Override wasCanceled()94 public boolean wasCanceled() { 95 return mError == SyncError.CANCELED; 96 } 97 } 98