Email.java revision 4836f3c289f728048435ea2b5055e65b167f5a88
1/*
2 * Copyright (C) 2008 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
17package com.android.email;
18
19import com.android.email.activity.AccountShortcutPicker;
20import com.android.email.activity.MessageCompose;
21import com.android.email.mail.internet.BinaryTempFileBody;
22import com.android.email.service.BootReceiver;
23import com.android.email.service.MailService;
24
25import android.app.Application;
26import android.content.ComponentName;
27import android.content.Context;
28import android.content.pm.PackageManager;
29
30import java.io.File;
31
32public class Email extends Application {
33    public static final String LOG_TAG = "Email";
34
35    public static File tempDirectory;
36
37    /**
38     * If this is enabled there will be additional logging information sent to
39     * Log.d, including protocol dumps.
40     */
41    public static boolean DEBUG = false;
42
43    /**
44     * If this is enabled than logging that normally hides sensitive information
45     * like passwords will show that information.
46     */
47    public static boolean DEBUG_SENSITIVE = false;
48
49    /**
50     * The MIME type(s) of attachments we're willing to send. At the moment it is not possible
51     * to open a chooser with a list of filter types, so the chooser is only opened with the first
52     * item in the list. The entire list will be used to filter down attachments that are added
53     * with Intent.ACTION_SEND.
54     *
55     * TODO: It should be legal to send anything requested by another app.  This would provide
56     * parity with Gmail's behavior.
57     */
58    public static final String[] ACCEPTABLE_ATTACHMENT_SEND_TYPES = new String[] {
59        "image/*",
60        "video/*",
61    };
62
63    /**
64     * The MIME type(s) of attachments we're willing to view.
65     */
66    public static final String[] ACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[] {
67        "image/*",
68        "audio/*",
69        "text/*",
70    };
71
72    /**
73     * The MIME type(s) of attachments we're not willing to view.
74     */
75    public static final String[] UNACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[] {
76    };
77
78    /**
79     * The MIME type(s) of attachments we're willing to download to SD.
80     */
81    public static final String[] ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
82        "image/*",
83    };
84
85    /**
86     * The MIME type(s) of attachments we're not willing to download to SD.
87     */
88    public static final String[] UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
89    };
90
91    /**
92     * The special name "INBOX" is used throughout the application to mean "Whatever folder
93     * the server refers to as the user's Inbox. Placed here to ease use.
94     */
95    public static final String INBOX = "INBOX";
96
97    /**
98     * Specifies how many messages will be shown in a folder by default. This number is set
99     * on each new folder and can be incremented with "Load more messages..." by the
100     * VISIBLE_LIMIT_INCREMENT
101     */
102    public static final int VISIBLE_LIMIT_DEFAULT = 25;
103
104    /**
105     * Number of additional messages to load when a user selects "Load more messages..."
106     */
107    public static final int VISIBLE_LIMIT_INCREMENT = 25;
108
109    /**
110     * The maximum size of an attachment we're willing to download (either View or Save)
111     * Attachments that are base64 encoded (most) will be about 1.375x their actual size
112     * so we should probably factor that in. A 5MB attachment will generally be around
113     * 6.8MB downloaded but only 5MB saved.
114     */
115    public static final int MAX_ATTACHMENT_DOWNLOAD_SIZE = (5 * 1024 * 1024);
116
117    /**
118     * The maximum size of an attachment we're willing to upload (measured as stored on disk).
119     * Attachments that are base64 encoded (most) will be about 1.375x their actual size
120     * so we should probably factor that in. A 5MB attachment will generally be around
121     * 6.8MB uploaded.
122     */
123    public static final int MAX_ATTACHMENT_UPLOAD_SIZE = (5 * 1024 * 1024);
124
125    /**
126     * Called throughout the application when the number of accounts has changed. This method
127     * enables or disables the Compose activity, the boot receiver and the service based on
128     * whether any accounts are configured.
129     */
130    public static void setServicesEnabled(Context context) {
131        setServicesEnabled(context, Preferences.getPreferences(context).getAccounts().length > 0);
132    }
133
134    public static void setServicesEnabled(Context context, boolean enabled) {
135        PackageManager pm = context.getPackageManager();
136        if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
137                PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
138            /*
139             * If no accounts now exist but the service is still enabled we're about to disable it
140             * so we'll reschedule to kill off any existing alarms.
141             */
142            MailService.actionReschedule(context);
143        }
144        pm.setComponentEnabledSetting(
145                new ComponentName(context, MessageCompose.class),
146                enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
147                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
148                PackageManager.DONT_KILL_APP);
149        pm.setComponentEnabledSetting(
150                new ComponentName(context, AccountShortcutPicker.class),
151                enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
152                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
153                PackageManager.DONT_KILL_APP);
154        pm.setComponentEnabledSetting(
155                new ComponentName(context, BootReceiver.class),
156                enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
157                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
158                PackageManager.DONT_KILL_APP);
159        pm.setComponentEnabledSetting(
160                new ComponentName(context, MailService.class),
161                enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
162                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
163                PackageManager.DONT_KILL_APP);
164        if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
165                PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
166            /*
167             * And now if accounts do exist then we've just enabled the service and we want to
168             * schedule alarms for the new accounts.
169             */
170            MailService.actionReschedule(context);
171        }
172    }
173
174    @Override
175    public void onCreate() {
176        super.onCreate();
177        Preferences prefs = Preferences.getPreferences(this);
178        DEBUG = prefs.geteEnableDebugLogging();
179        DEBUG_SENSITIVE = prefs.getEnableSensitiveLogging();
180        MessagingController.getInstance(this).resetVisibleLimits(prefs.getAccounts());
181
182        /*
183         * We have to give MimeMessage a temp directory because File.createTempFile(String, String)
184         * doesn't work in Android and MimeMessage does not have access to a Context.
185         */
186        BinaryTempFileBody.setTempDirectory(getCacheDir());
187    }
188}
189
190
191
192
193
194
195
196
197