• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008-2009 Marc Blank
3  * Licensed to The Android Open Source Project.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.exchange.adapter;
19 
20 import com.android.email.provider.EmailContent.Account;
21 import com.android.email.provider.EmailContent.Mailbox;
22 import com.android.exchange.EasSyncService;
23 
24 import android.content.Context;
25 
26 import java.io.IOException;
27 import java.io.InputStream;
28 
29 /**
30  * Parent class of all sync adapters (EasMailbox, EasCalendar, and EasContacts)
31  *
32  */
33 public abstract class AbstractSyncAdapter {
34 
35     public static final int SECONDS = 1000;
36     public static final int MINUTES = SECONDS*60;
37     public static final int HOURS = MINUTES*60;
38     public static final int DAYS = HOURS*24;
39     public static final int WEEKS = DAYS*7;
40 
41     public Mailbox mMailbox;
42     public EasSyncService mService;
43     public Context mContext;
44     public Account mAccount;
45 
46     // Create the data for local changes that need to be sent up to the server
sendLocalChanges(Serializer s)47     public abstract boolean sendLocalChanges(Serializer s)
48         throws IOException;
49     // Parse incoming data from the EAS server, creating, modifying, and deleting objects as
50     // required through the EmailProvider
parse(InputStream is)51     public abstract boolean parse(InputStream is)
52         throws IOException;
53     // The name used to specify the collection type of the target (Email, Calendar, or Contacts)
getCollectionName()54     public abstract String getCollectionName();
cleanup()55     public abstract void cleanup();
56 
AbstractSyncAdapter(Mailbox mailbox, EasSyncService service)57     public AbstractSyncAdapter(Mailbox mailbox, EasSyncService service) {
58         mMailbox = mailbox;
59         mService = service;
60         mContext = service.mContext;
61         mAccount = service.mAccount;
62     }
63 
userLog(String ....strings)64     public void userLog(String ...strings) {
65         mService.userLog(strings);
66     }
67 
incrementChangeCount()68     public void incrementChangeCount() {
69         mService.mChangeCount++;
70     }
71 
72     /**
73      * Returns the current SyncKey; override if the SyncKey is stored elsewhere (as for Contacts)
74      * @return the current SyncKey for the Mailbox
75      * @throws IOException
76      */
getSyncKey()77     public String getSyncKey() throws IOException {
78         if (mMailbox.mSyncKey == null) {
79             userLog("Reset SyncKey to 0");
80             mMailbox.mSyncKey = "0";
81         }
82         return mMailbox.mSyncKey;
83     }
84 
setSyncKey(String syncKey, boolean inCommands)85     public void setSyncKey(String syncKey, boolean inCommands) throws IOException {
86         mMailbox.mSyncKey = syncKey;
87     }
88 }
89 
90