Commit 320aec0f authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android][Signin] Add utility methods to CoreAccountInfo

Adds a getAndroidAccount, getId, getEmail, getGaiaId static helpers to
CoreAccountInfo. These helpers all do the same task - they return
Account/CoreAccountId/Email/GaiaId from the argument if it's not null,
and return null otherwise. IdentityManager.getPrimaryAccountId will be
replaced by this in subsequent CLs.

Bug: 1051000
Change-Id: Id0cc2bb5049f5464cbfc06a4866c7a9bf2074724
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2061813
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Auto-Submit: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743082}
parent 68d4bec3
......@@ -4,9 +4,13 @@
package org.chromium.components.signin.base;
import android.accounts.Account;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.components.signin.AccountManagerFacade;
/**
* Structure storing the core information about a Google account that is always known. The {@link
......@@ -80,4 +84,42 @@ public class CoreAccountInfo {
return mId.equals(other.mId) && mEmail.equals(other.mEmail)
&& mGaiaId.equals(other.mGaiaId);
}
/**
* Null-checking helper to create {@link Account} from a possibly null {@link CoreAccountInfo}.
*
* @return {@link Account} for the argument if it is not null, null otherwise.
*/
public static @Nullable Account getAndroidAccountFrom(@Nullable CoreAccountInfo accountInfo) {
return accountInfo == null
? null
: AccountManagerFacade.createAccountFromName(accountInfo.getEmail());
}
/**
* Null-checking helper to get an account id from a possibly null {@link CoreAccountInfo}.
*
* @return {@link #getId()} for the argument if it is not null, null otherwise.
*/
public static @Nullable CoreAccountId getIdFrom(@Nullable CoreAccountInfo accountInfo) {
return accountInfo == null ? null : accountInfo.getId();
}
/**
* Null-checking helper to get an email from a possibly null {@link CoreAccountInfo}.
*
* @return {@link #getEmail()} for the argument if it is not null, null otherwise.
*/
public static @Nullable String getEmailFrom(@Nullable CoreAccountInfo accountInfo) {
return accountInfo == null ? null : accountInfo.getEmail();
}
/**
* Null-checking helper to get a GaiaId from a possibly null {@link CoreAccountInfo}.
*
* @return {@link #getGaiaId()} ()} for the argument if it is not null, null otherwise.
*/
public static @Nullable String getGaiaIdFrom(@Nullable CoreAccountInfo accountInfo) {
return accountInfo == null ? null : accountInfo.getGaiaId();
}
}
......@@ -141,8 +141,7 @@ public class IdentityManager {
* is available.
*/
public @Nullable CoreAccountId getPrimaryAccountId() {
CoreAccountInfo primaryAccountInfo = getPrimaryAccountInfo();
return primaryAccountInfo == null ? null : primaryAccountInfo.getId();
return CoreAccountInfo.getIdFrom(getPrimaryAccountInfo());
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment