Delete obsolete emailsync code

b/5784532

Change-Id: I33a693e91b99253c4f82758c875c8cf21bace543
This commit is contained in:
Tony Mantler 2014-06-30 13:10:48 -07:00
parent e292027fa7
commit 035f5fd71c
10 changed files with 1 additions and 2982 deletions

View File

@ -43,7 +43,7 @@ LOCAL_ASSET_DIR := $(LOCAL_PATH)/$(unified_email_dir)/assets
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.chips:com.android.mail:com.android.email:com.android.emailcommon:com.android.ex.photo:android.support.v7.gridlayout:com.android.datetimepicker
LOCAL_STATIC_JAVA_LIBRARIES := android-common com.android.emailcommon com.android.emailsync guava libchips libphotoviewer
LOCAL_STATIC_JAVA_LIBRARIES := android-common com.android.emailcommon guava libchips libphotoviewer
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13

View File

@ -1,30 +0,0 @@
# Copyright 2012, 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.
LOCAL_PATH := $(call my-dir)
# Build the com.android.emailcommon static library. At the moment, this includes
# the emailcommon files themselves plus everything under src/org (apache code). All of our
# AIDL files are also compiled into the static library
include $(CLEAR_VARS)
LOCAL_MODULE := com.android.emailsync
LOCAL_SRC_FILES := $(call all-java-files-under, src/com/android/emailsync)
LOCAL_STATIC_JAVA_LIBRARIES := com.android.emailcommon
LOCAL_SDK_VERSION := 14
include $(BUILD_STATIC_JAVA_LIBRARY)

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.emailcommon"
android:versionCode="1">
<uses-sdk android:targetSdkVersion="19" android:minSdkVersion="14" />
</manifest>

View File

