Merge branch 'develop' into update_propfind_for_server_8.1
[pub/Android/ownCloud.git] / src / com / owncloud / android / syncadapter / AbstractOwnCloudSyncAdapter.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author sassman
5 * @author David A. Velasco
6 * Copyright (C) 2011 Bartek Przybylski
7 * Copyright (C) 2015 ownCloud Inc.
8 *
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.
12 *
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.
17 *
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/>.
20 *
21 */
22
23 package com.owncloud.android.syncadapter;
24
25 import java.io.IOException;
26
27 import org.apache.http.HttpRequest;
28 import org.apache.http.HttpResponse;
29 import org.apache.http.client.ClientProtocolException;
30
31 import com.owncloud.android.datamodel.FileDataStorageManager;
32 import com.owncloud.android.lib.common.accounts.AccountUtils;
33 import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
34 import com.owncloud.android.lib.common.OwnCloudAccount;
35 import com.owncloud.android.lib.common.OwnCloudClient;
36 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
37
38 import android.accounts.Account;
39 import android.accounts.AccountManager;
40 import android.accounts.AuthenticatorException;
41 import android.accounts.OperationCanceledException;
42 import android.content.AbstractThreadedSyncAdapter;
43 import android.content.ContentProviderClient;
44 import android.content.Context;
45
46 /**
47 * Base synchronization adapter for ownCloud designed to be subclassed for different
48 * resource types, like FileSync, ConcatsSync, CalendarSync, etc..
49 *
50 * Implements the standard {@link AbstractThreadedSyncAdapter}.
51 */
52 public abstract class AbstractOwnCloudSyncAdapter extends
53 AbstractThreadedSyncAdapter {
54
55 private AccountManager accountManager;
56 private Account account;
57 private ContentProviderClient mContentProviderClient;
58 private FileDataStorageManager mStoreManager;
59
60 private OwnCloudClient mClient = null;
61
62 public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize) {
63 super(context, autoInitialize);
64 this.setAccountManager(AccountManager.get(context));
65 }
66
67 public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) {
68 super(context, autoInitialize, allowParallelSyncs);
69 this.setAccountManager(AccountManager.get(context));
70 }
71
72 public AccountManager getAccountManager() {
73 return accountManager;
74 }
75
76 public void setAccountManager(AccountManager accountManager) {
77 this.accountManager = accountManager;
78 }
79
80 public Account getAccount() {
81 return account;
82 }
83
84 public void setAccount(Account account) {
85 this.account = account;
86 }
87
88 public ContentProviderClient getContentProviderClient() {
89 return mContentProviderClient;
90 }
91
92 public void setContentProviderClient(ContentProviderClient contentProvider) {
93 this.mContentProviderClient = contentProvider;
94 }
95
96 public void setStorageManager(FileDataStorageManager storage_manager) {
97 mStoreManager = storage_manager;
98 }
99
100 public FileDataStorageManager getStorageManager() {
101 return mStoreManager;
102 }
103
104 protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {
105 AccountUtils.constructFullURLForAccount(getContext(), account);
106 OwnCloudAccount ocAccount = new OwnCloudAccount(account, getContext());
107 mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
108 getClientFor(ocAccount, getContext());
109 }
110
111 protected OwnCloudClient getClient() {
112 return mClient;
113 }
114
115
116 /* method called by ContactSyncAdapter, that is never used */
117 protected HttpResponse fireRawRequest(HttpRequest query)
118 throws ClientProtocolException, OperationCanceledException,
119 AuthenticatorException, IOException {
120 return null;
121 }
122
123 }