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.messaging.datamodel;
18 
19 public class DataModelException extends Exception {
20     private static final long serialVersionUID = 1L;
21 
22     private static final int FIRST = 100;
23 
24     // ERRORS GENERATED INTERNALLY BY DATA MODEL.
25 
26     // ERRORS RELATED WITH SMS.
27     public static final int ERROR_SMS_TEMPORARY_FAILURE = 116;
28     public static final int ERROR_SMS_PERMANENT_FAILURE = 117;
29     public static final int ERROR_MMS_TEMPORARY_FAILURE = 118;
30     public static final int ERROR_MMS_PERMANENT_UNKNOWN_FAILURE = 119;
31 
32     // Request expired.
33     public static final int ERROR_EXPIRED = 120;
34     // Request canceled by user.
35     public static final int ERROR_CANCELED = 121;
36 
37     public static final int ERROR_MOBILE_DATA_DISABLED  = 123;
38     public static final int ERROR_MMS_SERVICE_BLOCKED   = 124;
39     public static final int ERROR_MMS_INVALID_ADDRESS   = 125;
40     public static final int ERROR_MMS_NETWORK_PROBLEM   = 126;
41     public static final int ERROR_MMS_MESSAGE_NOT_FOUND = 127;
42     public static final int ERROR_MMS_MESSAGE_FORMAT_CORRUPT = 128;
43     public static final int ERROR_MMS_CONTENT_NOT_ACCEPTED = 129;
44     public static final int ERROR_MMS_MESSAGE_NOT_SUPPORTED = 130;
45     public static final int ERROR_MMS_REPLY_CHARGING_ERROR = 131;
46     public static final int ERROR_MMS_ADDRESS_HIDING_NOT_SUPPORTED = 132;
47     public static final int ERROR_MMS_LACK_OF_PREPAID = 133;
48     public static final int ERROR_MMS_CAN_NOT_PERSIST = 134;
49     public static final int ERROR_MMS_NO_AVAILABLE_APN = 135;
50     public static final int ERROR_MMS_INVALID_MESSAGE_TO_SEND = 136;
51     public static final int ERROR_MMS_INVALID_MESSAGE_RECEIVED = 137;
52     public static final int ERROR_MMS_NO_CONFIGURATION = 138;
53 
54     private static final int LAST = 138;
55 
56     private final boolean mIsInjection;
57     private final int mErrorCode;
58     private final String mMessage;
59     private final long mBackoff;
60 
DataModelException(final int errorCode, final Exception innerException, final long backoff, final boolean injection, final String message)61     public DataModelException(final int errorCode, final Exception innerException,
62             final long backoff, final boolean injection, final String message) {
63         // Since some of the exceptions passed in may not be serializable, only record message
64         // instead of setting inner exception for Exception class. Otherwise, we will get
65         // serialization issues when we pass ServerRequestException as intent extra later.
66         if (errorCode < FIRST || errorCode > LAST) {
67             throw new IllegalArgumentException("error code out of range: " + errorCode);
68         }
69         mIsInjection = injection;
70         mErrorCode = errorCode;
71         if (innerException != null) {
72             mMessage = innerException.getMessage() + " -- " +
73                     (mIsInjection ? "[INJECTED] -- " : "") + message;
74         } else {
75             mMessage = (mIsInjection ? "[INJECTED] -- " : "") + message;
76         }
77 
78         mBackoff = backoff;
79     }
80 
DataModelException(final int errorCode)81     public DataModelException(final int errorCode) {
82         this(errorCode, null, 0, false, null);
83     }
84 
DataModelException(final int errorCode, final Exception innerException)85     public DataModelException(final int errorCode, final Exception innerException) {
86         this(errorCode, innerException, 0, false, null);
87     }
88 
DataModelException(final int errorCode, final String message)89     public DataModelException(final int errorCode, final String message) {
90         this(errorCode, null, 0, false, message);
91     }
92 
93     @Override
getMessage()94     public String getMessage() {
95         return mMessage;
96     }
97 
getErrorCode()98     public int getErrorCode() {
99         return mErrorCode;
100     }
101 }
102