Android SampleSyncAdapter示例中的authToken

时间:2012-12-01 18:43:17

标签: android android-syncadapter

这段代码来自Android SampleSyncAdapter示例项目中的AuthenticatorActivity。它说,

  

我们存储从服务器返回的authToken作为   '密码'对于这个帐户 - 所以我们永远不会存储用户的实际情况   密码本地。

但我根本没有看到authToken被使用。为什么?这是错误还是故意的?

/**
 * Called when response is received from the server for authentication
 * request. See onAuthenticationResult(). Sets the
 * AccountAuthenticatorResult which is sent back to the caller. We store the
 * authToken that's returned from the server as the 'password' for this
 * account - so we're never storing the user's actual password locally.
 *
 * @param result the confirmCredentials result.
 */
private void finishLogin(String authToken) {

    Log.i(TAG, "finishLogin()");
    final Account account = new Account(mUsername, Constants.ACCOUNT_TYPE);
    if (mRequestNewAccount) {
        mAccountManager.addAccountExplicitly(account, mPassword, null);
        // Set contacts sync for this account.
        ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
    } else {
        mAccountManager.setPassword(account, mPassword);
    }
    final Intent intent = new Intent();
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);
    finish();
}

1 个答案:

答案 0 :(得分:2)

同意,这很令人困惑,特别是因为SampleSyncAdapter代表了围绕这些类的一些唯一文档。也就是说,我认为评论是错误的,因为AbstractAccountAuthenticator和服务都依赖于密码。我已经提交了一个错误澄清:

http://code.google.com/p/android/issues/detail?id=40878&thanks=40878&ts=1354582803