--- /dev/null
+/* ownCloud Android client application\r
+ * Copyright (C) 2011 Bartek Przybylski\r
+ * Copyright (C) 2012-2013 ownCloud Inc.\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License version 2,\r
+ * as published by the Free Software Foundation.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ */\r
+\r
+package com.owncloud.android.syncadapter;\r
+\r
+import java.io.IOException;\r
+import java.util.Date;\r
+\r
+import org.apache.http.HttpRequest;\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.client.ClientProtocolException;\r
+import org.apache.http.conn.ConnectionKeepAliveStrategy;\r
+import org.apache.http.protocol.HttpContext;\r
+\r
+import com.owncloud.android.authentication.AccountUtils;\r
+import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException;\r
+import com.owncloud.android.datamodel.DataStorageManager;\r
+import com.owncloud.android.network.OwnCloudClientUtils;\r
+\r
+\r
+import android.accounts.Account;\r
+import android.accounts.AccountManager;\r
+import android.accounts.AuthenticatorException;\r
+import android.accounts.OperationCanceledException;\r
+import android.content.AbstractThreadedSyncAdapter;\r
+import android.content.ContentProviderClient;\r
+import android.content.Context;\r
+import eu.alefzero.webdav.WebdavClient;\r
+\r
+/**\r
+ * Base SyncAdapter for OwnCloud Designed to be subclassed for the concrete\r
+ * SyncAdapter, like ConcatsSync, CalendarSync, FileSync etc..\r
+ * \r
+ * @author sassman\r
+ * \r
+ */\r
+public abstract class AbstractOwnCloudSyncAdapter extends\r
+ AbstractThreadedSyncAdapter {\r
+\r
+ private AccountManager accountManager;\r
+ private Account account;\r
+ private ContentProviderClient contentProvider;\r
+ private Date lastUpdated;\r
+ private DataStorageManager mStoreManager;\r
+\r
+ private WebdavClient mClient = null;\r
+\r
+ public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize) {\r
+ super(context, autoInitialize);\r
+ this.setAccountManager(AccountManager.get(context));\r
+ }\r
+\r
+ public AccountManager getAccountManager() {\r
+ return accountManager;\r
+ }\r
+\r
+ public void setAccountManager(AccountManager accountManager) {\r
+ this.accountManager = accountManager;\r
+ }\r
+\r
+ public Account getAccount() {\r
+ return account;\r
+ }\r
+\r
+ public void setAccount(Account account) {\r
+ this.account = account;\r
+ }\r
+\r
+ public ContentProviderClient getContentProvider() {\r
+ return contentProvider;\r
+ }\r
+\r
+ public void setContentProvider(ContentProviderClient contentProvider) {\r
+ this.contentProvider = contentProvider;\r
+ }\r
+\r
+ public Date getLastUpdated() {\r
+ return lastUpdated;\r
+ }\r
+\r
+ public void setLastUpdated(Date lastUpdated) {\r
+ this.lastUpdated = lastUpdated;\r
+ }\r
+\r
+ public void setStorageManager(DataStorageManager storage_manager) {\r
+ mStoreManager = storage_manager;\r
+ }\r
+\r
+ public DataStorageManager getStorageManager() {\r
+ return mStoreManager;\r
+ }\r
+\r
+ protected ConnectionKeepAliveStrategy getKeepAliveStrategy() {\r
+ return new ConnectionKeepAliveStrategy() {\r
+ public long getKeepAliveDuration(HttpResponse response,\r
+ HttpContext context) {\r
+ // Change keep alive straategy basing on response: ie\r
+ // forbidden/not found/etc\r
+ // should have keep alive 0\r
+ // default return: 5s\r
+ int statusCode = response.getStatusLine().getStatusCode();\r
+\r
+ // HTTP 400, 500 Errors as well as HTTP 118 - Connection timed\r
+ // out\r
+ if ((statusCode >= 400 && statusCode <= 418)\r
+ || (statusCode >= 421 && statusCode <= 426)\r
+ || (statusCode >= 500 && statusCode <= 510)\r
+ || statusCode == 118) {\r
+ return 0;\r
+ }\r
+\r
+ return 5 * 1000;\r
+ }\r
+ };\r
+ }\r
+\r
+ protected HttpResponse fireRawRequest(HttpRequest query)\r
+ throws ClientProtocolException, OperationCanceledException,\r
+ AuthenticatorException, IOException {\r
+ /*\r
+ * BasicHttpContext httpContext = new BasicHttpContext(); BasicScheme\r
+ * basicAuth = new BasicScheme();\r
+ * httpContext.setAttribute("preemptive-auth", basicAuth);\r
+ * \r
+ * HttpResponse response = getClient().execute(mHost, query,\r
+ * httpContext);\r
+ */\r
+ return null;\r
+ }\r
+\r
+ protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {\r
+ AccountUtils.constructFullURLForAccount(getContext(), account);\r
+ mClient = OwnCloudClientUtils.createOwnCloudClient(account, getContext());\r
+ }\r
+ \r
+ protected WebdavClient getClient() {\r
+ return mClient;\r
+ }\r
+}
\ No newline at end of file