List of usage examples for android.accounts OperationCanceledException printStackTrace
public void printStackTrace()
From source file:org.creativecommons.thelist.utils.ListUser.java
/** * Get auth token for existing account, if the account doesnt exist, create new CCID account * You must already have a valid ID//w ww . j a va 2s .c o m */ public void getAuthed(final AuthCallback callback) { Log.d(TAG, "Getting session token"); //sessionComplete = false; if (isTempUser()) { addNewAccount(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, new AuthCallback() { @Override public void onSuccess(String authtoken) { Log.v(TAG, "> getAuthed > addNewAccount token: " + authtoken); callback.onSuccess(authtoken); } }); } else { Account account = getAccount(); if (account == null) { Log.v(TAG, "getToken > getAccount > account is null"); return; } am.getAuthToken(account, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, null, mActivity, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bundle = future.getResult(); String authtoken = bundle.getString(AccountManager.KEY_AUTHTOKEN); Log.v(TAG, "> getAuthed > getAuthToken from existing account: " + authtoken); callback.onSuccess(authtoken); } catch (OperationCanceledException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (AuthenticatorException e) { e.printStackTrace(); } } }, null); } }
From source file:org.creativecommons.thelist.utils.ListUser.java
/** * Show all the accounts registered on the account manager. Request an auth token upon user select. *//*w w w .j av a2 s.c om*/ public void showAccountPicker(final AuthCallback callback) { //@param final boolean invalidate, final String authTokenType // mInvalidate = invalidate; final Account availableAccounts[] = am.getAccountsByType(AccountGeneral.ACCOUNT_TYPE); if (availableAccounts.length == 0) { //TODO: Show other dialog to add account addNewAccount(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, new AuthCallback() { @Override public void onSuccess(String authtoken) { Log.d(TAG, " > showAccountPicker (no accounts) > addNewAccount, " + "token received: " + authtoken); } }); } else { String name[] = new String[availableAccounts.length]; for (int i = 0; i < availableAccounts.length; i++) { name[i] = availableAccounts[i].name; } // Account picker mAlertDialog = new AlertDialog.Builder(mContext).setTitle("Pick Account").setCancelable(true) .setPositiveButton("Add New", new OkOnClickListener()) .setNegativeButton("Cancel", new CancelOnClickListener()) .setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1, name), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO: do we need this? // if(invalidate) // invalidateAuthToken(availableAccounts[which], authTokenType); // else // getExistingAccountAuthToken(availableAccounts[which], authTokenType); am.getAuthToken(availableAccounts[which], AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, null, mActivity, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bundle = future.getResult(); String authtoken = bundle .getString(AccountManager.KEY_AUTHTOKEN); Log.v(TAG, " > showAccountPicker > getAuthToken from existing account: " + authtoken); callback.onSuccess(authtoken); } catch (OperationCanceledException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (AuthenticatorException e) { e.printStackTrace(); } } }, null); } }) .create(); mAlertDialog.show(); } }
From source file:edu.mit.mobile.android.locast.accounts.AuthenticatorActivity.java
/** * * Called when response is received from the server for authentication request. See * onAuthenticationResult(). Sets the AccountAuthenticatorResult which is sent back to the * caller. Also sets the authToken in AccountManager for this account. * * @param userData/*from w w w .j av a 2s .co m*/ * TODO * @param the * confirmCredentials result. */ protected void finishLogin(Bundle userData) { Log.i(TAG, "finishLogin()"); // ensure that there isn't a demo account sticking around. // TODO this is NOT the place where this code belongs. Find it a better home if (Authenticator.isDemoMode(this)) { Log.d(TAG, "cleaning up demo mode account..."); ContentResolver.cancelSync(Authenticator.getFirstAccount(this), MediaProvider.AUTHORITY); mAccountManager.removeAccount( new Account(Authenticator.DEMO_ACCOUNT, AuthenticationService.ACCOUNT_TYPE), new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> arg0) { try { if (arg0.getResult()) { final ContentValues cv = new ContentValues(); // invalidate all the content to force a sync. // this is to ensure that items which were marked favorite get set as // such. cv.put(Cast._SERVER_MODIFIED_DATE, 0); cv.put(Cast._MODIFIED_DATE, 0); getContentResolver().update(Cast.CONTENT_URI, cv, null, null); if (Constants.DEBUG) { Log.d(TAG, "reset all cast modified dates to force a reload"); } } } catch (final OperationCanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final AuthenticatorException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }, null); } final Account account = new Account(mUsername, AuthenticationService.ACCOUNT_TYPE); if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, mPassword, userData); // Automatically enable sync for this account ContentResolver.setSyncAutomatically(account, MediaProvider.AUTHORITY, true); } else { mAccountManager.setPassword(account, mPassword); } final Intent intent = new Intent(); mAuthtoken = mPassword; intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AuthenticationService.ACCOUNT_TYPE); if (mAuthtokenType != null && mAuthtokenType.equals(AuthenticationService.AUTHTOKEN_TYPE)) { intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken); } setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:org.hfoss.posit.android.sync.Communicator.java
public static String getAuthKey(Context context) { AccountManager accountManager = AccountManager.get(context); // TODO: again just picking the first account here.. how are you // supposed to handle this? Account[] accounts = accountManager.getAccountsByType(SyncAdapter.ACCOUNT_TYPE); if (accounts.length == 0) return null; String authKey = null;//from w ww . j a v a2 s .c om try { authKey = accountManager.blockingGetAuthToken(accounts[0], SyncAdapter.AUTHTOKEN_TYPE, true /* notifyAuthFailure */); } catch (OperationCanceledException e) { Log.e(TAG, "getAuthKey(), cancelled during request: " + e.getMessage()); e.printStackTrace(); } catch (AuthenticatorException e) { Log.e(TAG, "getAuthKey(), authentication exception: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { Log.e(TAG, "getAuthKey() IOException" + e.getMessage()); e.printStackTrace(); } catch (IllegalStateException e) { Log.e(TAG, "getAuthKey() IllegalStateException" + e.getMessage()); e.printStackTrace(); } return authKey; }
From source file:com.he5ed.lib.cloudprovider.apis.BoxApi.java
@Override public synchronized void prepareApi(OnPrepareListener prepareListener) { mPrepareListener = prepareListener;//from w ww. java 2s. c o m AccountManager.get(mContext).getAuthToken(mAccount, CloudProvider.AUTH_TYPE, false, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { mAccessToken = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); validateAccessToken(); } catch (OperationCanceledException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } catch (AuthenticatorException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } } }, null); }
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
@Override public synchronized void prepareApi(BaseApi.OnPrepareListener prepareListener) { mPrepareListener = prepareListener;/*from w ww . java 2 s . c o m*/ AccountManager.get(mContext).getAuthToken(mAccount, CloudProvider.AUTH_TYPE, false, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { mAccessToken = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); validateAccessToken(); } catch (OperationCanceledException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } catch (AuthenticatorException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } } }, null); }
From source file:org.klnusbaum.udj.network.PlayerCommService.java
private void joinPlayer(Intent intent, AccountManager am, Account account, boolean attemptReauth) { if (!Utils.isNetworkAvailable(this)) { doLoginFail(am, account, PlayerJoinError.NO_NETWORK_ERROR); return;//from w w w . j ava 2 s .c o m } String userId = am.getUserData(account, Constants.USER_ID_DATA); String playerId = intent.getStringExtra(Constants.PLAYER_ID_EXTRA); String ownerId = intent.getStringExtra(Constants.PLAYER_OWNER_ID_EXTRA); if (userId.equals(ownerId)) { setLoggedInToPlayer(intent, am, account, playerId); return; } String authToken; String password = ""; boolean hasPassword = false; //TODO hanle error if account isn't provided try { //TODO handle if player id isn't provided authToken = am.blockingGetAuthToken(account, "", true); if (intent.hasExtra(Constants.PLAYER_PASSWORD_EXTRA)) { Log.d(TAG, "password given for player"); hasPassword = true; password = intent.getStringExtra(Constants.PLAYER_PASSWORD_EXTRA); } else { Log.d(TAG, "No password given for player"); } } catch (OperationCanceledException e) { Log.e(TAG, "Operation canceled exception"); doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR); return; } catch (AuthenticatorException e) { Log.e(TAG, "Authenticator exception"); doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR); return; } catch (IOException e) { Log.e(TAG, "IO exception"); doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR); return; } try { if (!hasPassword) { ServerConnection.joinPlayer(playerId, authToken); } else { ServerConnection.joinPlayer(playerId, password, authToken); } setLoggedInToPlayer(intent, am, account, playerId); } catch (IOException e) { Log.e(TAG, "IO exception when joining player"); Log.e(TAG, e.getMessage()); doLoginFail(am, account, PlayerJoinError.SERVER_ERROR); } catch (JSONException e) { Log.e(TAG, "JSON exception when joining player"); Log.e(TAG, e.getMessage()); doLoginFail(am, account, PlayerJoinError.SERVER_ERROR); } catch (AuthenticationException e) { handleLoginAuthException(intent, am, account, authToken, attemptReauth); } catch (PlayerInactiveException e) { Log.e(TAG, "Player inactive Exception when joining player"); doLoginFail(am, account, PlayerJoinError.PLAYER_INACTIVE_ERROR); } catch (ParseException e) { e.printStackTrace(); doLoginFail(am, account, PlayerJoinError.SERVER_ERROR); } catch (PlayerPasswordException e) { Log.e(TAG, "Player Password Exception"); e.printStackTrace(); doLoginFail(am, account, PlayerJoinError.PLAYER_PASSWORD_ERROR); } catch (PlayerFullException e) { Log.e(TAG, "Player Password Exception"); e.printStackTrace(); doLoginFail(am, account, PlayerJoinError.PLAYER_FULL_ERROR); } catch (BannedException e) { Log.e(TAG, "Player Password Exception"); e.printStackTrace(); doLoginFail(am, account, PlayerJoinError.BANNED_ERROR); } }