/** Sends the result or a Constants.ERROR_CODE_CANCELED error if a result isn't present. */
 public void finish() {
   if (mAccountAuthenticatorResponse != null) {
     // send the result bundle back if set, otherwise send an error.
     if (mResultBundle != null) {
       mAccountAuthenticatorResponse.onResult(mResultBundle);
     } else {
       mAccountAuthenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, "canceled");
     }
     mAccountAuthenticatorResponse = null;
   }
   super.finish();
 }
  @Override
  public Bundle addAccount(
      AccountAuthenticatorResponse response,
      String accountType,
      String authTokenType,
      String[] requiredFeatures,
      Bundle options) {
    Log.i(TAG, "addAccount()");
    AccountManager am = AccountManager.get(mContext);
    Account[] accounts = am.getAccountsByType(accountType);
    if (accounts.length > 0) {
      int errCode = AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION;
      Log.w(TAG, errAccountExists);

      // too bad this doesn't show the user an error or message of any kind
      final Bundle errBundle = new Bundle();
      errBundle.putInt(AccountManager.KEY_ERROR_CODE, errCode);
      errBundle.putString(AccountManager.KEY_ERROR_MESSAGE, errAccountExists);
      accountExistsHandler.sendEmptyMessage(0);

      // choose to return as response.onError over bundle
      response.onError(errCode, errAccountExists);
      return null;
    }

    final Intent intent = new Intent(mContext, LDAPAuthenticatorActivity.class);
    intent.putExtra(LDAPAuthenticatorActivity.PARAM_AUTHTOKEN_TYPE, authTokenType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);

    // choose to return as bundle over response.onResult
    return bundle;
  }
  /**
   * Retreives the AccountAuthenticatorResponse from either the intent of the icicle, if the icicle
   * is non-zero.
   *
   * @param icicle the save instance data of this Activity, may be null
   */
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mAccountAuthenticatorResponse =
        getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);

    if (mAccountAuthenticatorResponse != null) {
      mAccountAuthenticatorResponse.onRequestContinued();
    }
  }
 public final Bundle addAccount(
     AccountAuthenticatorResponse paramAccountAuthenticatorResponse,
     String paramString1,
     String paramString2,
     String[] paramArrayOfString,
     Bundle paramBundle) {
   if ((paramBundle != null)
       && (paramBundle.containsKey("password"))
       && (paramBundle.containsKey("username"))) {
     paramAccountAuthenticatorResponse =
         new Account(paramBundle.getString("username"), "com.android.test_exchange");
     AccountManager.get(a)
         .addAccountExplicitly(
             paramAccountAuthenticatorResponse, paramBundle.getString("password"), null);
     paramAccountAuthenticatorResponse = new Bundle();
     paramAccountAuthenticatorResponse.putString("authAccount", "com.android.test_exchange");
     return paramAccountAuthenticatorResponse;
   }
   paramString2 = new Bundle();
   paramString1 = bbm.a(a, paramString1);
   paramString1.putExtra("accountAuthenticatorResponse", paramAccountAuthenticatorResponse);
   paramString2.putParcelable("intent", paramString1);
   return paramString2;
 }