目录

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

[h2]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

[h2]getAvailable

Method

public Boolean getAvailable()

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

Returns

Type

Description

Boolean

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

[h2]getAvatarUrl

Method

public String getAvatarUrl()

获取用户头像URL。

Returns

Type

Description

String

用户头像URL。

[h2]getContent

Method

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

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

Parameters

Name

Description

callback

回调对象。

[h2]getDisplayName

Method

public String getDisplayName()

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

Returns

Type

Description

String

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

[h2]getOwner

Method

public AppIdentity getOwner()

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

Returns

Type

Description

AppIdentity

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

[h2]getSharedWith

Method

public List<AppIdentity> getSharedWith()

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

Returns

Type

Description

List<AppIdentity>

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

[h2]getSyncable

Method

public Boolean getSyncable()

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

Returns

Type

Description

Boolean

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

[h2]getTag

Method

public String getTag()

获取凭据的标签。

Returns

Type

Description

String

凭据的标签。

[h2]getTimeCreated

Method

public long getTimeCreated()

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

Returns

Type

Description

long

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

[h2]getTimeUpdated

Method

public long getTimeUpdated()

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

Returns

Type

Description

long

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

[h2]getTimeUsed

Method

public long getTimeUsed()

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

Returns

Type

Description

long

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

[h2]getType

Method

public CredentialType getType()

获取凭据类型。

Returns

Type

Description

CredentialType

凭据类型。

[h2]getUserAuth

Method

public Boolean getUserAuth()

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

Returns

Type

Description

Boolean

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

[h2]getUsername

Method

public String getUsername()

获取凭据的用户名。

Returns

Type

Description

String

凭据的用户名。

[h2]setAvatarUrl

Method

public void setAvatarUrl(String avatarUrl)

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

Parameters

Name

Description

avatarUrl

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

[h2]setDisplayName

Method

public void setDisplayName(String displayName)

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

Parameters

Name

Description

displayName

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

[h2]setNewContent

Method

public void setNewContent(byte[] newContent)

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

Parameters

Name

Description

newContent

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

[h2]setSharedWith

Method

public void setSharedWith(List<AppIdentity> sharedWith)

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

Parameters

Name

Description

sharedWith

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

[h2]setSyncable

Method

public void setSyncable(Boolean syncable)

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

Parameters

Name

Description

syncable

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

[h2]setTag

Method

public void setTag(String tag)

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

Parameters

Name

Description

tag

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

[h2]toString

Method

public String toString()

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

Returns

Type

Description

String

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