Search in sources :

Example 1 with AuthenticatorException

use of android.accounts.AuthenticatorException in project android_frameworks_base by ParanoidAndroid.

the class KeyguardAccountView method asyncCheckPassword.

private void asyncCheckPassword() {
    mCallback.userActivity(AWAKE_POKE_MILLIS);
    final String login = mLogin.getText().toString();
    final String password = mPassword.getText().toString();
    Account account = findIntendedAccount(login);
    if (account == null) {
        postOnCheckPasswordResult(false);
        return;
    }
    getProgressDialog().show();
    Bundle options = new Bundle();
    options.putString(AccountManager.KEY_PASSWORD, password);
    AccountManager.get(mContext).confirmCredentialsAsUser(account, options, null, /* activity */
    new AccountManagerCallback<Bundle>() {

        public void run(AccountManagerFuture<Bundle> future) {
            try {
                mCallback.userActivity(AWAKE_POKE_MILLIS);
                final Bundle result = future.getResult();
                final boolean verified = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
                postOnCheckPasswordResult(verified);
            } catch (OperationCanceledException e) {
                postOnCheckPasswordResult(false);
            } catch (IOException e) {
                postOnCheckPasswordResult(false);
            } catch (AuthenticatorException e) {
                postOnCheckPasswordResult(false);
            } finally {
                mLogin.post(new Runnable() {

                    public void run() {
                        getProgressDialog().hide();
                    }
                });
            }
        }
    }, null, /* handler */
    new UserHandle(mLockPatternUtils.getCurrentUser()));
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) UserHandle(android.os.UserHandle) AuthenticatorException(android.accounts.AuthenticatorException) IOException(java.io.IOException)

Example 2 with AuthenticatorException

use of android.accounts.AuthenticatorException in project android by nextcloud.

the class ActivitiesListActivity method fetchAndSetData.

/**
 * @param pageUrl String
 */
private void fetchAndSetData(String pageUrl) {
    final Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
    final Context context = MainApp.getAppContext();
    Thread t = new Thread(() -> {
        OwnCloudAccount ocAccount;
        try {
            ocAccount = new OwnCloudAccount(currentAccount, context);
            ownCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, MainApp.getAppContext());
            ownCloudClient.setOwnCloudVersion(AccountUtils.getServerVersion(currentAccount));
            isLoadingActivities = true;
            runOnUiThread(() -> setIndeterminate(isLoadingActivities));
            GetRemoteActivitiesOperation getRemoteNotificationOperation = new GetRemoteActivitiesOperation();
            if (pageUrl != null) {
                getRemoteNotificationOperation.setNextUrl(pageUrl);
            }
            Log_OC.d(TAG, "BEFORE getRemoteActivitiesOperation.execute");
            final RemoteOperationResult result = getRemoteNotificationOperation.execute(ownCloudClient);
            if (result.isSuccess() && result.getData() != null) {
                final ArrayList<Object> data = result.getData();
                final ArrayList<Object> activities = (ArrayList) data.get(0);
                nextPageUrl = (String) data.get(1);
                runOnUiThread(() -> {
                    populateList(activities, ownCloudClient, pageUrl == null);
                    if (activities.size() > 0) {
                        swipeEmptyListRefreshLayout.setVisibility(View.GONE);
                        swipeListRefreshLayout.setVisibility(View.VISIBLE);
                    } else {
                        setEmptyContent(noResultsHeadline, noResultsMessage);
                        swipeListRefreshLayout.setVisibility(View.GONE);
                        swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
                    }
                    isLoadingActivities = false;
                    setIndeterminate(isLoadingActivities);
                });
            } else {
                Log_OC.d(TAG, result.getLogMessage());
                // show error
                String logMessage = result.getLogMessage();
                if (result.getHttpCode() == 304) {
                    logMessage = noResultsMessage;
                }
                final String finalLogMessage = logMessage;
                runOnUiThread(() -> {
                    setEmptyContent(noResultsHeadline, finalLogMessage);
                    isLoadingActivities = false;
                    setIndeterminate(isLoadingActivities);
                });
            }
            hideRefreshLayoutLoader();
        } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
            Log_OC.e(TAG, "Account not found", e);
        } catch (IOException e) {
            Log_OC.e(TAG, "IO error", e);
        } catch (OperationCanceledException e) {
            Log_OC.e(TAG, "Operation has been canceled", e);
        } catch (AuthenticatorException e) {
            Log_OC.e(TAG, "Authentication Exception", e);
        }
    });
    t.start();
}
Also used : Context(android.content.Context) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) GetRemoteActivitiesOperation(com.owncloud.android.lib.resources.activities.GetRemoteActivitiesOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OperationCanceledException(android.accounts.OperationCanceledException) ArrayList(java.util.ArrayList) AccountUtils(com.owncloud.android.authentication.AccountUtils) AuthenticatorException(android.accounts.AuthenticatorException) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) BindString(butterknife.BindString) IOException(java.io.IOException) RichObject(com.owncloud.android.lib.resources.activities.models.RichObject)

Example 3 with AuthenticatorException

use of android.accounts.AuthenticatorException in project android by nextcloud.

the class PushUtils method deleteRegistrationForAccount.

