文档管理中心
API参考钥匙环服务Androidcom.huawei.hms.support.api.keyring.credentialClass SummaryCredential

Credential

展开

Class Info

public class Credential

一个可以保存到钥匙环服务的凭据,或者从钥匙环服务读取到的凭据。

Public Constructor Summary

展开

Constructor Name

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

构造Credential对象。

Public Method Summary

展开

Qualifier and Type

Method Name and Description

public Boolean

getAvailable()

获取凭据是否处于可用状态。对于userAuth设为True的凭据,当用户取消了锁屏密码后,永久变为不可用状态。

public String

getAvatarUrl()

获取用户头像URL。

public void

getContent(CredentialCallback<byte[]> callback)

获取凭据的保密内容。如果userAuth设置为true,则需要验证用户的生物特征或者锁屏码后才能获得凭据的内容。

public String

getDisplayName()

获取凭据所属用户的显示名称。

public AppIdentity

getOwner()

获取凭据的所有者,即最初保存本凭据的应用。

public List<AppIdentity>

getSharedWith()

获取凭据的共享关系,只有凭据的所有者可以获取。

public Boolean

getSyncable()

获取是否支持在设备间进行同步。预留能力,当前版本不支持同步。

public String

getTag()

获取凭据的标签。

public long

getTimeCreated()

获取凭据创建时间,返回UNIX时间戳。(单位:毫秒)

public long

getTimeUpdated()

获取凭据最后更新时间,返回UNIX时间戳。(单位:毫秒)

public long

getTimeUsed()

获取凭据最后使用时间,返回UNIX时间戳。(单位:毫秒)

public CredentialType

getType()

获取凭据类型。

public Boolean

getUserAuth()

调用getContent时,是否需要对用户的身份进行认证。

public String

getUsername()

获取凭据的用户名。

public void

setAvatarUrl(String avatarUrl)

设置用户头像URL。

public void

setDisplayName(String displayName)

设置显示名称。

public void

setNewContent(byte[] newContent)

设置凭据敏感信息的新内容,如密码、会话令牌、联邦认证URL的值,数据将被加密保存。

public void

setSharedWith(List<AppIdentity> sharedWith)

设置凭据的共享关系,授权给哪些应用使用。

public void

setSyncable(Boolean syncable)

设置是否支持在设备间进行同步。预留能力,当前版本不支持同步。

public void

setTag(String tag)

设置凭据的标签。

public String

toString()

获得去掉敏感信息的Credential对象的字符串表示。不包含username、content、newContent等属性。

Public Constructors

Credential

展开

Constructor

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

构造Credential对象。

Parameters

展开

Name

Description

username

用户名,最大长度128个字符。

注意

username会在凭据管理界面向用户展示,因此需要让用户可理解。凭据管理界面请参考凭据管理界面。

type

凭据类型。

userAuth

使用凭据时,是否需要验证用户的生物特征或锁屏口令。

newContent

凭据内容,如密码、会话令牌、联邦认证URL的值,数据将被加密保存。最大长度为16384。

Public Methods

getAvailable

展开

Method

public Boolean getAvailable()

获取凭据是否处于可用状态。对于userAuth设为True的凭据,当用户取消了锁屏密码后,永久变为不可用状态。

Returns

展开

Type

Description

Boolean

凭据可用状态。返回值为True时表示当前可用,False时表示当前不可用。

getAvatarUrl

展开

Method

public String getAvatarUrl()

获取用户头像URL。

Returns

展开

Type

Description

String

用户头像URL。

getContent

展开

Method

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

获取凭据的保密内容。如果userAuth设置为true,则需要验证用户的生物特征或者锁屏码后才能获得凭据的内容。

Parameters

展开

Name

Description

callback

回调对象。

getDisplayName

展开

Method

public String getDisplayName()

获取凭据所属用户的显示名称。

Returns

展开

Type

Description

String

凭据所属用户的显示名称。

getOwner

展开

Method

public AppIdentity getOwner()

获取凭据的所有者,即最初保存本凭据的应用。

Returns

