Search in sources :

Example 11 with FileDataStorageManager

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);
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) Account(android.accounts.Account) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ContentResolver(android.content.ContentResolver)

Example 12 with FileDataStorageManager

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());
        }
    }
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) IOException(java.io.IOException) AccountsException(android.accounts.AccountsException)

Example 13 with FileDataStorageManager

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);
        }
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Intent(android.content.Intent) SynchronizeFileOperation(com.owncloud.android.operations.SynchronizeFileOperation)

Example 14 with FileDataStorageManager

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
    }
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) IOException(java.io.IOException) AccountsException(android.accounts.AccountsException)

Example 15 with FileDataStorageManager

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!");
    }
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Aggregations

FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)23 OCFile (com.owncloud.android.datamodel.OCFile)9 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)6 Account (android.accounts.Account)4 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)4 AccountsException (android.accounts.AccountsException)2 Intent (android.content.Intent)2 File (java.io.File)2 IOException (java.io.IOException)2 ContentResolver (android.content.ContentResolver)1 SharedPreferences (android.content.SharedPreferences)1 MatrixCursor (android.database.MatrixCursor)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 Pair (android.support.v4.util.Pair)1 ScrollingMovementMethod (android.text.method.ScrollingMovementMethod)1 Pair (android.util.Pair)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1