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