java类android.accounts.AccountManager的实例源码

VAccountManagerService.java 文件源码 项目:TPlayer 阅读 26 收藏 0 点赞 0 评论 0
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);
        }
    }
}
VAccountManagerService.java 文件源码 项目:TPlayer 阅读 30 收藏 0 点赞 0 评论 0
public void checkAccount() {
    if (mCurrentAccount >= mAccountsOfType.length) {
        sendResult();
        return;
    }

    final IAccountAuthenticator accountAuthenticator = mAuthenticator;
    if (accountAuthenticator == null) {
        // It is possible that the authenticator has died, which is indicated by
        // mAuthenticator being set to null. If this happens then just abort.
        // There is no need to send back a result or error in this case since
        // that already happened when mAuthenticator was cleared.
        Log.v(TAG, "checkAccount: aborting session since we are no longer"
                + " connected to the authenticator, " + toDebugString());
        return;
    }
    try {
        accountAuthenticator.hasFeatures(this, mAccountsOfType[mCurrentAccount], mFeatures);
    } catch (RemoteException e) {
        onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "remote exception");
    }
}
AndroidAuthenticator.java 文件源码 项目:GitHub 阅读 30 收藏 0 点赞 0 评论 0
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount,
            mAuthTokenType, mNotifyAuthFailure, null, null);
    Bundle result;
    try {
        result = future.getResult();
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
    String authToken = null;
    if (future.isDone() && !future.isCancelled()) {
        if (result.containsKey(AccountManager.KEY_INTENT)) {
            Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
            throw new AuthFailureError(intent);
        }
        authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
    }
    if (authToken == null) {
        throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
    }

    return authToken;
}
VAccountManagerService.java 文件源码 项目:container 阅读 34 收藏 0 点赞 0 评论 0
void bind() {
    Log.v(TAG, "initiating bind to authenticator type " + mAuthenticatorInfo.desc.type);
    Intent intent = new Intent();
    intent.setAction(AccountManager.ACTION_AUTHENTICATOR_INTENT);
    intent.setClassName(mAuthenticatorInfo.serviceInfo.packageName, mAuthenticatorInfo.serviceInfo.name);
    intent.putExtra("_VA_|_user_id_", mUserId);

    if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
        Log.d(TAG, "bind attempt failed for " + toDebugString());
        onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "bind failure");
    }
}
AndroidAuthenticator.java 文件源码 项目:publicProject 阅读 19 收藏 0 点赞 0 评论 0
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount,
            mAuthTokenType, mNotifyAuthFailure, null, null);
    Bundle result;
    try {
        result = future.getResult();
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
    String authToken = null;
    if (future.isDone() && !future.isCancelled()) {
        if (result.containsKey(AccountManager.KEY_INTENT)) {
            Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
            throw new AuthFailureError(intent);
        }
        authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
    }
    if (authToken == null) {
        throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
    }

    return authToken;
}
CalendarSyncAdapter.java 文件源码 项目:FBEventSync 阅读 30 收藏 0 点赞 0 评论 0
private void createAuthNotification()
{
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(getContext(), AuthenticatorActivity.AUTH_NOTIFICATION_CHANNEL_ID)
                .setContentTitle(getContext().getString(R.string.sync_ntf_needs_reauthentication_title))
                .setContentText(getContext().getString(R.string.sync_ntf_needs_reauthentication_description))
                .setSmallIcon(R.mipmap.ic_launcher)
                .setAutoCancel(true);

    Intent intent = new Intent(getContext(), AuthenticatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, getContext().getString(R.string.account_type));
    intent.putExtra(AuthenticatorActivity.ARG_AUTH_TOKEN_TYPE, AuthenticatorActivity.ARG_AUTH_TOKEN_TYPE);
    intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, false);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());
    stackBuilder.addParentStack(AuthenticatorActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    NotificationManager ntfMgr =
            (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
    ntfMgr.notify(AuthenticatorActivity.AUTH_NOTIFICATION_ID, builder.build());
}
VAccountManagerService.java 文件源码 项目:container 阅读 30 收藏 0 点赞 0 评论 0
public void checkAccount() {
    if (mCurrentAccount >= mAccountsOfType.length) {
        sendResult();
        return;
    }

    final IAccountAuthenticator accountAuthenticator = mAuthenticator;
    if (accountAuthenticator == null) {
        // It is possible that the authenticator has died, which is indicated by
        // mAuthenticator being set to null. If this happens then just abort.
        // There is no need to send back a result or error in this case since
        // that already happened when mAuthenticator was cleared.
        Log.v(TAG, "checkAccount: aborting session since we are no longer"
                      + " connected to the authenticator, " + toDebugString());
        return;
    }
    try {
        accountAuthenticator.hasFeatures(this, mAccountsOfType[mCurrentAccount], mFeatures);
    } catch (RemoteException e) {
        onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "remote exception");
    }
}
Util.java 文件源码 项目:android-ponewheel 阅读 24 收藏 0 点赞 0 评论 0
public static String getUsername(Context c) {
    AccountManager manager = AccountManager.get(c);
    Account[] accounts = manager.getAccountsByType("com.google");
    List<String> possibleEmails = new LinkedList<String>();

    for (Account account : accounts) {
        // TODO: Check possibleEmail against an email regex or treat
        // account.name as an email address only for certain account.type values.
        possibleEmails.add(account.name);
    }

    if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) {
        String email = possibleEmails.get(0);
        String[] parts = email.split("@");

        if (parts.length > 1)
            return parts[0];
    }
    return null;
}
Profile.java 文件源码 项目:hypertrack-live-android 阅读 32 收藏 0 点赞 0 评论 0
private String getName() {
    AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS)
            != PackageManager.PERMISSION_GRANTED) {
        return null;
    }

    Account[] list = manager.getAccounts();

    for (Account account : list) {
        if (account.type.equalsIgnoreCase("com.google")) {
            return account.name;
        }
    }
    return null;
}
AndroidAuthenticator.java 文件源码 项目:airgram 阅读 24 收藏 0 点赞 0 评论 0
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount,
            mAuthTokenType, mNotifyAuthFailure, null, null);
    Bundle result;
    try {
        result = future.getResult();
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
    String authToken = null;
    if (future.isDone() && !future.isCancelled()) {
        if (result.containsKey(AccountManager.KEY_INTENT)) {
            Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
            throw new AuthFailureError(intent);
        }
        authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
    }
    if (authToken == null) {
        throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
    }

    return authToken;
}
VerifyOTP.java 文件源码 项目:XERUNG 阅读 26 收藏 0 点赞 0 评论 0
private ArrayList<String> getUserEmail(){

        ArrayList<String> email = new ArrayList<String>();

        Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
        Account[] accounts = AccountManager.get(VerifyOTP.this).getAccounts();
        for (Account account : accounts) {
            if (emailPattern.matcher(account.name).matches()) {
                String possibleEmail = account.name;
                if(possibleEmail != null)
                    if(possibleEmail.length() !=0 ){
                        email.add(possibleEmail);
                    }
            }
        }       
        return email;

    }
