1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.syncadapter
;
21 import java
.io
.IOException
;
23 import org
.apache
.http
.HttpRequest
;
24 import org
.apache
.http
.HttpResponse
;
25 import org
.apache
.http
.client
.ClientProtocolException
;
27 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
28 import com
.owncloud
.android
.oc_framework
.accounts
.AccountUtils
;
29 import com
.owncloud
.android
.oc_framework
.accounts
.AccountUtils
.AccountNotFoundException
;
30 import com
.owncloud
.android
.oc_framework
.network
.webdav
.OwnCloudClientFactory
;
31 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavClient
;
34 import android
.accounts
.Account
;
35 import android
.accounts
.AccountManager
;
36 import android
.accounts
.AuthenticatorException
;
37 import android
.accounts
.OperationCanceledException
;
38 import android
.content
.AbstractThreadedSyncAdapter
;
39 import android
.content
.ContentProviderClient
;
40 import android
.content
.Context
;
43 * Base synchronization adapter for ownCloud designed to be subclassed for different
44 * resource types, like FileSync, ConcatsSync, CalendarSync, etc..
46 * Implements the standard {@link AbstractThreadedSyncAdapter}.
49 * @author David A. Velasco
51 public abstract class AbstractOwnCloudSyncAdapter
extends
52 AbstractThreadedSyncAdapter
{
54 private AccountManager accountManager
;
55 private Account account
;
56 private ContentProviderClient mContentProviderClient
;
57 private FileDataStorageManager mStoreManager
;
59 private WebdavClient mClient
= null
;
61 public AbstractOwnCloudSyncAdapter(Context context
, boolean autoInitialize
) {
62 super(context
, autoInitialize
);
63 this.setAccountManager(AccountManager
.get(context
));
66 public AbstractOwnCloudSyncAdapter(Context context
, boolean autoInitialize
, boolean allowParallelSyncs
) {
67 super(context
, autoInitialize
, allowParallelSyncs
);
68 this.setAccountManager(AccountManager
.get(context
));
71 public AccountManager
getAccountManager() {
72 return accountManager
;
75 public void setAccountManager(AccountManager accountManager
) {
76 this.accountManager
= accountManager
;
79 public Account
getAccount() {
83 public void setAccount(Account account
) {
84 this.account
= account
;
87 public ContentProviderClient
getContentProviderClient() {
88 return mContentProviderClient
;
91 public void setContentProviderClient(ContentProviderClient contentProvider
) {
92 this.mContentProviderClient
= contentProvider
;
95 public void setStorageManager(FileDataStorageManager storage_manager
) {
96 mStoreManager
= storage_manager
;
99 public FileDataStorageManager
getStorageManager() {
100 return mStoreManager
;
103 protected void initClientForCurrentAccount() throws OperationCanceledException
, AuthenticatorException
, IOException
, AccountNotFoundException
{
104 AccountUtils
.constructFullURLForAccount(getContext(), account
);
105 mClient
= OwnCloudClientFactory
.createOwnCloudClient(account
, getContext());
108 protected WebdavClient
getClient() {
113 /* method called by ContactSyncAdapter, that is never used */
114 protected HttpResponse
fireRawRequest(HttpRequest query
)
115 throws ClientProtocolException
, OperationCanceledException
,
116 AuthenticatorException
, IOException
{