2009-07-05 19:54:49 +00:00
|
|
|
/*
|
|
|
|
* 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.exchange.adapter;
|
|
|
|
|
2009-08-13 16:32:58 +00:00
|
|
|
import com.android.email.provider.EmailContent.Account;
|
2009-07-23 22:31:28 +00:00
|
|
|
import com.android.email.provider.EmailContent.Mailbox;
|
|
|
|
import com.android.exchange.EasSyncService;
|
|
|
|
|
2009-08-13 16:32:58 +00:00
|
|
|
import android.content.Context;
|
|
|
|
|
2009-07-05 19:54:49 +00:00
|
|
|
import java.io.IOException;
|
2009-08-08 20:26:03 +00:00
|
|
|
import java.io.InputStream;
|
2009-07-05 19:54:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parent class of all sync adapters (EasMailbox, EasCalendar, and EasContacts)
|
|
|
|
*
|
|
|
|
*/
|
2009-07-31 01:17:52 +00:00
|
|
|
public abstract class AbstractSyncAdapter {
|
2009-08-17 21:07:47 +00:00
|
|
|
|
|
|
|
public static final int SECONDS = 1000;
|
|
|
|
public static final int MINUTES = SECONDS*60;
|
|
|
|
public static final int HOURS = MINUTES*60;
|
|
|
|
public static final int DAYS = HOURS*24;
|
|
|
|
public static final int WEEKS = DAYS*7;
|
|
|
|
|
2009-07-05 19:54:49 +00:00
|
|
|
public Mailbox mMailbox;
|
2009-07-27 17:24:58 +00:00
|
|
|
public EasSyncService mService;
|
2009-08-13 16:32:58 +00:00
|
|
|
public Context mContext;
|
|
|
|
public Account mAccount;
|
2009-07-05 19:54:49 +00:00
|
|
|
|
|
|
|
// Create the data for local changes that need to be sent up to the server
|
2009-08-23 23:04:32 +00:00
|
|
|
public abstract boolean sendLocalChanges(Serializer s)
|
2009-07-05 19:54:49 +00:00
|
|
|
throws IOException;
|
|
|
|
// Parse incoming data from the EAS server, creating, modifying, and deleting objects as
|
|
|
|
// required through the EmailProvider
|
2009-08-23 23:04:32 +00:00
|
|
|
public abstract boolean parse(InputStream is)
|
2009-07-05 19:54:49 +00:00
|
|
|
throws IOException;
|
|
|
|
// The name used to specify the collection type of the target (Email, Calendar, or Contacts)
|
|
|
|
public abstract String getCollectionName();
|
2009-08-23 23:04:32 +00:00
|
|
|
public abstract void cleanup();
|
2009-07-05 19:54:49 +00:00
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
public AbstractSyncAdapter(Mailbox mailbox, EasSyncService service) {
|
2009-07-05 19:54:49 +00:00
|
|
|
mMailbox = mailbox;
|
2009-07-27 17:24:58 +00:00
|
|
|
mService = service;
|
2009-08-13 16:32:58 +00:00
|
|
|
mContext = service.mContext;
|
|
|
|
mAccount = service.mAccount;
|
|
|
|
}
|
|
|
|
|
2009-08-23 23:04:32 +00:00
|
|
|
public void userLog(String ...strings) {
|
2009-08-13 16:32:58 +00:00
|
|
|
mService.userLog(strings);
|
|
|
|
}
|
|
|
|
|
2009-08-23 23:04:32 +00:00
|
|
|
public void incrementChangeCount() {
|
2009-08-13 16:32:58 +00:00
|
|
|
mService.mChangeCount++;
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
2009-08-23 23:04:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current SyncKey; override if the SyncKey is stored elsewhere (as for Contacts)
|
|
|
|
* @return the current SyncKey for the Mailbox
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
|
|
|
public String getSyncKey() throws IOException {
|
|
|
|
if (mMailbox.mSyncKey == null) {
|
|
|
|
userLog("Reset SyncKey to 0");
|
|
|
|
mMailbox.mSyncKey = "0";
|
|
|
|
}
|
|
|
|
return mMailbox.mSyncKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSyncKey(String syncKey, boolean inCommands) throws IOException {
|
|
|
|
mMailbox.mSyncKey = syncKey;
|
|
|
|
}
|
2009-07-05 19:54:49 +00:00
|
|
|
}
|
|
|
|
|