VAccountManagerService.java 文件源码 项目:container 阅读 32 收藏 0 点赞 0 评论 0
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);
        }
    }
}
BaseLoginActivity.java 文件源码 项目:EasyAppleSyncAdapter 阅读 19 收藏 0 点赞 0 评论 0
protected void init() {
    initCrypto();

    accountManager = AccountManager.get(getBaseContext());
    serverHandler = new AuthServerHandlerImpl();

    userName = (EditText) findViewById(R.id.user_name);
    password = (EditText) findViewById(R.id.password);
    signIn = (Button) findViewById(R.id.signin_button);
    progressLayout = findViewById(R.id.progress_layout);

    Intent intent = getIntent();
    authTokenType = getIntent().getStringExtra(GlobalConstant.AUTH_TYPE);
    if (authTokenType == null) {
        authTokenType = GlobalConstant.AUTHTOKEN_TYPE_FULL_ACCESS;
    }

    isNewAccount = intent.getBooleanExtra(GlobalConstant.IS_ADDING_NEW_ACCOUNT, true);
    if (!isNewAccount) {
        // existing account
        String accountName = getIntent().getStringExtra(GlobalConstant.ACCOUNT_NAME);
        userName.setText(accountName);
    }

    signIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            login();
        }
    });
}
BaseLoginActivity.java 文件源码 项目:EasyAppleSyncAdapter 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Pass the data from server to authenticator class
 *
 * @param intent the intent contain data from user and server {@link AccountManager#KEY_ACCOUNT_NAME},
 *               {@link AccountManager#KEY_AUTHTOKEN}, {@link AccountManager#KEY_ACCOUNT_TYPE} and
 *               {@link GlobalConstant#PARAM_USER_PASS}
 * @throws NoSuchPaddingException
 * @throws InvalidAlgorithmParameterException
 * @throws NoSuchAlgorithmException
 * @throws IllegalBlockSizeException
 * @throws BadPaddingException
 * @throws InvalidKeyException
 * @throws UnsupportedEncodingException
 * @throws SignInException
 */
private void passDataToAuthenticator(Intent intent)
        throws NoSuchPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException,
        IllegalBlockSizeException, BadPaddingException, InvalidKeyException, UnsupportedEncodingException,
        SignInException {

    if (intent.hasExtra(SIGNIN_ERROR)) throw new SignInException();

    String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
    String accountPassword = intent.getStringExtra(GlobalConstant.PARAM_USER_PASS);
    accountPassword = Crypto.armorEncrypt(accountPassword.getBytes("UTF-8"), this);

    final Account account = new Account(accountName, authTokenType);

    if (isNewAccount) {
        String iCalId = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN);
        String authtoken = intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);

        // encrypt user id and pass it to intent
        iCalId = Crypto.armorEncrypt(iCalId.getBytes("UTF-8"), this);
        intent.putExtra(AccountManager.KEY_AUTHTOKEN, iCalId);

        final Bundle extraData = new Bundle();
        extraData.putString(PARAM_PRINCIPAL, iCalId);

        accountManager.addAccountExplicitly(account, accountPassword, extraData);
        accountManager.setAuthToken(account, authtoken, iCalId);
    } else {
        accountManager.setPassword(account, accountPassword);
    }

    // encrypt password and pass it to intent
    intent.putExtra(GlobalConstant.PARAM_USER_PASS, accountPassword);


    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);
    finish();
}
AuthenticatorActivity.java 文件源码 项目:account-transfer-api 阅读 18 收藏 0 点赞 0 评论 0
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_activity);
    mAccountManager = AccountManager.get(getBaseContext());

    findViewById(R.id.submit)
            .setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            addAccount();
                        }
                    });
}
XAccountManager.java 文件源码 项目:XPrivacy 阅读 26 收藏 0 点赞 0 评论 0
@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");
}
MainActivity.java 文件源码 项目:account-transfer-api 阅读 20 收藏 0 点赞 0 评论 0
private void populateAccountTextView() {
    AccountManager am = AccountManager.get(this);
    Account[] accounts = am.getAccountsByType(ACCOUNT_TYPE);
    String accountString = "Accounts of type " + ACCOUNT_TYPE + " are : \n";
    if (accounts.length != 0) {
        for (Account account : accounts) {
            accountString += "Account:" +  account.name + "\n";
        }
    } else {
        accountString = "No Accounts of type " + ACCOUNT_TYPE +
                " found. Please add accounts before exporting.";
        mAccountTextView.setTextColor(Color.RED);
    }
    mAccountTextView.setText(accountString);
}
ChooseAccountTypeActivity.java 文件源码 项目:TPlayer 阅读 20 收藏 0 点赞 0 评论 0
private void setResultAndFinish(final String type) {
    Bundle bundle = new Bundle();
    bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, type);
    setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
    VLog.v(TAG, "ChooseAccountTypeActivity.setResultAndFinish: "
            + "selected account type " + type);
    finish();
}
AccountSettings.java 文件源码 项目:EasyAppleSyncAdapter 阅读 30 收藏 0 点赞 0 评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public AccountSettings(@NonNull Context context, @NonNull Account account) throws InvalidAccountException {
    this.context = context;
    this.account = account;

    accountManager = AccountManager.get(context);
}
VAccountManagerService.java 文件源码 项目:VirtualHook 阅读 37 收藏 0 点赞 0 评论 0
public void refreshAuthenticatorCache(String packageName) {
    cache.authenticators.clear();
    Intent intent = new Intent(AccountManager.ACTION_AUTHENTICATOR_INTENT);
    if (packageName != null) {
        intent.setPackage(packageName);
    }
    generateServicesMap(
            VPackageManagerService.get().queryIntentServices(intent, null, PackageManager.GET_META_DATA, 0),
            cache.authenticators, new AppAccountParser());
}
Utils.java 文件源码 项目:MiPushFramework 阅读 21 收藏 0 点赞 0 评论 0
public static final String getXiaomiUserId(Context context) {
    Account[] accounts = AccountManager.get(context).getAccounts();
    for (int i = 0; i < accounts.length; i++) {
        if (accounts[i].type.equals("com.xiaomi")) {
            String str = accounts[i].name;
            if (!str.trim().isEmpty()) {
                return str;
            }
        }
    }
    return null;
}
DeviceUtils.java 文件源码 项目:My-Android-Base-Code 阅读 33 收藏 0 点赞 0 评论 0
public static String getDeviceEmailAddress(Activity activity) {
    Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
        return "";
    }
    Account[] accounts = AccountManager.get(activity).getAccounts();
    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches()) {
            return account.name;
        }
    }
    return "";
}
AuthenticatorActivity.java 文件源码 项目:Phony-Android 阅读 24 收藏 0 点赞 0 评论 0
@Override
protected void onPostExecute(final Intent intent) {
    mAuthTask = null;
    showProgress(false);

    if (!intent.hasExtra(AccountManager.KEY_ERROR_MESSAGE)) {
        finishLogin(intent);
    } else {
        mPasswordView.setError(getString(R.string.error_incorrect_password));
        mPasswordView.requestFocus();
    }
}
PhonyAuthenticator.java 文件源码 项目:Phony-Android 阅读 43 收藏 0 点赞 0 评论 0
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
    Log.d(TAG, "addAccount: called.");

    final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
    intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}
