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
.authentication
.AccountUtils
;
28 import com
.owncloud
.android
.authentication
.AccountUtils
.AccountNotFoundException
;
29 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
30 import com
.owncloud
.android
.network
.OwnCloudClientUtils
;
31 import com
.owncloud
.android
.network
.webdav
.WebdavClient
;
33 import android
.accounts
.Account
;
34 import android
.accounts
.AccountManager
;
35 import android
.accounts
.AuthenticatorException
;
36 import android
.accounts
.OperationCanceledException
;
37 import android
.content
.AbstractThreadedSyncAdapter
;
38 import android
.content
.ContentProviderClient
;
39 import android
.content
.Context
;
42 * Base synchronization adapter for ownCloud designed to be subclassed for different
43 * resource types, like FileSync, ConcatsSync, CalendarSync, etc..
45 * Implements the standard {@link AbstractThreadedSyncAdapter}.
48 * @author David A. Velasco
50 public abstract class AbstractOwnCloudSyncAdapter
extends
51 AbstractThreadedSyncAdapter
{
53 private AccountManager accountManager
;
54 private Account account
;
55 private ContentProviderClient contentProvider
;
56 private FileDataStorageManager mStoreManager
;
58 private WebdavClient mClient
= null
;
60 public AbstractOwnCloudSyncAdapter(Context context
, boolean autoInitialize
) {
61 super(context
, autoInitialize
);
62 this.setAccountManager(AccountManager
.get(context
));
65 public AccountManager
getAccountManager() {
66 return accountManager
;
69 public void setAccountManager(AccountManager accountManager
) {
70 this.accountManager
= accountManager
;
73 public Account
getAccount() {
77 public void setAccount(Account account
) {
78 this.account
= account
;
81 public ContentProviderClient
getContentProvider() {
82 return contentProvider
;
85 public void setContentProvider(ContentProviderClient contentProvider
) {
86 this.contentProvider
= contentProvider
;
89 public void setStorageManager(FileDataStorageManager storage_manager
) {
90 mStoreManager
= storage_manager
;
93 public FileDataStorageManager
getStorageManager() {
97 protected void initClientForCurrentAccount() throws OperationCanceledException
, AuthenticatorException
, IOException
, AccountNotFoundException
{
98 AccountUtils
.constructFullURLForAccount(getContext(), account
);
99 mClient
= OwnCloudClientUtils
.createOwnCloudClient(account
, getContext());
102 protected WebdavClient
getClient() {
107 /* method called by ContactSyncAdapter, that is never used */
108 protected HttpResponse
fireRawRequest(HttpRequest query
)
109 throws ClientProtocolException
, OperationCanceledException
,
110 AuthenticatorException
, IOException
{