<string name="sync_string_contacts">Contacts</string>
<string name="sync_fail_ticker">Synchronization failed</string>
<string name="sync_fail_content">Synchronization of %1$s could not be completed</string>
+ <string name="sync_conflicts_in_favourites_ticker">Conflicts found</string>
+ <string name="sync_conflicts_in_favourites_content">%1$d kept-in-sync files could not be sync\'ed</string>
+ <string name="sync_fail_in_favourites_ticker">Kept-in-sync files failed</string>
+ <string name="sync_fail_in_favourites_content">Contents of %1$d files could not be sync\'ed (%2$d conflicts)</string>
<string name="use_ssl">Use Secure Connection</string>
<string name="location_no_provider">ownCloud cannot track your device. Please check your location settings</string>
return;
}
WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mOCAccount, mContext);
- SynchronizeFileOperation sfo = new SynchronizeFileOperation(mFile, mStorage, mOCAccount, true, false, mContext);
+ SynchronizeFileOperation sfo = new SynchronizeFileOperation(mFile, null, mStorage, mOCAccount, true, false, mContext);
RemoteOperationResult result = sfo.execute(wc);
for (FileObserverStatusListener l : mListeners) {
l.onObservedFileStatusUpdate(mPath, getRemotePath(), mOCAccount, result);
mPendingDownloads.putIfAbsent(downloadKey, newDownload);\r
newDownload.addDatatransferProgressListener(this);\r
requestedDownloads.add(downloadKey);\r
+ sendBroadcastNewDownload(newDownload);\r
\r
} catch (IllegalArgumentException e) {\r
Log.e(TAG, "Not enough information provided in intent: " + e.getMessage());\r
/// notify result\r
notifyDownloadResult(mCurrentDownload, downloadResult);\r
\r
- sendFinalBroadcast(mCurrentDownload, downloadResult);\r
+ sendBroadcastDownloadFinished(mCurrentDownload, downloadResult);\r
}\r
}\r
\r
\r
\r
/**\r
- * Sends a broadcast in order to the interested activities can update their view\r
+ * Sends a broadcast when a download finishes in order to the interested activities can update their view\r
* \r
* @param download Finished download operation\r
* @param downloadResult Result of the download operation\r
*/\r
- private void sendFinalBroadcast(DownloadFileOperation download, RemoteOperationResult downloadResult) {\r
+ private void sendBroadcastDownloadFinished(DownloadFileOperation download, RemoteOperationResult downloadResult) {\r
Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE);\r
end.putExtra(EXTRA_DOWNLOAD_RESULT, downloadResult.isSuccess());\r
end.putExtra(ACCOUNT_NAME, download.getAccount().name);\r
end.putExtra(EXTRA_FILE_PATH, download.getSavePath());\r
sendBroadcast(end);\r
}\r
+ \r
+ \r
+ /**\r
+ * Sends a broadcast when a new download is added to the queue.\r
+ * \r
+ * @param download Added download operation\r
+ */\r
+ private void sendBroadcastNewDownload(DownloadFileOperation download) {\r
+ Intent end = new Intent(DOWNLOAD_ADDED_MESSAGE);\r
+ /*end.putExtra(ACCOUNT_NAME, download.getAccount().name);\r
+ end.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());*/\r
+ end.putExtra(EXTRA_FILE_PATH, download.getSavePath());\r
+ sendBroadcast(end);\r
+ }\r
\r
}\r
package com.owncloud.android.files.services;
import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.OwnCloudFileObserver.FileObserverStatusListener;
import com.owncloud.android.operations.RemoteOperationResult;
import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.ui.activity.ConflictsResolveActivity;
import com.owncloud.android.utils.FileStorageUtils;
public class FileObserverService extends Service implements FileObserverStatusListener {
- public final static String KEY_FILE_CMD = "KEY_FILE_CMD";
- public final static String KEY_CMD_ARG_FILE = "KEY_CMD_ARG_FILE";
- public final static String KEY_CMD_ARG_ACCOUNT = "KEY_CMD_ARG_ACCOUNT";
-
public final static int CMD_INIT_OBSERVED_LIST = 1;
public final static int CMD_ADD_OBSERVED_FILE = 2;
public final static int CMD_DEL_OBSERVED_FILE = 3;
- public final static int CMD_ADD_DOWNLOADING_FILE = 4;
+
+ public final static String KEY_FILE_CMD = "KEY_FILE_CMD";
+ public final static String KEY_CMD_ARG_FILE = "KEY_CMD_ARG_FILE";
+ public final static String KEY_CMD_ARG_ACCOUNT = "KEY_CMD_ARG_ACCOUNT";
private static String TAG = FileObserverService.class.getSimpleName();
- private static List<OwnCloudFileObserver> mObservers;
- private static List<DownloadCompletedReceiver> mDownloadReceivers;
- private static Object mReceiverListLock = new Object();
+
+ private static Map<String, OwnCloudFileObserver> mObserversMap;
+ private static DownloadCompletedReceiverBis mDownloadReceiver;
private IBinder mBinder = new LocalBinder();
public class LocalBinder extends Binder {
}
@Override
+ public void onCreate() {
+ super.onCreate();
+ mDownloadReceiver = new DownloadCompletedReceiverBis();
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(FileDownloader.DOWNLOAD_ADDED_MESSAGE);
+ filter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE);
+ registerReceiver(mDownloadReceiver, filter);
+
+ mObserversMap = new HashMap<String, OwnCloudFileObserver>();
+ initializeObservedList();
+ }
+
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ unregisterReceiver(mDownloadReceiver);
+ mObserversMap = null; // TODO study carefully the life cycle of Services to grant the best possible observance
+ }
+
+
+ @Override
public IBinder onBind(Intent intent) {
return mBinder;
}
removeObservedFile( (OCFile)intent.getParcelableExtra(KEY_CMD_ARG_FILE),
(Account)intent.getParcelableExtra(KEY_CMD_ARG_ACCOUNT));
break;
- case CMD_ADD_DOWNLOADING_FILE:
- addDownloadingFile( (OCFile)intent.getParcelableExtra(KEY_CMD_ARG_FILE),
- (Account)intent.getParcelableExtra(KEY_CMD_ARG_ACCOUNT));
- break;
default:
Log.wtf(TAG, "Incorrect key given");
}
return Service.START_STICKY;
}
+
+ /**
+ * Read from the local database the list of files that must to be kept synchronized and
+ * starts file observers to monitor local changes on them
+ */
private void initializeObservedList() {
- if (mObservers != null) return; // nothing to do here
- mObservers = new ArrayList<OwnCloudFileObserver>();
- mDownloadReceivers = new ArrayList<DownloadCompletedReceiver>();
+ mObserversMap.clear();
Cursor c = getContentResolver().query(
ProviderTableMeta.CONTENT_URI,
null,
observer.setStorageManager(storage);
observer.setOCFile(storage.getFileByPath(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH))));
observer.addObserverStatusListener(this);
- observer.startWatching();
- mObservers.add(observer);
- Log.d(TAG, "Started watching file " + path);
+ mObserversMap.put(path, observer);
+ if (new File(path).exists()) {
+ observer.startWatching();
+ Log.d(TAG, "Started watching file " + path);
+ }
} while (c.moveToNext());
c.close();
/**
* Registers the local copy of a remote file to be observed for local changes,
* an automatically updated in the ownCloud server.
+ *
+ * This method does NOT perform a {@link SynchronizeFileOperation} over the file.
*
+ * TODO We are ignoring that, currently, a local file can be linked to different files
+ * in ownCloud if it's uploaded several times. That's something pending to update: we
+ * will avoid that the same local file is linked to different remote files.
+ *
* @param file Object representing a remote file which local copy must be observed.
* @param account OwnCloud account containing file.
*/
private void addObservedFile(OCFile file, Account account) {
if (file == null) {
- Log.e(TAG, "Trying to observe a NULL file");
+ Log.e(TAG, "Trying to add a NULL file to observer");
return;
}
- if (mObservers == null) {
- // this is very rare case when service was killed by system
- // and observers list was deleted in that procedure
- initializeObservedList();
- }
String localPath = file.getStoragePath();
- if (!file.isDown()) {
- // this is a file downloading / to be download for the first time
+ if (localPath == null || localPath.length() <= 0) { // file downloading / to be download for the first time
localPath = FileStorageUtils.getDefaultSavePathFor(account.name, file);
}
- OwnCloudFileObserver tmpObserver = null, observer = null;
- for (int i = 0; i < mObservers.size(); ++i) {
- tmpObserver = mObservers.get(i);
- if (tmpObserver.getPath().equals(localPath)) {
- observer = tmpObserver;
- }
- tmpObserver.setContext(getApplicationContext()); // 'refreshing' context to all the observers? why?
- }
+ OwnCloudFileObserver observer = mObserversMap.get(localPath);
if (observer == null) {
/// the local file was never registered to observe before
observer = new OwnCloudFileObserver(localPath, OwnCloudFileObserver.CHANGES_ONLY);
observer.setOCFile(file);
observer.addObserverStatusListener(this);
observer.setContext(getApplicationContext());
-
- } else {
- /* LET'S IGNORE THAT, CURRENTLY, A LOCAL FILE CAN BE LINKED TO DIFFERENT FILES IN OWNCLOUD;
- * we should change that
- *
- /// the local file is already observed for some other OCFile(s)
- observer.addOCFile(account, file); // OCFiles should have a reference to the account containing them to not be confused
- */
- }
- mObservers.add(observer);
- Log.d(TAG, "Observer added for path " + localPath);
+ mObserversMap.put(localPath, observer);
+ Log.d(TAG, "Observer added for path " + localPath);
- if (!file.isDown()) {
- // if the file is not down, it can't be observed for changes
- DownloadCompletedReceiver receiver = new DownloadCompletedReceiver(localPath, observer);
- registerReceiver(receiver, new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE));
-
- } else {
- observer.startWatching();
- Log.d(TAG, "Started watching " + localPath);
-
+ if (file.isDown()) {
+ observer.startWatching();
+ Log.d(TAG, "Started watching " + localPath);
+ } // else - the observance can't be started on a file not already down; mDownloadReceiver will get noticed when the download of the file finishes
}
}
/**
* Unregisters the local copy of a remote file to be observed for local changes.
*
+ * Starts to watch it, if the file has a local copy to watch.
+ *
+ * TODO We are ignoring that, currently, a local file can be linked to different files
+ * in ownCloud if it's uploaded several times. That's something pending to update: we
+ * will avoid that the same local file is linked to different remote files.
+ *
* @param file Object representing a remote file which local copy must be not observed longer.
* @param account OwnCloud account containing file.
*/
private void removeObservedFile(OCFile file, Account account) {
if (file == null) {
- Log.e(TAG, "Trying to unobserve a NULL file");
+ Log.e(TAG, "Trying to remove a NULL file");
return;
}
- if (mObservers == null) {
- initializeObservedList();
- }
String localPath = file.getStoragePath();
- if (!file.isDown()) {
- // this happens when a file not in the device is set to be kept synchronized, and quickly unset again,
- // while the download is not finished
+ if (localPath == null || localPath.length() <= 0) {
localPath = FileStorageUtils.getDefaultSavePathFor(account.name, file);
}
- for (int i = 0; i < mObservers.size(); ++i) {
- OwnCloudFileObserver observer = mObservers.get(i);
- if (observer.getPath().equals(localPath)) {
- observer.stopWatching();
- mObservers.remove(i); // assuming, again, that a local file can be only linked to only ONE remote file; currently false
- if (!file.isDown()) {
- // TODO unregister download receiver ;forget this until list of receivers is replaced for a single receiver
- }
- Log.d(TAG, "Stopped watching " + localPath);
- break;
- }
+ OwnCloudFileObserver observer = mObserversMap.get(localPath);
+ if (observer != null) {
+ observer.stopWatching();
+ mObserversMap.remove(observer);
+ Log.d(TAG, "Stopped watching " + localPath);
}
}
- /**
- * Temporarily disables the observance of a file that is going to be download.
- *
- * @param file Object representing the remote file which local copy must not be observed temporarily.
- * @param account OwnCloud account containing file.
- */
- private void addDownloadingFile(OCFile file, Account account) {
- OwnCloudFileObserver observer = null;
- for (OwnCloudFileObserver o : mObservers) {
- if (o.getRemotePath().equals(file.getRemotePath()) && o.getAccount().equals(account)) {
- observer = o;
- break;
- }
- }
- if (observer == null) {
- Log.e(TAG, "Couldn't find observer for remote file " + file.getRemotePath());
- return;
- }
- observer.stopWatching();
- DownloadCompletedReceiver dcr = new DownloadCompletedReceiver(observer.getPath(), observer);
- registerReceiver(dcr, new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE));
- }
-
-
- private static void addReceiverToList(DownloadCompletedReceiver r) {
- synchronized(mReceiverListLock) {
- mDownloadReceivers.add(r);
- }
- }
-
- private static void removeReceiverFromList(DownloadCompletedReceiver r) {
- synchronized(mReceiverListLock) {
- mDownloadReceivers.remove(r);
- }
- }
-
@Override
public void onObservedFileStatusUpdate(String localPath, String remotePath, Account account, RemoteOperationResult result) {
if (!result.isSuccess()) {
}
} // else, nothing else to do; now it's duty of FileUploader service
}
+
+
- private class DownloadCompletedReceiver extends BroadcastReceiver {
- String mPath;
- OwnCloudFileObserver mObserver;
-
- public DownloadCompletedReceiver(String path, OwnCloudFileObserver observer) {
- mPath = path;
- mObserver = observer;
- addReceiverToList(this);
- }
+ /**
+ * Private receiver listening to events broadcast by the FileDownloader service.
+ *
+ * Starts and stops the observance on registered files when they are being download,
+ * in order to avoid to start unnecessary synchronizations.
+ */
+ private class DownloadCompletedReceiverBis extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- if (mPath.equals(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH))) {
- if ((new File(mPath)).exists()) {
- // the download could be successful, or not; in both cases, the file could be down, due to a former download or upload
- context.unregisterReceiver(this);
- removeReceiverFromList(this);
- mObserver.startWatching();
- Log.d(TAG, "Started watching " + mPath);
- return;
- } // else - keep waiting for a future retry of the download ;
- // mObserver.startWatching() won't ever work if the file is not in the device when it's called
+ String downloadPath = intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH);
+ OwnCloudFileObserver observer = mObserversMap.get(downloadPath);
+ if (observer != null) {
+ if (intent.getAction().equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE) &&
+ new File(downloadPath).exists()) { // the download could be successful, or not; in both cases, the file could be down, due to a former download or upload
+ observer.startWatching();
+ Log.d(TAG, "Watching again " + downloadPath);
+
+ } else if (intent.getAction().equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) {
+ observer.stopWatching();
+ Log.d(TAG, "Disabling observance of " + downloadPath);
+ }
}
}
- @Override
- public boolean equals(Object o) {
- if (o instanceof DownloadCompletedReceiver)
- return mPath.equals(((DownloadCompletedReceiver)o).mPath);
- return super.equals(o);
- }
}
+
}
private String TAG = SynchronizeFileOperation.class.getSimpleName();
//private String mRemotePath;
private OCFile mLocalFile;
+ private OCFile mServerFile;
private DataStorageManager mStorageManager;
private Account mAccount;
private boolean mSyncFileContents;
private boolean mTransferWasRequested = false;
public SynchronizeFileOperation(
- OCFile localFile,
- DataStorageManager dataStorageManager,
+ OCFile localFile,
+ OCFile serverFile, // make this null to let the operation checks the server; added to reuse info from SynchronizeFolderOperation
+ DataStorageManager storageManager,
Account account,
boolean syncFileContents,
- boolean localChangeAlreadyKnown,
+ boolean localChangeAlreadyKnown,
Context context) {
- //mRemotePath = remotePath;
mLocalFile = localFile;
- mStorageManager = dataStorageManager;
+ mServerFile = serverFile;
+ mStorageManager = storageManager;
mAccount = account;
mSyncFileContents = syncFileContents;
mLocalChangeAlreadyKnown = localChangeAlreadyKnown;
mContext = context;
}
-
+
@Override
protected RemoteOperationResult run(WebdavClient client) {
} else {
/// local copy in the device -> need to think a bit more before do anything
- propfind = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(mLocalFile.getRemotePath()));
- int status = client.executeMethod(propfind);
- boolean isMultiStatus = status == HttpStatus.SC_MULTI_STATUS;
- if (isMultiStatus) {
- MultiStatus resp = propfind.getResponseBodyAsMultiStatus();
- WebdavEntry we = new WebdavEntry(resp.getResponses()[0],
+ if (mServerFile == null) {
+ /// take the duty of check the server for the current state of the file there
+ propfind = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(mLocalFile.getRemotePath()));
+ int status = client.executeMethod(propfind);
+ boolean isMultiStatus = status == HttpStatus.SC_MULTI_STATUS;
+ if (isMultiStatus) {
+ MultiStatus resp = propfind.getResponseBodyAsMultiStatus();
+ WebdavEntry we = new WebdavEntry(resp.getResponses()[0],
client.getBaseUri().getPath());
- OCFile serverFile = fillOCFile(we);
+ mServerFile = fillOCFile(we);
+
+ } else {
+ client.exhaustResponse(propfind.getResponseBodyAsStream());
+ result = new RemoteOperationResult(false, status);
+ }
+ }
+
+ if (result == null) { // true if the server was not checked, or nothing was wrong with the remote request
/// check changes in server and local file
boolean serverChanged = false;
- if (serverFile.getEtag() != null) {
- serverChanged = (!serverFile.getEtag().equals(mLocalFile.getEtag())); // TODO could this be dangerous when the user upgrades the server from non-tagged to tagged?
+ if (mServerFile.getEtag() != null) {
+ serverChanged = (!mServerFile.getEtag().equals(mLocalFile.getEtag())); // TODO could this be dangerous when the user upgrades the server from non-tagged to tagged?
} else {
// server without etags
- serverChanged = (serverFile.getModificationTimestamp() > mLocalFile.getModificationTimestamp());
+ serverChanged = (mServerFile.getModificationTimestamp() > mLocalFile.getModificationTimestamp());
}
boolean localChanged = (mLocalChangeAlreadyKnown || mLocalFile.getLocalModificationTimestamp() > mLocalFile.getLastSyncDateForData());
// TODO this will be always true after the app is upgraded to database version 3; will result in unnecessary uploads
/// decide action to perform depending upon changes
if (localChanged && serverChanged) {
- // conflict
result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
} else if (localChanged) {
// the update of local data will be done later by the FileUploader service when the upload finishes
} else {
// TODO CHECK: is this really useful in some point in the code?
- serverFile.setKeepInSync(mLocalFile.keepInSync());
- serverFile.setParentId(mLocalFile.getParentId());
- mStorageManager.saveFile(serverFile);
+ mServerFile.setKeepInSync(mLocalFile.keepInSync());
+ mServerFile.setParentId(mLocalFile.getParentId());
+ mStorageManager.saveFile(mServerFile);
}
result = new RemoteOperationResult(ResultCode.OK);
result = new RemoteOperationResult(ResultCode.OK);
}
- } else {
- client.exhaustResponse(propfind.getResponseBodyAsStream());
- result = new RemoteOperationResult(false, status);
- }
+ }
}
import android.accounts.Account;
import android.content.Context;
-import android.content.Intent;
import android.util.Log;
import com.owncloud.android.datamodel.DataStorageManager;
import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.services.FileDownloader;
-import com.owncloud.android.files.services.FileObserverService;
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.utils.FileStorageUtils;
import eu.alefzero.webdav.WebdavClient;
/** Files and folders contained in the synchronized folder */
private List<OCFile> mChildren;
+
+ private int mConflictsFound;
+
+ private int mFailsInFavouritesFound;
public SynchronizeFolderOperation( String remotePath,
}
+ public int getConflictsFound() {
+ return mConflictsFound;
+ }
+
+ public int getFailsInFavouritesFound() {
+ return mFailsInFavouritesFound;
+ }
+
/**
* Returns the list of files and folders contained in the synchronized folder, if called after synchronization is complete.
*
@Override
protected RemoteOperationResult run(WebdavClient client) {
RemoteOperationResult result = null;
+ mFailsInFavouritesFound = 0;
+ mConflictsFound = 0;
// code before in FileSyncAdapter.fetchData
PropFindMethod query = null;
if (mParentId == DataStorageManager.ROOT_PARENT_ID) {
WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getBaseUri().getPath());
OCFile parent = fillOCFile(we);
- parent.setParentId(mParentId);
mStorageManager.saveFile(parent);
mParentId = parent.getFileId();
}
// read contents in folder
List<OCFile> updatedFiles = new Vector<OCFile>(resp.getResponses().length - 1);
+ List<SynchronizeFileOperation> filesToSyncContents = new Vector<SynchronizeFileOperation>();
for (int i = 1; i < resp.getResponses().length; ++i) {
WebdavEntry we = new WebdavEntry(resp.getResponses()[i], client.getBaseUri().getPath());
OCFile file = fillOCFile(we);
- file.setParentId(mParentId);
OCFile oldFile = mStorageManager.getFileByPath(file.getRemotePath());
if (oldFile != null) {
- if (oldFile.keepInSync() && file.getModificationTimestamp() > oldFile.getModificationTimestamp()) {
- disableObservance(file); // first disable observer so we won't get file upload right after download
- requestContentDownload(file);
- }
file.setKeepInSync(oldFile.keepInSync());
+ file.setLastSyncDateForData(oldFile.getLastSyncDateForData());
+ if (file.keepInSync()) {
+ //disableObservance(file); // first disable observer so we won't get file upload right after download
+ // // now, the FileDownloader service sends a broadcast before start a download; the FileObserverService is listening for it
+ //requestFileSynchronization(file, oldFile, client);
+ SynchronizeFileOperation operation = new SynchronizeFileOperation( oldFile,
+ file,
+ mStorageManager,
+ mAccount,
+ true,
+ false,
+ mContext
+ );
+ filesToSyncContents.add(operation);
+ }
}
updatedFiles.add(file);
// save updated contents in local database; all at once, trying to get a best performance in database update (not a big deal, indeed)
mStorageManager.saveFiles(updatedFiles);
-
+ // request for the synchronization of files AFTER saving last properties
+ SynchronizeFileOperation op = null;
+ RemoteOperationResult contentsResult = null;
+ for (int i=0; i < filesToSyncContents.size(); i++) {
+ op = filesToSyncContents.get(i);
+ contentsResult = op.execute(client); // returns without waiting for upload or download finishes
+ if (!contentsResult.isSuccess()) {
+ if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
+ mConflictsFound++;
+ } else {
+ mFailsInFavouritesFound++;
+ if (contentsResult.getException() != null) {
+ Log.d(TAG, "Error while synchronizing favourites : " + contentsResult.getLogMessage(), contentsResult.getException());
+ } else {
+ Log.d(TAG, "Error while synchronizing favourites : " + contentsResult.getLogMessage());
+ }
+ }
+ } // won't let these fails break the synchronization process
+ }
+
+
// removal of obsolete files
mChildren = mStorageManager.getDirectoryContent(mStorageManager.getFileById(mParentId));
OCFile file;
}
// prepare result object
- result = new RemoteOperationResult(isMultiStatus(status), status);
+ if (isMultiStatus(status)) {
+ if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {
+ result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job
+
+ } else {
+ result = new RemoteOperationResult(true, status);
+ }
+ } else {
+ result = new RemoteOperationResult(false, status);
+ }
Log.i(TAG, "Synchronizing " + mAccount.name + ", folder " + mRemotePath + ": " + result.getLogMessage());
file.setMimetype(we.contentType());
file.setModificationTimestamp(we.modifiedTimesamp());
file.setLastSyncDateForProperties(mCurrentSyncTime);
+ file.setParentId(mParentId);
return file;
}
-
- /**
- * Request to stop the observance of local updates for a file.
- *
- * @param file OCFile representing the remote file to stop to monitor for local updates
- */
- private void disableObservance(OCFile file) {
- Log.d(TAG, "Disabling observation of remote file" + file.getRemotePath());
- Intent intent = new Intent(mContext, FileObserverService.class);
- intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_ADD_DOWNLOADING_FILE);
- intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, file);
- intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
- mContext.startService(intent);
-
- }
-
-
- /**
- * Requests a download to the file download service
- *
- * @param file OCFile representing the remote file to download
- */
- private void requestContentDownload(OCFile file) {
- Intent intent = new Intent(mContext, FileDownloader.class);
- intent.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
- intent.putExtra(FileDownloader.EXTRA_FILE, file);
- mContext.startService(intent);
- }
-
}
*/
public class UpdateOCVersionOperation extends RemoteOperation {
- private static final String TAG = UploadFileOperation.class.getSimpleName();
+ private static final String TAG = UpdateOCVersionOperation.class.getSimpleName();
private Account mAccount;
private Context mContext;
import com.owncloud.android.datamodel.DataStorageManager;\r
import com.owncloud.android.datamodel.FileDataStorageManager;\r
import com.owncloud.android.datamodel.OCFile;\r
-//<<<<<<< HEAD
import com.owncloud.android.operations.RemoteOperationResult;\r
import com.owncloud.android.operations.SynchronizeFolderOperation;\r
import com.owncloud.android.operations.UpdateOCVersionOperation;\r
-/*=======
-import com.owncloud.android.files.services.FileDownloader;\r
-import com.owncloud.android.files.services.FileObserverService;\r
-import com.owncloud.android.utils.OwnCloudVersion;\r
->>>>>>> origin/master*/
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
\r
import android.accounts.Account;\r
import android.app.Notification;\r
private int mFailedResultsCounter; \r
private RemoteOperationResult mLastFailedResult;\r
private SyncResult mSyncResult;\r
+ private int mConflictsFound;\r
+ private int mFailsInFavouritesFound;\r
\r
public FileSyncAdapter(Context context, boolean autoInitialize) {\r
super(context, autoInitialize);\r
mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);\r
mFailedResultsCounter = 0;\r
mLastFailedResult = null;\r
+ mConflictsFound = 0;\r
+ mFailsInFavouritesFound = 0;\r
mSyncResult = syncResult;\r
mSyncResult.fullSyncRequested = false;\r
mSyncResult.delayUntil = 60*60*24; // sync after 24h\r
\r
/// notify the user about the failure of MANUAL synchronization\r
notifyFailedSynchronization();\r
+ \r
+ } else if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {\r
+ notifyFailsInFavourites();\r
}\r
sendStickyBroadcast(false, null, mLastFailedResult); // message to signal the end to the UI\r
}\r
\r
}\r
- \r
- \r
+\r
\r
/**\r
* Called by system SyncManager when a synchronization is required to be cancelled.\r
// synchronized folder -> notice to UI - ALWAYS, although !result.isSuccess\r
sendStickyBroadcast(true, remotePath, null);\r
\r
- if (result.isSuccess()) {\r
+ if (result.isSuccess() || result.getCode() == ResultCode.SYNC_CONFLICT) {\r
+ \r
+ if (result.getCode() == ResultCode.SYNC_CONFLICT) {\r
+ mConflictsFound += synchFolderOp.getConflictsFound();\r
+ mFailsInFavouritesFound += synchFolderOp.getFailsInFavouritesFound();\r
+ }\r
// synchronize children folders \r
List<OCFile> children = synchFolderOp.getChildren();\r
fetchChildren(children); // beware of the 'hidden' recursion here!\r
\r
-//<<<<<<< HEAD
} else {\r
if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED) {\r
mSyncResult.stats.numAuthExceptions++;\r
\r
} else if (result.getException() instanceof IOException) { \r
mSyncResult.stats.numIoExceptions++;\r
-/*=======
- // insertion or update of files\r
- List<OCFile> updatedFiles = new Vector<OCFile>(resp.getResponses().length - 1);\r
- for (int i = 1; i < resp.getResponses().length; ++i) {\r
- WebdavEntry we = new WebdavEntry(resp.getResponses()[i], getUri().getPath());\r
- OCFile file = fillOCFile(we);\r
- file.setParentId(parentId);\r
- if (getStorageManager().getFileByPath(file.getRemotePath()) != null &&\r
- getStorageManager().getFileByPath(file.getRemotePath()).keepInSync() &&\r
- file.getModificationTimestamp() > getStorageManager().getFileByPath(file.getRemotePath())\r
- .getModificationTimestamp()) {\r
- // first disable observer so we won't get file upload right after download\r
- Log.d(TAG, "Disabling observation of remote file" + file.getRemotePath());\r
- Intent intent = new Intent(getContext(), FileObserverService.class);\r
- intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_ADD_DOWNLOADING_FILE);\r
- intent.putExtra(FileObserverService.KEY_CMD_ARG, file.getRemotePath());\r
- getContext().startService(intent);\r
- intent = new Intent(this.getContext(), FileDownloader.class);\r
- intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());\r
- intent.putExtra(FileDownloader.EXTRA_FILE, file);\r
- file.setKeepInSync(true);\r
- getContext().startService(intent);\r
- }\r
- if (getStorageManager().getFileByPath(file.getRemotePath()) != null)\r
- file.setKeepInSync(getStorageManager().getFileByPath(file.getRemotePath()).keepInSync());\r
->>>>>>> origin/master*/
- \r
}\r
mFailedResultsCounter++;\r
mLastFailedResult = result;\r
((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_fail_ticker, notification);\r
}\r
\r
- \r
+\r
+ /**\r
+ * Notifies the user about conflicts and strange fails when trying to synchronize the contents of favourite files.\r
+ * \r
+ * By now, we won't consider a failed synchronization.\r
+ */\r
+ private void notifyFailsInFavourites() {\r
+ if (mFailedResultsCounter > 0) {\r
+ Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_fail_in_favourites_ticker), System.currentTimeMillis());\r
+ notification.flags |= Notification.FLAG_AUTO_CANCEL;\r
+ // TODO put something smart in the contentIntent below\r
+ notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);\r
+ notification.setLatestEventInfo(getContext().getApplicationContext(), \r
+ getContext().getString(R.string.sync_fail_in_favourites_ticker), \r
+ String.format(getContext().getString(R.string.sync_fail_in_favourites_content), mFailedResultsCounter + mConflictsFound, mConflictsFound), \r
+ notification.contentIntent);\r
+ ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_fail_in_favourites_ticker, notification);\r
+ \r
+ } else {\r
+ Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_conflicts_in_favourites_ticker), System.currentTimeMillis());\r
+ notification.flags |= Notification.FLAG_AUTO_CANCEL;\r
+ // TODO put something smart in the contentIntent below\r
+ notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);\r
+ notification.setLatestEventInfo(getContext().getApplicationContext(), \r
+ getContext().getString(R.string.sync_conflicts_in_favourites_ticker), \r
+ String.format(getContext().getString(R.string.sync_conflicts_in_favourites_content), mConflictsFound), \r
+ notification.contentIntent);\r
+ ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_conflicts_in_favourites_ticker, notification);\r
+ } \r
+ }\r
\r
}\r
}\r
\r
} else {\r
- mLastRemoteOperation = new SynchronizeFileOperation(mFile, mStorageManager, mAccount, true, false, getActivity());\r
+ mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity());\r
WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());\r
mLastRemoteOperation.execute(wc, this, mHandler);\r
\r