Home | History | Annotate | Download | only in mail
      1 /*
      2  * Copyright (C) 2015 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.phone.common.mail;
     18 
     19 /**
     20  * This exception is used for most types of failures that occur during server interactions.
     21  *
     22  * Data passed through this exception should be considered non-localized.  Any strings should
     23  * either be internal-only (for debugging) or server-generated.
     24  *
     25  * TO DO: Does it make sense to further collapse AuthenticationFailedException and
     26  * CertificateValidationException and any others into this?
     27  */
     28 public class MessagingException extends Exception {
     29     public static final long serialVersionUID = -1;
     30 
     31     public static final int NO_ERROR = -1;
     32     /** Any exception that does not specify a specific issue */
     33     public static final int UNSPECIFIED_EXCEPTION = 0;
     34     /** Connection or IO errors */
     35     public static final int IOERROR = 1;
     36     /** The configuration requested TLS but the server did not support it. */
     37     public static final int TLS_REQUIRED = 2;
     38     /** Authentication is required but the server did not support it. */
     39     public static final int AUTH_REQUIRED = 3;
     40     /** General security failures */
     41     public static final int GENERAL_SECURITY = 4;
     42     /** Authentication failed */
     43     public static final int AUTHENTICATION_FAILED = 5;
     44     /** Attempt to create duplicate account */
     45     public static final int DUPLICATE_ACCOUNT = 6;
     46     /** Required security policies reported - advisory only */
     47     public static final int SECURITY_POLICIES_REQUIRED = 7;
     48    /** Required security policies not supported */
     49     public static final int SECURITY_POLICIES_UNSUPPORTED = 8;
     50    /** The protocol (or protocol version) isn't supported */
     51     public static final int PROTOCOL_VERSION_UNSUPPORTED = 9;
     52     /** The server's SSL certificate couldn't be validated */
     53     public static final int CERTIFICATE_VALIDATION_ERROR = 10;
     54     /** Authentication failed during autodiscover */
     55     public static final int AUTODISCOVER_AUTHENTICATION_FAILED = 11;
     56     /** Autodiscover completed with a result (non-error) */
     57     public static final int AUTODISCOVER_AUTHENTICATION_RESULT = 12;
     58     /** Ambiguous failure; server error or bad credentials */
     59     public static final int AUTHENTICATION_FAILED_OR_SERVER_ERROR = 13;
     60     /** The server refused access */
     61     public static final int ACCESS_DENIED = 14;
     62     /** The server refused access */
     63     public static final int ATTACHMENT_NOT_FOUND = 15;
     64     /** A client SSL certificate is required for connections to the server */
     65     public static final int CLIENT_CERTIFICATE_REQUIRED = 16;
     66     /** The client SSL certificate specified is invalid */
     67     public static final int CLIENT_CERTIFICATE_ERROR = 17;
     68     /** The server indicates it does not support OAuth authentication */
     69     public static final int OAUTH_NOT_SUPPORTED = 18;
     70     /** The server indicates it experienced an internal error */
     71     public static final int SERVER_ERROR = 19;
     72 
     73     protected int mExceptionType;
     74     // Exception type-specific data
     75     protected Object mExceptionData;
     76 
     77     public MessagingException(String message, Throwable throwable) {
     78         this(UNSPECIFIED_EXCEPTION, message, throwable);
     79     }
     80 
     81     public MessagingException(int exceptionType, String message, Throwable throwable) {
     82         super(message, throwable);
     83         mExceptionType = exceptionType;
     84         mExceptionData = null;
     85     }
     86 
     87     /**
     88      * Constructs a MessagingException with an exceptionType and a null message.
     89      * @param exceptionType The exception type to set for this exception.
     90      */
     91     public MessagingException(int exceptionType) {
     92         this(exceptionType, null, null);
     93     }
     94 
     95     /**
     96      * Constructs a MessagingException with a message.
     97      * @param message the message for this exception
     98      */
     99     public MessagingException(String message) {
    100         this(UNSPECIFIED_EXCEPTION, message, null);
    101     }
    102 
    103     /**
    104      * Constructs a MessagingException with an exceptionType and a message.
    105      * @param exceptionType The exception type to set for this exception.
    106      */
    107     public MessagingException(int exceptionType, String message) {
    108         this(exceptionType, message, null);
    109     }
    110 
    111     /**
    112      * Constructs a MessagingException with an exceptionType, a message, and data
    113      * @param exceptionType The exception type to set for this exception.
    114      * @param message the message for the exception (or null)
    115      * @param data exception-type specific data for the exception (or null)
    116      */
    117     public MessagingException(int exceptionType, String message, Object data) {
    118         super(message);
    119         mExceptionType = exceptionType;
    120         mExceptionData = data;
    121     }
    122 
    123     /**
    124      * Return the exception type.  Will be OTHER_EXCEPTION if not explicitly set.
    125      *
    126      * @return Returns the exception type.
    127      */
    128     public int getExceptionType() {
    129         return mExceptionType;
    130     }
    131     /**
    132      * Return the exception data.  Will be null if not explicitly set.
    133      *
    134      * @return Returns the exception data.
    135      */
    136     public Object getExceptionData() {
    137         return mExceptionData;
    138     }
    139 }