android.accounts.OperationCanceledException Java Examples

The following examples show how to use android.accounts.OperationCanceledException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseActivity.java    From attendee-checkin with Apache License 2.0 6 votes vote down vote up
@Override
public void run(AccountManagerFuture<Bundle> bundleAccountManagerFuture) {
    try {
        Bundle result = bundleAccountManagerFuture.getResult();
        Intent intent = (Intent) result.get(AccountManager.KEY_INTENT);
        if (intent == null) {
            String authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
            GutenbergApplication app = GutenbergApplication.from(BaseActivity.this);
            app.setAuthToken(authToken);
            app.requestSync(false);
        } else {
            startActivityForResult(intent, REQUEST_AUTHENTICATE);
        }
    } catch (OperationCanceledException | IOException | AuthenticatorException e) {
        Log.e(TAG, "Error authenticating.", e);
    }
}
 
Example #2
Source File: OAuthAuthenticatorTest.java    From auth with MIT License 6 votes vote down vote up
@Test
public void accessTokenReturnedAfterRefresh()
        throws AuthenticatorException, OperationCanceledException, IOException,
                TokenRefreshError {
    am.addAccountExplicitly(account, null, null);
    final String accessToken = "access1";
    am.setPassword(account, "refresh1");

    TokenPair response = new TokenPair(accessToken, "refresh2");
    withServiceResponse(callback -> response);

    // when
    Bundle result = getAuthTokenWithResponse();

    // then
    assertNull(result);
    assertEquals(accessToken, am.blockingGetAuthToken(account, "bearer", true));
}
 
Example #3
Source File: OdooAccountManager.java    From framework with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Remove account from device
 *
 * @param context
 * @param username
 * @return true, if account removed successfully
 */