@ -1,300 +0,0 @@
/*
* Copyright (C) 2008-2009 Marc Blank
* Licensed to 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.emailsync;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.text.format.DateUtils;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.HostAuth;
import com.android.emailcommon.provider.Mailbox;
import com.android.mail.utils.LogUtils;
import java.util.concurrent.LinkedBlockingQueue;
/**
* Base class for all protocol services SyncManager (extends Service, implements
* Runnable) instantiates subclasses to run a sync (either timed, or push, or
* mail placed in outbox, etc.) EasSyncService is currently implemented; my goal
* would be to move IMAP to this structure when it comes time to introduce push
* functionality.
*/
public abstract class AbstractSyncService implements Runnable {
public String TAG = "AbstractSyncService";
public static final int EXIT_DONE = 0;
public static final int EXIT_IO_ERROR = 1;
public static final int EXIT_LOGIN_FAILURE = 2;
public static final int EXIT_EXCEPTION = 3;
public static final int EXIT_SECURITY_FAILURE = 4;
public static final int EXIT_ACCESS_DENIED = 5;
public Mailbox mMailbox;
protected long mMailboxId;
protected int mExitStatus = EXIT_EXCEPTION;
protected String mExitReason;
protected String mMailboxName;
public Account mAccount;
public Context mContext;
public int mChangeCount = 0;
public volatile int mSyncReason = 0;
protected volatile boolean mStop = false;
public volatile Thread mThread;
protected final Object mSynchronizer = new Object();
// Whether or not the sync service is valid (usable)
public boolean mIsValid = true;
public boolean mUserLog = false;
public boolean mFileLog = false;
protected volatile long mRequestTime = 0;
protected LinkedBlockingQueue<Request> mRequestQueue = new LinkedBlockingQueue<Request>();
/**
* Sent by SyncManager to request that the service stop itself cleanly
*/
public abstract void stop();
/**
* Sent by SyncManager to indicate that an alarm has fired for this service, and that its
* pending (network) operation has timed out. The service is NOT automatically stopped,
* although the behavior is service dependent.
*
* @return true if the operation was stopped normally; false if the thread needed to be
* interrupted.
*/
public abstract boolean alarm();
/**
* Sent by SyncManager to request that the service reset itself cleanly; the meaning of this
* operation is service dependent.
*/
public abstract void reset();
/**
* Called to validate an account; abstract to allow each protocol to do what
* is necessary. For consistency with the Email app's original
* functionality, success is indicated by a failure to throw an Exception
* (ugh). Parameters are self-explanatory
*
* @param hostAuth
* @return a Bundle containing a result code and, depending on the result, a PolicySet or an
* error message
*/
public abstract Bundle validateAccount(HostAuth hostAuth, Context context);
/**
* Called to clear the syncKey for the calendar associated with this service; this is necessary
* because changes to calendar sync state cause a reset of data.
*/
public abstract void resetCalendarSyncKey();
public AbstractSyncService(Context _context, Mailbox _mailbox) {
mContext = _context;
mMailbox = _mailbox;
mMailboxId = _mailbox.mId;
mMailboxName = _mailbox.mServerId;
mAccount = Account.restoreAccountWithId(_context, _mailbox.mAccountKey);
}
// Will be required when subclasses are instantiated by name
public AbstractSyncService(String prefix) {
}
/**
* The UI can call this static method to perform account validation. This method wraps each
* protocol's validateAccount method. Arguments are self-explanatory, except where noted.
*
* @param klass the protocol class (EasSyncService.class for example)
* @param hostAuth
* @param context
* @return a Bundle containing a result code and, depending on the result, a PolicySet or an
* error message
*/
public static Bundle validate(Class<? extends AbstractSyncService> klass,
HostAuth hostAuth, Context context) {
AbstractSyncService svc;
try {
svc = klass.newInstance();
return svc.validateAccount(hostAuth, context);
} catch (IllegalAccessException e) {
} catch (InstantiationException e) {
}
return null;
}
public static class ValidationResult {
static final int NO_FAILURE = 0;
static final int CONNECTION_FAILURE = 1;
static final int VALIDATION_FAILURE = 2;
static final int EXCEPTION = 3;
static final ValidationResult succeeded = new ValidationResult(true, NO_FAILURE, null);
boolean success;
int failure = NO_FAILURE;
String reason = null;
Exception exception = null;
ValidationResult(boolean _success, int _failure, String _reason) {
success = _success;
failure = _failure;
reason = _reason;
}
ValidationResult(boolean _success) {
success = _success;
}
ValidationResult(Exception e) {
success = false;
failure = EXCEPTION;
exception = e;
}
public boolean isSuccess() {
return success;
}
public String getReason() {
return reason;
}
}
public boolean isStopped() {
return mStop;
}
public Object getSynchronizer() {
return mSynchronizer;
}
/**
* Convenience methods to do user logging (i.e. connection activity). Saves a bunch of
* repetitive code.
*/
public void userLog(String string, int code, String string2) {
if (mUserLog) {
userLog(string + code + string2);
}
}
public void userLog(String string, int code) {
if (mUserLog) {
userLog(string + code);
}
}
public void userLog(String str, Exception e) {
if (mUserLog) {
LogUtils.e(TAG, str, e);
} else {
LogUtils.e(TAG, str + e);
}
if (mFileLog) {
FileLogger.log(e);
}
}
/**
* Standard logging for EAS.
* If user logging is active, we concatenate any arguments and log them using LogUtils.d
* We also check for file logging, and log appropriately
* @param strings strings to concatenate and log
*/
public void userLog(String ...strings) {
if (mUserLog) {
String logText;
if (strings.length == 1) {
logText = strings[0];
} else {
StringBuilder sb = new StringBuilder(64);
for (String string: strings) {
sb.append(string);
}
logText = sb.toString();
}
LogUtils.d(TAG, logText);
if (mFileLog) {
FileLogger.log(TAG, logText);
}
}
}
/**
* Error log is used for serious issues that should always be logged
* @param str the string to log
*/
public void errorLog(String str) {
LogUtils.e(TAG, str);
if (mFileLog) {
FileLogger.log(TAG, str);
}
}
/**
* Waits for up to 10 seconds for network connectivity; returns whether or not there is
* network connectivity.
*
* @return whether there is network connectivity
*/
public boolean hasConnectivity() {
ConnectivityManager cm =
(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
int tries = 0;
while (tries++ < 1) {
// Use the same test as in ExchangeService#waitForConnectivity
// TODO: Create common code for this test in emailcommon
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null) {
return true;
}
try {
Thread.sleep(10 * DateUtils.SECOND_IN_MILLIS);
} catch (InterruptedException e) {
}
}
return false;
}
/**
* Request handling (common functionality)
* Can be overridden if desired
*/
public void addRequest(Request req) {
if (!mRequestQueue.contains(req)) {
mRequestQueue.offer(req);
}
}
public void removeRequest(Request req) {
mRequestQueue.remove(req);
}
public boolean hasPendingRequests() {
return !mRequestQueue.isEmpty();
}
public void clearRequests() {
mRequestQueue.clear();
}
}

