Search in sources :

Example 1 with AccountsException

use of android.accounts.AccountsException 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 2 with AccountsException

use of android.accounts.AccountsException 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 3 with AccountsException

use of android.accounts.AccountsException in project PocketHub by pockethub.

the class AccountUtils method updateAccount.

/**
     * Update account
     *
     * @param account
     * @param activity
     * @return true if account was updated, false otherwise
     */
public static boolean updateAccount(final Account account, final Activity activity) {
    int count = UPDATE_COUNT.get();
    synchronized (UPDATE_COUNT) {
        // while the lock was being waited for
        if (count != UPDATE_COUNT.get()) {
            return true;
        }
        AccountManager manager = AccountManager.get(activity);
        try {
            if (!hasAuthenticator(manager)) {
                throw new AuthenticatorConflictException();
            }
            manager.updateCredentials(account, ACCOUNT_TYPE, null, activity, null, null).getResult();
            UPDATE_COUNT.incrementAndGet();
            return true;
        } catch (OperationCanceledException e) {
            Log.d(TAG, "Excepting retrieving account", e);
            activity.finish();
            return false;
        } catch (AccountsException e) {
            Log.d(TAG, "Excepting retrieving account", e);
            return false;
        } catch (AuthenticatorConflictException e) {
            activity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    showConflictMessage(activity);
                }
            });
            return false;
        } catch (IOException e) {
            Log.d(TAG, "Excepting retrieving account", e);
            return false;
        }
    }
}
Also used : OperationCanceledException(android.accounts.OperationCanceledException) AccountManager(android.accounts.AccountManager) IOException(java.io.IOException) AccountsException(android.accounts.AccountsException)

Example 4 with AccountsException

use of android.accounts.AccountsException in project PocketHub by pockethub.

the class AccountUtils method getAccount.

/**
     * Get account used for authentication
     *
     * @param manager
     * @param activity
     * @return account
     * @throws IOException
     * @throws AccountsException
     */
public static Account getAccount(final AccountManager manager, final Activity activity) throws IOException, AccountsException {
    final boolean loggable = Log.isLoggable(TAG, DEBUG);
    if (loggable) {
        Log.d(TAG, "Getting account");
    }
    if (activity == null) {
        throw new IllegalArgumentException("Activity cannot be null");
    }
    if (activity.isFinishing()) {
        throw new OperationCanceledException();
    }
    Account[] accounts;
    try {
        if (!hasAuthenticator(manager)) {
            throw new AuthenticatorConflictException();
        }
        while ((accounts = getAccounts(manager)).length == 0) {
            if (loggable) {
                Log.d(TAG, "No GitHub accounts for activity=" + activity);
            }
            Bundle result = manager.addAccount(ACCOUNT_TYPE, null, null, null, activity, null, null).getResult();
            if (loggable) {
                Log.d(TAG, "Added account " + result.getString(KEY_ACCOUNT_NAME));
            }
        }
    } catch (OperationCanceledException e) {
        Log.d(TAG, "Excepting retrieving account", e);
        activity.finish();
        throw e;
    } catch (AccountsException e) {
        Log.d(TAG, "Excepting retrieving account", e);
        throw e;
    } catch (AuthenticatorConflictException e) {
        activity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                showConflictMessage(activity);
            }
        });
        throw e;
    } catch (IOException e) {
        Log.d(TAG, "Excepting retrieving account", e);
        throw e;
    }
    if (loggable) {
        Log.d(TAG, "Returning account " + accounts[0].name);
    }
    return accounts[0];
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) IOException(java.io.IOException) AccountsException(android.accounts.AccountsException)

Example 5 with AccountsException

use of android.accounts.AccountsException in project PocketHub by pockethub.

the class AuthenticatedUserLoader method loadInBackground.

@Override
public final D loadInBackground() {
    final AccountManager manager = AccountManager.get(activity);
    final Account account;
    try {
        account = AccountUtils.getAccount(manager, activity);
    } catch (IOException e) {
        return getAccountFailureData();
    } catch (AccountsException e) {
        return getAccountFailureData();
    }
    contextScope.enter(getContext());
    try {
        return load(account);
    } finally {
        contextScope.exit(getContext());
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) IOException(java.io.IOException) AccountsException(android.accounts.AccountsException)

Aggregations

AccountsException (android.accounts.AccountsException)6 IOException (java.io.IOException)6 Account (android.accounts.Account)3 AccountManager (android.accounts.AccountManager)2 OperationCanceledException (android.accounts.OperationCanceledException)2 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 OAuthUserProvider (net.idlesoft.android.apps.github.authenticator.OAuthUserProvider)1 Repository (org.eclipse.egit.github.core.Repository)1 RepositoryIssue (org.eclipse.egit.github.core.RepositoryIssue)1 User (org.eclipse.egit.github.core.User)1 GitHubClient (org.eclipse.egit.github.core.client.GitHubClient)1 GitHubRequest (org.eclipse.egit.github.core.client.GitHubRequest)1 GitHubResponse (org.eclipse.egit.github.core.client.GitHubResponse)1