private static void deleteRegistrationForAccount(Account account) {
    Context context = MainApp.getAppContext();
    OwnCloudAccount ocAccount = null;
    arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver());
    try {
        ocAccount = new OwnCloudAccount(account, context);
        OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context);
        RemoteOperation unregisterAccountDeviceForNotificationsOperation = new UnregisterAccountDeviceForNotificationsOperation();
        RemoteOperationResult remoteOperationResult = unregisterAccountDeviceForNotificationsOperation.execute(mClient);
        if (remoteOperationResult.getHttpCode() == HttpStatus.SC_ACCEPTED) {
            String arbitraryValue;
            if (!TextUtils.isEmpty(arbitraryValue = arbitraryDataProvider.getValue(account, KEY_PUSH))) {
                Gson gson = new Gson();
                PushConfigurationState pushArbitraryData = gson.fromJson(arbitraryValue, PushConfigurationState.class);
                RemoteOperation unregisterAccountDeviceForProxyOperation = new UnregisterAccountDeviceForProxyOperation(context.getResources().getString(R.string.push_server_url), pushArbitraryData.getDeviceIdentifier(), pushArbitraryData.getDeviceIdentifierSignature(), pushArbitraryData.getUserPublicKey());
                remoteOperationResult = unregisterAccountDeviceForProxyOperation.execute(mClient);
                if (remoteOperationResult.isSuccess()) {
                    arbitraryDataProvider.deleteKeyForAccount(account.name, KEY_PUSH);
                }
            }
        }
    } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
        Log_OC.d(TAG, "Failed to find an account");
    } catch (AuthenticatorException e) {
        Log_OC.d(TAG, "Failed via AuthenticatorException");
    } catch (IOException e) {
        Log_OC.d(TAG, "Failed via IOException");
    } catch (OperationCanceledException e) {
        Log_OC.d(TAG, "Failed via OperationCanceledException");
    }
}
Also used : Context(android.content.Context) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UnregisterAccountDeviceForProxyOperation(com.owncloud.android.lib.resources.notifications.UnregisterAccountDeviceForProxyOperation) OperationCanceledException(android.accounts.OperationCanceledException) AccountUtils(com.owncloud.android.authentication.AccountUtils) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Gson(com.google.gson.Gson) AuthenticatorException(android.accounts.AuthenticatorException) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) IOException(java.io.IOException) PushConfigurationState(com.owncloud.android.datamodel.PushConfigurationState) UnregisterAccountDeviceForNotificationsOperation(com.owncloud.android.lib.resources.notifications.UnregisterAccountDeviceForNotificationsOperation) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient)

Example 4 with AuthenticatorException

use of android.accounts.AuthenticatorException in project android by nextcloud.

the class OCFileListFragment method onMessageEvent.

@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(FavoriteEvent event) {
    Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
    OwnCloudAccount ocAccount = null;
    AccountManager mAccountMgr = AccountManager.get(getActivity());
    try {
        ocAccount = new OwnCloudAccount(currentAccount, MainApp.getAppContext());
        OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, MainApp.getAppContext());
        String userId = mAccountMgr.getUserData(currentAccount, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
        if (TextUtils.isEmpty(userId)) {
            userId = mClient.getCredentials().getUsername();
        }
        ToggleFavoriteOperation toggleFavoriteOperation = new ToggleFavoriteOperation(event.shouldFavorite, event.remotePath, userId);
        RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(mClient);
        if (remoteOperationResult.isSuccess()) {
            mAdapter.setFavoriteAttributeForItemID(event.remoteId, event.shouldFavorite);
        }
    } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
        Log_OC.e(TAG, "Account not found", e);
    } catch (AuthenticatorException e) {
        Log_OC.e(TAG, "Authentication failed", e);
    } catch (IOException e) {
        Log_OC.e(TAG, "IO error", e);
    } catch (OperationCanceledException e) {
        Log_OC.e(TAG, "Operation has been canceled", e);
    }
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OperationCanceledException(android.accounts.OperationCanceledException) AccountUtils(com.owncloud.android.authentication.AccountUtils) AuthenticatorException(android.accounts.AuthenticatorException) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) ToggleFavoriteOperation(com.owncloud.android.lib.resources.files.ToggleFavoriteOperation) IOException(java.io.IOException) AccountManager(android.accounts.AccountManager) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 5 with AuthenticatorException

use of android.accounts.AuthenticatorException in project apps-android-commons by commons-app.

the class CommonsApplication method revalidateAuthToken.

public Boolean revalidateAuthToken() {
    AccountManager accountManager = AccountManager.get(this);
    Account curAccount = getCurrentAccount();
    if (curAccount == null) {
        // This should never happen
        return false;
    }
    accountManager.invalidateAuthToken(AccountUtil.accountType(), getMWApi().getAuthCookie());
    try {
        String authCookie = accountManager.blockingGetAuthToken(curAccount, "", false);
        getMWApi().setAuthCookie(authCookie);
        return true;
    } catch (OperationCanceledException | NullPointerException | IOException | AuthenticatorException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : Account(android.accounts.Account) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) AccountManager(android.accounts.AccountManager) IOException(java.io.IOException)

Aggregations

AuthenticatorException (android.accounts.AuthenticatorException)27 OperationCanceledException (android.accounts.OperationCanceledException)21 IOException (java.io.IOException)21 Account (android.accounts.Account)13 Bundle (android.os.Bundle)13 Intent (android.content.Intent)7 AccountUtils (com.owncloud.android.authentication.AccountUtils)7 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)7 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)6 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)6 AccountManager (android.accounts.AccountManager)5 Context (android.content.Context)4 Test (org.junit.Test)4 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)3 UserHandle (android.os.UserHandle)2 GoogleHeaders (com.google.api.client.googleapis.GoogleHeaders)2 HttpRequest (com.google.api.client.http.HttpRequest)2 AtomParser (com.google.api.client.xml.atom.AtomParser)2 Gson (com.google.gson.Gson)2 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)2