展开

Type

Description

AppIdentity

凭据的所有者,即最初保存本凭据的应用。

getSharedWith

展开

Method

public List<AppIdentity> getSharedWith()

获取凭据的共享关系,只有凭据的所有者可以获取,授权使用凭据的应用无法获取到共享关系。

Returns

展开

Type

Description

List<AppIdentity>

凭据的共享关系,只有凭据的所有者可以获取。

getSyncable

展开

Method

public Boolean getSyncable()

获取是否支持在设备间进行同步。预留能力,当前版本不支持同步。

Returns

展开

Type

Description

Boolean

是否支持在设备间进行同步。

getTag

展开

Method

public String getTag()

获取凭据的标签。

Returns

展开

Type

Description

String

凭据的标签。

getTimeCreated

展开

Method

public long getTimeCreated()

获取凭据创建时间,返回UNIX时间戳(单位:毫秒)。

Returns

展开

Type

Description

long

凭据创建时间,返回UNIX时间戳(单位:毫秒)。

getTimeUpdated

展开

Method

public long getTimeUpdated()

获取凭据最后更新时间,返回UNIX时间戳(单位:毫秒)。

Returns

展开

Type

Description

long

凭据最后更新时间,返回UNIX时间戳(单位:毫秒)。

getTimeUsed

展开

Method

public long getTimeUsed()

获取凭据最后使用时间,返回UNIX时间戳(单位:毫秒)。

Returns

展开

Type

Description

long

凭据最后使用时间,返回UNIX时间戳(单位:毫秒)。

getType

展开

Method

public CredentialType getType()

获取凭据类型。

Returns

展开

Type

Description

CredentialType

凭据类型。

getUserAuth

展开

Method

public Boolean getUserAuth()

调用getContent时,是否需要对用户的身份进行认证。

Returns

展开

Type

Description

Boolean

返回值为True时,表示调用getContent方法时,需要对用户的身份进行认证;返回值为False时,则不需要。

getUsername

展开

Method

public String getUsername()

获取凭据的用户名。

Returns

展开

Type

Description

String

凭据的用户名。

setAvatarUrl

展开

Method

public void setAvatarUrl(String avatarUrl)

户头像URL,最大长度为16384。

Parameters

展开

Name

Description

avatarUrl

户头像URL,最大长度为16384。如果您希望直接保存图像的内容,建议使用data URI scheme。

setDisplayName

展开

Method

public void setDisplayName(String displayName)

设置显示名称,最大长度为128。

Parameters

展开

Name

Description

displayName

显示名称,最大长度为128。

setNewContent

展开

Method

public void setNewContent(byte[] newContent)

设置凭据敏感信息的新内容,如口令、Token、联邦认证URL的值,数据将被加密保存。最大长度为16384。

Parameters

展开

Name

Description

newContent

凭据敏感信息的新内容,如口令、Token、联邦认证URL的值。最大长度为16384。

setSharedWith

展开

Method

public void setSharedWith(List<AppIdentity> sharedWith)

设置凭据的共享关系,授权给哪些应用使用。最多支持共享给128个应用。

Parameters

展开

Name

Description

sharedWith

凭据的共享关系,授权给哪些应用使用。最多支持共享给128个应用。

setSyncable

展开

Method

public void setSyncable(Boolean syncable)

设置是否支持在设备间进行同步。数据同步过程中,使用密码技术对凭据的敏感信息进行加密,华为不掌握凭据的内容。预留能力,当前版本不支持同步。

Parameters

展开

Name

Description

syncable

是否支持在设备间进行同步。

setTag

展开

Method

public void setTag(String tag)

设置凭据的标签,您可以在标签中保存一些自定义的信息,最大长度为1024。

Parameters

展开

Name

Description

tag

凭据的标签,最大长度为1024。

toString

展开

Method

public String toString()

获得去掉敏感信息的Credential对象的字符串表示。不包含username、content、newContent等属性。

Returns

展开

Type

Description

String

去掉敏感信息的Credential对象的字符串表示。不包含username、content、newContent等属性。