Support syncStatus and lastSyncResult in EmailProvider
* Also, trigger a sync on refreshUri Change-Id: Ia8dee593decfc2101873071ad64fcc3fd1fd5f23
This commit is contained in:
parent
fdf84f35bc
commit
1dc7772d43
@ -25,10 +25,11 @@ apache_src_dir := ../../UnifiedEmail/src/org
|
||||
|
||||
imported_unified_email_files := \
|
||||
$(unified_email_src_dir)/com/android/mail/utils/LogUtils.java \
|
||||
$(unified_email_src_dir)/com/android/mail/utils/LoggingInputStream.java
|
||||
$(unified_email_src_dir)/com/android/mail/utils/LoggingInputStream.java \
|
||||
$(unified_email_src_dir)/com/android/mail/providers/UIProvider.java
|
||||
|
||||
LOCAL_MODULE := com.android.emailcommon
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := guava
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := guava android-common
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src/com/android/emailcommon)
|
||||
LOCAL_SRC_FILES += \
|
||||
src/com/android/emailcommon/service/IEmailService.aidl \
|
||||
|
@ -32,6 +32,7 @@ import android.os.RemoteException;
|
||||
|
||||
import com.android.emailcommon.utility.TextUtilities;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
import com.android.mail.providers.UIProvider;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.io.File;
|
||||
@ -92,6 +93,10 @@ public abstract class EmailContent {
|
||||
public static final String ADD_COLUMN_NAME = "add";
|
||||
public static final String SET_COLUMN_NAME = "set";
|
||||
|
||||
public static final int SYNC_STATUS_NONE = UIProvider.SyncStatus.NO_SYNC;
|
||||
public static final int SYNC_STATUS_USER = UIProvider.SyncStatus.USER_REFRESH;
|
||||
public static final int SYNC_STATUS_BACKGROUND = UIProvider.SyncStatus.BACKGROUND_SYNC;
|
||||
|
||||
// Newly created objects get this id
|
||||
public static final int NOT_SAVED = -1;
|
||||
// The base Uri that this piece of content came from
|
||||
@ -1413,6 +1418,10 @@ public abstract class EmailContent {
|
||||
public static final String LAST_SEEN_MESSAGE_KEY = "lastSeenMessageKey";
|
||||
// The last time a message in this mailbox has been read (in millis)
|
||||
public static final String LAST_TOUCHED_TIME = "lastTouchedTime";
|
||||
// The UIProvider sync status
|
||||
public static final String UI_SYNC_STATUS = "uiSyncStatus";
|
||||
// The UIProvider last sync result
|
||||
public static final String UI_LAST_SYNC_RESULT = "uiLastSyncResult";
|
||||
}
|
||||
|
||||
public interface HostAuthColumns {
|
||||
|
@ -57,6 +57,8 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
|
||||
public String mSyncStatus;
|
||||
public long mLastSeenMessageKey;
|
||||
public long mLastTouchedTime;
|
||||
public int mUiSyncStatus;
|
||||
public int mUiLastSyncResult;
|
||||
|
||||
public static final int CONTENT_ID_COLUMN = 0;
|
||||
public static final int CONTENT_DISPLAY_NAME_COLUMN = 1;
|
||||
@ -76,6 +78,8 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
|
||||
public static final int CONTENT_PARENT_KEY_COLUMN = 15;
|
||||
public static final int CONTENT_LAST_SEEN_MESSAGE_KEY_COLUMN = 16;
|
||||
public static final int CONTENT_LAST_TOUCHED_TIME_COLUMN = 17;
|
||||
public static final int CONTENT_UI_SYNC_STATUS_COLUMN = 18;
|
||||
public static final int CONTENT_UI_LAST_SYNC_RESULT_COLUMN = 19;
|
||||
|
||||
/**
|
||||
* <em>NOTE</em>: If fields are added or removed, the method {@link #getHashes()}
|
||||
@ -89,6 +93,7 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
|
||||
MailboxColumns.FLAG_VISIBLE, MailboxColumns.FLAGS, MailboxColumns.VISIBLE_LIMIT,
|
||||
MailboxColumns.SYNC_STATUS, MailboxColumns.PARENT_KEY,
|
||||
MailboxColumns.LAST_SEEN_MESSAGE_KEY, MailboxColumns.LAST_TOUCHED_TIME,
|
||||
MailboxColumns.UI_SYNC_STATUS, MailboxColumns.UI_LAST_SYNC_RESULT
|
||||
};
|
||||
|
||||
private static final String ACCOUNT_AND_MAILBOX_TYPE_SELECTION =
|
||||
@ -308,6 +313,8 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
|
||||
mSyncStatus = cursor.getString(CONTENT_SYNC_STATUS_COLUMN);
|
||||
mLastSeenMessageKey = cursor.getLong(CONTENT_LAST_SEEN_MESSAGE_KEY_COLUMN);
|
||||
mLastTouchedTime = cursor.getLong(CONTENT_LAST_TOUCHED_TIME_COLUMN);
|
||||
mUiSyncStatus = cursor.getInt(CONTENT_UI_SYNC_STATUS_COLUMN);
|
||||
mUiLastSyncResult = cursor.getInt(CONTENT_UI_LAST_SYNC_RESULT_COLUMN);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -330,6 +337,8 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
|
||||
values.put(MailboxColumns.SYNC_STATUS, mSyncStatus);
|
||||
values.put(MailboxColumns.LAST_SEEN_MESSAGE_KEY, mLastSeenMessageKey);
|
||||
values.put(MailboxColumns.LAST_TOUCHED_TIME, mLastTouchedTime);
|
||||
values.put(MailboxColumns.UI_SYNC_STATUS, mUiSyncStatus);
|
||||
values.put(MailboxColumns.UI_LAST_SYNC_RESULT, mUiLastSyncResult);
|
||||
return values;
|
||||
}
|
||||
|
||||
@ -573,6 +582,8 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
|
||||
dest.writeString(mSyncStatus);
|
||||
dest.writeLong(mLastSeenMessageKey);
|
||||
dest.writeLong(mLastTouchedTime);
|
||||
dest.writeInt(mUiSyncStatus);
|
||||
dest.writeInt(mUiLastSyncResult);
|
||||
}
|
||||
|
||||
public Mailbox(Parcel in) {
|
||||
@ -595,6 +606,8 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
|
||||
mSyncStatus = in.readString();
|
||||
mLastSeenMessageKey = in.readLong();
|
||||
mLastTouchedTime = in.readLong();
|
||||
mUiSyncStatus = in.readInt();
|
||||
mUiLastSyncResult = in.readInt();
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<Mailbox> CREATOR = new Parcelable.Creator<Mailbox>() {
|
||||
|
@ -33,10 +33,6 @@ import com.android.emailcommon.CalendarProviderStub;
|
||||
import com.android.emailcommon.mail.Address;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.android.emailcommon.provider.Policy;
|
||||
import com.android.emailcommon.provider.QuickResponse;
|
||||
import com.android.emailcommon.provider.EmailContent.AccountColumns;
|
||||
import com.android.emailcommon.provider.EmailContent.Attachment;
|
||||
import com.android.emailcommon.provider.EmailContent.AttachmentColumns;
|
||||
@ -49,6 +45,10 @@ import com.android.emailcommon.provider.EmailContent.MessageColumns;
|
||||
import com.android.emailcommon.provider.EmailContent.PolicyColumns;
|
||||
import com.android.emailcommon.provider.EmailContent.QuickResponseColumns;
|
||||
import com.android.emailcommon.provider.EmailContent.SyncColumns;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.android.emailcommon.provider.Policy;
|
||||
import com.android.emailcommon.provider.QuickResponse;
|
||||
import com.android.emailcommon.service.LegacyPolicySet;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
@ -112,8 +112,9 @@ public final class DBHelper {
|
||||
// Version 28: Add notifiedMessageId and notifiedMessageCount to Account
|
||||
// Version 29: Add protocolPoliciesEnforced and protocolPoliciesUnsupported to Policy
|
||||
// Version 30: Use CSV of RFC822 addresses instead of "packed" values
|
||||
// Version 31: Add columns to mailbox for ui status/last result
|
||||
|
||||
public static final int DATABASE_VERSION = 30;
|
||||
public static final int DATABASE_VERSION = 31;
|
||||
|
||||
// Any changes to the database format *must* include update-in-place code.
|
||||
// Original version: 2
|
||||
@ -389,7 +390,9 @@ public final class DBHelper {
|
||||
+ MailboxColumns.SYNC_STATUS + " text, "
|
||||
+ MailboxColumns.MESSAGE_COUNT + " integer not null default 0, "
|
||||
+ MailboxColumns.LAST_SEEN_MESSAGE_KEY + " integer, "
|
||||
+ MailboxColumns.LAST_TOUCHED_TIME + " integer default 0"
|
||||
+ MailboxColumns.LAST_TOUCHED_TIME + " integer default 0, "
|
||||
+ MailboxColumns.UI_SYNC_STATUS + " integer default 0, "
|
||||
+ MailboxColumns.UI_LAST_SYNC_RESULT + " integer default 0"
|
||||
+ ");";
|
||||
db.execSQL("create table " + Mailbox.TABLE_NAME + s);
|
||||
db.execSQL("create index mailbox_" + MailboxColumns.SERVER_ID
|
||||
@ -806,6 +809,18 @@ public final class DBHelper {
|
||||
upgradeFromVersion29ToVersion30(db);
|
||||
oldVersion = 30;
|
||||
}
|
||||
if (oldVersion == 30) {
|
||||
try {
|
||||
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
||||
+ " add column " + Mailbox.UI_SYNC_STATUS + " integer;");
|
||||
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
||||
+ " add column " + Mailbox.UI_LAST_SYNC_RESULT + " integer;");
|
||||
} catch (SQLException e) {
|
||||
// Shouldn't be needed unless we're debugging and interrupt the process
|
||||
Log.w(TAG, "Exception upgrading EmailProvider.db from 30 to 31 " + e);
|
||||
}
|
||||
oldVersion = 31;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -200,7 +200,6 @@ public class EmailProvider extends ContentProvider {
|
||||
private static final int UI_UPDATEDRAFT = UI_BASE + 7;
|
||||
private static final int UI_SENDDRAFT = UI_BASE + 8;
|
||||
private static final int UI_FOLDER_REFRESH = UI_BASE + 9;
|
||||
private static final int UI_FOLDER_STATUS = UI_BASE + 10;
|
||||
private static final int UI_FOLDER = UI_BASE + 11;
|
||||
|
||||
// MUST ALWAYS EQUAL THE LAST OF THE PREVIOUS BASE CONSTANTS
|
||||
@ -404,7 +403,6 @@ public class EmailProvider extends ContentProvider {
|
||||
matcher.addURI(EmailContent.AUTHORITY, "uiupdatedraft/#", UI_UPDATEDRAFT);
|
||||
matcher.addURI(EmailContent.AUTHORITY, "uisenddraft/#", UI_SENDDRAFT);
|
||||
matcher.addURI(EmailContent.AUTHORITY, "uirefresh/#", UI_FOLDER_REFRESH);
|
||||
matcher.addURI(EmailContent.AUTHORITY, "uistatus/#", UI_FOLDER_STATUS);
|
||||
matcher.addURI(EmailContent.AUTHORITY, "uifolder/#", UI_FOLDER);
|
||||
}
|
||||
|
||||
@ -903,9 +901,6 @@ public class EmailProvider extends ContentProvider {
|
||||
private static final Uri UIPROVIDER_MESSAGE_NOTIFIER =
|
||||
Uri.parse("content://" + UIProvider.AUTHORITY + "/uimessages");
|
||||
|
||||
private static final Uri UIPROVIDER_MAILBOX_NOTIFIER =
|
||||
Uri.parse("content://" + UIProvider.AUTHORITY + "/uifolder");
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
int match = findMatch(uri, "insert");
|
||||
@ -1133,10 +1128,8 @@ public class EmailProvider extends ContentProvider {
|
||||
}
|
||||
c = uiQuery(match, uri, projection);
|
||||
return c;
|
||||
case UI_FOLDER_STATUS:
|
||||
return uiFolderStatus(uri);
|
||||
case UI_FOLDER_REFRESH:
|
||||
return uiFolderRefresh(uri);
|
||||
return uiFolderRefresh(uri, projection);
|
||||
case ACCOUNT_DEFAULT_ID:
|
||||
// Start with a snapshot of the cache
|
||||
Map<String, Cursor> accountCache = mCacheAccount.getSnapshot();
|
||||
@ -1661,6 +1654,7 @@ outer:
|
||||
// Notify all notifier cursors
|
||||
sendNotifierChange(getBaseNotificationUri(match), NOTIFICATION_OP_UPDATE, id);
|
||||
|
||||
resolver.notifyChange(uri, null);
|
||||
resolver.notifyChange(notificationUri, null);
|
||||
return result;
|
||||
}
|
||||
@ -1877,6 +1871,8 @@ outer:
|
||||
.add(UIProvider.FolderColumns.UNREAD_COUNT, MailboxColumns.UNREAD_COUNT)
|
||||
.add(UIProvider.FolderColumns.TOTAL_COUNT, MailboxColumns.MESSAGE_COUNT)
|
||||
.add(UIProvider.FolderColumns.REFRESH_URI, uriWithId("uirefresh"))
|
||||
.add(UIProvider.FolderColumns.SYNC_STATUS, MailboxColumns.UI_SYNC_STATUS)
|
||||
.add(UIProvider.FolderColumns.LAST_SYNC_RESULT, MailboxColumns.UI_LAST_SYNC_RESULT)
|
||||
.build();
|
||||
|
||||
/**
|
||||
@ -2457,12 +2453,7 @@ outer:
|
||||
}
|
||||
};
|
||||
|
||||
private Cursor uiFolderStatus(Uri uri) {
|
||||
// Will implement this when the status states are finalized
|
||||
return null;
|
||||
}
|
||||
|
||||
private Cursor uiFolderRefresh(Uri uri) {
|
||||
private Cursor uiFolderRefresh(Uri uri, String[] projection) {
|
||||
Context context = getContext();
|
||||
String idString = uri.getPathSegments().get(1);
|
||||
long id = Long.parseLong(idString);
|
||||
@ -2474,6 +2465,6 @@ outer:
|
||||
service.startSync(id, true);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
return uiFolderStatus(uri);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user