1 /* 2 * Copyright (C) 2007-2008 Esmertec AG. 3 * Copyright (C) 2007-2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.im.engine; 19 20 import java.io.Serializable; 21 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 /** 26 * Represents a generic error returned from the server. The IM servers can 27 * respond to an error condition with an error code and possibly a description 28 * of the problem. Different IM protocol may have different set of error codes 29 * and descriptions. 30 */ 31 public class ImErrorInfo implements Parcelable, Serializable { 32 public static final int NO_ERROR = 0; 33 34 public static final int ILLEGAL_CONTACT_LIST_MANAGER_STATE = -100; 35 public static final int CONTACT_LIST_EXISTS = -101; 36 public static final int CONTACT_LIST_NOT_FOUND = -102; 37 38 public static final int INVALID_HOST_NAME = -200; 39 public static final int UNKNOWN_SERVER = -201; 40 public static final int CANT_CONNECT_TO_SERVER = -202; 41 public static final int INVALID_USERNAME = -203; 42 public static final int INVALID_SESSION_CONTEXT = -204; 43 public static final int UNKNOWN_LOGIN_ERROR = -300; 44 public static final int NOT_LOGGED_IN = 301; 45 46 public static final int UNSUPPORTED_CIR_CHANNEL = -400; 47 48 public static final int ILLEGAL_CONTACT_ADDRESS = -500; 49 public static final int CONTACT_EXISTS_IN_LIST = -501; 50 public static final int CANT_ADD_BLOCKED_CONTACT = -600; 51 52 public static final int PARSER_ERROR = -700; 53 public static final int SERIALIZER_ERROR = -750; 54 55 public static final int NETWORK_ERROR = -800; 56 57 public static final int ILLEGAL_SERVER_RESPONSE = -900; 58 59 public static final int UNKNOWN_ERROR = -1000; 60 61 private int mCode; 62 private String mDescription; 63 64 /** 65 * Creates a new error with specified code and description. 66 * 67 * @param code the error code. 68 * @param description the description of the error. 69 */ ImErrorInfo(int code, String description)70 public ImErrorInfo(int code, String description) { 71 mCode = code; 72 mDescription = description; 73 } 74 ImErrorInfo(Parcel source)75 public ImErrorInfo(Parcel source) { 76 mCode = source.readInt(); 77 mDescription = source.readString(); 78 } 79 80 /** 81 * Gets the error code. 82 * 83 * @return the error code. 84 */ getCode()85 public int getCode() { 86 return mCode; 87 } 88 89 /** 90 * Gets the description of the error. 91 * 92 * @return the description of the error. 93 */ getDescription()94 public String getDescription() { 95 return mDescription; 96 } 97 98 @Override toString()99 public String toString() { 100 return mCode + " - " + mDescription; 101 } 102 writeToParcel(Parcel dest, int flags)103 public void writeToParcel(Parcel dest, int flags) { 104 dest.writeInt(mCode); 105 dest.writeString(mDescription); 106 } 107 describeContents()108 public int describeContents() { 109 return 0; 110 } 111 112 public static final Parcelable.Creator<ImErrorInfo> CREATOR = new Parcelable.Creator<ImErrorInfo>() { 113 public ImErrorInfo createFromParcel(Parcel source) { 114 return new ImErrorInfo(source); 115 } 116 117 public ImErrorInfo[] newArray(int size) { 118 return new ImErrorInfo[size]; 119 } 120 }; 121 122 } 123