public static boolean removeAccount(Context context, String username) {
    OUser user = getDetails(context, username);
    if (user != null) {
        AccountManager accountManager = AccountManager.get(context);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            if (accountManager.removeAccountExplicitly(user.getAccount())) {
                dropDatabase(user);
            }
            return true;
        } else {
            try {
                AccountManagerFuture<Boolean> result = accountManager.
                        removeAccount(user.getAccount(), null, null);
                if (result.getResult()) {
                    dropDatabase(user);
                }
                return true;
            } catch (OperationCanceledException | IOException | AuthenticatorException e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}
 
Example #4
Source File: ContentManager.java    From retrowatch with Apache License 2.0 6 votes vote down vote up
public synchronized void queryGmailLabels() {
	// Get the account list, and pick the user specified address
	AccountManager.get(mContext).getAccountsByTypeAndFeatures(ACCOUNT_TYPE_GOOGLE, FEATURES_MAIL,
			new AccountManagerCallback<Account[]>() {
		@Override
		public void run(AccountManagerFuture<Account[]> future) {
			Account[] accounts = null;
			try {
				accounts = future.getResult();
			} catch (OperationCanceledException oce) {
				Logs.e(TAG, "Got OperationCanceledException: "+oce.toString());
			} catch (IOException ioe) {
				Logs.e(TAG, "Got OperationCanceledException: "+ioe.toString());
			} catch (AuthenticatorException ae) {
				Logs.e(TAG, "Got OperationCanceledException: "+ae.toString());
			}
			mGmailUnreadCount = onAccountResults(accounts);
			addGmailToContentList(mGmailUnreadCount);
			Logs.d(TAG, "# Gmail unread count = "+ mGmailUnreadCount);
		}
	}, null /* handler */);
}
 
Example #5
Source File: ContentManager.java    From retrowatch with Apache License 2.0 6 votes vote down vote up
public synchronized void queryGmailLabels() {
	// Get the account list, and pick the user specified address
	AccountManager.get(mContext).getAccountsByTypeAndFeatures(ACCOUNT_TYPE_GOOGLE, FEATURES_MAIL,
			new AccountManagerCallback<Account[]>() {
		@Override
		public void run(AccountManagerFuture<Account[]> future) {
			Account[] accounts = null;
			try {
				accounts = future.getResult();
			} catch (OperationCanceledException oce) {
				Logs.e(TAG, "Got OperationCanceledException: "+oce.toString());
			} catch (IOException ioe) {
				Logs.e(TAG, "Got OperationCanceledException: "+ioe.toString());
			} catch (AuthenticatorException ae) {
				Logs.e(TAG, "Got OperationCanceledException: "+ae.toString());
			}
			mGmailUnreadCount = onAccountResults(accounts);
			addGmailToContentList(mGmailUnreadCount);
			Logs.d(TAG, "# Gmail unread count = "+ mGmailUnreadCount);
		}
	}, null /* handler */);
}
 
Example #6
Source File: LogonManager.java    From letv with Apache License 2.0 6 votes vote down vote up
private void syncLogon4LetvPhone() {
    new Thread() {
        public void run() {
            try {
                String blockingGetAuthToken = LogonManager.this.accountManager.blockingGetAuthToken(LogonManager.this.accounts[0], LogonManager.this.AUTH_TOKEN_TYPE_LETV, true);
                LemallPlatform.getInstance().setSsoToken(blockingGetAuthToken);
                LogonManager.this.syncToken4Logon(blockingGetAuthToken, (IWebviewListener) LogonManager.this.context);
            } catch (OperationCanceledException e) {
                e.printStackTrace();
            } catch (AuthenticatorException e2) {
                e2.printStackTrace();
            } catch (IOException e3) {
                e3.printStackTrace();
            }
        }
    }.start();
}
 
Example #7
Source File: AddAccountActivity.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
private void addAccount(String accountName) {
    AccountManager accountManager = AccountManager.get(this);
    Bundle bundle = new Bundle();
    if (!TextUtils.isEmpty(accountName)) {
        bundle.putString(AccountManager.KEY_ACCOUNT_NAME, accountName);
    }

    accountManager.addAccount(GOOGLE_ACCOUNT_TYPE, null, null, bundle, this,
        accountManagerFuture -> {
            try {
                Bundle result = accountManagerFuture.getResult();
                // This callback executes slightly before the app is back in the foreground
                // so we need to wait.
                waitForForeground(() -> accountCreated(result), 1000);
            } catch (OperationCanceledException | AuthenticatorException | IOException e) {
                Log.e(TAG, "addAccount - failed", e);
                Toast.makeText(AddAccountActivity.this,
                    R.string.fail_to_add_account, Toast.LENGTH_LONG).show();
            }
        }, null);
}
 
Example #8
Source File: PolicyManagementFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
@TargetApi(VERSION_CODES.LOLLIPOP_MR1)
private void removeAccount(Account account) {
    mAccountManager.removeAccount(account, getActivity(), future -> {
        try {
            Bundle result = future.getResult();
            boolean success = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
            if (success) {
                showToast(R.string.success_remove_account, account);
            } else {
                showToast(R.string.fail_to_remove_account, account);
            }
        } catch (OperationCanceledException | IOException | AuthenticatorException e) {
            Log.e(TAG, "Failed to remove account: "  + account, e);
            showToast(R.string.fail_to_remove_account, account);
        }

    }, null);
}
 
Example #9
Source File: HttpNegotiateAuthenticator.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void run(AccountManagerFuture<Bundle> future) {
    Bundle result;
    try {
        result = future.getResult();
    } catch (OperationCanceledException | AuthenticatorException | IOException e) {
        Log.w(TAG, "ERR_UNEXPECTED: Error while attempting to obtain a token.", e);
        nativeSetResult(mRequestData.nativeResultObject, NetError.ERR_UNEXPECTED, null);
        return;
    }

    if (result.containsKey(AccountManager.KEY_INTENT)) {
        final Context appContext = ContextUtils.getApplicationContext();

        // We wait for a broadcast that should be sent once the user is done interacting
        // with the notification
        // TODO(dgn) We currently hang around if the notification is swiped away, until
        // a LOGIN_ACCOUNTS_CHANGED_ACTION filter is received. It might be for something
        // unrelated then we would wait again here. Maybe we should limit the number of
        // retries in some way?
        BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                appContext.unregisterReceiver(this);
                mRequestData.accountManager.getAuthToken(mRequestData.account,
                        mRequestData.authTokenType, mRequestData.options,
                        true /* notifyAuthFailure */, new GetTokenCallback(mRequestData),
                        null);
            }

        };
        appContext.registerReceiver(broadcastReceiver,
                new IntentFilter(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION));
    } else {
        processResult(result, mRequestData);
    }
}
 
