• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.email;
18 
19 import com.android.email.activity.AccountShortcutPicker;
20 import com.android.email.activity.MessageCompose;
21 import com.android.email.mail.internet.BinaryTempFileBody;
22 import com.android.email.service.BootReceiver;
23 import com.android.email.service.MailService;
24 
25 import android.app.Application;
26 import android.content.ComponentName;
27 import android.content.Context;
28 import android.content.pm.PackageManager;
29 
30 import java.io.File;
31 
32 public 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         "*/*",
68     };
69 
70     /**
71      * The MIME type(s) of attachments we're not willing to view.
72      */
73     public static final String[] UNACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[] {
74     };
75 
76     /**
77      * The MIME type(s) of attachments we're willing to download to SD.
78      */
79     public static final String[] ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
80         "image/*",
81     };
82 
83     /**
84      * The MIME type(s) of attachments we're not willing to download to SD.
85      */
86     public static final String[] UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
87     };
88 
89     /**
90      * The special name "INBOX" is used throughout the application to mean "Whatever folder
91      * the server refers to as the user's Inbox. Placed here to ease use.
92      */
93     public static final String INBOX = "INBOX";
94 
95     /**
96      * Specifies how many messages will be shown in a folder by default. This number is set
97      * on each new folder and can be incremented with "Load more messages..." by the
98      * VISIBLE_LIMIT_INCREMENT
99      */
100     public static final int VISIBLE_LIMIT_DEFAULT = 25;
101 
102     /**
103      * Number of additional messages to load when a user selects "Load more messages..."
104      */
105     public static final int VISIBLE_LIMIT_INCREMENT = 25;
106 
107     /**
108      * The maximum size of an attachment we're willing to download (either View or Save)
109      * Attachments that are base64 encoded (most) will be about 1.375x their actual size
110      * so we should probably factor that in. A 5MB attachment will generally be around
111      * 6.8MB downloaded but only 5MB saved.
112      */
113     public static final int MAX_ATTACHMENT_DOWNLOAD_SIZE = (5 * 1024 * 1024);
114 
115     /**
116      * The maximum size of an attachment we're willing to upload (measured as stored on disk).
117      * Attachments that are base64 encoded (most) will be about 1.375x their actual size
118      * so we should probably factor that in. A 5MB attachment will generally be around
119      * 6.8MB uploaded.
120      */
121     public static final int MAX_ATTACHMENT_UPLOAD_SIZE = (5 * 1024 * 1024);
122 
123     /**
124      * Called throughout the application when the number of accounts has changed. This method
125      * enables or disables the Compose activity, the boot receiver and the service based on
126      * whether any accounts are configured.
127      */
setServicesEnabled(Context context)128     public static void setServicesEnabled(Context context) {
129         setServicesEnabled(context, Preferences.getPreferences(context).getAccounts().length > 0);
130     }
131 
setServicesEnabled(Context context, boolean enabled)132     public static void setServicesEnabled(Context context, boolean enabled) {
133         PackageManager pm = context.getPackageManager();
134         if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
135                 PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
136             /*
137              * If no accounts now exist but the service is still enabled we're about to disable it
138              * so we'll reschedule to kill off any existing alarms.
139              */
140             MailService.actionReschedule(context);
141         }
142         pm.setComponentEnabledSetting(
143                 new ComponentName(context, MessageCompose.class),
144                 enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
145                     PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
146                 PackageManager.DONT_KILL_APP);
147         pm.setComponentEnabledSetting(
148                 new ComponentName(context, AccountShortcutPicker.class),
149                 enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
150                     PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
151                 PackageManager.DONT_KILL_APP);
152         pm.setComponentEnabledSetting(
153                 new ComponentName(context, BootReceiver.class),
154                 enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
155                     PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
156                 PackageManager.DONT_KILL_APP);
157         pm.setComponentEnabledSetting(
158                 new ComponentName(context, MailService.class),
159                 enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
160                     PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
161                 PackageManager.DONT_KILL_APP);
162         if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
163                 PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
164             /*
165              * And now if accounts do exist then we've just enabled the service and we want to
166              * schedule alarms for the new accounts.
167              */
168             MailService.actionReschedule(context);
169         }
170     }
171 
172     @Override
onCreate()173     public void onCreate() {
174         super.onCreate();
175         Preferences prefs = Preferences.getPreferences(this);
176         DEBUG = prefs.geteEnableDebugLogging();
177         DEBUG_SENSITIVE = prefs.getEnableSensitiveLogging();
178         MessagingController.getInstance(this).resetVisibleLimits(prefs.getAccounts());
179 
180         /*
181          * We have to give MimeMessage a temp directory because File.createTempFile(String, String)
182          * doesn't work in Android and MimeMessage does not have access to a Context.
183          */
184         BinaryTempFileBody.setTempDirectory(getCacheDir());
185     }
186 }
187 
188 
189 
190 
191 
192 
193 
194 
195