private void close() { synchronized (mSessions) { if (mSessions.remove(toString()) == null) { // the session was already closed, so bail out now return; } } if (mResponse != null) { // stop listening for response deaths mResponse.asBinder().unlinkToDeath(this, 0 /* flags */); // clear this so that we don't accidentally send any further results mResponse = null; } unbind(); }
@Override public void onServiceDisconnected(ComponentName name) { mAuthenticator = null; IAccountManagerResponse response = getResponseAndClose(); if (response != null) { try { response.onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "disconnected"); } catch (RemoteException e) { Log.v(TAG, "Session.onServiceDisconnected: " + "caught RemoteException while responding", e); } } }
@Override public void onResult(Bundle result) throws RemoteException { IAccountManagerResponse response = getResponseAndClose(); if (response != null) { try { if (result == null) { response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, "null bundle"); return; } Log.v(TAG, getClass().getSimpleName() + " calling onResult() on response " + response); final Bundle newResult = new Bundle(); newResult.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT, false)); response.onResult(newResult); } catch (RemoteException e) { // if the caller is dead then there is no one to care about remote exceptions Log.v(TAG, "failure while notifying response", e); } } } }.bind();
private void onResult(IAccountManagerResponse response, Bundle result) { try { response.onResult(result); } catch (RemoteException e) { // if the caller is dead then there is no one to care about remote // exceptions e.printStackTrace(); } }
@Override public void renameAccount(int userId, IAccountManagerResponse response, Account accountToRename, String newName) { if (accountToRename == null) throw new IllegalArgumentException("account is null"); Account resultingAccount = renameAccountInternal(userId, accountToRename, newName); Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, resultingAccount.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, resultingAccount.type); try { response.onResult(result); } catch (RemoteException e) { Log.w(TAG, e.getMessage()); } }
@Override public void onError(int errorCode, String errorMessage) { mNumErrors++; IAccountManagerResponse response = getResponseAndClose(); if (response != null) { Log.v(TAG, getClass().getSimpleName() + " calling onError() on response " + response); try { response.onError(errorCode, errorMessage); } catch (RemoteException e) { Log.v(TAG, "Session.onError: caught RemoteException while responding", e); } } else { Log.v(TAG, "Session.onError: already closed"); } }
Log.v(TAG, getClass().getSimpleName() + " calling onError() on response " + response); response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, "null bundle returned"); } else { (intent == null)) { response.onError(result.getInt(AccountManager.KEY_ERROR_CODE), result.getString(AccountManager.KEY_ERROR_MESSAGE)); } else { response.onResult(result);
public void sendResult() { IAccountManagerResponse response = getResponseAndClose(); if (response != null) { try { Account[] accounts = new Account[mAccountsWithFeatures.size()]; for (int i = 0; i < accounts.length; i++) { accounts[i] = mAccountsWithFeatures.get(i); } if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, getClass().getSimpleName() + " calling onResult() on response " + response); } Bundle result = new Bundle(); result.putParcelableArray(AccountManager.KEY_ACCOUNTS, accounts); response.onResult(result); } catch (RemoteException e) { // if the caller is dead then there is no one to care about remote exceptions Log.v(TAG, "failure while notifying response", e); } } }
Session(IAccountManagerResponse response, int userId, AuthenticatorInfo info, boolean expectActivityLaunch, boolean stripAuthTokenFromResult, String accountName, boolean authDetailsRequired, boolean updateLastAuthenticatedTime) { if (info == null) throw new IllegalArgumentException("accountType is null"); this.mStripAuthTokenFromResult = stripAuthTokenFromResult; this.mResponse = response; this.mUserId = userId; this.mAuthenticatorInfo = info; this.mExpectActivityLaunch = expectActivityLaunch; this.mCreationTime = SystemClock.elapsedRealtime(); this.mAccountName = accountName; this.mAuthDetailsRequired = authDetailsRequired; this.mUpdateLastAuthenticatedTime = updateLastAuthenticatedTime; synchronized (mSessions) { mSessions.put(toString(), this); } if (response != null) { try { response.asBinder().linkToDeath(this, 0 /* flags */); } catch (RemoteException e) { mResponse = null; binderDied(); } } }
public void confirmCredentials(int userId, IAccountManagerResponse response, final Account account, final Bundle options, final boolean expectActivityLaunch) { if (response == null) throw new IllegalArgumentException("response is null"); if (account == null) throw new IllegalArgumentException("account is null"); AuthenticatorInfo info = getAuthenticatorInfo(account.type); if (info == null) { try { response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist"); } catch (RemoteException e) { e.printStackTrace(); } return; } new Session(response, userId, info, expectActivityLaunch, true, account.name, true, true) { @Override public void run() throws RemoteException { mAuthenticator.confirmCredentials(this, account, options); } }.bind(); }
@Override public void onResult(Bundle result) throws RemoteException { IAccountManagerResponse response = getResponseAndClose(); if (response != null) { try { if (result == null) { response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, "null bundle"); return; } Log.v(TAG, getClass().getSimpleName() + " calling onResult() on response " + response); final Bundle newResult = new Bundle(); newResult.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT, false)); response.onResult(newResult); } catch (RemoteException e) { // if the caller is dead then there is no one to care about remote exceptions Log.v(TAG, "failure while notifying response", e); } } } }.bind();
@Override public void onResult(Bundle result) throws RemoteException { if (result != null && result.containsKey(AccountManager.KEY_BOOLEAN_RESULT) && !result.containsKey(AccountManager.KEY_INTENT)) { final boolean removalAllowed = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT); if (removalAllowed) { removeAccountInternal(userId, account); } IAccountManagerResponse response = getResponseAndClose(); if (response != null) { Log.v(TAG, getClass().getSimpleName() + " calling onResult() on response " + response); Bundle result2 = new Bundle(); result2.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, removalAllowed); try { response.onResult(result2); } catch (RemoteException e) { e.printStackTrace(); } } } super.onResult(result); }
private void close() { synchronized (mSessions) { if (mSessions.remove(toString()) == null) { // the session was already closed, so bail out now return; } } if (mResponse != null) { // stop listening for response deaths mResponse.asBinder().unlinkToDeath(this, 0 /* flags */); // clear this so that we don't accidentally send any further results mResponse = null; } unbind(); }
if (info == null) { try { response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist"); } catch (RemoteException e) { e.printStackTrace();
@Override public void onResult(Bundle result) throws RemoteException { IAccountManagerResponse response = getResponseAndClose(); if (response != null) { try { if (result == null) { response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, "null bundle"); return; } Log.v(TAG, getClass().getSimpleName() + " calling onResult() on response " + response); final Bundle newResult = new Bundle(); newResult.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT, false)); response.onResult(newResult); } catch (RemoteException e) { // if the caller is dead then there is no one to care about remote exceptions Log.v(TAG, "failure while notifying response", e); } } } }.bind();
@Override public void getAccountsByFeatures(int userId, IAccountManagerResponse response, String type, String[] features) { if (response == null) throw new IllegalArgumentException("response is null"); if (type == null) throw new IllegalArgumentException("accountType is null"); AuthenticatorInfo info = getAuthenticatorInfo(type); if (info == null) { Bundle bundle = new Bundle(); bundle.putParcelableArray(AccountManager.KEY_ACCOUNTS, new Account[0]); try { response.onResult(bundle); } catch (RemoteException e) { e.printStackTrace(); } return; } if (features == null || features.length == 0) { Bundle bundle = new Bundle(); bundle.putParcelableArray(AccountManager.KEY_ACCOUNTS, getAccounts(userId, type)); try { response.onResult(bundle); } catch (RemoteException e) { e.printStackTrace(); } } else { new GetAccountsByTypeAndFeatureSession(response, userId, info, features).bind(); } }
private void close() { synchronized (mSessions) { if (mSessions.remove(toString()) == null) { // the session was already closed, so bail out now return; } } if (mResponse != null) { // stop listening for response deaths mResponse.asBinder().unlinkToDeath(this, 0 /* flags */); // clear this so that we don't accidentally send any further results mResponse = null; } unbind(); }
@Override public void editProperties(int userId, IAccountManagerResponse response, final String accountType, final boolean expectActivityLaunch) { if (response == null) throw new IllegalArgumentException("response is null"); if (accountType == null) throw new IllegalArgumentException("accountType is null"); AuthenticatorInfo info = this.getAuthenticatorInfo(accountType); if (info == null) { try { response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist"); } catch (RemoteException e) { e.printStackTrace(); } return; } new Session(response, userId, info, expectActivityLaunch, true, null) { @Override public void run() throws RemoteException { mAuthenticator.editProperties(this, mAuthenticatorInfo.desc.type); } @Override protected String toDebugString(long now) { return super.toDebugString(now) + ", editProperties" + ", accountType " + accountType; } }.bind(); }
Log.v(TAG, getClass().getSimpleName() + " calling onError() on response " + response); response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, "null bundle returned"); } else { (intent == null)) { response.onError(result.getInt(AccountManager.KEY_ERROR_CODE), result.getString(AccountManager.KEY_ERROR_MESSAGE)); } else { response.onResult(result);
private void onResult(IAccountManagerResponse response, Bundle result) { try { response.onResult(result); } catch (RemoteException e) { // if the caller is dead then there is no one to care about remote // exceptions e.printStackTrace(); } }