Example #10
Source File: ContactsSyncAdapterService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    try {
        ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult);
    } catch (OperationCanceledException e) {
        FileLog.e(e);
    }
}
 
Example #11
Source File: RESTHelper.java    From android-java-connect-rest-sample with MIT License 5 votes vote down vote up
/**
 * Returns a retrofit rest adaptor class. The adaptor is created in calling code.
 *
 * @return A new RestAdapter instance.
 */
public Retrofit getRetrofit(final Context context) {
    //This method catches outgoing REST calls and injects the Authorization and host headers before
    //sending to REST endpoint
    Interceptor interceptor = new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            try {
                final String token = AuthenticationManager.getInstance(context).getAccessToken();
                Request request = chain.request();
                request = request.newBuilder()
                        .addHeader("Authorization", "Bearer " + token)
                        // This header has been added to identify this sample in the Microsoft Graph service.
                        // If you're using this code for your project please remove the following line.
                        .addHeader("SampleID", "android-java-connect-rest-sample")
                        .build();

                Response response = chain.proceed(request);
                return response;
            } catch (AuthenticatorException | IOException | UserNotAuthenticatedWrapperException | OperationCanceledException e) {
                Log.e(TAG, e.getMessage());
                return null;
            }
        }
    };

    return getRetrofit(interceptor);
}
 
Example #12
Source File: AccountSensitiveDataStorageUtils.java    From android-java-connect-rest-sample with MIT License 5 votes vote down vote up
/**
 * Get the stored data from a secure store, decrypting the data if needed.
 * @return The data store on the secure storage.
 */
public String retrieveStringData(AccountManager accountManager, Account account, String tokenType, AccountManagerCallback<Bundle> callback)
        throws UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException, IOException {
    String data = null;

    // Try retrieving an access token from the account manager. The boolean #SHOW_NOTIF_ON_AUTHFAILURE in the invocation
    // tells Android to show a notification if the token can't be retrieved. When the
    // notification is selected, it will launch the intent for re-authorisation. You could
    // launch it automatically here if you wanted to by grabbing the intent from the bundle.
    AccountManagerFuture<Bundle> futureManager;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        //noinspection deprecation
        futureManager = accountManager.getAuthToken(
                account,
                tokenType,
                SHOW_NOTIF_ON_AUTHFAILURE,
                callback,
                null);
    }
    else {
        futureManager = accountManager.getAuthToken(
                account,
                tokenType,
                null,
                SHOW_NOTIF_ON_AUTHFAILURE,
                callback,
                null);
    }
    String encryptedToken = futureManager.getResult().getString(AccountManager.KEY_AUTHTOKEN);
    if (encryptedToken != null) {
        data = dataEncUtils.decrypt(encryptedToken);
    }

    return data;
}
 
Example #13
Source File: OIDCAccountManager.java    From android-java-connect-rest-sample with MIT License 5 votes vote down vote up
public boolean removeAccount(Account account) {
    boolean removed = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1){
        removed = this.manager.removeAccountExplicitly(account);
    }
    else {
        @SuppressWarnings("deprecation") AccountManagerFuture<Boolean> futureRemoved = this.manager.removeAccount(account, null, null);
        try {
            removed = futureRemoved.getResult();
        } catch (OperationCanceledException | IOException | AuthenticatorException e) {
            Log.w("LogoutTask", "Coudln't remove account using pre LOLIPOP remove call");
        }
    }
    return removed;
}
 
