2 * ownCloud Android client application
5 * @author David A. Velasco
6 * Copyright (C) 2011 Bartek Przybylski
7 * Copyright (C) 2015 ownCloud Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 package com
.owncloud
.android
.syncadapter
;
25 import java
.io
.IOException
;
27 import org
.apache
.http
.HttpRequest
;
28 import org
.apache
.http
.HttpResponse
;
29 import org
.apache
.http
.client
.ClientProtocolException
;
31 import com
.owncloud
.android
.MainApp
;
32 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
33 import com
.owncloud
.android
.lib
.common
.accounts
.AccountUtils
;
34 import com
.owncloud
.android
.lib
.common
.accounts
.AccountUtils
.AccountNotFoundException
;
35 import com
.owncloud
.android
.lib
.common
.OwnCloudAccount
;
36 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
37 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
39 import android
.accounts
.Account
;
40 import android
.accounts
.AccountManager
;
41 import android
.accounts
.AuthenticatorException
;
42 import android
.accounts
.OperationCanceledException
;
43 import android
.content
.AbstractThreadedSyncAdapter
;
44 import android
.content
.ContentProviderClient
;
45 import android
.content
.Context
;
48 * Base synchronization adapter for ownCloud designed to be subclassed for different
49 * resource types, like FileSync, ConcatsSync, CalendarSync, etc..
51 * Implements the standard {@link AbstractThreadedSyncAdapter}.
53 public abstract class AbstractOwnCloudSyncAdapter
extends
54 AbstractThreadedSyncAdapter
{
56 private AccountManager accountManager
;
57 private Account account
;
58 private ContentProviderClient mContentProviderClient
;
59 private FileDataStorageManager mStoreManager
;
61 private OwnCloudClient mClient
= null
;
63 public AbstractOwnCloudSyncAdapter(Context context
, boolean autoInitialize
) {
64 super(context
, autoInitialize
);
65 this.setAccountManager(AccountManager
.get(context
));
68 public AbstractOwnCloudSyncAdapter(Context context
, boolean autoInitialize
,
69 boolean allowParallelSyncs
) {
70 super(context
, autoInitialize
, allowParallelSyncs
);
71 this.setAccountManager(AccountManager
.get(context
));
74 public AccountManager
getAccountManager() {
75 return accountManager
;
78 public void setAccountManager(AccountManager accountManager
) {
79 this.accountManager
= accountManager
;
82 public Account
getAccount() {
86 public void setAccount(Account account
) {
87 this.account
= account
;
90 public ContentProviderClient
getContentProviderClient() {
91 return mContentProviderClient
;
94 public void setContentProviderClient(ContentProviderClient contentProvider
) {
95 this.mContentProviderClient
= contentProvider
;
98 public void setStorageManager(FileDataStorageManager storage_manager
) {
99 mStoreManager
= storage_manager
;
102 public FileDataStorageManager
getStorageManager() {
103 return mStoreManager
;
106 protected void initClientForCurrentAccount() throws OperationCanceledException
,
107 AuthenticatorException
, IOException
, AccountNotFoundException
{
108 AccountUtils
.constructFullURLForAccount(getContext(), account
);
109 OwnCloudAccount ocAccount
= new OwnCloudAccount(account
, getContext());
110 mClient
= OwnCloudClientManagerFactory
.getDefaultSingleton().
111 getClientFor(ocAccount
, getContext());
114 protected OwnCloudClient
getClient() {
119 /* method called by ContactSyncAdapter, that is never used */
120 protected HttpResponse
fireRawRequest(HttpRequest query
)
121 throws ClientProtocolException
, OperationCanceledException
,
122 AuthenticatorException
, IOException
{