View File

@ -1,113 +0,0 @@
/*
* Copyright (C) 2008-2009 Marc Blank
* Licensed to 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.emailsync;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import com.android.emailcommon.provider.EmailContent.Message;
import com.android.emailcommon.provider.EmailContent.MessageColumns;
import com.android.emailcommon.provider.ProviderUnavailableException;
import com.android.mail.utils.LogUtils;
import java.util.ArrayList;
/**
* EmailSyncAlarmReceiver (USAR) is used by the SyncManager to start up-syncs of user-modified data
* back to the Exchange server.
*
* Here's how this works for Email, for example:
*
* 1) User modifies or deletes an email from the UI.
* 2) SyncManager, which has a ContentObserver watching the Message class, is alerted to a change
* 3) SyncManager sets an alarm (to be received by USAR) for a few seconds in the
* future (currently 15), the delay preventing excess syncing (think of it as a debounce mechanism).
* 4) ESAR Receiver's onReceive method is called
* 5) ESAR goes through all change and deletion records and compiles a list of mailboxes which have
* changes to be uploaded.
* 6) ESAR calls SyncManager to start syncs of those mailboxes
*
* If EmailProvider isn't available, the upsyncs will happen the next time ExchangeService starts
*
*/
public class EmailSyncAlarmReceiver extends BroadcastReceiver {
final String[] MAILBOX_DATA_PROJECTION = {MessageColumns.MAILBOX_KEY};
@Override
public void onReceive(final Context context, Intent intent) {
new Thread(new Runnable() {
@Override
public void run() {
handleReceive(context);
}
}).start();
}
private void handleReceive(Context context) {
ArrayList<Long> mailboxesToNotify = new ArrayList<Long>();
ContentResolver cr = context.getContentResolver();
// Get a selector for EAS accounts (we don't want to sync on changes to POP/IMAP messages)
String selector = SyncManager.getAccountSelector();
try {
// Find all of the deletions
Cursor c = cr.query(Message.DELETED_CONTENT_URI, MAILBOX_DATA_PROJECTION, selector,
null, null);
if (c == null) throw new ProviderUnavailableException();
try {
// Keep track of which mailboxes to notify; we'll only notify each one once
while (c.moveToNext()) {
long mailboxId = c.getLong(0);
if (!mailboxesToNotify.contains(mailboxId)) {
mailboxesToNotify.add(mailboxId);
}
}
} finally {
c.close();
}
// Now, find changed messages
c = cr.query(Message.UPDATED_CONTENT_URI, MAILBOX_DATA_PROJECTION, selector,
null, null);
if (c == null) throw new ProviderUnavailableException();
try {
// Keep track of which mailboxes to notify; we'll only notify each one once
while (c.moveToNext()) {
long mailboxId = c.getLong(0);
if (!mailboxesToNotify.contains(mailboxId)) {
mailboxesToNotify.add(mailboxId);
}
}
} finally {
c.close();
}
// Request service from the mailbox
for (Long mailboxId: mailboxesToNotify) {
SyncManager.serviceRequest(mailboxId, SyncManager.SYNC_UPSYNC);
}
} catch (ProviderUnavailableException e) {
LogUtils.e("EmailSyncAlarmReceiver",
"EmailProvider unavailable; aborting alarm receiver");
}
}
}

View File