Example #14
Source File: OIDCAccountManager.java    From android-java-connect-rest-sample with MIT License 5 votes vote down vote up
public void invalidateAllAccountTokens(Account account) {
    if(account != null) {
        try {
            String idToken = getIdToken(account.name, null);
            String accessToken = getAccessToken(account.name, null);
            String refreshToken = getRefreshToken(account.name, null);
            this.secureStorage.invalidateStringData(this.manager, account, idToken);
            this.secureStorage.invalidateStringData(this.manager, account, accessToken);
            this.secureStorage.invalidateStringData(this.manager, account, refreshToken);
        } catch (AuthenticatorException | UserNotAuthenticatedWrapperException | OperationCanceledException | IOException e) {
            Log.w(TAG, String.format("Could not invalidate account %1$s tokens", account.name), e);
        }
    }
}
 
Example #15
Source File: OIDCAccountManager.java    From android-java-connect-rest-sample with MIT License 5 votes vote down vote up
public void invalidateAuthTokens(Account account) {
    if(account != null) {
        try {
            String idToken = getIdToken(account.name, null);
            String accessToken = getAccessToken(account.name, null);
            this.secureStorage.invalidateStringData(this.manager, account, idToken);
            this.secureStorage.invalidateStringData(this.manager, account, accessToken);
        } catch (AuthenticatorException | UserNotAuthenticatedWrapperException | OperationCanceledException | IOException e) {
            Log.w(TAG, String.format("Could not invalidate account %1$s tokens", account.name), e);
        }
    }
}
 
Example #16
Source File: OIDCAccountManager.java    From android-java-connect-rest-sample with MIT License 5 votes vote down vote up
public void invalidateAccessToken(Account account) {
    if(account != null) {
        try {
            String accessToken = getAccessToken(account, null);
            this.secureStorage.invalidateStringData(this.manager, account, accessToken);
        } catch (AuthenticatorException | UserNotAuthenticatedWrapperException | OperationCanceledException | IOException e) {
            Log.w(TAG, String.format("Could not invalidate account %1$s AT", account.name), e);
        }
    }
}
 
Example #17
Source File: ContactsSyncAdapterService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    try {
        ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult);
    } catch (OperationCanceledException e) {
        FileLog.e(e);
    }
}
 
Example #18
Source File: ContactsSyncAdapterService.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras,
		String authority, ContentProviderClient provider,
		SyncResult syncResult) {
	try {
		ContactsSyncAdapterService.performSync(mContext, account,
				extras, authority, provider, syncResult);
	} catch (OperationCanceledException e) {
	}
}
 
Example #19
Source File: CalendarSyncAdapterService.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras,
		String authority, ContentProviderClient provider,
		SyncResult syncResult) {
	try {
		CalendarSyncAdapterService.performSync(mContext, account,
				extras, authority, provider, syncResult);
	} catch (OperationCanceledException e) {
	}
}
 
Example #20
Source File: ContactsSyncAdapterService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    try {
        ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult);
    } catch (OperationCanceledException e) {
        FileLog.e(e);
    }
}
 
Example #21
Source File: XAccountManager.java    From XPrivacy with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Bundle getResult() throws OperationCanceledException, IOException, AuthenticatorException {
	Bundle bundle = mFuture.getResult();
	String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
	String accountType = bundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
	if (isAccountAllowed(accountName, accountType, mUid))
		return bundle;
	else
		throw new OperationCanceledException("XPrivacy");
}
 
Example #22
Source File: XAccountManager.java    From XPrivacy with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Bundle getResult(long timeout, TimeUnit unit) throws OperationCanceledException, IOException,
		AuthenticatorException {
	Bundle bundle = mFuture.getResult(timeout, unit);
	String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
	String accountType = bundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
	if (isAccountAllowed(accountName, accountType, mUid))
		return bundle;
	else
		throw new OperationCanceledException("XPrivacy");
}
 
