目录

Credential

Class Info

public class Credential

Credential which can be saved to or accessed from Keyring.

Public Constructor Summary

Constructor Name

public Credential(String username, CredentialType type, Boolean userAuth, byte[] newContent)

Constructs a Credential object.

Public Method Summary

Qualifier and Type

Method Name and Description

public Boolean

getAvailable()

Checks whether a credential is available. The credential whose userAuth is true will become unavailable permanently after the user cancels their lock screen password.

public String

getAvatarUrl()

Obtains the URL of a user's avatar.

public void

getContent(CredentialCallback<byte[]> callback)

Obtains the secret content of a credential. If userAuth is set to true for a credential, the user needs to complete verification through their biometric feature or lock screen password before the credential content can be obtained.

public String

getDisplayName()

Obtains the display name of the credential owner.

public AppIdentity

getOwner()

Obtains the credential owner, that is, the app which saves the credential.

public List<AppIdentity>

getSharedWith()

Obtains the sharing relationship of a credential. Only the credential owner can obtain the sharing relationship.

public Boolean

getSyncable()

Checks whether a credential can be synchronized between devices. This method is reserved. In this version, the credential cannot be synchronized between devices.

public String

getTag()

Obtains the tag of a credential.

public long

getTimeCreated()

Obtains the time when a credential is created, which is a UNIX time. The unit is milliseconds.

public long

getTimeUpdated()

Obtains the time when a credential is updated the last time, which is a UNIX time. The unit is milliseconds.

public long

getTimeUsed()

Obtains the time when a credential is used the last time, which is a UNIX time. The unit is milliseconds.

public CredentialType

getType()

Obtains the credential type.

public Boolean

getUserAuth()

Checks whether the user identity needs to be verified when the getContent method is called.

public String

getUsername()

Obtains the user name of a credential.

public void

setAvatarUrl(String avatarUrl)

Sets the URL of a user's avatar.

public void

setDisplayName(String displayName)

Sets a display name.

public void

setNewContent(byte[] newContent)

Sets the new sensitive information of a credential, such as the password, session token, and federated authentication URL. The sensitive information will be encrypted for storage.

public void

setSharedWith(List<AppIdentity> sharedWith)

Sets the sharing relationship of a credential to specify apps that can use the credential.

public void

setSyncable(Boolean syncable)

Sets whether a credential can be synchronized between devices. This method is reserved. In this version, the credential cannot be synchronized between devices.

public void

setTag(String tag)

Sets the tag of a credential.

public String

toString()

Obtains the string of a Credential object from which sensitive information has been deleted. The string does not include attributes such as username, content, and newContent.

Public Constructors

[h2]Credential

Constructor

public Credential(String username, CredentialType type, Boolean userAuth, byte[] newContent)

Constructs a Credential object.

Parameters

Name

Description

username

User name, which can contain a maximum of 128 characters.

CAUTION:

The user name will be displayed to the user on the credential management screen. Therefore, it must be understandable. For details about the credential management screen, please refer to Credential Management Screen.

type

Credential type.

userAuth

Indicates whether the user's biometric feature or lock screen password needs to be verified for using a credential.

newContent

Credential content, such as the password, session token, and federated authentication URL. The content will be encrypted for storage. The value can contain a maximum of 16,384 characters.

Public Methods

[h2]getAvailable

Method

public Boolean getAvailable()

Checks whether a credential is available. The credential whose userAuth is true will become unavailable permanently after the user cancels their lock screen password.

Returns

Type

Description

Boolean

true if the credential is available; false otherwise.

[h2]getAvatarUrl

Method

public String getAvatarUrl()

Obtains the URL of a user's avatar.

Returns

Type

Description

String

URL of a user's avatar.

[h2]getContent

Method

public void getContent(CredentialCallback<byte[]> callback)

Obtains the secret content of a credential. If userAuth is set to true for a credential, the user needs to complete verification through their biometric feature or lock screen password before the credential content can be obtained.

Parameters

Name

Description

callback

Callback object.

[h2]getDisplayName

Method

public String getDisplayName()

Obtains the display name of the credential owner.

Returns

Type

Description

String

Display name of the credential owner.

[h2]getOwner

Method

public AppIdentity getOwner()

Obtains the credential owner, that is, the app which saves the credential.

Returns

Type

Description