@ -1,120 +0,0 @@
/*
* Copyright (C) 2009 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.emailsync;
import android.content.Context;
import android.os.Environment;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
public class FileLogger {
private static FileLogger LOGGER = null;
private static FileWriter sLogWriter = null;
public static String LOG_FILE_NAME =
Environment.getExternalStorageDirectory() + "/emaillog.txt";
public synchronized static FileLogger getLogger (Context c) {
LOGGER = new FileLogger();
return LOGGER;
}
private FileLogger() {
try {
sLogWriter = new FileWriter(LOG_FILE_NAME, true);
} catch (IOException e) {
// Doesn't matter
}
}
static public synchronized void close() {
if (sLogWriter != null) {
try {
sLogWriter.close();
} catch (IOException e) {
// Doesn't matter
}
sLogWriter = null;
}
}
static public synchronized void log(Exception e) {
if (sLogWriter != null) {
log("Exception", "Stack trace follows...");
PrintWriter pw = new PrintWriter(sLogWriter);
e.printStackTrace(pw);
pw.flush();
}
}
@SuppressWarnings("deprecation")
static public synchronized void log(String prefix, String str) {
if (LOGGER == null) {
LOGGER = new FileLogger();
log("Logger", "\r\n\r\n --- New Log ---");
}
Date d = new Date();
int hr = d.getHours();
int min = d.getMinutes();
int sec = d.getSeconds();
// I don't use DateFormat here because (in my experience), it's much slower
StringBuffer sb = new StringBuffer(256);
sb.append('[');
sb.append(hr);
sb.append(':');
if (min < 10)
sb.append('0');
sb.append(min);
sb.append(':');
if (sec < 10) {
sb.append('0');
}
sb.append(sec);
sb.append("] ");
if (prefix != null) {
sb.append(prefix);
sb.append("| ");
}
sb.append(str);
sb.append("\r\n");
String s = sb.toString();
if (sLogWriter != null) {
try {
sLogWriter.write(s);
sLogWriter.flush();
} catch (IOException e) {
// Something might have happened to the sdcard
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
// If the card is mounted and we can create the writer, retry
LOGGER = new FileLogger();
if (sLogWriter != null) {
try {
log("FileLogger", "Exception writing log; recreating...");
log(prefix, str);
} catch (Exception e1) {
// Nothing to do at this point
}
}
}
}
}
}
}

View File

@ -1,42 +0,0 @@
/*
* Copyright (C) 2008-2009 Marc Blank
* Licensed to 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.emailsync;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
/**
* MailboxAlarmReceiver is used to "wake up" the ExchangeService at the appropriate time(s). It may
* also be used for individual sync adapters, but this isn't implemented at the present time.
*
*/
public class MailboxAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
long mailboxId = intent.getLongExtra("mailbox", SyncManager.EXTRA_MAILBOX_ID);
// EXCHANGE_SERVICE_MAILBOX_ID tells us that the service is asking to be started
if (mailboxId == SyncManager.SYNC_SERVICE_MAILBOX_ID) {
context.startService(new Intent(context, SyncManager.class));
} else {
SyncManager.alert(context, mailboxId);
}
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (C) 2010 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.emailsync;
import com.android.emailsync.Request;
/**
* MessageMoveRequest is the EAS wrapper for requesting a "move to folder"
*/
public class MessageMoveRequest extends Request {
public final long mMailboxId;
public MessageMoveRequest(long messageId, long mailboxId) {
super(messageId);
mMailboxId = mailboxId;
}
// MessageMoveRequests are unique by their message id (i.e. it's meaningless to have two
// separate message moves queued at the same time)
@Override
public boolean equals(Object o) {
if (!(o instanceof MessageMoveRequest)) return false;
return ((MessageMoveRequest)o).mMessageId == mMessageId;
}
@Override
public int hashCode() {
return (int)mMessageId;
}
}

View File

@ -1,38 +0,0 @@
/*
* Copyright (C) 2010 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.emailsync;
/**
* Requests for mailbox actions are handled by subclasses of this abstract class.
* Three subclasses are now defined: PartRequest (attachment load), MeetingResponseRequest
* (respond to a meeting invitation), and MessageMoveRequest (move a message to another folder)
*/
public abstract class Request {
public final long mTimeStamp = System.currentTimeMillis();
public final long mMessageId;
public Request(long messageId) {
mMessageId = messageId;
}
// Subclasses of Request may have different semantics regarding equality; therefore,
// we force them to implement the equals method
@Override
public abstract boolean equals(Object o);
@Override
public abstract int hashCode();
}

File diff suppressed because it is too large Load Diff