summaryrefslogtreecommitdiffstats
path: root/src/com/android/phone/common/mail/MessagingException.java
blob: e4c674ada33c448386d696ac5c8e7375bf519c52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.phone.common.mail;

/**
 * This exception is used for most types of failures that occur during server interactions.
 *
 * Data passed through this exception should be considered non-localized.  Any strings should
 * either be internal-only (for debugging) or server-generated.
 *
 * TO DO: Does it make sense to further collapse AuthenticationFailedException and
 * CertificateValidationException and any others into this?
 */
public class MessagingException extends Exception {
    public static final long serialVersionUID = -1;

    public static final int NO_ERROR = -1;
    /** Any exception that does not specify a specific issue */
    public static final int UNSPECIFIED_EXCEPTION = 0;
    /** Connection or IO errors */
    public static final int IOERROR = 1;
    /** The configuration requested TLS but the server did not support it. */
    public static final int TLS_REQUIRED = 2;
    /** Authentication is required but the server did not support it. */
    public static final int AUTH_REQUIRED = 3;
    /** General security failures */
    public static final int GENERAL_SECURITY = 4;
    /** Authentication failed */
    public static final int AUTHENTICATION_FAILED = 5;
    /** Attempt to create duplicate account */
    public static final int DUPLICATE_ACCOUNT = 6;
    /** Required security policies reported - advisory only */
    public static final int SECURITY_POLICIES_REQUIRED = 7;
   /** Required security policies not supported */
    public static final int SECURITY_POLICIES_UNSUPPORTED = 8;
   /** The protocol (or protocol version) isn't supported */
    public static final int PROTOCOL_VERSION_UNSUPPORTED = 9;
    /** The server's SSL certificate couldn't be validated */
    public static final int CERTIFICATE_VALIDATION_ERROR = 10;
    /** Authentication failed during autodiscover */
    public static final int AUTODISCOVER_AUTHENTICATION_FAILED = 11;
    /** Autodiscover completed with a result (non-error) */
    public static final int AUTODISCOVER_AUTHENTICATION_RESULT = 12;
    /** Ambiguous failure; server error or bad credentials */
    public static final int AUTHENTICATION_FAILED_OR_SERVER_ERROR = 13;
    /** The server refused access */
    public static final int ACCESS_DENIED = 14;
    /** The server refused access */
    public static final int ATTACHMENT_NOT_FOUND = 15;
    /** A client SSL certificate is required for connections to the server */
    public static final int CLIENT_CERTIFICATE_REQUIRED = 16;
    /** The client SSL certificate specified is invalid */
    public static final int CLIENT_CERTIFICATE_ERROR = 17;
    /** The server indicates it does not support OAuth authentication */
    public static final int OAUTH_NOT_SUPPORTED = 18;
    /** The server indicates it experienced an internal error */
    public static final int SERVER_ERROR = 19;

    protected int mExceptionType;
    // Exception type-specific data
    protected Object mExceptionData;

    public MessagingException(String message, Throwable throwable) {
        this(UNSPECIFIED_EXCEPTION, message, throwable);
    }

    public MessagingException(int exceptionType, String message, Throwable throwable) {
        super(message, throwable);
        mExceptionType = exceptionType;
        mExceptionData = null;
    }

    /**
     * Constructs a MessagingException with an exceptionType and a null message.
     * @param exceptionType The exception type to set for this exception.
     */
    public MessagingException(int 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);
    }

    /**
     * Constructs a MessagingException with an exceptionType and a message.
     * @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;
    }

    /**
     * Return the exception type.  Will be OTHER_EXCEPTION if not explicitly set.
     *
     * @return Returns the exception type.
     */
    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;
    }
}