Example #23
Source File: HttpNegotiateAuthenticator.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void run(AccountManagerFuture<Bundle> future) {
    Bundle result;
    try {
        result = future.getResult();
    } catch (OperationCanceledException | AuthenticatorException | IOException e) {
        Log.w(TAG, "ERR_UNEXPECTED: Error while attempting to obtain a token.", e);
        nativeSetResult(mRequestData.nativeResultObject, NetError.ERR_UNEXPECTED, null);
        return;
    }

    if (result.containsKey(AccountManager.KEY_INTENT)) {
        final Context appContext = ContextUtils.getApplicationContext();

        // We wait for a broadcast that should be sent once the user is done interacting
        // with the notification
        // TODO(dgn) We currently hang around if the notification is swiped away, until
        // a LOGIN_ACCOUNTS_CHANGED_ACTION filter is received. It might be for something
        // unrelated then we would wait again here. Maybe we should limit the number of
        // retries in some way?
        BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                appContext.unregisterReceiver(this);
                mRequestData.accountManager.getAuthToken(mRequestData.account,
                        mRequestData.authTokenType, mRequestData.options,
                        true /* notifyAuthFailure */, new GetTokenCallback(mRequestData),
                        null);
            }

        };
        appContext.registerReceiver(broadcastReceiver,
                new IntentFilter(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION));
    } else {
        processResult(result, mRequestData);
    }
}
 
Example #24
Source File: CalendarSyncAdapterService.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult syncResult) {
    try {
        CalendarSyncAdapterService.performSync(CalendarSyncAdapterService.this, account, extras, authority,
                provider, syncResult);
    } catch (OperationCanceledException e) {
        Log.e(getClass().getSimpleName(), "OperationCanceledException", e);
    }
}
 
Example #25
Source File: ContactsSyncAdapterService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    try {
        ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult);
    } catch (OperationCanceledException e) {
        FileLog.e(e);
    }
}
 
Example #26
Source File: AbstractOwnCloudSyncAdapter.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
protected void initClientForCurrentAccount() throws OperationCanceledException,
        AuthenticatorException, IOException, AccountNotFoundException {
    AccountUtils.constructFullURLForAccount(getContext(), account);
    OwnCloudAccount ocAccount = new OwnCloudAccount(account, getContext());
    mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
            getClientFor(ocAccount, getContext());
}
 
Example #27
Source File: AccountHelper.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
private boolean removeAccount(Account account) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        return mAccountManager.removeAccountExplicitly(account);
    } else {
        //noinspection deprecation
        AccountManagerFuture<Boolean> feature = mAccountManager.removeAccount(account, null, null);
        try {
            return feature.getResult();
        } catch (OperationCanceledException | IOException | AuthenticatorException e) {
            e.printStackTrace();
            return false;
        }
    }
}
 
Example #28
Source File: LogonManager.java    From letv with Apache License 2.0 5 votes vote down vote up
public void run(AccountManagerFuture<Bundle> arg0) {
    try {
        Bundle result = (Bundle) arg0.getResult();
        if (result != null) {
            LemallPlatform.getInstance().setSsoToken(result.getString("authtoken"));
        }
    } catch (OperationCanceledException e) {
        e.printStackTrace();
    } catch (AuthenticatorException e2) {
        e2.printStackTrace();
    } catch (IOException e3) {
        e3.printStackTrace();
    }
}
 
Example #29
Source File: OAuthAccountManager.java    From auth with MIT License 5 votes vote down vote up
@Override
@NonNull
public String getAccessToken() throws IOException {
    if (!isLoggedIn()) return "";

    try {
        return accountManager.blockingGetAuthToken(account, TokenType.BEARER, false);
    } catch (OperationCanceledException | AuthenticatorException e) {
        e.printStackTrace();
    }
    return "";
}
 
Example #30
Source File: ContactsSyncAdapterService.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    try {
        ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult);
    } catch (OperationCanceledException e) {
        e.printStackTrace();
    }
}