AppIdentity

Credential owner, that is, the app which saves the credential.

[h2]getSharedWith

Method

public List<AppIdentity> getSharedWith()

Obtains the sharing relationship of a credential. Only the credential owner can obtain the sharing relationship.

Returns

Type

Description

List<AppIdentity>

Sharing relationship of a credential. Only the credential owner can obtain the sharing relationship.

[h2]getSyncable

Method

public Boolean getSyncable()

Checks whether a credential can be synchronized between devices. This method is reserved. In this version, the credential cannot be synchronized between devices.

Returns

Type

Description

Boolean

true if the credential can be synchronized between devices; false otherwise.

[h2]getTag

Method

public String getTag()

Obtains the tag of a credential.

Returns

Type

Description

String

Tag of a credential.

[h2]getTimeCreated

Method

public long getTimeCreated()

Obtains the time when a credential is created, which is a UNIX time. The unit is milliseconds.

Returns

Type

Description

long

Time when a credential is created, which is a UNIX time. The unit is milliseconds.

[h2]getTimeUpdated

Method

public long getTimeUpdated()

Obtains the time when a credential is updated the last time, which is a UNIX time. The unit is milliseconds.

Returns

Type

Description

long

Time when a credential is updated the last time, which is a UNIX time. The unit is milliseconds.

[h2]getTimeUsed

Method

public long getTimeUsed()

Obtains the time when a credential is used the last time, which is a UNIX time. The unit is milliseconds.

Returns

Type

Description

long

Time when a credential is used the last time, which is a UNIX time. The unit is milliseconds.

[h2]getType

Method

public CredentialType getType()

Obtains the credential type.

Returns

Type

Description

CredentialType

Credential type.

[h2]getUserAuth

Method

public Boolean getUserAuth()

Checks whether the user identity needs to be verified when the getContent method is called.

Returns

Type

Description

Boolean

true if the user identity needs to be verified; false otherwise.

[h2]getUsername

Method

public String getUsername()

Obtains the user name of a credential.

Returns

Type

Description

String

User name of a credential.

[h2]setAvatarUrl

Method

public void setAvatarUrl(String avatarUrl)

Sets the URL of a user's avatar, which can contain a maximum of 16,384 characters.

Parameters

Name

Description

avatarUrl

URL of a user's avatar, which can contain a maximum of 16,384 characters. If you want to directly save the avatar content, you are advised to use the data URI scheme.

[h2]setDisplayName

Method

public void setDisplayName(String displayName)

Sets the display name, which can contain a maximum of 128 characters.

Parameters

Name

Description

displayName

Display name, which can contain a maximum of 128 characters.

[h2]setNewContent

Method

public void setNewContent(byte[] newContent)

Sets the new sensitive information of a credential, such as the password, token, and federated authentication URL. The sensitive information will be encrypted for storage. The value can contain a maximum of 16,384 characters.

Parameters

Name

Description

newContent

New sensitive information of the credential, for example, the password, token, and federated authentication URL. The value can contain a maximum of 16,384 characters.

[h2]setSharedWith

Method

public void setSharedWith(List<AppIdentity> sharedWith)

Sets the sharing relationship of a credential to specify apps that can use the credential. A credential can be shared with a maximum of 128 apps.

Parameters

Name

Description

sharedWith

Sharing relationship of a credential, which specifies apps that can use the credential. A credential can be shared with a maximum of 128 apps.

[h2]setSyncable

Method

public void setSyncable(Boolean syncable)

Sets whether a credential can be synchronized between devices. During synchronization, sensitive information in the credential is encrypted using password technologies. Huawei will not obtain the credential content. This method is reserved. In this version, the credential cannot be synchronized between devices.

Parameters

Name

Description

syncable

Indicates whether a credential can be synchronized between devices.

[h2]setTag

Method

public void setTag(String tag)

Sets the tag of a credential. You can save some customized information in the tag, which can contain a maximum of 1024 characters.

Parameters

Name

Description

tag

Tag of a credential, which can contain a maximum of 1024 characters.

[h2]toString

Method

public String toString()

Obtains the string of a Credential object from which sensitive information has been deleted. The string does not include attributes such as username, content, and newContent.

Returns

Type

Description

String

String of a Credential object from which sensitive information has been deleted. The string does not include attributes such as username, content, and newContent.