use of com.owncloud.android.datamodel.FileDataStorageManager in project android by owncloud.
the class DocumentsStorageProvider method initiateStorageMap.
private void initiateStorageMap() {
mRootIdToStorageManager = new HashMap<Long, FileDataStorageManager>();
ContentResolver contentResolver = getContext().getContentResolver();
for (Account account : AccountUtils.getAccounts(getContext())) {
final FileDataStorageManager storageManager = new FileDataStorageManager(account, contentResolver);
final OCFile rootDir = storageManager.getFileByPath("/");
mRootIdToStorageManager.put(rootDir.getFileId(), storageManager);
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by owncloud.
the class SyncFolderHandler method doOperation.
/**
* Performs the next operation in the queue
*/
private void doOperation(Account account, String remotePath) {
mCurrentSyncOperation = mPendingOperations.get(account.name, remotePath);
if (mCurrentSyncOperation != null) {
RemoteOperationResult result = null;
try {
if (mCurrentAccount == null || !mCurrentAccount.equals(account)) {
mCurrentAccount = account;
mStorageManager = new FileDataStorageManager(account, mService.getContentResolver());
}
// else, reuse storage manager from previous operation
// always get client from client manager, to get fresh credentials in case of update
OwnCloudAccount ocAccount = new OwnCloudAccount(account, mService);
mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, mService);
result = mCurrentSyncOperation.execute(mOwnCloudClient, mStorageManager);
} catch (AccountsException e) {
Log_OC.e(TAG, "Error while trying to get authorization", e);
} catch (IOException e) {
Log_OC.e(TAG, "Error while trying to get authorization", e);
} finally {
mPendingOperations.removePayload(account.name, remotePath);
mService.dispatchResultToOperationListeners(mCurrentSyncOperation, result);
sendBroadcastFinishedSyncFolder(account, remotePath, result.isSuccess());
}
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by owncloud.
the class AvailableOfflineObserver method startSyncOperation.
/**
* Triggers an operation to synchronize the contents of a file inside the observed folder with
* its remote counterpart in the associated ownCloud account.
*
* @param fileName Name of a file inside the watched folder.
*/
private void startSyncOperation(String fileName) {
FileDataStorageManager storageManager = new FileDataStorageManager(mAccount, mContext.getContentResolver());
// a fresh object is needed; many things could have occurred to the file
// since it was registered to observe again, assuming that local files
// are linked to a remote file AT MOST, SOMETHING TO BE DONE;
OCFile file = storageManager.getFileByLocalPath(mPath + File.separator + fileName);
if (file == null) {
Log_OC.w(TAG, "Could not find OC file for observed " + mPath + File.separator + fileName);
} else {
SynchronizeFileOperation sfo = new SynchronizeFileOperation(file, null, mAccount, false, mContext);
RemoteOperationResult result = sfo.execute(storageManager, mContext);
if (result.getCode() == ResultCode.SYNC_CONFLICT) {
// ISSUE 5: if the user is not running the app (this is a service!),
// this can be very intrusive; a notification should be preferred
Intent i = new Intent(mContext, ConflictsResolveActivity.class);
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount);
mContext.startActivity(i);
}
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by owncloud.
the class FileSyncAdapter method onPerformSync.
/**
* {@inheritDoc}
*/
@Override
public synchronized void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient providerClient, SyncResult syncResult) {
mCancellation = false;
mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
mFailedResultsCounter = 0;
mLastFailedResult = null;
mConflictsFound = 0;
mFailsInFavouritesFound = 0;
mForgottenLocalFiles = new HashMap<>();
mSyncResult = syncResult;
mSyncResult.fullSyncRequested = false;
// avoid too many automatic synchronizations
mSyncResult.delayUntil = (System.currentTimeMillis() / 1000) + 3 * 60 * 60;
this.setAccount(account);
this.setContentProviderClient(providerClient);
this.setStorageManager(new FileDataStorageManager(account, providerClient));
try {
this.initClientForCurrentAccount();
} catch (IOException e) {
/// the account is unknown for the Synchronization Manager, unreachable this context,
// or can not be authenticated; don't try this again
mSyncResult.tooManyRetries = true;
notifyFailedSynchronization();
return;
} catch (AccountsException e) {
/// the account is unknown for the Synchronization Manager, unreachable this context,
// or can not be authenticated; don't try this again
mSyncResult.tooManyRetries = true;
notifyFailedSynchronization();
return;
}
Log_OC.d(TAG, "Synchronization of ownCloud account " + account.name + " starting");
// message to signal the start
sendLocalBroadcast(EVENT_FULL_SYNC_START, null, null);
try {
updateOCVersion();
mCurrentSyncTime = System.currentTimeMillis();
if (!mCancellation) {
synchronizeFolder(getStorageManager().getFileByPath(OCFile.ROOT_PATH), false);
} else {
Log_OC.d(TAG, "Leaving synchronization before synchronizing the root folder " + "because cancelation request");
}
} finally {
if (mFailedResultsCounter > 0 && mIsManualSync) {
/// don't let the system synchronization manager retries MANUAL synchronizations
// (be careful: "MANUAL" currently includes the synchronization requested when
// a new account is created and when the user changes the current account)
mSyncResult.tooManyRetries = true;
/// notify the user about the failure of MANUAL synchronization
notifyFailedSynchronization();
}
if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {
notifyFailsInFavourites();
}
if (mForgottenLocalFiles.size() > 0) {
notifyForgottenLocalFiles();
}
// message to signal
sendLocalBroadcast(EVENT_FULL_SYNC_END, null, mLastFailedResult);
// the end to the UI
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by owncloud.
the class BaseActivity method onAccountSet.
/**
* Called when the ownCloud {@link Account} associated to the Activity was just updated.
* <p/>
* Child classes must grant that state depending on the {@link Account} is updated.
*/
protected void onAccountSet(boolean stateWasRecovered) {
if (getAccount() != null) {
mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
mCapabilities = mStorageManager.getCapability(mCurrentAccount.name);
} else {
Log_OC.e(TAG, "onAccountChanged was called with NULL account associated!");
}
}
Aggregations