2009-03-04 03:32:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.email;
|
|
|
|
|
|
|
|
import com.android.email.activity.AccountShortcutPicker;
|
|
|
|
import com.android.email.activity.MessageCompose;
|
2009-06-08 22:27:17 +00:00
|
|
|
import com.android.email.provider.EmailContent;
|
2010-08-10 00:48:53 +00:00
|
|
|
import com.android.email.service.AttachmentDownloadService;
|
2009-03-04 03:32:22 +00:00
|
|
|
import com.android.email.service.MailService;
|
2010-08-26 07:00:48 +00:00
|
|
|
import com.android.exchange.Eas;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Context;
|
2010-08-10 00:48:53 +00:00
|
|
|
import android.content.Intent;
|
2009-03-04 03:32:22 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2009-06-08 22:27:17 +00:00
|
|
|
import android.database.Cursor;
|
2010-08-24 01:48:25 +00:00
|
|
|
import android.text.format.DateUtils;
|
2009-07-28 17:41:59 +00:00
|
|
|
import android.util.Log;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
2010-08-24 01:48:25 +00:00
|
|
|
import java.util.HashMap;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
|
|
|
public class Email extends Application {
|
|
|
|
public static final String LOG_TAG = "Email";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If this is enabled there will be additional logging information sent to
|
|
|
|
* Log.d, including protocol dumps.
|
2009-07-16 21:09:15 +00:00
|
|
|
*
|
|
|
|
* This should only be used for logs that are useful for debbuging user problems,
|
|
|
|
* not for internal/development logs.
|
|
|
|
*
|
|
|
|
* This can be enabled by typing "debug" in the AccountFolderList activity.
|
|
|
|
* Changing the value to 'true' here will likely have no effect at all!
|
|
|
|
*
|
|
|
|
* TODO: rename this to sUserDebug, and rename LOGD below to DEBUG.
|
2009-03-04 03:32:22 +00:00
|
|
|
*/
|
|
|
|
public static boolean DEBUG = false;
|
|
|
|
|
|
|
|
/**
|
Refactoring MessageListXL
I always thought our Activities are way too fat, meaning we've put too many
things into activities without any structure.
The major problems with this are:
- They have too many fields, which are not final and not even orthogonal.
This makes them very hard to understand/maintain. Changing one tiny bit
can always cause unanticipated side-effects.
- Very hard, or almost impossible to test.
I really think we should break them into independent and self-contained
subcomponents which can be tested separately.
Introducing MessageListXLStateManager, which manages the current account,
mailbox and message, and show/hide/update fragments accordingly
for MessageListXL.
With this class, MessageListXL will be able to switch accounts/mailboxes/
messages by just calling the methods such as selectAccount(), without
worrying about when to show/hide what fragment and how to initialize them.
(In other words, MessageListXLStateManager encapsulates the two-pane screen
transition. It's not intended to be reused for the phone UI.)
I didn't make it a nested class in MessageListXL, because nested classes can't
have real private members (private member are accessible from outer classes and
even brother classes!!), and I wanted it to be really self-contained anyway.
Change-Id: I1c121e99e30f12cc118e1c35abc9b30f49939a4a
2010-07-22 22:01:31 +00:00
|
|
|
* If true, logging regarding activity/fragment lifecycle will be enabled.
|
|
|
|
*/
|
|
|
|
public static final boolean DEBUG_LIFECYCLE = true; // STOPSHIP Turn this off.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If this is enabled then logging that normally hides sensitive information
|
2009-03-04 03:32:22 +00:00
|
|
|
* like passwords will show that information.
|
|
|
|
*/
|
2010-06-30 22:43:12 +00:00
|
|
|
public static final boolean DEBUG_SENSITIVE = false;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
2009-08-09 04:58:54 +00:00
|
|
|
/**
|
2009-07-16 21:09:15 +00:00
|
|
|
* Set this to 'true' to enable as much Email logging as possible.
|
|
|
|
* Do not check-in with it set to 'true'!
|
|
|
|
*/
|
|
|
|
public static final boolean LOGD = false;
|
|
|
|
|
2010-09-09 00:57:21 +00:00
|
|
|
/**
|
|
|
|
* If true, enable the UI thread check when accessing the filesystem.
|
|
|
|
*/
|
|
|
|
public static final boolean DEBUG_THREAD_CHECK = false; // DON'T SUBMIT WITH TRUE
|
|
|
|
|
2010-11-01 23:15:15 +00:00
|
|
|
/**
|
|
|
|
* If true, inhibit hardware graphics acceleration in UI (for a/b testing)
|
|
|
|
*/
|
|
|
|
public static boolean sDebugInhibitGraphicsAcceleration = false;
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
2009-09-28 06:49:10 +00:00
|
|
|
* The MIME type(s) of attachments we're willing to send via attachments.
|
2009-08-09 04:58:54 +00:00
|
|
|
*
|
2009-09-28 06:49:10 +00:00
|
|
|
* Any attachments may be added via Intents with Intent.ACTION_SEND or ACTION_SEND_MULTIPLE.
|
2009-03-04 03:32:22 +00:00
|
|
|
*/
|
2009-09-28 06:49:10 +00:00
|
|
|
public static final String[] ACCEPTABLE_ATTACHMENT_SEND_INTENT_TYPES = new String[] {
|
|
|
|
"*/*",
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're willing to send from the internal UI.
|
|
|
|
*
|
|
|
|
* NOTE: At the moment it is not possible to open a chooser with a list of filter types, so
|
|
|
|
* the chooser is only opened with the first item in the list.
|
|
|
|
*/
|
|
|
|
public static final String[] ACCEPTABLE_ATTACHMENT_SEND_UI_TYPES = new String[] {
|
2009-03-04 03:32:22 +00:00
|
|
|
"image/*",
|
|
|
|
"video/*",
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're willing to view.
|
|
|
|
*/
|
|
|
|
public static final String[] ACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[] {
|
2009-05-04 17:28:41 +00:00
|
|
|
"*/*",
|
2009-03-04 03:32:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're not willing to view.
|
|
|
|
*/
|
|
|
|
public static final String[] UNACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[] {
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're willing to download to SD.
|
|
|
|
*/
|
|
|
|
public static final String[] ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
|
|
|
|
"image/*",
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're not willing to download to SD.
|
|
|
|
*/
|
|
|
|
public static final String[] UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies how many messages will be shown in a folder by default. This number is set
|
|
|
|
* on each new folder and can be incremented with "Load more messages..." by the
|
|
|
|
* VISIBLE_LIMIT_INCREMENT
|
|
|
|
*/
|
2009-04-15 17:58:59 +00:00
|
|
|
public static final int VISIBLE_LIMIT_DEFAULT = 25;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
|
|
|
/**
|
2009-04-15 17:58:59 +00:00
|
|
|
* Number of additional messages to load when a user selects "Load more messages..."
|
2009-03-04 03:32:22 +00:00
|
|
|
*/
|
|
|
|
public static final int VISIBLE_LIMIT_INCREMENT = 25;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum size of an attachment we're willing to download (either View or Save)
|
|
|
|
* Attachments that are base64 encoded (most) will be about 1.375x their actual size
|
|
|
|
* so we should probably factor that in. A 5MB attachment will generally be around
|
|
|
|
* 6.8MB downloaded but only 5MB saved.
|
|
|
|
*/
|
|
|
|
public static final int MAX_ATTACHMENT_DOWNLOAD_SIZE = (5 * 1024 * 1024);
|
|
|
|
|
2009-03-25 04:31:47 +00:00
|
|
|
/**
|
|
|
|
* The maximum size of an attachment we're willing to upload (measured as stored on disk).
|
|
|
|
* Attachments that are base64 encoded (most) will be about 1.375x their actual size
|
|
|
|
* so we should probably factor that in. A 5MB attachment will generally be around
|
|
|
|
* 6.8MB uploaded.
|
|
|
|
*/
|
|
|
|
public static final int MAX_ATTACHMENT_UPLOAD_SIZE = (5 * 1024 * 1024);
|
|
|
|
|
2010-04-14 16:28:04 +00:00
|
|
|
/**
|
|
|
|
* This is used to force stacked UI to return to the "welcome" screen any time we change
|
|
|
|
* the accounts list (e.g. deleting accounts in the Account Manager preferences.)
|
|
|
|
*/
|
|
|
|
private static boolean sAccountsChangedNotification = false;
|
|
|
|
|
2010-02-01 23:34:03 +00:00
|
|
|
public static final String EXCHANGE_ACCOUNT_MANAGER_TYPE = "com.android.exchange";
|
2010-07-08 17:08:47 +00:00
|
|
|
public static final String POP_IMAP_ACCOUNT_MANAGER_TYPE = "com.android.email";
|
2010-02-01 23:34:03 +00:00
|
|
|
|
2010-05-13 23:07:55 +00:00
|
|
|
private static File sTempDirectory;
|
|
|
|
|
2010-09-09 00:57:21 +00:00
|
|
|
private static Thread sUiThread;
|
|
|
|
|
2010-05-17 20:13:56 +00:00
|
|
|
public static void setTempDirectory(Context context) {
|
|
|
|
sTempDirectory = context.getCacheDir();
|
|
|
|
}
|
|
|
|
|
2010-05-13 23:07:55 +00:00
|
|
|
public static File getTempDirectory() {
|
|
|
|
if (sTempDirectory == null) {
|
2010-05-17 20:13:56 +00:00
|
|
|
throw new RuntimeException(
|
|
|
|
"TempDirectory not set. " +
|
|
|
|
"If in a unit test, call Email.setTempDirectory(context) in setUp().");
|
2010-05-13 23:07:55 +00:00
|
|
|
}
|
|
|
|
return sTempDirectory;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* Called throughout the application when the number of accounts has changed. This method
|
|
|
|
* enables or disables the Compose activity, the boot receiver and the service based on
|
2009-09-23 22:06:19 +00:00
|
|
|
* whether any accounts are configured. Returns true if there are any accounts configured.
|
2009-03-04 03:32:22 +00:00
|
|
|
*/
|
2009-09-23 22:06:19 +00:00
|
|
|
public static boolean setServicesEnabled(Context context) {
|
2009-06-08 22:27:17 +00:00
|
|
|
Cursor c = null;
|
|
|
|
try {
|
|
|
|
c = context.getContentResolver().query(
|
2009-08-09 04:58:54 +00:00
|
|
|
EmailContent.Account.CONTENT_URI,
|
2009-06-15 21:40:06 +00:00
|
|
|
EmailContent.Account.ID_PROJECTION,
|
2009-06-08 22:27:17 +00:00
|
|
|
null, null, null);
|
|
|
|
boolean enable = c.getCount() > 0;
|
2009-09-08 09:23:04 +00:00
|
|
|
setServicesEnabled(context, enable);
|
2009-09-23 22:06:19 +00:00
|
|
|
return enable;
|
2009-06-08 22:27:17 +00:00
|
|
|
} finally {
|
|
|
|
if (c != null) {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
}
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void setServicesEnabled(Context context, boolean enabled) {
|
|
|
|
PackageManager pm = context.getPackageManager();
|
2010-08-10 00:48:53 +00:00
|
|
|
if (!enabled && pm.getComponentEnabledSetting(
|
|
|
|
new ComponentName(context, MailService.class)) ==
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
|
2009-03-04 03:32:22 +00:00
|
|
|
/*
|
|
|
|
* If no accounts now exist but the service is still enabled we're about to disable it
|
|
|
|
* so we'll reschedule to kill off any existing alarms.
|
|
|
|
*/
|
|
|
|
MailService.actionReschedule(context);
|
|
|
|
}
|
|
|
|
pm.setComponentEnabledSetting(
|
|
|
|
new ComponentName(context, MessageCompose.class),
|
|
|
|
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
|
|
PackageManager.DONT_KILL_APP);
|
|
|
|
pm.setComponentEnabledSetting(
|
|
|
|
new ComponentName(context, AccountShortcutPicker.class),
|
|
|
|
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
|
|
PackageManager.DONT_KILL_APP);
|
|
|
|
pm.setComponentEnabledSetting(
|
|
|
|
new ComponentName(context, MailService.class),
|
|
|
|
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
|
|
PackageManager.DONT_KILL_APP);
|
2010-08-10 00:48:53 +00:00
|
|
|
pm.setComponentEnabledSetting(
|
|
|
|
new ComponentName(context, AttachmentDownloadService.class),
|
|
|
|
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
|
|
PackageManager.DONT_KILL_APP);
|
|
|
|
if (enabled && pm.getComponentEnabledSetting(
|
|
|
|
new ComponentName(context, MailService.class)) ==
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
|
2009-03-04 03:32:22 +00:00
|
|
|
/*
|
|
|
|
* And now if accounts do exist then we've just enabled the service and we want to
|
|
|
|
* schedule alarms for the new accounts.
|
|
|
|
*/
|
2010-08-24 01:48:25 +00:00
|
|
|
MailService.actionReschedule(context);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
2010-08-10 00:48:53 +00:00
|
|
|
// Start/stop the AttachmentDownloadService, depending on whether there are any accounts
|
|
|
|
Intent intent = new Intent(context, AttachmentDownloadService.class);
|
|
|
|
if (enabled) {
|
|
|
|
context.startService(intent);
|
|
|
|
} else {
|
|
|
|
context.stopService(intent);
|
|
|
|
}
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
2010-09-09 00:57:21 +00:00
|
|
|
sUiThread = Thread.currentThread();
|
2009-03-04 03:32:22 +00:00
|
|
|
Preferences prefs = Preferences.getPreferences(this);
|
2009-08-14 00:43:25 +00:00
|
|
|
DEBUG = prefs.getEnableDebugLogging();
|
2010-11-01 23:15:15 +00:00
|
|
|
sDebugInhibitGraphicsAcceleration = prefs.getInhibitGraphicsAcceleration();
|
2010-05-17 20:13:56 +00:00
|
|
|
setTempDirectory(this);
|
2010-08-24 01:48:25 +00:00
|
|
|
|
|
|
|
// Tie MailRefreshManager to the Controller.
|
|
|
|
RefreshManager.getInstance(this);
|
|
|
|
// Reset all accounts to default visible window
|
|
|
|
Controller.getInstance(this).resetVisibleLimits();
|
|
|
|
|
|
|
|
// Enable logging in the EAS service, so it starts up as early as possible.
|
2010-08-26 07:00:48 +00:00
|
|
|
updateLoggingFlags(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load enabled debug flags from the preferences and update the EAS debug flag.
|
|
|
|
*/
|
|
|
|
public static void updateLoggingFlags(Context context) {
|
|
|
|
//EXCHANGE-REMOVE-SECTION-START
|
|
|
|
Preferences prefs = Preferences.getPreferences(context);
|
|
|
|
int debugLogging = prefs.getEnableDebugLogging() ? Eas.DEBUG_BIT : 0;
|
|
|
|
int exchangeLogging = prefs.getEnableExchangeLogging() ? Eas.DEBUG_EXCHANGE_BIT : 0;
|
|
|
|
int fileLogging = prefs.getEnableExchangeFileLogging() ? Eas.DEBUG_FILE_BIT : 0;
|
|
|
|
int debugBits = debugLogging | exchangeLogging | fileLogging;
|
|
|
|
Controller.getInstance(context).serviceLogging(debugBits);
|
|
|
|
//EXCHANGE-REMOVE-SECTION-END
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-28 17:41:59 +00:00
|
|
|
/**
|
|
|
|
* Internal, utility method for logging.
|
|
|
|
* The calls to log() must be guarded with "if (Email.LOGD)" for performance reasons.
|
|
|
|
*/
|
|
|
|
public static void log(String message) {
|
|
|
|
Log.d(LOG_TAG, message);
|
|
|
|
}
|
2009-09-08 09:23:04 +00:00
|
|
|
|
2010-04-14 16:28:04 +00:00
|
|
|
/**
|
|
|
|
* Called by the accounts reconciler to notify that accounts have changed, or by "Welcome"
|
|
|
|
* to clear the flag.
|
|
|
|
* @param setFlag true to set the notification flag, false to clear it
|
|
|
|
*/
|
|
|
|
public static synchronized void setNotifyUiAccountsChanged(boolean setFlag) {
|
|
|
|
sAccountsChangedNotification = setFlag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from activity onResume() functions to check for an accounts-changed condition, at
|
|
|
|
* which point they should finish() and jump to the Welcome activity.
|
|
|
|
*/
|
|
|
|
public static synchronized boolean getNotifyUiAccountsChanged() {
|
|
|
|
return sAccountsChangedNotification;
|
|
|
|
}
|
2010-09-09 00:57:21 +00:00
|
|
|
|
|
|
|
public static void warnIfUiThread() {
|
|
|
|
if (Thread.currentThread().equals(sUiThread)) {
|
|
|
|
Log.w(Email.LOG_TAG, "Method called on the UI thread", new Exception("STACK TRACE"));
|
|
|
|
}
|
|
|
|
}
|
2009-07-28 17:41:59 +00:00
|
|
|
}
|