AuthenticatorService.java 文件源码 项目:PlusGram 阅读 22 收藏 0 点赞 0 评论 0
@Override
public IBinder onBind(Intent intent) {
    if (intent.getAction().equals(AccountManager.ACTION_AUTHENTICATOR_INTENT)) {
        return getAuthenticator().getIBinder();
    } else {
        return null;
    }
}
HttpNegotiateAuthenticatorTest.java 文件源码 项目:chromium-net-for-android 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Tests the behavior of {@link HttpNegotiateAuthenticator.GetTokenCallback} when the result it
 * receives contains an intent rather than a token directly.
 */
@Test
public void testGetTokenCallbackWithIntent() {
    String type = "Dummy_Account";
    HttpNegotiateAuthenticator authenticator = createWithoutNative(type);
    RequestData requestData = new RequestData();
    requestData.nativeResultObject = 42;
    requestData.authTokenType = "foo";
    requestData.account = new Account("a", type);
    requestData.accountManager = sMockAccountManager;
    Bundle b = new Bundle();
    b.putParcelable(AccountManager.KEY_INTENT, new Intent());

    authenticator.new GetTokenCallback(requestData).run(makeFuture(b));
    verifyZeroInteractions(sMockAccountManager);

    // Verify that the broadcast receiver is registered
    Intent intent = new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION);
    ShadowApplication shadowApplication = Robolectric.getShadowApplication();
    List<BroadcastReceiver> receivers = shadowApplication.getReceiversForIntent(intent);
    assertThat("There is one registered broadcast receiver", receivers.size(), equalTo(1));

    // Send the intent to the receiver.
    BroadcastReceiver receiver = receivers.get(0);
    receiver.onReceive(Robolectric.getShadowApplication().getApplicationContext(), intent);

    // Verify that the auth token is properly requested from the account manager.
    verify(sMockAccountManager).getAuthToken(
            eq(new Account("a", type)),
            eq("foo"),
            isNull(Bundle.class),
            eq(true),
            any(HttpNegotiateAuthenticator.GetTokenCallback.class),
            any(Handler.class));
}
VAccountManagerService.java 文件源码 项目:container 阅读 35 收藏 0 点赞 0 评论 0
public void refreshAuthenticatorCache(String packageName) {
    cache.authenticators.clear();
    Intent intent = new Intent(AccountManager.ACTION_AUTHENTICATOR_INTENT);
    if (packageName != null) {
        intent.setPackage(packageName);
    }
    generateServicesMap(
            VPackageManagerService.get().queryIntentServices(intent, null, PackageManager.GET_META_DATA, 0),
            cache.authenticators, new AppAccountParser());
}
DeviceUtils.java 文件源码 项目:MVP-Android 阅读 32 收藏 0 点赞 0 评论 0
public static String getDeviceEmailAddress(Activity activity) {
    Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
        return "";
    }
    Account[] accounts = AccountManager.get(activity).getAccounts();
    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches()) {
            return account.name;
        }
    }
    return "";
}
SyncAdapter.java 文件源码 项目:react-native-sync-adapter 阅读 41 收藏 0 点赞 0 评论 0
static Account getSyncAccount(Context context, int syncInterval, int syncFlexTime) {
    // Get an instance of the Android account manager
    AccountManager accountManager =
            (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    // Create the account type and default account
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.rnsb_sync_account_type));

    // If the password doesn't exist, the account doesn't exist
    if (null == accountManager.getPassword(newAccount)) {

    /*
     * Add the account and account type, no password or user data
     * If successful, return the Account object, otherwise report an error.
     */
        if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
            return null;
        }
        /*
         * If you don't set android:syncable="true" in
         * in your <provider> element in the manifest,
         * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
         * here.
         */
        onAccountCreated(newAccount, context, syncInterval, syncFlexTime);
    }
    return newAccount;
}
VAccountManagerService.java 文件源码 项目:container 阅读 34 收藏 0 点赞 0 评论 0
@Override
public void getAuthTokenLabel(int userId, IAccountManagerResponse response, final String accountType,
                              final String authTokenType) {
    if (accountType == null) throw new IllegalArgumentException("accountType is null");
    if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
    AuthenticatorInfo info = 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, false, false, null) {

        @Override
        public void run() throws RemoteException {
            mAuthenticator.getAuthTokenLabel(this, authTokenType);
        }

        @Override
        public void onResult(Bundle result) throws RemoteException {
            if (result != null) {
                String label = result.getString(AccountManager.KEY_AUTH_TOKEN_LABEL);
                Bundle bundle = new Bundle();
                bundle.putString(AccountManager.KEY_AUTH_TOKEN_LABEL, label);
                super.onResult(bundle);
            } else {
                super.onResult(null);
            }
        }
    }.bind();
}


问题


面经


文章

微信
公众号

扫码关注公众号