1/*
2 * Copyright (C) 2008-2009 Marc Blank
3 * Licensed to 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
18package com.android.exchange;
19
20import android.util.Log;
21
22import com.android.emailcommon.service.EmailServiceProxy;
23import com.android.emailcommon.service.SyncWindow;
24
25/**
26 * Constants used throughout the EAS implementation are stored here.
27 *
28 */
29public class Eas {
30    // For debugging
31    public static boolean WAIT_DEBUG = false;   // DO NOT CHECK IN WITH THIS SET TO TRUE
32    public static boolean DEBUG = false;         // DO NOT CHECK IN WITH THIS SET TO TRUE
33
34    // The following two are for user logging (the second providing more detail)
35    public static boolean USER_LOG = false;     // DO NOT CHECK IN WITH THIS SET TO TRUE
36    public static boolean PARSER_LOG = false;   // DO NOT CHECK IN WITH THIS SET TO TRUE
37    public static boolean FILE_LOG = false;     // DO NOT CHECK IN WITH THIS SET TO TRUE
38
39    public static final String CLIENT_VERSION = "EAS-1.3";
40    public static final String ACCOUNT_MAILBOX_PREFIX = "__eas";
41
42    // Define our default protocol version as 2.5 (Exchange 2003)
43    public static final String SUPPORTED_PROTOCOL_EX2003 = "2.5";
44    public static final double SUPPORTED_PROTOCOL_EX2003_DOUBLE = 2.5;
45    public static final String SUPPORTED_PROTOCOL_EX2007 = "12.0";
46    public static final double SUPPORTED_PROTOCOL_EX2007_DOUBLE = 12.0;
47    public static final String SUPPORTED_PROTOCOL_EX2007_SP1 = "12.1";
48    public static final double SUPPORTED_PROTOCOL_EX2007_SP1_DOUBLE = 12.1;
49    public static final String SUPPORTED_PROTOCOL_EX2010 = "14.0";
50    public static final double SUPPORTED_PROTOCOL_EX2010_DOUBLE = 14.0;
51    public static final String SUPPORTED_PROTOCOL_EX2010_SP1 = "14.1";
52    public static final double SUPPORTED_PROTOCOL_EX2010_SP1_DOUBLE = 14.1;
53    public static final String DEFAULT_PROTOCOL_VERSION = SUPPORTED_PROTOCOL_EX2003;
54
55    public static final String EXCHANGE_ACCOUNT_MANAGER_TYPE = "com.android.exchange";
56
57    // From EAS spec
58    //                Mail Cal
59    // 0 No filter    Yes  Yes
60    // 1 1 day ago    Yes  No
61    // 2 3 days ago   Yes  No
62    // 3 1 week ago   Yes  No
63    // 4 2 weeks ago  Yes  Yes
64    // 5 1 month ago  Yes  Yes
65    // 6 3 months ago No   Yes
66    // 7 6 months ago No   Yes
67
68    public static final String FILTER_AUTO =  Integer.toString(SyncWindow.SYNC_WINDOW_AUTO);
69    // TODO Rationalize this with SYNC_WINDOW_ALL
70    public static final String FILTER_ALL = "0";
71    public static final String FILTER_1_DAY = Integer.toString(SyncWindow.SYNC_WINDOW_1_DAY);
72    public static final String FILTER_3_DAYS =  Integer.toString(SyncWindow.SYNC_WINDOW_3_DAYS);
73    public static final String FILTER_1_WEEK =  Integer.toString(SyncWindow.SYNC_WINDOW_1_WEEK);
74    public static final String FILTER_2_WEEKS =  Integer.toString(SyncWindow.SYNC_WINDOW_2_WEEKS);
75    public static final String FILTER_1_MONTH =  Integer.toString(SyncWindow.SYNC_WINDOW_1_MONTH);
76    public static final String FILTER_3_MONTHS = "6";
77    public static final String FILTER_6_MONTHS = "7";
78
79    public static final String BODY_PREFERENCE_TEXT = "1";
80    public static final String BODY_PREFERENCE_HTML = "2";
81
82    public static final String MIME_BODY_PREFERENCE_TEXT = "0";
83    public static final String MIME_BODY_PREFERENCE_MIME = "2";
84
85    // For EAS 12, we use HTML, so we want a larger size than in EAS 2.5
86    public static final String EAS12_TRUNCATION_SIZE = "200000";
87    // For EAS 2.5, truncation is a code; the largest is "7", which is 100k
88    public static final String EAS2_5_TRUNCATION_SIZE = "7";
89
90    public static final int FOLDER_STATUS_OK = 1;
91    public static final int FOLDER_STATUS_INVALID_KEY = 9;
92
93    public static final int EXCHANGE_ERROR_NOTIFICATION = 0x10;
94
95    public static void setUserDebug(int state) {
96        // DEBUG takes precedence and is never true in a user build
97        if (!DEBUG) {
98            USER_LOG = (state & EmailServiceProxy.DEBUG_BIT) != 0;
99            PARSER_LOG = (state & EmailServiceProxy.DEBUG_VERBOSE_BIT) != 0;
100            FILE_LOG = (state & EmailServiceProxy.DEBUG_FILE_BIT) != 0;
101            if (FILE_LOG || PARSER_LOG) {
102                USER_LOG = true;
103            }
104            Log.d("Eas Debug", "Logging: " + (USER_LOG ? "User " : "") +
105                    (PARSER_LOG ? "Parser " : "") + (FILE_LOG ? "File" : ""));
106        }
107    }
108
109    static public Double getProtocolVersionDouble(String version) {
110        if (SUPPORTED_PROTOCOL_EX2003.equals(version)) {
111            return SUPPORTED_PROTOCOL_EX2003_DOUBLE;
112        } else if (SUPPORTED_PROTOCOL_EX2007.equals(version)) {
113            return SUPPORTED_PROTOCOL_EX2007_DOUBLE;
114        } if (SUPPORTED_PROTOCOL_EX2007_SP1.equals(version)) {
115            return SUPPORTED_PROTOCOL_EX2007_SP1_DOUBLE;
116        } if (SUPPORTED_PROTOCOL_EX2010.equals(version)) {
117            return SUPPORTED_PROTOCOL_EX2010_DOUBLE;
118        } if (SUPPORTED_PROTOCOL_EX2010_SP1.equals(version)) {
119            return SUPPORTED_PROTOCOL_EX2010_SP1_DOUBLE;
120        }
121        throw new IllegalArgumentException("illegal protocol version");
122    }
123}
124