Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
fec9804c
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fec9804c
编写于
10月 09, 2022
作者:
L
libing23
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify osAccount and distributed-account doc
Signed-off-by:
N
libing23
<
libing23@huawei.com
>
上级
c5c3f349
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
1855 addition
and
354 deletion
+1855
-354
zh-cn/application-dev/reference/apis/js-apis-distributed-account.md
...ication-dev/reference/apis/js-apis-distributed-account.md
+147
-10
zh-cn/application-dev/reference/apis/js-apis-osAccount.md
zh-cn/application-dev/reference/apis/js-apis-osAccount.md
+1708
-344
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-distributed-account.md
浏览文件 @
fec9804c
...
@@ -36,11 +36,74 @@ getDistributedAccountAbility(): DistributedAccountAbility
...
@@ -36,11 +36,74 @@ getDistributedAccountAbility(): DistributedAccountAbility
提供查询和更新分布式帐号登录状态方法(需要先获取分布式帐号的单实例对象)。
提供查询和更新分布式帐号登录状态方法(需要先获取分布式帐号的单实例对象)。
### queryOsAccountDistributedInfo
### getOsAccountDistributedInfo<sup>9+</sup>
getOsAccountDistributedInfo(callback: AsyncCallback
<
DistributedInfo
>
): void
获取分布式帐号信息,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**需要权限:**
ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS 或 ohos.permission.GET_DISTRIBUTED_ACCOUNTS 或 ohos.permission.DISTRIBUTED_DATASYNC。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
[DistributedInfo](#distributedinfo)
>
| 是 | 获取分布式帐号信息的回调。 |
**示例:**
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
try
{
accountAbility
.
getOsAccountDistributedInfo
((
err
,
data
)
=>
{
console
.
log
(
"
getOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
'
Query account info name:
'
+
data
.
name
);
console
.
log
(
'
Query account info id:
'
+
data
.
id
);
});
}
catch
(
e
)
{
console
.
log
(
"
getOsAccountDistributedInfo exception:
"
+
JSON
.
stringify
(
e
));
}
```
### getOsAccountDistributedInfo<sup>9+</sup>
getOsAccountDistributedInfo(): Promise
<
DistributedInfo
>
获取分布式帐号信息,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**需要权限:**
ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS 或 ohos.permission.GET_DISTRIBUTED_ACCOUNTS 或 ohos.permission.DISTRIBUTED_DATASYNC。
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[DistributedInfo](#distributedinfo)
>
| Promise实例,用于获取异步返回结果。 |
**示例:**
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
try
{
accountAbility
.
getOsAccountDistributedInfo
().
then
((
data
)
=>
{
console
.
log
(
'
Query account info name:
'
+
data
.
name
);
console
.
log
(
'
Query account info id:
'
+
data
.
id
);
}).
catch
((
err
)
=>
{
console
.
log
(
"
getOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
"
getOsAccountDistributedInfo exception:
"
+
JSON
.
stringify
(
e
));
}
```
### queryOsAccountDistributedInfo<sup>(deprecated)</sup>
queryOsAccountDistributedInfo(callback: AsyncCallback
<
DistributedInfo
>
): void
queryOsAccountDistributedInfo(callback: AsyncCallback
<
DistributedInfo
>
): void
获取分布式帐号信息,使用callback回调异步返回结果。
获取分布式帐号信息,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[getOsAccountDistributedInfo](#getosaccountdistributedinfo9)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -62,11 +125,14 @@ queryOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): v
...
@@ -62,11 +125,14 @@ queryOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): v
});
});
```
```
### queryOsAccountDistributedInfo
### queryOsAccountDistributedInfo
<sup>(deprecated)</sup>
queryOsAccountDistributedInfo(): Promise
<
DistributedInfo
>
queryOsAccountDistributedInfo(): Promise
<
DistributedInfo
>
获取分布式帐号信息,使用Promise方式异步返回结果。
获取分布式帐号信息,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[getOsAccountDistributedInfo](#getosaccountdistributedinfo9-1)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -89,11 +155,80 @@ queryOsAccountDistributedInfo(): Promise<DistributedInfo>
...
@@ -89,11 +155,80 @@ queryOsAccountDistributedInfo(): Promise<DistributedInfo>
});
});
```
```
### updateOsAccountDistributedInfo
### setOsAccountDistributedInfo<sup>9+</sup>
setOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback
<
void
>
): void
更新分布式帐号信息,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**需要权限:**
ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| accountInfo |
[
DistributedInfo
](
#distributedinfo
)
| 是 | 分布式帐号信息。 |
| callback | AsyncCallback
<
void
>
| 是 | 更新分布式帐号信息的回调。 |
**示例:**
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
let
accountInfo
=
{
id
:
'
12345
'
,
name
:
'
ZhangSan
'
,
event
:
'
Ohos.account.event.LOGIN
'
};
try
{
accountAbility
.
setOsAccountDistributedInfo
(
accountInfo
,
(
err
)
=>
{
console
.
log
(
"
setOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
"
setOsAccountDistributedInfo exception:
"
+
JSON
.
stringify
(
e
));
}
```
### setOsAccountDistributedInfo<sup>9+</sup>
setOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise
<
void
>
更新分布式帐号信息,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**需要权限:**
ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| accountInfo |
[
DistributedInfo
](
#distributedinfo
)
| 是 | 分布式帐户信息。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| Promise实例,用于获取异步返回结果。 |
**示例:**
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
let
accountInfo
=
{
id
:
'
12345
'
,
name
:
'
ZhangSan
'
,
event
:
'
Ohos.account.event.LOGIN
'
};
try
{
accountAbility
.
setOsAccountDistributedInfo
(
accountInfo
).
then
(()
=>
{
console
.
log
(
'
setOsAccountDistributedInfo Success
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
"
setOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
"
setOsAccountDistributedInfo exception:
"
+
JSON
.
stringify
(
e
));
}
```
### updateOsAccountDistributedInfo<sup>(deprecated)</sup>
updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback
<
void
>
): void
updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback
<
void
>
): void
更新分布式帐号信息,使用callback回调异步返回结果。
更新分布式帐号信息,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[setOsAccountDistributedInfo](#setosaccountdistributedinfo9)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -115,12 +250,14 @@ updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCall
...
@@ -115,12 +250,14 @@ updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCall
});
});
```
```
### updateOsAccountDistributedInfo
### updateOsAccountDistributedInfo
<sup>(deprecated)</sup>
updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise
<
void
>
updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise
<
void
>
更新分布式帐号信息,使用Promise方式异步返回结果。
更新分布式帐号信息,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[setOsAccountDistributedInfo](#setosaccountdistributedinfo9-1)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS。
...
@@ -147,8 +284,6 @@ updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>
...
@@ -147,8 +284,6 @@ updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>
console
.
log
(
"
updateOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
"
updateOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
});
});
```
```
## DistributedInfo
## DistributedInfo
提供操作系统帐户的分布式信息。
提供操作系统帐户的分布式信息。
...
@@ -160,4 +295,6 @@ updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>
...
@@ -160,4 +295,6 @@ updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>
| name | string | 是 | 分布式帐号名称,非空字符串。 |
| name | string | 是 | 分布式帐号名称,非空字符串。 |
| id | string | 是 | 分布式帐号UID,非空字符串。 |
| id | string | 是 | 分布式帐号UID,非空字符串。 |
| event | string | 是 | 分布式帐号登录状态,包括登录、登出、Token失效和注销,分别对应以下字符串:
<br/>
-
Ohos.account.event.LOGIN
<br/>
-
Ohos.account.event.LOGOUT
<br/>
-
Ohos.account.event.TOKEN_INVALID
<br/>
-
Ohos.account.event.LOGOFF |
| event | string | 是 | 分布式帐号登录状态,包括登录、登出、Token失效和注销,分别对应以下字符串:
<br/>
-
Ohos.account.event.LOGIN
<br/>
-
Ohos.account.event.LOGOUT
<br/>
-
Ohos.account.event.TOKEN_INVALID
<br/>
-
Ohos.account.event.LOGOFF |
| nickname
<sup>
9+
</sup>
| string | 否 | 分布式帐号的昵称,非空字符串。 |
| avatar
<sup>
9+
</sup>
| string | 否 | 分布式帐号的头像,非空字符串。 |
| scalableData | object | 否 | 分布式帐号扩展信息,根据业务所需,以k-v形式传递定制化信息。
<br/>
说明:该参数是预留的可选项,目前查询和更新的方法实现中未使用。 |
| scalableData | object | 否 | 分布式帐号扩展信息,根据业务所需,以k-v形式传递定制化信息。
<br/>
说明:该参数是预留的可选项,目前查询和更新的方法实现中未使用。 |
zh-cn/application-dev/reference/apis/js-apis-osAccount.md
浏览文件 @
fec9804c
...
@@ -70,9 +70,13 @@ activateOsAccount(localId: number, callback: AsyncCallback<void>): void
...
@@ -70,9 +70,13 @@ activateOsAccount(localId: number, callback: AsyncCallback<void>): void
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
try
{
accountManager
.
activateOsAccount
(
localId
,
(
err
)
=>
{
accountManager
.
activateOsAccount
(
localId
,
(
err
)
=>
{
console
.
log
(
'
activateOsAccount err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
activateOsAccount err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
activateOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### activateOsAccount
### activateOsAccount
...
@@ -103,19 +107,84 @@ activateOsAccount(localId: number): Promise<void>
...
@@ -103,19 +107,84 @@ activateOsAccount(localId: number): Promise<void>
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
try
{
accountManager
.
activateOsAccount
(
localId
).
then
(()
=>
{
accountManager
.
activateOsAccount
(
localId
).
then
(()
=>
{
console
.
log
(
'
activateOsAccount success
'
);
console
.
log
(
'
activateOsAccount success
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
activateOsAccount err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
activateOsAccount err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
activateOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### isMultiOsAccountEnable
### isMultiOsAccountEnabled<sup>9+</sup>
isMultiOsAccountEnabled(callback: AsyncCallback
<
boolean
>
): void
判断是否支持多系统帐号,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | --------------------------------------------------- |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调结果,支持多系统帐号则返回true,否则返回false。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
isMultiOsAccountEnabled
((
err
,
isEnabled
)
=>
{
console
.
log
(
'
isMultiOsAccountEnabled err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
isMultiOsAccountEnabled isEnabled:
'
+
isEnabled
);
});
}
catch
(
e
)
{
console
.
log
(
'
isMultiOsAccountEnabled exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isMultiOsAccountEnabled<sup>9+</sup>
isMultiOsAccountEnabled(): Promise
<
boolean
>
判断是否支持多系统帐号,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
| 类型 | 说明 |
| :--------------------- | :----------------------------------------------------------- |
| Promise
<
boolean
>
| Promise实例,用于获取异步返回结果,支持多系统帐号则返回true,否则返回false。 |
**示例:**
```
js
try
{
let
accountManager
=
account_osAccount
.
getAccountManager
();
accountManager
.
isMultiOsAccountEnabled
().
then
((
isEnabled
)
=>
{
console
.
log
(
'
isMultiOsAccountEnabled, isEnabled:
'
+
isEnabled
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
isMultiOsAccountEnabled err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
isMultiOsAccountEnabled exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isMultiOsAccountEnable<sup>(deprecated)</sup>
isMultiOsAccountEnable(callback: AsyncCallback
<
boolean
>
): void
isMultiOsAccountEnable(callback: AsyncCallback
<
boolean
>
): void
判断是否支持多系统帐号,使用callback回调异步返回结果。
判断是否支持多系统帐号,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[isMultiOsAccountEnabled](#ismultiosaccountenabled9)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -134,12 +203,16 @@ isMultiOsAccountEnable(callback: AsyncCallback<boolean>): void
...
@@ -134,12 +203,16 @@ isMultiOsAccountEnable(callback: AsyncCallback<boolean>): void
});
});
```
```
### isMultiOsAccountEnable
### isMultiOsAccountEnable
<sup>(deprecated)</sup>
isMultiOsAccountEnable(): Promise
<
boolean
>
isMultiOsAccountEnable(): Promise
<
boolean
>
判断是否支持多系统帐号,使用Promise方式异步返回结果。
判断是否支持多系统帐号,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[isMultiOsAccountEnabled](#ismultiosaccountenabled9-1)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
**返回值:**
...
@@ -159,12 +232,86 @@ isMultiOsAccountEnable(): Promise<boolean>
...
@@ -159,12 +232,86 @@ isMultiOsAccountEnable(): Promise<boolean>
});
});
```
```
### isOsAccountActived
### isOsAccountActivated<sup>9+</sup>
isOsAccountActivated(localId: number, callback: AsyncCallback
<
boolean
>
): void
判断指定系统帐号是否处于激活状态,使用callback回调异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------------- |
| localId | number | 是 | 系统帐号ID。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调结果,处于激活状态则返回true,否则返回false。 |
**示例:**
判断ID为100的系统帐号是否处于激活状态
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
osLocalId
=
100
;
try
{
accountManager
.
isOsAccountActivated
(
osLocalId
,
(
err
,
isActive
)
=>
{
console
.
log
(
'
isOsAccountActivated err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
isOsAccountActivated isActive:
'
+
isActive
);
});
}
catch
(
e
)
{
console
.
log
(
'
isOsAccountActivated exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isOsAccountActivated<sup>9+</sup>
isOsAccountActivated(localId: number): Promise
<
boolean
>
判断指定系统帐号是否处于激活状态,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ------------ |
| localId | number | 是 | 系统帐号ID。 |
**返回值:**
| 类型 | 说明 |
| :--------------------- | :----------------------------------------------------------- |
| Promise
<
boolean
>
| Promise实例,用于获取异步返回结果,处于激活状态则返回true,否则返回false。 |
**示例:**
判断ID为100的系统帐号是否处于激活状态
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
osLocalId
=
100
;
try
{
accountManager
.
isOsAccountActivated
(
osLocalId
).
then
((
isActive
)
=>
{
console
.
log
(
'
isOsAccountActivated, isActive:
'
+
isActive
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
isOsAccountActivated err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
isOsAccountActivated exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isOsAccountActived<sup>(deprecated)</sup>
isOsAccountActived(localId: number, callback: AsyncCallback
<
boolean
>
): void
isOsAccountActived(localId: number, callback: AsyncCallback
<
boolean
>
): void
判断指定系统帐号是否处于激活状态,使用callback回调异步返回结果。
判断指定系统帐号是否处于激活状态,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃, 建议使用[isOsAccountActivated](#isosaccountactivated9)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -187,12 +334,16 @@ isOsAccountActived(localId: number, callback: AsyncCallback<boolean>): voi
...
@@ -187,12 +334,16 @@ isOsAccountActived(localId: number, callback: AsyncCallback<boolean>): voi
});
});
```
```
### isOsAccountActived
### isOsAccountActived
<sup>(deprecated)</sup>
isOsAccountActived(localId: number): Promise
<
boolean
>
isOsAccountActived(localId: number): Promise
<
boolean
>
判断指定系统帐号是否处于激活状态,使用Promise方式异步返回结果。
判断指定系统帐号是否处于激活状态,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃, 建议使用[isOsAccountActivated](#isosaccountactivated9-1)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -221,12 +372,88 @@ isOsAccountActived(localId: number): Promise<boolean>
...
@@ -221,12 +372,88 @@ isOsAccountActived(localId: number): Promise<boolean>
});
});
```
```
### isOsAccountConstraintEnable
### isConstraintEnabled<sup>9+</sup>
isConstraintEnabled(localId: number, constraint: string, callback: AsyncCallback
<
boolean
>
): void
判断指定系统帐号是否具有指定约束,使用callback回调异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ---------------------------- | ---- | ------------------------------------------------- |
| localId | number | 是 | 指定的系统帐号ID。 |
| constraint | string | 是 | 指定的
[
约束
](
#系统帐号约束列表
)
名称。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调结果,具有指定约束则返回true,否则返回false。 |
**示例:**
判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
try
{
accountManager
.
isConstraintEnabled
(
localId
,
'
constraint.wifi
'
,
(
err
,
isEnabled
)
=>
{
console
.
log
(
'
isConstraintEnabled err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
isConstraintEnabled isEnabled:
'
+
isEnabled
);
});
}
catch
(
e
)
{
console
.
log
(
'
isConstraintEnabled exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isConstraintEnabled<sup>9+</sup>
isConstraintEnabled(localId: number, constraint: string): Promise
<
boolean
>
判断指定系统帐号是否具有指定约束,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ------------------------------------- |
| localId | number | 是 | 指定的系统帐号ID。 |
| constraint | string | 是 | 指定的
[
约束
](
#系统帐号约束列表
)
名称。 |
**返回值:**
| 类型 | 说明 |
| :--------------------- | :----------------------------------------------------------- |
| Promise
<
boolean
>
| Promise实例,用于获取异步返回结果,具有指定约束则返回true,否则返回false。 |
**示例:**
判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
try
{
accountManager
.
isConstraintEnabled
(
localId
,
'
constraint.wifi
'
).
then
((
isEnabled
)
=>
{
console
.
log
(
'
isConstraintEnabled, isEnabled:
'
+
isEnabled
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
isConstraintEnabled err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
isConstraintEnabled exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isOsAccountConstraintEnable<sup>(deprecated)</sup>
isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback
<
boolean
>
): void
isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback
<
boolean
>
): void
判断指定系统帐号是否具有指定约束,使用callback回调异步返回结果。
判断指定系统帐号是否具有指定约束,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[isConstraintEnabled](#isconstraintenabled9)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -250,12 +477,16 @@ isOsAccountConstraintEnable(localId: number, constraint: string, callback: Async
...
@@ -250,12 +477,16 @@ isOsAccountConstraintEnable(localId: number, constraint: string, callback: Async
});
});
```
```
### isOsAccountConstraintEnable
### isOsAccountConstraintEnable
<sup>(deprecated)</sup>
isOsAccountConstraintEnable(localId: number, constraint: string): Promise
<
boolean
>
isOsAccountConstraintEnable(localId: number, constraint: string): Promise
<
boolean
>
判断指定系统帐号是否具有指定约束,使用Promise方式异步返回结果。
判断指定系统帐号是否具有指定约束,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[isConstraintEnabled](#isconstraintenabled9-1)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -285,12 +516,73 @@ isOsAccountConstraintEnable(localId: number, constraint: string): Promise<boo
...
@@ -285,12 +516,73 @@ isOsAccountConstraintEnable(localId: number, constraint: string): Promise<boo
});
});
```
```
### isTestOsAccount
### isTestable<sup>9+</sup>
isTestable(callback: AsyncCallback
<
boolean
>
): void
检查当前系统帐号是否为测试帐号,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ----------------------------------------------- |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调结果,是测试帐号则返回true,否则返回false。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
isTestable
((
err
,
isTest
)
=>
{
console
.
log
(
'
isTestable err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
isTestable isTest:
'
+
isTest
);
});
}
catch
(
e
)
{
console
.
log
(
'
isTestable exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isTestable<sup>9+</sup>
isTestable(): Promise
<
boolean
>
检查当前系统帐号是否为测试帐号,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
| 类型 | 说明 |
| :--------------------- | :----------------------------------------------------------- |
| Promise
<
boolean
>
| Promise实例,用于获取异步返回结果,是测试帐号则返回true,否则返回false。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
isTestable
().
then
((
isTest
)
=>
{
console
.
log
(
'
isTestable, isTest:
'
+
isTest
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
isTestable err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
isTestable exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isTestOsAccount<sup>(deprecated)</sup>
isTestOsAccount(callback: AsyncCallback
<
boolean
>
): void
isTestOsAccount(callback: AsyncCallback
<
boolean
>
): void
检查当前系统帐号是否为测试帐号,使用callback回调异步返回结果。
检查当前系统帐号是否为测试帐号,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[isTestable](#istestable9)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -309,12 +601,16 @@ isTestOsAccount(callback: AsyncCallback<boolean>): void
...
@@ -309,12 +601,16 @@ isTestOsAccount(callback: AsyncCallback<boolean>): void
});
});
```
```
### isTestOsAccount
### isTestOsAccount
<sup>(deprecated)</sup>
isTestOsAccount(): Promise
<
boolean
>
isTestOsAccount(): Promise
<
boolean
>
检查当前系统帐号是否为测试帐号,使用Promise方式异步返回结果。
检查当前系统帐号是否为测试帐号,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[isTestable](#istestable9-1)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
**返回值:**
...
@@ -334,12 +630,114 @@ isTestOsAccount(): Promise<boolean>
...
@@ -334,12 +630,114 @@ isTestOsAccount(): Promise<boolean>
});
});
```
```
### isOsAccountVerified
### isVerified<sup>9+</sup>
isVerified(callback: AsyncCallback
<
boolean
>
): void
检查当前系统帐号是否已验证,使用callback回调异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------- |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调结果,已验证则返回true,否则返回false。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
isVerified
((
err
,
isVeri
)
=>
{
console
.
log
(
'
isVerified err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
isVerified isVeri:
'
+
isVeri
);
});
}
catch
(
e
)
{
console
.
log
(
'
isVerified exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isVerified<sup>9+</sup>
isOsAccountVerified(localId: number, callback: AsyncCallback
<
boolean
>
): void
检查指定系统帐号是否已验证,使用callback回调异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------- |
| localId | number | 否 | 指定的系统帐号ID。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调结果,已验证则返回true,否则返回false。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
isVerified
((
err
,
isVeri
)
=>
{
console
.
log
(
'
isVerified err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
isVerified isVeri:
'
+
isVeri
);
});
}
catch
(
e
)
{
console
.
log
(
'
isVerified exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isVerified<sup>9+</sup>
isOsAccountVerified(localId?: number): Promise
<
boolean
>
检查指定系统帐号是否已验证,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ------------------ |
| localId | number | 否 | 指定的系统帐号ID。 |
**返回值:**
| 类型 | 说明 |
| :--------------------- | :----------------------------------------------------------- |
| Promise
<
boolean
>
| Promise实例,用于获取异步返回结果,已验证则返回true,否则返回false。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
isVerified
().
then
((
isVeri
)
=>
{
console
.
log
(
'
isVerified, isVeri:
'
+
isVeri
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
isVerified err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
isVerified exception:
'
+
JSON
.
stringify
(
e
));
}
```
### isOsAccountVerified<sup>(deprecated)</sup>
isOsAccountVerified(callback: AsyncCallback
<
boolean
>
): void
isOsAccountVerified(callback: AsyncCallback
<
boolean
>
): void
检查当前系统帐号是否已验证,使用callback回调异步返回结果。
检查当前系统帐号是否已验证,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[isVerified](#isverified9)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -358,12 +756,16 @@ isOsAccountVerified(callback: AsyncCallback<boolean>): void
...
@@ -358,12 +756,16 @@ isOsAccountVerified(callback: AsyncCallback<boolean>): void
});
});
```
```
### isOsAccountVerified
### isOsAccountVerified
<sup>(deprecated)</sup>
isOsAccountVerified(localId: number, callback: AsyncCallback
<
boolean
>
): void
isOsAccountVerified(localId: number, callback: AsyncCallback
<
boolean
>
): void
检查指定系统帐号是否已验证,使用callback回调异步返回结果。
检查指定系统帐号是否已验证,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[isVerified](#isverified9-1)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -385,12 +787,16 @@ isOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): vo
...
@@ -385,12 +787,16 @@ isOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): vo
});
});
```
```
### isOsAccountVerified
### isOsAccountVerified
<sup>(deprecated)</sup>
isOsAccountVerified(localId?: number): Promise
<
boolean
>
isOsAccountVerified(localId?: number): Promise
<
boolean
>
检查指定系统帐号是否已验证,使用Promise方式异步返回结果。
检查指定系统帐号是否已验证,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[isVerified](#isverified9-2)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -441,11 +847,15 @@ removeOsAccount(localId: number, callback: AsyncCallback<void>): void
...
@@ -441,11 +847,15 @@ removeOsAccount(localId: number, callback: AsyncCallback<void>): void
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
createOsAccount
(
'
testAccountName
'
,
account_osAccount
.
OsAccountType
.
NORMAL
,
(
err
,
osAccountInfo
)
=>
{
accountManager
.
createOsAccount
(
'
testAccountName
'
,
account_osAccount
.
OsAccountType
.
NORMAL
,
(
err
,
osAccountInfo
)
=>
{
accountManager
.
removeOsAccount
(
osAccountInfo
.
localId
,
(
err
)
=>
{
accountManager
.
removeOsAccount
(
osAccountInfo
.
localId
,
(
err
)
=>
{
console
.
log
(
'
removeOsAccount err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
removeOsAccount err:
'
+
JSON
.
stringify
(
err
));
});
});
});
});
}
catch
(
e
)
{
console
.
log
(
'
removeOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### removeOsAccount
### removeOsAccount
...
@@ -476,6 +886,7 @@ removeOsAccount(localId: number): Promise<void>
...
@@ -476,6 +886,7 @@ removeOsAccount(localId: number): Promise<void>
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
createOsAccount
(
'
testAccountName
'
,
account_osAccount
.
OsAccountType
.
NORMAL
,
(
err
,
osAccountInfo
)
=>
{
accountManager
.
createOsAccount
(
'
testAccountName
'
,
account_osAccount
.
OsAccountType
.
NORMAL
,
(
err
,
osAccountInfo
)
=>
{
accountManager
.
removeOsAccount
(
osAccountInfo
.
localId
).
then
(()
=>
{
accountManager
.
removeOsAccount
(
osAccountInfo
.
localId
).
then
(()
=>
{
console
.
log
(
'
removeOsAccount Success
'
);
console
.
log
(
'
removeOsAccount Success
'
);
...
@@ -483,6 +894,9 @@ removeOsAccount(localId: number): Promise<void>
...
@@ -483,6 +894,9 @@ removeOsAccount(localId: number): Promise<void>
console
.
log
(
'
removeOsAccount err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
removeOsAccount err:
'
+
JSON
.
stringify
(
err
));
});
});
});
});
}
catch
(
e
)
{
console
.
log
(
'
removeOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### setOsAccountConstraints
### setOsAccountConstraints
...
@@ -511,9 +925,13 @@ setOsAccountConstraints(localId: number, constraints: Array<string>, enabl
...
@@ -511,9 +925,13 @@ setOsAccountConstraints(localId: number, constraints: Array<string>, enabl
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
try
{
accountManager
.
setOsAccountConstraints
(
localId
,
[
'
constraint.wifi
'
],
true
,
(
err
)
=>
{
accountManager
.
setOsAccountConstraints
(
localId
,
[
'
constraint.wifi
'
],
true
,
(
err
)
=>
{
console
.
log
(
'
setOsAccountConstraints err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
setOsAccountConstraints err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
setOsAccountConstraints exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### setOsAccountConstraints
### setOsAccountConstraints
...
@@ -547,11 +965,15 @@ setOsAccountConstraints(localId: number, constraints: Array<string>, enabl
...
@@ -547,11 +965,15 @@ setOsAccountConstraints(localId: number, constraints: Array<string>, enabl
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
try
{
accountManager
.
setOsAccountConstraints
(
localId
,
[
'
constraint.location.set
'
],
false
).
then
(()
=>
{
accountManager
.
setOsAccountConstraints
(
localId
,
[
'
constraint.location.set
'
],
false
).
then
(()
=>
{
console
.
log
(
'
setOsAccountConstraints Success
'
);
console
.
log
(
'
setOsAccountConstraints Success
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
setOsAccountConstraints err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
setOsAccountConstraints err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
setOsAccountConstraints exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### setOsAccountName
### setOsAccountName
...
@@ -580,9 +1002,13 @@ setOsAccountName(localId: number, localName: string, callback: AsyncCallback<
...
@@ -580,9 +1002,13 @@ setOsAccountName(localId: number, localName: string, callback: AsyncCallback<
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
let
newName
=
'
demoName
'
;
let
newName
=
'
demoName
'
;
try
{
accountManager
.
setOsAccountName
(
localId
,
newName
,
(
err
)
=>
{
accountManager
.
setOsAccountName
(
localId
,
newName
,
(
err
)
=>
{
console
.
debug
(
'
setOsAccountName err:
'
+
JSON
.
stringify
(
err
));
console
.
debug
(
'
setOsAccountName err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
setOsAccountName exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### setOsAccountName
### setOsAccountName
...
@@ -616,19 +1042,88 @@ setOsAccountName(localId: number, localName: string): Promise<void>
...
@@ -616,19 +1042,88 @@ setOsAccountName(localId: number, localName: string): Promise<void>
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
let
nameLimit
=
'
demoName
'
;
let
nameLimit
=
'
demoName
'
;
try
{
accountManager
.
setOsAccountName
(
localId
,
nameLimit
).
then
(()
=>
{
accountManager
.
setOsAccountName
(
localId
,
nameLimit
).
then
(()
=>
{
console
.
log
(
'
setOsAccountName Success
'
);
console
.
log
(
'
setOsAccountName Success
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
setOsAccountName err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
setOsAccountName err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
setOsAccountName exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getOsAccountCount<sup>9+</sup>
getOsAccountCount(callback: AsyncCallback
<
number
>
): void
获取已创建的系统帐号数量,使用callback回调异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------ |
| callback | AsyncCallback
<
number
>
| 是 | 回调结果,返回的是已创建的系统帐号的数量。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
getOsAccountCount
((
err
,
accountCnt
)
=>
{
console
.
log
(
'
obtains the number of all os accounts created err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
obtains the number of all os accounts created accountCnt:
'
+
accountCnt
);
});
}
catch
(
e
)
{
console
.
log
(
'
obtains the number of all os accounts created exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getOsAccountCount<sup>9+</sup>
getOsAccountCount(): Promise
<
number
>
获取已创建的系统帐号数量,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
| 类型 | 说明 |
| :-------------------- | :----------------------------------------------------------- |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是已创建的系统帐号的数量。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
getOsAccountCount
().
then
((
accountCnt
)
=>
{
console
.
log
(
'
getOsAccountCount, accountCnt:
'
+
accountCnt
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
getOsAccountCount err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
getOsAccountCount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### getCreatedOsAccountsCount
### getCreatedOsAccountsCount
<sup>(deprecated)</sup>
getCreatedOsAccountsCount(callback: AsyncCallback
<
number
>
): void
getCreatedOsAccountsCount(callback: AsyncCallback
<
number
>
): void
获取已创建的系统帐号数量,使用callback回调异步返回结果。
获取已创建的系统帐号数量,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[getOsAccountCount](#getosaccountcount9)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -649,13 +1144,131 @@ getCreatedOsAccountsCount(callback: AsyncCallback<number>): void
...
@@ -649,13 +1144,131 @@ getCreatedOsAccountsCount(callback: AsyncCallback<number>): void
});
});
```
```
### getCreatedOsAccountsCount
### getCreatedOsAccountsCount
<sup>(deprecated)</sup>
getCreatedOsAccountsCount(): Promise
<
number
>
getCreatedOsAccountsCount(): Promise
<
number
>
获取已创建的系统帐号数量,使用Promise方式异步返回结果。
获取已创建的系统帐号数量,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
> **说明:** 从API version 9开始废弃,建议使用[getOsAccountCount](#getosaccountcount9-1)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
| 类型 | 说明 |
| :-------------------- | :----------------------------------------------------------- |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是已创建的系统帐号的数量。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
accountManager
.
getCreatedOsAccountsCount
().
then
((
accountCnt
)
=>
{
console
.
log
(
'
getCreatedOsAccountsCount, accountCnt:
'
+
accountCnt
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
getCreatedOsAccountsCount err:
'
+
JSON
.
stringify
(
err
));
});
```
### queryOsAccountLocalIdFromProcess<sup>9+</sup>
queryOsAccountLocalIdFromProcess(callback: AsyncCallback
<
number
>
): void
获取当前进程所属的系统帐号的帐号ID,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | -------------------------------------------------- |
| callback | AsyncCallback
<
number
>
| 是 | 回调结果,返回的是当前进程所属的系统帐号的帐号ID。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryOsAccountLocalIdFromProcess
((
err
,
accountID
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdFromProcess err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryOsAccountLocalIdFromProcess accountID:
'
+
accountID
);
});
}
catch
(
e
)
{
console
.
log
(
'
queryOsAccountLocalIdFromProcess exception:
'
+
JSON
.
stringify
(
e
));
}
```
### queryOsAccountLocalIdFromProcess<sup>9+</sup>
queryOsAccountLocalIdFromProcess(): Promise
<
number
>
获取当前进程所属的系统帐号的帐号ID,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
| 类型 | 说明 |
| :-------------------- | :----------------------------------------------------------- |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是当前进程所属的系统帐号的帐号ID。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryOsAccountLocalIdFromProcess
().
then
((
accountID
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdFromProcess, accountID:
'
+
accountID
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdFromProcess err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
queryOsAccountLocalIdFromProcess exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup>
getOsAccountLocalIdFromProcess(callback: AsyncCallback
<
number
>
): void
获取当前进程所属的系统帐号的帐号ID,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[queryOsAccountLocalIdFromProcess](#queryosaccountlocalidfromprocess9)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | -------------------------------------------------- |
| callback | AsyncCallback
<
number
>
| 是 | 回调结果,返回的是当前进程所属的系统帐号的帐号ID。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
accountManager
.
getOsAccountLocalIdFromProcess
((
err
,
accountID
)
=>
{
console
.
log
(
'
getOsAccountLocalIdFromProcess err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getOsAccountLocalIdFromProcess accountID:
'
+
accountID
);
});
```
### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup>
getOsAccountLocalIdFromProcess(): Promise
<
number
>
获取当前进程所属的系统帐号的帐号ID,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[queryOsAccountLocalIdFromProcess](#queryosaccountlocalidfromprocess9-1)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -663,74 +1276,95 @@ getCreatedOsAccountsCount(): Promise<number>
...
@@ -663,74 +1276,95 @@ getCreatedOsAccountsCount(): Promise<number>
| 类型 | 说明 |
| 类型 | 说明 |
| :-------------------- | :----------------------------------------------------------- |
| :-------------------- | :----------------------------------------------------------- |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是
已创建的系统帐号的数量
。 |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是
当前进程所属的系统帐号的帐号ID
。 |
**示例:**
**示例:**
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
accountManager
.
get
CreatedOsAccountsCount
().
then
((
accountCnt
)
=>
{
accountManager
.
get
OsAccountLocalIdFromProcess
().
then
((
accountID
)
=>
{
console
.
log
(
'
get
CreatedOsAccountsCount, accountCnt:
'
+
accountCnt
);
console
.
log
(
'
get
OsAccountLocalIdFromProcess, accountID:
'
+
accountID
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
get
CreatedOsAccountsCount
err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
get
OsAccountLocalIdFromProcess
err:
'
+
JSON
.
stringify
(
err
));
});
});
```
```
###
getOsAccountLocalIdFromProcess
###
queryOsAccountLocalIdFromUid<sup>9+</sup>
getOsAccountLocalIdFromProcess(
callback: AsyncCallback
<
number
>
): void
queryOsAccountLocalIdFromUid(uid: number,
callback: AsyncCallback
<
number
>
): void
获取当前进程
所属的系统帐号的帐号ID,使用callback回调异步返回结果。
从进程uid中获取该uid
所属的系统帐号的帐号ID,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | -------------------------------------------------- |
| -------- | --------------------------- | ---- | --------------------------------------------- |
| callback | AsyncCallback
<
number
>
| 是 | 回调结果,返回的是当前进程所属的系统帐号的帐号ID。 |
| uid | number | 是 | 进程uid。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调结果,返回的是uid所属的系统帐号的帐号ID。 |
**示例:**
**示例:**
查询值为12345678的uid所属的系统帐号的帐号ID
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
accountManager
.
getOsAccountLocalIdFromProcess
((
err
,
accountID
)
=>
{
let
uid
=
12345678
;
console
.
log
(
'
getOsAccountLocalIdFromProcess err:
'
+
JSON
.
stringify
(
err
));
try
{
console
.
log
(
'
getOsAccountLocalIdFromProcess accountID:
'
+
accountID
);
accountManager
.
queryOsAccountLocalIdFromUid
(
uid
,
(
err
,
accountID
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdFromUid err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryOsAccountLocalIdFromUid:
'
+
accountID
);
});
});
}
catch
(
e
)
{
console
.
log
(
'
queryOsAccountLocalIdFromUid exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
###
getOsAccountLocalIdFromProcess
###
queryOsAccountLocalIdFromUid<sup>9+</sup>
getOsAccountLocalIdFromProcess(
): Promise
<
number
>
queryOsAccountLocalIdFromUid(uid: number
): Promise
<
number
>
获取当前进程
所属的系统帐号的帐号ID,使用Promise方式异步返回结果。
从进程uid中获取该uid
所属的系统帐号的帐号ID,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | --------- |
| uid | number | 是 | 进程uid。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| :-------------------- | :----------------------------------------------------------- |
| :-------------------- | :----------------------------------------------------------- |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是
当前进程
所属的系统帐号的帐号ID。 |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是
uid
所属的系统帐号的帐号ID。 |
**示例:**
**示例:**
查询值为12345678的uid所属的系统帐号的帐号ID
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
accountManager
.
getOsAccountLocalIdFromProcess
().
then
((
accountID
)
=>
{
let
uid
=
12345678
;
console
.
log
(
'
getOsAccountLocalIdFromProcess, accountID:
'
+
accountID
);
try
{
accountManager
.
queryOsAccountLocalIdFromUid
(
uid
).
then
((
accountID
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdFromUid:
'
+
accountID
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
getOsAccountLocalIdFromProcess
err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryOsAccountLocalIdFromUid
err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
queryOsAccountLocalIdFromUid exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### getOsAccountLocalIdFromUid
### getOsAccountLocalIdFromUid
<sup>(deprecated)</sup>
getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback
<
number
>
): void
getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback
<
number
>
): void
从进程uid中获取该uid所属的系统帐号的帐号ID,使用callback回调异步返回结果。
从进程uid中获取该uid所属的系统帐号的帐号ID,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[queryOsAccountLocalIdFromUid](#queryosaccountlocalidfromuid9)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -751,12 +1385,16 @@ getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback<number>):
...
@@ -751,12 +1385,16 @@ getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback<number>):
});
});
```
```
### getOsAccountLocalIdFromUid
### getOsAccountLocalIdFromUid
<sup>(deprecated)</sup>
getOsAccountLocalIdFromUid(uid: number): Promise
<
number
>
getOsAccountLocalIdFromUid(uid: number): Promise
<
number
>
从进程uid中获取该uid所属的系统帐号的帐号ID,使用Promise方式异步返回结果。
从进程uid中获取该uid所属的系统帐号的帐号ID,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[queryOsAccountLocalIdFromUid](#queryosaccountlocalidfromuid9-1)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -783,12 +1421,86 @@ getOsAccountLocalIdFromUid(uid: number): Promise<number>
...
@@ -783,12 +1421,86 @@ getOsAccountLocalIdFromUid(uid: number): Promise<number>
});
});
```
```
### getOsAccountLocalIdFromDomain<sup>8+</sup>
### queryOsAccountLocalIdFromDomain<sup>9+</sup>
getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback
<
number
>
): void
根据域帐号信息,获取与其关联的系统帐号的帐号ID。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | --------------------------------------- | ---- | -------------------------------------------- |
| domainInfo |
[
DomainAccountInfo
](
#domainaccountinfo8
)
| 是 | 域帐号信息。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调结果,返回的是和域帐号关联的系统帐号ID。 |
**示例:**
```
js
let
domainInfo
=
{
domain
:
'
testDomain
'
,
accountName
:
'
testAccountName
'
};
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryOsAccountLocalIdFromDomain
(
domainInfo
,
(
err
,
accountID
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdFromDomain:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryOsAccountLocalIdFromDomain:
'
+
accountID
);
});
}
catch
(
e
)
{
console
.
log
(
'
queryOsAccountLocalIdFromDomain:
'
+
JSON
.
stringify
(
e
));
}
```
### queryOsAccountLocalIdFromDomain<sup>9+</sup>
queryOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise
<
number
>
根据域帐号信息,获取与其关联的系统帐号的帐号ID,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | --------------------------------------- | ---- | ------------ |
| domainInfo |
[
DomainAccountInfo
](
#domainaccountinfo8
)
| 是 | 域帐号信息。 |
**返回值:**
| 类型 | 说明 |
| :-------------------- | :----------------------------------------------------------- |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是和域帐号关联的系统帐号ID。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
domainInfo
=
{
domain
:
'
testDomain
'
,
accountName
:
'
testAccountName
'
};
try
{
accountManager
.
queryOsAccountLocalIdFromDomain
(
domainInfo
).
then
((
accountID
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdFromDomain:
'
+
accountID
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdFromDomain err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
queryOsAccountLocalIdFromDomain exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup>
getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback
<
number
>
): void
getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback
<
number
>
): void
根据域帐号信息,获取与其关联的系统帐号的帐号ID。
根据域帐号信息,获取与其关联的系统帐号的帐号ID。
> **说明:** 从API version 9开始废弃,建议使用[queryOsAccountLocalIdFromDomain](#queryosaccountlocalidfromdomain9)
>
> 从 API version 8开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -811,12 +1523,16 @@ getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCall
...
@@ -811,12 +1523,16 @@ getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCall
});
});
```
```
### getOsAccountLocalIdFromDomain<sup>
8+
</sup>
### getOsAccountLocalIdFromDomain<sup>
(deprecated)
</sup>
getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise
<
number
>
getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise
<
number
>
根据域帐号信息,获取与其关联的系统帐号的帐号ID,使用Promise方式异步返回结果。
根据域帐号信息,获取与其关联的系统帐号的帐号ID,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[queryOsAccountLocalIdFromDomain](#queryosaccountlocalidfromdomain9-1)
>
> 从 API version 8开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -865,10 +1581,14 @@ queryMaxOsAccountNumber(callback: AsyncCallback<number>): void
...
@@ -865,10 +1581,14 @@ queryMaxOsAccountNumber(callback: AsyncCallback<number>): void
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryMaxOsAccountNumber
((
err
,
maxCnt
)
=>
{
accountManager
.
queryMaxOsAccountNumber
((
err
,
maxCnt
)
=>
{
console
.
log
(
'
queryMaxOsAccountNumber err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryMaxOsAccountNumber err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryMaxOsAccountNumber maxCnt:
'
+
maxCnt
);
console
.
log
(
'
queryMaxOsAccountNumber maxCnt:
'
+
maxCnt
);
});
});
}
catch
(
e
)
{
console
.
log
(
'
queryMaxOsAccountNumber exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### queryMaxOsAccountNumber
### queryMaxOsAccountNumber
...
@@ -891,19 +1611,97 @@ queryMaxOsAccountNumber(): Promise<number>
...
@@ -891,19 +1611,97 @@ queryMaxOsAccountNumber(): Promise<number>
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryMaxOsAccountNumber
().
then
((
maxCnt
)
=>
{
accountManager
.
queryMaxOsAccountNumber
().
then
((
maxCnt
)
=>
{
console
.
log
(
'
queryMaxOsAccountNumber, maxCnt:
'
+
maxCnt
);
console
.
log
(
'
queryMaxOsAccountNumber, maxCnt:
'
+
maxCnt
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
queryMaxOsAccountNumber err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryMaxOsAccountNumber err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
queryMaxOsAccountNumber exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getOsAccountConstraints<sup>9+</sup>
getOsAccountConstraints(localId: number, callback: AsyncCallback
<
Array
<
string
>>
): void
获取指定系统帐号的全部约束,使用callback回调异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| localId | number | 是 | 系统帐号ID。 |
| callback | AsyncCallback
<
Array
<
string
>>
| 是 | 回调结果,返回的是该系统帐号的全部
[
约束
](
#系统帐号约束列表
)
。 |
**示例:**
获取ID为100的系统帐号的全部约束
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
try
{
accountManager
.
getOsAccountConstraints
(
localId
,
(
err
,
constraints
)
=>
{
console
.
log
(
'
getOsAccountConstraints err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getOsAccountConstraints:
'
+
JSON
.
stringify
(
constraints
));
});
}
catch
(
e
)
{
console
.
log
(
'
getOsAccountConstraints exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getOsAccountConstraints<sup>9+</sup>
getOsAccountConstraints(localId: number): Promise
<
Array
<
string
>>
获取指定系统帐号的全部约束,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ------------ |
| localId | number | 是 | 系统帐号ID。 |
**返回值:**
| 类型 | 说明 |
| :--------------------------------- | :----------------------------------------------------------- |
| Promise
<
Array
<
string
>>
| Promise实例,用于获取异步返回结果,返回的是该系统帐号的全部
[
约束
](
#系统帐号约束列表
)
。 |
**示例:**
获取ID为100的系统帐号的全部约束
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
try
{
accountManager
.
getOsAccountConstraints
(
localId
).
then
((
constraints
)
=>
{
console
.
log
(
'
getOsAccountConstraints, constraints:
'
+
constraints
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
getOsAccountConstraints err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
getOsAccountConstraints exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### getOsAccountAllConstraints
### getOsAccountAllConstraints
<sup>(deprecated)</sup>
getOsAccountAllConstraints(localId: number, callback: AsyncCallback
<
Array
<
string
>>
): void
getOsAccountAllConstraints(localId: number, callback: AsyncCallback
<
Array
<
string
>>
): void
获取指定系统帐号的全部约束,使用callback回调异步返回结果。
获取指定系统帐号的全部约束,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[getOsAccountConstraints](#getosaccountconstraints9)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -926,10 +1724,14 @@ getOsAccountAllConstraints(localId: number, callback: AsyncCallback<Array<
...
@@ -926,10 +1724,14 @@ getOsAccountAllConstraints(localId: number, callback: AsyncCallback<Array<
});
});
```
```
### getOsAccountAllConstraints
### getOsAccountAllConstraints
<sup>(deprecated)</sup>
getOsAccountAllConstraints(localId: number): Promise
<
Array
<
string
>>
getOsAccountAllConstraints(localId: number): Promise
<
Array
<
string
>>
> **说明:** 从API version 9开始废弃,建议使用[getOsAccountConstraints](#getosaccountconstraints9-1)
>
> 从 API version 7开始支持。
获取指定系统帐号的全部约束,使用Promise方式异步返回结果。
获取指定系统帐号的全部约束,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
...
@@ -982,10 +1784,14 @@ queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>&
...
@@ -982,10 +1784,14 @@ queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>&
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryAllCreatedOsAccounts
((
err
,
accountArr
)
=>
{
accountManager
.
queryAllCreatedOsAccounts
((
err
,
accountArr
)
=>
{
console
.
log
(
'
queryAllCreatedOsAccounts err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryAllCreatedOsAccounts err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryAllCreatedOsAccounts accountArr:
'
+
JSON
.
stringify
(
accountArr
));
console
.
log
(
'
queryAllCreatedOsAccounts accountArr:
'
+
JSON
.
stringify
(
accountArr
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
queryAllCreatedOsAccounts exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### queryAllCreatedOsAccounts
### queryAllCreatedOsAccounts
...
@@ -1010,19 +1816,87 @@ queryAllCreatedOsAccounts(): Promise<Array<OsAccountInfo>>
...
@@ -1010,19 +1816,87 @@ queryAllCreatedOsAccounts(): Promise<Array<OsAccountInfo>>
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryAllCreatedOsAccounts
().
then
((
accountArr
)
=>
{
accountManager
.
queryAllCreatedOsAccounts
().
then
((
accountArr
)
=>
{
console
.
log
(
'
queryAllCreatedOsAccounts, accountArr:
'
+
JSON
.
stringify
(
accountArr
));
console
.
log
(
'
queryAllCreatedOsAccounts, accountArr:
'
+
JSON
.
stringify
(
accountArr
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
queryAllCreatedOsAccounts err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryAllCreatedOsAccounts err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
queryAllCreatedOsAccounts exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getActivatedOsAccountIds<sup>9+</sup>
getActivatedOsAccountIds(callback: AsyncCallback
<
Array
<
number
>>
): void
查询当前处于激活状态的系统帐号的ID列表,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 | 回调结果,返回的是当前处于激活状态的系统帐号的ID列表。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
getActivatedOsAccountIds
((
err
,
idArray
)
=>
{
console
.
log
(
'
getActivatedOsAccountIds err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getActivatedOsAccountIds idArray length:
'
+
idArray
.
length
);
for
(
let
i
=
0
;
i
<
idArray
.
length
;
i
++
)
{
console
.
info
(
'
activated os account id:
'
+
idArray
[
i
]);
}
});
}
catch
(
e
)
{
console
.
log
(
'
getActivatedOsAccountIds exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getActivatedOsAccountIds<sup>9+</sup>
getActivatedOsAccountIds(): Promise
<
Array
<
number
>>
查询当前处于激活状态的系统帐号的ID列表,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
| 类型 | 说明 |
| :--------------------------------- | :----------------------------------------------------------- |
| Promise
<
Array
<
number
>>
| Promise实例,用于获取异步返回结果,返回的是当前处于激活状态的系统帐号的ID列表。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
getActivatedOsAccountIds
().
then
((
idArray
)
=>
{
console
.
log
(
'
getActivatedOsAccountIds, idArray:
'
+
idArray
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
getActivatedOsAccountIds err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
getActivatedOsAccountIds exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### queryActivatedOsAccountIds<sup>
8+
</sup>
### queryActivatedOsAccountIds<sup>
(deprecated)
</sup>
queryActivatedOsAccountIds(callback: AsyncCallback
<
Array
<
number
>>
): void
queryActivatedOsAccountIds(callback: AsyncCallback
<
Array
<
number
>>
): void
查询当前处于激活状态的系统帐号的ID列表,使用callback回调异步返回结果。
查询当前处于激活状态的系统帐号的ID列表,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[getActivatedOsAccountIds](#getactivatedosaccountids9)
>
> 从 API version 8开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -1044,10 +1918,14 @@ queryActivatedOsAccountIds(callback: AsyncCallback<Array<number>>):
...
@@ -1044,10 +1918,14 @@ queryActivatedOsAccountIds(callback: AsyncCallback<Array<number>>):
});
});
```
```
### queryActivatedOsAccountIds<sup>
8+
</sup>
### queryActivatedOsAccountIds<sup>
(deprecated)
</sup>
queryActivatedOsAccountIds(): Promise
<
Array
<
number
>>
queryActivatedOsAccountIds(): Promise
<
Array
<
number
>>
> **说明:** 从API version 9开始废弃,建议使用[getActivatedOsAccountIds](#getactivatedosaccountids9-1)
>
> 从 API version 8开始支持。
查询当前处于激活状态的系统帐号的ID列表,使用Promise方式异步返回结果。
查询当前处于激活状态的系统帐号的ID列表,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -1093,10 +1971,14 @@ createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback&
...
@@ -1093,10 +1971,14 @@ createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback&
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
createOsAccount
(
'
testName
'
,
account_osAccount
.
OsAccountType
.
NORMAL
,
(
err
,
osAccountInfo
)
=>
{
accountManager
.
createOsAccount
(
'
testName
'
,
account_osAccount
.
OsAccountType
.
NORMAL
,
(
err
,
osAccountInfo
)
=>
{
console
.
log
(
'
createOsAccount err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
createOsAccount err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
createOsAccount osAccountInfo:
'
+
JSON
.
stringify
(
osAccountInfo
));
console
.
log
(
'
createOsAccount osAccountInfo:
'
+
JSON
.
stringify
(
osAccountInfo
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
createOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### createOsAccount
### createOsAccount
...
@@ -1128,11 +2010,15 @@ createOsAccount(localName: string, type: OsAccountType): Promise<OsAccountInf
...
@@ -1128,11 +2010,15 @@ createOsAccount(localName: string, type: OsAccountType): Promise<OsAccountInf
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
createOsAccount
(
'
testAccountName
'
,
account_osAccount
.
OsAccountType
.
NORMAL
).
then
((
accountInfo
)
=>
{
accountManager
.
createOsAccount
(
'
testAccountName
'
,
account_osAccount
.
OsAccountType
.
NORMAL
).
then
((
accountInfo
)
=>
{
console
.
log
(
'
createOsAccount, accountInfo:
'
+
JSON
.
stringify
(
accountInfo
));
console
.
log
(
'
createOsAccount, accountInfo:
'
+
JSON
.
stringify
(
accountInfo
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
createOsAccount err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
createOsAccount err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
createOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### createOsAccountForDomain<sup>8+</sup>
### createOsAccountForDomain<sup>8+</sup>
...
@@ -1160,10 +2046,14 @@ createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, cal
...
@@ -1160,10 +2046,14 @@ createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, cal
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
domainInfo
=
{
domain
:
'
testDomain
'
,
accountName
:
'
testAccountName
'
};
let
domainInfo
=
{
domain
:
'
testDomain
'
,
accountName
:
'
testAccountName
'
};
try
{
accountManager
.
createOsAccountForDomain
(
account_osAccount
.
OsAccountType
.
NORMAL
,
domainInfo
,
(
err
,
osAccountInfo
)
=>
{
accountManager
.
createOsAccountForDomain
(
account_osAccount
.
OsAccountType
.
NORMAL
,
domainInfo
,
(
err
,
osAccountInfo
)
=>
{
console
.
log
(
'
createOsAccountForDomain err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
createOsAccountForDomain err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
createOsAccountForDomain osAccountInfo:
'
+
JSON
.
stringify
(
osAccountInfo
));
console
.
log
(
'
createOsAccountForDomain osAccountInfo:
'
+
JSON
.
stringify
(
osAccountInfo
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
createOsAccountForDomain exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### createOsAccountForDomain<sup>8+</sup>
### createOsAccountForDomain<sup>8+</sup>
...
@@ -1178,37 +2068,106 @@ createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Pr
...
@@ -1178,37 +2068,106 @@ createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Pr
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | --------------------------------------- | ---- | ---------------------- |
| type |
[
OsAccountType
](
#osaccounttype
)
| 是 | 创建的系统帐号的类型。 |
| domainInfo |
[
DomainAccountInfo
](
#domainaccountinfo8
)
| 是 | 域帐号信息。 |
**返回值:**
| 类型 | 说明 |
| :--------------------------------------------- | :----------------------------------------------------------- |
| Promise
<
[OsAccountInfo](#osaccountinfo)
>
| Promise实例,用于获取异步返回结果,返回的是新创建的系统帐号的信息。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
domainInfo
=
{
domain
:
'
testDomain
'
,
accountName
:
'
testAccountName
'
};
try
{
accountManager
.
createOsAccountForDomain
(
account_osAccount
.
OsAccountType
.
NORMAL
,
domainInfo
).
then
((
accountInfo
)
=>
{
console
.
log
(
'
createOsAccountForDomain, account info:
'
+
JSON
.
stringify
(
accountInfo
));
}).
catch
((
err
)
=>
{
console
.
log
(
'
createOsAccountForDomain err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
createOsAccountForDomain exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getCurrentOsAccount<sup>9+</sup>
getCurrentOsAccount(callback: AsyncCallback
<
OsAccountInfo
>
): void
查询当前进程所属的系统帐号的信息,使用callback回调异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| callback | AsyncCallback
<
[OsAccountInfo](#osaccountinfo)
>
| 是 | 回调结果,返回的是当前进程所属的系统帐号信息。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
getCurrentOsAccount
((
err
,
curAccountInfo
)
=>
{
console
.
log
(
'
getCurrentOsAccount err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getCurrentOsAccount curAccountInfo:
'
+
JSON
.
stringify
(
curAccountInfo
));
});
}
catch
(
e
)
{
console
.
log
(
'
getCurrentOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getCurrentOsAccount<sup>9+</sup>
getCurrentOsAccount(): Promise
<
OsAccountInfo
>
查询当前进程所属的系统帐号的信息,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS
| 参数名 | 类型 | 必填 | 说明 |
**系统能力:**
SystemCapability.Account.OsAccount
| ---------- | --------------------------------------- | ---- | ---------------------- |
| type |
[
OsAccountType
](
#osaccounttype
)
| 是 | 创建的系统帐号的类型。 |
| domainInfo |
[
DomainAccountInfo
](
#domainaccountinfo8
)
| 是 | 域帐号信息。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| :--------------------------------------------- | :----------------------------------------------------------- |
| :--------------------------------------------- | :----------------------------------------------------------- |
| Promise
<
[OsAccountInfo](#osaccountinfo)
>
| Promise实例,用于获取异步返回结果,返回的是
新创建的系统帐号的
信息。 |
| Promise
<
[OsAccountInfo](#osaccountinfo)
>
| Promise实例,用于获取异步返回结果,返回的是
当前进程所属的系统帐号
信息。 |
**示例:**
**示例:**
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
domainInfo
=
{
domain
:
'
testDomain
'
,
accountName
:
'
testAccountName
'
};
try
{
accountManager
.
createOsAccountForDomain
(
account_osAccount
.
OsAccountType
.
NORMAL
,
domainInfo
).
then
((
accountInfo
)
=>
{
accountManager
.
getCurrentOsAccount
(
).
then
((
accountInfo
)
=>
{
console
.
log
(
'
createOsAccountForDomain, account i
nfo:
'
+
JSON
.
stringify
(
accountInfo
));
console
.
log
(
'
getCurrentOsAccount, accountI
nfo:
'
+
JSON
.
stringify
(
accountInfo
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
createOsAccountForDomain
err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getCurrentOsAccount
err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
getCurrentOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### queryCurrentOsAccount
### queryCurrentOsAccount
<sup>(deprecated)</sup>
queryCurrentOsAccount(callback: AsyncCallback
<
OsAccountInfo
>
): void
queryCurrentOsAccount(callback: AsyncCallback
<
OsAccountInfo
>
): void
查询当前进程所属的系统帐号的信息,使用callback回调异步返回结果。
查询当前进程所属的系统帐号的信息,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[getCurrentOsAccount](#getcurrentosaccount9)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -1229,12 +2188,16 @@ queryCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void
...
@@ -1229,12 +2188,16 @@ queryCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void
});
});
```
```
### queryCurrentOsAccount
### queryCurrentOsAccount
<sup>(deprecated)</sup>
queryCurrentOsAccount(): Promise
<
OsAccountInfo
>
queryCurrentOsAccount(): Promise
<
OsAccountInfo
>
查询当前进程所属的系统帐号的信息,使用Promise方式异步返回结果。
查询当前进程所属的系统帐号的信息,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[getCurrentOsAccount](#getcurrentosaccount9-1)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -1280,10 +2243,14 @@ queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>
...
@@ -1280,10 +2243,14 @@ queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
try
{
accountManager
.
queryOsAccountById
(
localId
,
(
err
,
accountInfo
)
=>
{
accountManager
.
queryOsAccountById
(
localId
,
(
err
,
accountInfo
)
=>
{
console
.
log
(
'
queryOsAccountById err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryOsAccountById err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryOsAccountById accountInfo:
'
+
JSON
.
stringify
(
accountInfo
));
console
.
log
(
'
queryOsAccountById accountInfo:
'
+
JSON
.
stringify
(
accountInfo
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
queryOsAccountById exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### queryOsAccountById
### queryOsAccountById
...
@@ -1315,19 +2282,84 @@ queryOsAccountById(localId: number): Promise<OsAccountInfo>
...
@@ -1315,19 +2282,84 @@ queryOsAccountById(localId: number): Promise<OsAccountInfo>
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
try
{
accountManager
.
queryOsAccountById
(
localId
).
then
((
accountInfo
)
=>
{
accountManager
.
queryOsAccountById
(
localId
).
then
((
accountInfo
)
=>
{
console
.
log
(
'
queryOsAccountById, accountInfo:
'
+
JSON
.
stringify
(
accountInfo
));
console
.
log
(
'
queryOsAccountById, accountInfo:
'
+
JSON
.
stringify
(
accountInfo
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
queryOsAccountById err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryOsAccountById err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
queryOsAccountById exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getOsAccountType<sup>9+</sup>
getOsAccountType(callback: AsyncCallback
<
OsAccountType
>
): void
查询当前进程所属的系统帐号的帐号类型,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback
<
[OsAccountType](#osaccounttype)
>
| 是 | 回调结果,返回的是当前进程所属的系统帐号的帐号类型。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
getOsAccountType
((
err
,
accountType
)
=>
{
console
.
log
(
'
getOsAccountType err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getOsAccountType accountType:
'
+
accountType
);
});
}
catch
(
e
)
{
console
.
log
(
'
getOsAccountType exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getOsAccountType<sup>9+</sup>
getOsAccountType(): Promise
<
OsAccountType
>
查询当前进程所属的系统帐号的帐号类型,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
| 类型 | 说明 |
| :--------------------------------------------- | :----------------------------------------------------------- |
| Promise
<
[OsAccountType](#osaccounttype)
>
| Promise实例,用于获取异步返回结果,返回的是当前进程所属的系统帐号的帐号类型。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
getOsAccountType
().
then
((
accountType
)
=>
{
console
.
log
(
'
getOsAccountType, accountType:
'
+
accountType
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
getOsAccountType err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
getOsAccountType exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### getOsAccountTypeFromProcess
### getOsAccountTypeFromProcess
<sup>(deprecated)</sup>
getOsAccountTypeFromProcess(callback: AsyncCallback
<
OsAccountType
>
): void
getOsAccountTypeFromProcess(callback: AsyncCallback
<
OsAccountType
>
): void
查询当前进程所属的系统帐号的帐号类型,使用callback回调异步返回结果。
查询当前进程所属的系统帐号的帐号类型,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[getOsAccountType](#getosaccounttype9)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -1346,12 +2378,16 @@ getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): void
...
@@ -1346,12 +2378,16 @@ getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): void
});
});
```
```
### getOsAccountTypeFromProcess
### getOsAccountTypeFromProcess
<sup>(deprecated)</sup>
getOsAccountTypeFromProcess(): Promise
<
OsAccountType
>
getOsAccountTypeFromProcess(): Promise
<
OsAccountType
>
查询当前进程所属的系统帐号的帐号类型,使用Promise方式异步返回结果。
查询当前进程所属的系统帐号的帐号类型,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[getOsAccountType](#getosaccounttype9-1)
>
> 从 API version 7开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
**返回值:**
...
@@ -1371,12 +2407,77 @@ getOsAccountTypeFromProcess(): Promise<OsAccountType>
...
@@ -1371,12 +2407,77 @@ getOsAccountTypeFromProcess(): Promise<OsAccountType>
});
});
```
```
### getDistributedVirtualDeviceId
### queryDistributedVirtualDeviceId<sup>9+</sup>
queryDistributedVirtualDeviceId(callback: AsyncCallback
<
string
>
): void
获取分布式虚拟设备ID,使用callback回调异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback
<
string
>
| 是 | 回调结果,返回的是分布式虚拟设备ID。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryDistributedVirtualDeviceId
((
err
,
virtualID
)
=>
{
console
.
log
(
'
queryDistributedVirtualDeviceId err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryDistributedVirtualDeviceId virtualID:
'
+
virtualID
);
});
}
catch
(
e
)
{
console
.
log
(
'
queryDistributedVirtualDeviceId exception:
'
+
JSON
.
stringify
(
e
));
}
```
### queryDistributedVirtualDeviceId<sup>9+</sup>
queryDistributedVirtualDeviceId(): Promise
<
string
>
获取分布式虚拟设备ID,使用Promise方式异步返回结果。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**返回值:**
| 类型 | 说明 |
| :-------------------- | :----------------------------------------------------------- |
| Promise
<
string
>
| Promise实例,用于获取异步返回结果,返回的是分布式虚拟设备ID。 |
**示例:**
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryDistributedVirtualDeviceId
().
then
((
virtualID
)
=>
{
console
.
log
(
'
queryDistributedVirtualDeviceId, virtualID:
'
+
virtualID
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
queryDistributedVirtualDeviceId err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
queryDistributedVirtualDeviceId exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getDistributedVirtualDeviceId<sup>(deprecated)</sup>
getDistributedVirtualDeviceId(callback: AsyncCallback
<
string
>
): void
getDistributedVirtualDeviceId(callback: AsyncCallback
<
string
>
): void
获取分布式虚拟设备ID,使用callback回调异步返回结果。
获取分布式虚拟设备ID,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.DISTRIBUTED_DATASYNC 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.DISTRIBUTED_DATASYNC 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -1397,12 +2498,16 @@ getDistributedVirtualDeviceId(callback: AsyncCallback<string>): void
...
@@ -1397,12 +2498,16 @@ getDistributedVirtualDeviceId(callback: AsyncCallback<string>): void
});
});
```
```
### getDistributedVirtualDeviceId
### getDistributedVirtualDeviceId
<sup>(deprecated)</sup>
getDistributedVirtualDeviceId(): Promise
<
string
>
getDistributedVirtualDeviceId(): Promise
<
string
>
获取分布式虚拟设备ID,使用Promise方式异步返回结果。
获取分布式虚拟设备ID,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9-1)
>
> 从 API version 7开始支持。
**需要权限:**
ohos.permission.DISTRIBUTED_DATASYNC 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.DISTRIBUTED_DATASYNC 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -1448,10 +2553,14 @@ getOsAccountProfilePhoto(localId: number, callback: AsyncCallback<string>)
...
@@ -1448,10 +2553,14 @@ getOsAccountProfilePhoto(localId: number, callback: AsyncCallback<string>)
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
try
{
accountManager
.
getOsAccountProfilePhoto
(
localId
,
(
err
,
photo
)
=>
{
accountManager
.
getOsAccountProfilePhoto
(
localId
,
(
err
,
photo
)
=>
{
console
.
log
(
'
getOsAccountProfilePhoto err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getOsAccountProfilePhoto err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
get photo:
'
+
photo
+
'
by localId:
'
+
localId
);
console
.
log
(
'
get photo:
'
+
photo
+
'
by localId:
'
+
localId
);
});
});
}
catch
(
e
)
{
console
.
log
(
'
getOsAccountProfilePhoto exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### getOsAccountProfilePhoto
### getOsAccountProfilePhoto
...
@@ -1483,11 +2592,15 @@ getOsAccountProfilePhoto(localId: number): Promise<string>
...
@@ -1483,11 +2592,15 @@ getOsAccountProfilePhoto(localId: number): Promise<string>
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
let
localId
=
100
;
try
{
accountManager
.
getOsAccountProfilePhoto
(
localId
).
then
((
photo
)
=>
{
accountManager
.
getOsAccountProfilePhoto
(
localId
).
then
((
photo
)
=>
{
console
.
log
(
'
getOsAccountProfilePhoto:
'
+
photo
);
console
.
log
(
'
getOsAccountProfilePhoto:
'
+
photo
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
getOsAccountProfilePhoto err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getOsAccountProfilePhoto err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
getOsAccountProfilePhoto exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### setOsAccountProfilePhoto
### setOsAccountProfilePhoto
...
@@ -1519,9 +2632,13 @@ setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback
...
@@ -1519,9 +2632,13 @@ setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback
'
Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y
'
+
'
Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y
'
+
'
q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo
'
+
'
q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo
'
+
'
+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==
'
'
+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==
'
try
{
accountManager
.
setOsAccountProfilePhoto
(
localId
,
photo
,
(
err
)
=>
{
accountManager
.
setOsAccountProfilePhoto
(
localId
,
photo
,
(
err
)
=>
{
console
.
log
(
'
setOsAccountProfilePhoto err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
setOsAccountProfilePhoto err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
setOsAccountProfilePhoto exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### setOsAccountProfilePhoto
### setOsAccountProfilePhoto
...
@@ -1558,19 +2675,93 @@ setOsAccountProfilePhoto(localId: number, photo: string): Promise<void>
...
@@ -1558,19 +2675,93 @@ setOsAccountProfilePhoto(localId: number, photo: string): Promise<void>
'
Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y
'
+
'
Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y
'
+
'
q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo
'
+
'
q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo
'
+
'
+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==
'
'
+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==
'
try
{
accountManager
.
setOsAccountProfilePhoto
(
localId
,
photo
).
then
(()
=>
{
accountManager
.
setOsAccountProfilePhoto
(
localId
,
photo
).
then
(()
=>
{
console
.
log
(
'
setOsAccountProfilePhoto success
'
);
console
.
log
(
'
setOsAccountProfilePhoto success
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
setOsAccountProfilePhoto err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
setOsAccountProfilePhoto err:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
setOsAccountProfilePhoto exception:
'
+
JSON
.
stringify
(
e
));
}
```
### queryOsAccountLocalIdBySerialNumber<sup>9+</sup>
queryOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback
<
number
>
): void
通过SN码查询与其关联的系统帐号的帐号ID,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | --------------------------- | ---- | ------------------------------------------------ |
| serialNumber | number | 是 | 帐号SN码。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调结果,返回的是与SN码关联的系统帐号的帐号ID。 |
**示例:**
查询与SN码12345关联的系统帐号的ID
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
serialNumber
=
12345
;
try
{
accountManager
.
queryOsAccountLocalIdBySerialNumber
(
serialNumber
,
(
err
,
localId
)
=>
{
console
.
log
(
'
ger localId err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
get localId:
'
+
localId
+
'
by serialNumber:
'
+
serialNumber
);
});
}
catch
(
e
)
{
console
.
log
(
'
ger localId exception:
'
+
JSON
.
stringify
(
e
));
}
```
### queryOsAccountLocalIdBySerialNumber<sup>9+</sup>
queryOsAccountLocalIdBySerialNumber(serialNumber: number): Promise
<
number
>
通过SN码查询与其关联的系统帐号的帐号ID,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------ | ---- | ---------- |
| serialNumber | number | 是 | 帐号SN码。 |
**返回值:**
| 类型 | 说明 |
| :-------------------- | :----------------------------------------------------------- |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是与SN码关联的系统帐号的帐号ID。 |
**示例:**
查询与SN码12345关联的系统帐号的ID
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
serialNumber
=
12345
;
try
{
accountManager
.
queryOsAccountLocalIdBySerialNumber
(
serialNumber
).
then
((
localId
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdBySerialNumber localId:
'
+
localId
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
queryOsAccountLocalIdBySerialNumber err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
queryOsAccountLocalIdBySerialNumber exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### getOsAccountLocalIdBySerialNumber<sup>
8+
</sup>
### getOsAccountLocalIdBySerialNumber<sup>
(deprecated)
</sup>
getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback
<
number
>
): void
getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback
<
number
>
): void
通过SN码查询与其关联的系统帐号的帐号ID,使用callback回调异步返回结果。
通过SN码查询与其关联的系统帐号的帐号ID,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[queryOsAccountLocalIdBySerialNumber](#queryosaccountlocalidbyserialnumber9)
>
> 从 API version 8开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -1591,12 +2782,16 @@ getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback&
...
@@ -1591,12 +2782,16 @@ getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback&
});
});
```
```
### getOsAccountLocalIdBySerialNumber<sup>
8+
</sup>
### getOsAccountLocalIdBySerialNumber<sup>
(deprecated)
</sup>
getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise
<
number
>
getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise
<
number
>
通过SN码查询与其关联的系统帐号的帐号ID,使用Promise方式异步返回结果。
通过SN码查询与其关联的系统帐号的帐号ID,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[queryOsAccountLocalIdBySerialNumber](#queryosaccountlocalidbyserialnumber9-1)
>
> 从 API version 8开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -1623,12 +2818,82 @@ getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise<number>
...
@@ -1623,12 +2818,82 @@ getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise<number>
});
});
```
```
### getSerialNumberByOsAccountLocalId<sup>8+</sup>
### querySerialNumberByOsAccountLocalId<sup>9+</sup>
querySerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback
<
number
>
): void
通过系统帐号ID获取与该系统帐号关联的SN码,使用callback回调异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------ |
| localId | number | 是 | 系统帐号ID。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调结果,返回的是与该系统帐号关联的SN码。 |
**示例:**
获取ID为100的系统帐号关联的SN码
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
try
{
accountManager
.
querySerialNumberByOsAccountLocalId
(
localId
,
(
err
,
serialNumber
)
=>
{
console
.
log
(
'
ger serialNumber err:
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
get serialNumber:
'
+
serialNumber
+
'
by localId:
'
+
localId
);
});
}
catch
(
e
)
{
console
.
log
(
'
ger serialNumber exception:
'
+
JSON
.
stringify
(
e
));
}
```
### querySerialNumberByOsAccountLocalId<sup>9+</sup>
querySerialNumberByOsAccountLocalId(localId: number): Promise
<
number
>
通过系统帐号ID获取与该系统帐号关联的SN码,使用Promise方式异步返回结果。
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ------------ |
| localId | number | 是 | 系统帐号ID。 |
**返回值:**
| 类型 | 说明 |
| :-------------------- | :----------------------------------------------------------- |
| Promise
<
number
>
| Promise实例,用于获取异步返回结果,返回的是与该系统帐号关联的SN码。 |
**示例:**
获取ID为100的系统帐号关联的SN码
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
localId
=
100
;
try
{
accountManager
.
querySerialNumberByOsAccountLocalId
(
localId
).
then
((
serialNumber
)
=>
{
console
.
log
(
'
querySerialNumberByOsAccountLocalId serialNumber:
'
+
serialNumber
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
querySerialNumberByOsAccountLocalId err:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
'
querySerialNumberByOsAccountLocalId exception:
'
+
JSON
.
stringify
(
e
));
}
```
### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup>
getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback
<
number
>
): void
getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback
<
number
>
): void
通过系统帐号ID获取与该系统帐号关联的SN码,使用callback回调异步返回结果。
通过系统帐号ID获取与该系统帐号关联的SN码,使用callback回调异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[querySerialNumberByOsAccountLocalId](#queryserialnumberbyosaccountlocalid9)
>
> 从 API version 8开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -1649,12 +2914,16 @@ getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback<nu
...
@@ -1649,12 +2914,16 @@ getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback<nu
});
});
```
```
### getSerialNumberByOsAccountLocalId<sup>
8+
</sup>
### getSerialNumberByOsAccountLocalId<sup>
(deprecated)
</sup>
getSerialNumberByOsAccountLocalId(localId: number): Promise
<
number
>
getSerialNumberByOsAccountLocalId(localId: number): Promise
<
number
>
通过系统帐号ID获取与该系统帐号关联的SN码,使用Promise方式异步返回结果。
通过系统帐号ID获取与该系统帐号关联的SN码,使用Promise方式异步返回结果。
> **说明:** 从API version 9开始废弃,建议使用[querySerialNumberByOsAccountLocalId](#queryserialnumberbyosaccountlocalid9-1)
>
> 从 API version 8开始支持。
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
**参数:**
**参数:**
...
@@ -1708,7 +2977,11 @@ on(type: 'activate' | 'activating', name: string, callback: Callback<number&g
...
@@ -1708,7 +2977,11 @@ on(type: 'activate' | 'activating', name: string, callback: Callback<number&g
function
onCallback
(
receiveLocalId
){
function
onCallback
(
receiveLocalId
){
console
.
log
(
'
receive localId:
'
+
receiveLocalId
);
console
.
log
(
'
receive localId:
'
+
receiveLocalId
);
}
}
try
{
accountManager
.
on
(
'
activating
'
,
'
osAccountOnOffNameA
'
,
onCallback
);
accountManager
.
on
(
'
activating
'
,
'
osAccountOnOffNameA
'
,
onCallback
);
}
catch
(
e
)
{
console
.
log
(
'
receive localId exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### off
### off
...
@@ -1738,7 +3011,11 @@ off(type: 'activate' | 'activating', name: string, callback?: Callback<number
...
@@ -1738,7 +3011,11 @@ off(type: 'activate' | 'activating', name: string, callback?: Callback<number
function
offCallback
(){
function
offCallback
(){
console
.
log
(
'
off enter
'
)
console
.
log
(
'
off enter
'
)
}
}
try
{
accountManager
.
off
(
'
activating
'
,
'
osAccountOnOffNameA
'
,
offCallback
);
accountManager
.
off
(
'
activating
'
,
'
osAccountOnOffNameA
'
,
offCallback
);
}
catch
(
e
)
{
console
.
log
(
'
off exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### getBundleIdFromUid<sup>9+</sup>
### getBundleIdFromUid<sup>9+</sup>
...
@@ -1763,10 +3040,14 @@ getBundleIdFromUid(uid: number, callback: AsyncCallback<number>): void;
...
@@ -1763,10 +3040,14 @@ getBundleIdFromUid(uid: number, callback: AsyncCallback<number>): void;
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
testUid
=
1000000
;
let
testUid
=
1000000
;
try
{
accountManager
.
getBundleIdFromUid
(
testUid
,
(
err
,
bundleId
)
=>
{
accountManager
.
getBundleIdFromUid
(
testUid
,
(
err
,
bundleId
)
=>
{
console
.
info
(
'
getBundleIdFromUid errInfo:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
getBundleIdFromUid errInfo:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
getBundleIdFromUid bundleId:
'
+
JSON
.
stringify
(
bundleId
));
console
.
info
(
'
getBundleIdFromUid bundleId:
'
+
JSON
.
stringify
(
bundleId
));
});
});
}
catch
(
e
)
{
console
.
info
(
'
getBundleIdFromUid exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### getBundleIdFromUid<sup>9+</sup>
### getBundleIdFromUid<sup>9+</sup>
...
@@ -1795,11 +3076,15 @@ getBundleIdFromUid(uid: number): Promise<number>;
...
@@ -1795,11 +3076,15 @@ getBundleIdFromUid(uid: number): Promise<number>;
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
testUid
=
1000000
;
let
testUid
=
1000000
;
try
{
accountManager
.
getBundleIdFromUid
(
testUid
).
then
((
result
)
=>
{
accountManager
.
getBundleIdFromUid
(
testUid
).
then
((
result
)
=>
{
console
.
info
(
'
getBundleIdFromUid bundleId:
'
+
JSON
.
stringify
(
result
));
console
.
info
(
'
getBundleIdFromUid bundleId:
'
+
JSON
.
stringify
(
result
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
'
getBundleIdFromUid errInfo:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
getBundleIdFromUid errInfo:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
info
(
'
getBundleIdFromUid exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### isMainOsAccount<sup>9+</sup>
### isMainOsAccount<sup>9+</sup>
...
@@ -1810,7 +3095,7 @@ isMainOsAccount(callback: AsyncCallback<boolean>): void;
...
@@ -1810,7 +3095,7 @@ isMainOsAccount(callback: AsyncCallback<boolean>): void;
此接口为系统接口,三方应用不支持调用。
此接口为系统接口,三方应用不支持调用。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -1824,10 +3109,14 @@ isMainOsAccount(callback: AsyncCallback<boolean>): void;
...
@@ -1824,10 +3109,14 @@ isMainOsAccount(callback: AsyncCallback<boolean>): void;
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
isMainOsAccount
((
err
,
result
)
=>
{
accountManager
.
isMainOsAccount
((
err
,
result
)
=>
{
console
.
info
(
'
isMainOsAccount errInfo:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
isMainOsAccount errInfo:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
isMainOsAccount result:
'
+
JSON
.
stringify
(
result
));
console
.
info
(
'
isMainOsAccount result:
'
+
JSON
.
stringify
(
result
));
});
});
}
catch
(
e
)
{
console
.
info
(
'
isMainOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### isMainOsAccount<sup>9+</sup>
### isMainOsAccount<sup>9+</sup>
...
@@ -1837,7 +3126,7 @@ isMainOsAccount(): Promise<boolean>;
...
@@ -1837,7 +3126,7 @@ isMainOsAccount(): Promise<boolean>;
此接口为系统接口,三方应用不支持调用。
此接口为系统接口,三方应用不支持调用。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -1851,11 +3140,15 @@ isMainOsAccount(): Promise<boolean>;
...
@@ -1851,11 +3140,15 @@ isMainOsAccount(): Promise<boolean>;
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
isMainOsAccount
().
then
((
result
)
=>
{
accountManager
.
isMainOsAccount
().
then
((
result
)
=>
{
console
.
info
(
'
isMainOsAccount result:
'
+
JSON
.
stringify
(
result
));
console
.
info
(
'
isMainOsAccount result:
'
+
JSON
.
stringify
(
result
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
'
isMainOsAccount errInfo:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
isMainOsAccount errInfo:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
info
(
'
isMainOsAccount exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### queryOsAccountConstraintSourceTypes<sup>9+</sup>
### queryOsAccountConstraintSourceTypes<sup>9+</sup>
...
@@ -1865,7 +3158,7 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string, callbac
...
@@ -1865,7 +3158,7 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string, callbac
此接口为系统接口,三方应用不支持调用。
此接口为系统接口,三方应用不支持调用。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -1881,10 +3174,14 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string, callbac
...
@@ -1881,10 +3174,14 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string, callbac
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryOsAccountConstraintSourceTypes
(
100
,
'
constraint.wifi
'
,(
err
,
sourceTypeInfos
)
=>
{
accountManager
.
queryOsAccountConstraintSourceTypes
(
100
,
'
constraint.wifi
'
,(
err
,
sourceTypeInfos
)
=>
{
console
.
info
(
'
queryOsAccountConstraintSourceType errInfo:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
queryOsAccountConstraintSourceType errInfo:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
queryOsAccountConstraintSourceType sourceTypeInfos:
'
+
JSON
.
stringify
(
sourceTypeInfos
));
console
.
info
(
'
queryOsAccountConstraintSourceType sourceTypeInfos:
'
+
JSON
.
stringify
(
sourceTypeInfos
));
});
});
}
catch
(
e
)
{
console
.
info
(
'
queryOsAccountConstraintSourceType exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
### queryOsAccountConstraintSourceTypes<sup>9+</sup>
### queryOsAccountConstraintSourceTypes<sup>9+</sup>
...
@@ -1895,7 +3192,7 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string): Promis
...
@@ -1895,7 +3192,7 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string): Promis
此接口为系统接口,三方应用不支持调用。
此接口为系统接口,三方应用不支持调用。
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
**需要权限:**
ohos.permission.MANAGE_LOCAL_ACCOUNTS
或 ohos.permission.GET_LOCAL_ACCOUNTS
**系统能力:**
SystemCapability.Account.OsAccount
**系统能力:**
SystemCapability.Account.OsAccount
...
@@ -1916,11 +3213,15 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string): Promis
...
@@ -1916,11 +3213,15 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string): Promis
```
js
```
js
let
accountManager
=
account_osAccount
.
getAccountManager
();
let
accountManager
=
account_osAccount
.
getAccountManager
();
try
{
accountManager
.
queryOsAccountConstraintSourceTypes
(
100
,
'
constraint.wifi
'
).
then
((
result
)
=>
{
accountManager
.
queryOsAccountConstraintSourceTypes
(
100
,
'
constraint.wifi
'
).
then
((
result
)
=>
{
console
.
info
(
'
queryOsAccountConstraintSourceType sourceTypeInfos:
'
+
JSON
.
stringify
(
result
));
console
.
info
(
'
queryOsAccountConstraintSourceType sourceTypeInfos:
'
+
JSON
.
stringify
(
result
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
'
queryOsAccountConstraintSourceType errInfo:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
queryOsAccountConstraintSourceType errInfo:
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
info
(
'
queryOsAccountConstraintSourceType exception:
'
+
JSON
.
stringify
(
e
));
}
```
```
## UserAuth<sup>8+</sup>
## UserAuth<sup>8+</sup>
...
@@ -1998,8 +3299,12 @@ getAvailableStatus(authType: AuthType, authTrustLevel: AuthTrustLevel): number;
...
@@ -1998,8 +3299,12 @@ getAvailableStatus(authType: AuthType, authTrustLevel: AuthTrustLevel): number;
let
userAuth
=
new
account_osAccount
.
UserAuth
();
let
userAuth
=
new
account_osAccount
.
UserAuth
();
let
authType
=
account_osAccount
.
AuthType
.
PIN
;
let
authType
=
account_osAccount
.
AuthType
.
PIN
;
let
authTrustLevel
=
account_osAccount
.
AuthTrustLevel
.
ATL1
;
let
authTrustLevel
=
account_osAccount
.
AuthTrustLevel
.
ATL1
;
try
{
let
status
=
userAuth
.
getAvailableStatus
(
authType
,
authTrustLevel
);
let
status
=
userAuth
.
getAvailableStatus
(
authType
,
authTrustLevel
);
console
.
log
(
'
getAvailableStatus status =
'
+
status
);
console
.
log
(
'
getAvailableStatus status =
'
+
status
);
}
catch
(
e
)
{
console
.
log
(
'
getAvailableStatus exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### getProperty<sup>8+</sup>
### getProperty<sup>8+</sup>
...
@@ -2033,10 +3338,14 @@ getProperty(request: GetPropertyRequest, callback: AsyncCallback<ExecutorProp
...
@@ -2033,10 +3338,14 @@ getProperty(request: GetPropertyRequest, callback: AsyncCallback<ExecutorProp
authType
:
account_osAccount
.
AuthType
.
PIN
,
authType
:
account_osAccount
.
AuthType
.
PIN
,
keys
:
keys
keys
:
keys
};
};
try
{
userAuth
.
getProperty
(
request
,
(
err
,
result
)
=>
{
userAuth
.
getProperty
(
request
,
(
err
,
result
)
=>
{
console
.
log
(
'
getProperty err =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getProperty err =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getProperty result =
'
+
JSON
.
stringify
(
result
));
console
.
log
(
'
getProperty result =
'
+
JSON
.
stringify
(
result
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
getProperty exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### getProperty<sup>8+</sup>
### getProperty<sup>8+</sup>
...
@@ -2075,11 +3384,15 @@ getProperty(request: GetPropertyRequest): Promise<ExecutorProperty>;
...
@@ -2075,11 +3384,15 @@ getProperty(request: GetPropertyRequest): Promise<ExecutorProperty>;
authType
:
account_osAccount
.
AuthType
.
PIN
,
authType
:
account_osAccount
.
AuthType
.
PIN
,
keys
:
keys
keys
:
keys
};
};
try
{
userAuth
.
getProperty
(
request
).
then
((
result
)
=>
{
userAuth
.
getProperty
(
request
).
then
((
result
)
=>
{
console
.
log
(
'
getProperty result =
'
+
JSON
.
stringify
(
result
));
console
.
log
(
'
getProperty result =
'
+
JSON
.
stringify
(
result
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
getProperty error =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getProperty error =
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
getProperty exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### setProperty<sup>8+</sup>
### setProperty<sup>8+</sup>
...
@@ -2109,10 +3422,14 @@ setProperty(request: SetPropertyRequest, callback: AsyncCallback<number>):
...
@@ -2109,10 +3422,14 @@ setProperty(request: SetPropertyRequest, callback: AsyncCallback<number>):
key
:
account_osAccount
.
SetPropertyType
.
INIT_ALGORITHM
,
key
:
account_osAccount
.
SetPropertyType
.
INIT_ALGORITHM
,
setInfo
:
new
Uint8Array
([
0
])
setInfo
:
new
Uint8Array
([
0
])
};
};
try
{
userAuth
.
setProperty
(
request
,
(
err
,
result
)
=>
{
userAuth
.
setProperty
(
request
,
(
err
,
result
)
=>
{
console
.
log
(
'
setProperty error =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
setProperty error =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
setProperty result =
'
+
JSON
.
stringify
(
result
));
console
.
log
(
'
setProperty result =
'
+
JSON
.
stringify
(
result
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
setProperty exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### setProperty<sup>8+</sup>
### setProperty<sup>8+</sup>
...
@@ -2147,11 +3464,15 @@ setProperty(request: SetPropertyRequest): Promise<number>;
...
@@ -2147,11 +3464,15 @@ setProperty(request: SetPropertyRequest): Promise<number>;
key
:
account_osAccount
.
SetPropertyType
.
INIT_ALGORITHM
,
key
:
account_osAccount
.
SetPropertyType
.
INIT_ALGORITHM
,
setInfo
:
new
Uint8Array
([
0
])
setInfo
:
new
Uint8Array
([
0
])
};
};
try
{
userAuth
.
setProperty
(
request
).
then
((
result
)
=>
{
userAuth
.
setProperty
(
request
).
then
((
result
)
=>
{
console
.
log
(
'
setProperty result =
'
+
JSON
.
stringify
(
result
));
console
.
log
(
'
setProperty result =
'
+
JSON
.
stringify
(
result
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
setProperty error =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
setProperty error =
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
setProperty exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### auth<sup>8+</sup>
### auth<sup>8+</sup>
...
@@ -2188,12 +3509,16 @@ auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel,
...
@@ -2188,12 +3509,16 @@ auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel,
let
challenge
=
new
Uint8Array
([
0
]);
let
challenge
=
new
Uint8Array
([
0
]);
let
authType
=
account_osAccount
.
AuthType
.
PIN
;
let
authType
=
account_osAccount
.
AuthType
.
PIN
;
let
authTrustLevel
=
account_osAccount
.
AuthTrustLevel
.
ATL1
;
let
authTrustLevel
=
account_osAccount
.
AuthTrustLevel
.
ATL1
;
try
{
userAuth
.
auth
(
challenge
,
authType
,
authTrustLevel
,
{
userAuth
.
auth
(
challenge
,
authType
,
authTrustLevel
,
{
onResult
:
function
(
result
,
extraInfo
){
onResult
:
function
(
result
,
extraInfo
){
console
.
log
(
'
auth result =
'
+
result
);
console
.
log
(
'
auth result =
'
+
result
);
console
.
log
(
'
auth extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
console
.
log
(
'
auth extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
}
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
auth exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### authUser<sup>8+</sup>
### authUser<sup>8+</sup>
...
@@ -2232,17 +3557,21 @@ authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLev
...
@@ -2232,17 +3557,21 @@ authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLev
let
challenge
=
new
Uint8Array
([
0
]);
let
challenge
=
new
Uint8Array
([
0
]);
let
authType
=
account_osAccount
.
AuthType
.
PIN
;
let
authType
=
account_osAccount
.
AuthType
.
PIN
;
let
authTrustLevel
=
account_osAccount
.
AuthTrustLevel
.
ATL1
;
let
authTrustLevel
=
account_osAccount
.
AuthTrustLevel
.
ATL1
;
try
{
userAuth
.
authUser
(
userID
,
challenge
,
authType
,
authTrustLevel
,
{
userAuth
.
authUser
(
userID
,
challenge
,
authType
,
authTrustLevel
,
{
onResult
:
function
(
result
,
extraInfo
){
onResult
:
function
(
result
,
extraInfo
){
console
.
log
(
'
authUser result =
'
+
result
);
console
.
log
(
'
authUser result =
'
+
result
);
console
.
log
(
'
authUser extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
console
.
log
(
'
authUser extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
}
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
authUser exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### cancelAuth<sup>8+</sup>
### cancelAuth<sup>8+</sup>
cancelAuth(contextID: Uint8Array):
number
;
cancelAuth(contextID: Uint8Array):
void
;
取消特定的认证。
取消特定的认证。
...
@@ -2258,12 +3587,6 @@ cancelAuth(contextID: Uint8Array): number;
...
@@ -2258,12 +3587,6 @@ cancelAuth(contextID: Uint8Array): number;
| ----------| ---------- | ---- | ------------------------------------------ |
| ----------| ---------- | ---- | ------------------------------------------ |
| contextID | Uint8Array | 是 | 指示身份验证上下文ID,此ID动态生成没有具体值。 |
| contextID | Uint8Array | 是 | 指示身份验证上下文ID,此ID动态生成没有具体值。 |
**返回值:**
| 类型 | 说明 |
| :----- | :-------------------------------------------------------- |
| number | 返回一个
[
数字
](
#resultcode8
)
,指示取消是否成功。 |
**示例:**
**示例:**
```
js
```
js
let
userAuth
=
new
account_osAccount
.
UserAuth
();
let
userAuth
=
new
account_osAccount
.
UserAuth
();
...
@@ -2275,8 +3598,11 @@ cancelAuth(contextID: Uint8Array): number;
...
@@ -2275,8 +3598,11 @@ cancelAuth(contextID: Uint8Array): number;
console
.
log
(
'
auth extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
console
.
log
(
'
auth extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
}
}
});
});
let
result
=
userAuth
.
cancelAuth
(
contextID
);
try
{
console
.
log
(
'
cancelAuth result =
'
+
result
);
userAuth
.
cancelAuth
(
contextID
);
}
catch
(
e
)
{
console
.
log
(
'
cancelAuth exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
## PINAuth<sup>8+</sup>
## PINAuth<sup>8+</sup>
...
@@ -2300,7 +3626,7 @@ constructor()
...
@@ -2300,7 +3626,7 @@ constructor()
let
pinAuth
=
new
account_osAccount
.
PINAuth
();
let
pinAuth
=
new
account_osAccount
.
PINAuth
();
```
```
### registerInputer
### registerInputer
<sup>8+</sup>
registerInputer(inputer: IInputer): boolean;
registerInputer(inputer: IInputer): boolean;
...
@@ -2328,15 +3654,19 @@ registerInputer(inputer: IInputer): boolean;
...
@@ -2328,15 +3654,19 @@ registerInputer(inputer: IInputer): boolean;
```
js
```
js
let
pinAuth
=
new
account_osAccount
.
PINAuth
();
let
pinAuth
=
new
account_osAccount
.
PINAuth
();
let
password
=
new
Uint8Array
([
0
,
0
,
0
,
0
,
0
]);
let
password
=
new
Uint8Array
([
0
,
0
,
0
,
0
,
0
]);
try
{
let
result
=
pinAuth
.
registerInputer
({
let
result
=
pinAuth
.
registerInputer
({
onGetData
:
(
pinSubType
,
callback
)
=>
{
onGetData
:
(
pinSubType
,
callback
)
=>
{
callback
.
onSetData
(
pinSubType
,
password
);
callback
.
onSetData
(
pinSubType
,
password
);
}
}
});
});
console
.
log
(
'
registerInputer result =
'
+
result
);
console
.
log
(
'
registerInputer result =
'
+
result
);
}
catch
(
e
)
{
console
.
log
(
'
registerInputer exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### unregisterInputer
### unregisterInputer
<sup>8+</sup>
unregisterInputer(): void;
unregisterInputer(): void;
...
@@ -2396,10 +3726,14 @@ openSession(callback: AsyncCallback<Uint8Array>): void;
...
@@ -2396,10 +3726,14 @@ openSession(callback: AsyncCallback<Uint8Array>): void;
**示例:**
**示例:**
```
js
```
js
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
try
{
userIDM
.
openSession
((
err
,
challenge
)
=>
{
userIDM
.
openSession
((
err
,
challenge
)
=>
{
console
.
log
(
'
openSession error =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
openSession error =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
openSession challenge =
'
+
JSON
.
stringify
(
challenge
));
console
.
log
(
'
openSession challenge =
'
+
JSON
.
stringify
(
challenge
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
openSession exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### openSession<sup>8+</sup>
### openSession<sup>8+</sup>
...
@@ -2423,11 +3757,15 @@ openSession(): Promise<Uint8Array>;
...
@@ -2423,11 +3757,15 @@ openSession(): Promise<Uint8Array>;
**示例:**
**示例:**
```
js
```
js
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
try
{
userIDM
.
openSession
().
then
((
challenge
)
=>
{
userIDM
.
openSession
().
then
((
challenge
)
=>
{
console
.
info
(
'
openSession challenge =
'
+
JSON
.
stringify
(
challenge
));
console
.
info
(
'
openSession challenge =
'
+
JSON
.
stringify
(
challenge
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
'
openSession error =
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
openSession error =
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
openSession exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### addCredential<sup>8+</sup>
### addCredential<sup>8+</sup>
...
@@ -2465,12 +3803,16 @@ addCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;
...
@@ -2465,12 +3803,16 @@ addCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;
};
};
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
userIDM
.
openSession
((
err
,
challenge
)
=>
{
userIDM
.
openSession
((
err
,
challenge
)
=>
{
try
{
userIDM
.
addCredential
(
credentialInfo
,
{
userIDM
.
addCredential
(
credentialInfo
,
{
onResult
:
(
result
,
extraInfo
)
=>
{
onResult
:
(
result
,
extraInfo
)
=>
{
console
.
log
(
'
updateCredential result =
'
+
result
);
console
.
log
(
'
updateCredential result =
'
+
result
);
console
.
log
(
'
updateCredential extraInfo =
'
+
extraInfo
);
console
.
log
(
'
updateCredential extraInfo =
'
+
extraInfo
);
}
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
updateCredential exception =
'
+
JSON
.
stringify
(
e
));
}
});
});
```
```
...
@@ -2516,12 +3858,16 @@ updateCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;
...
@@ -2516,12 +3858,16 @@ updateCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void;
return
;
return
;
}
}
credentialInfo
.
token
=
extraInfo
.
token
;
credentialInfo
.
token
=
extraInfo
.
token
;
try
{
userIDM
.
updateCredential
(
credentialInfo
,
{
userIDM
.
updateCredential
(
credentialInfo
,
{
onResult
:
(
result
,
extraInfo
)
=>
{
onResult
:
(
result
,
extraInfo
)
=>
{
console
.
log
(
'
updateCredential result =
'
+
result
);
console
.
log
(
'
updateCredential result =
'
+
result
);
console
.
log
(
'
updateCredential extraInfo =
'
+
extraInfo
);
console
.
log
(
'
updateCredential extraInfo =
'
+
extraInfo
);
}
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
updateCredential exception =
'
+
JSON
.
stringify
(
e
));
}
}
}
});
});
});
});
...
@@ -2547,7 +3893,7 @@ closeSession(): void;
...
@@ -2547,7 +3893,7 @@ closeSession(): void;
### cancel<sup>8+</sup>
### cancel<sup>8+</sup>
cancel(challenge: Uint8Array):
number
;
cancel(challenge: Uint8Array):
void
;
根据挑战值取消条目。
根据挑战值取消条目。
...
@@ -2563,18 +3909,16 @@ cancel(challenge: Uint8Array): number;
...
@@ -2563,18 +3909,16 @@ cancel(challenge: Uint8Array): number;
| -------- | ----------- | ---- | ----- |
| -------- | ----------- | ---- | ----- |
| challenge | Uint8Array | 是 | 挑战值。 |
| challenge | Uint8Array | 是 | 挑战值。 |
**返回值:**
| 类型 | 说明 |
| :----- | :-------------------------------------------------------- |
| number | 返回一个
[
数字
](
#resultcode8
)
,指示取消是否成功。 |
**示例:**
**示例:**
```
js
```
js
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
challenge
=
new
Uint8Array
([
0
]);
let
challenge
=
new
Uint8Array
([
0
]);
let
result
=
userIDM
.
cancel
(
challenge
);
try
{
console
.
log
(
'
cancel result:
'
+
result
);
userIDM
.
cancel
(
challenge
);
}
catch
(
err
)
{
console
.
log
(
"
cancel err:
"
+
JSON
.
stringify
(
err
));
}
```
```
### delUser<sup>8+</sup>
### delUser<sup>8+</sup>
...
@@ -2600,12 +3944,16 @@ delUser(token: Uint8Array, callback: IIdmCallback): void;
...
@@ -2600,12 +3944,16 @@ delUser(token: Uint8Array, callback: IIdmCallback): void;
```
js
```
js
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
token
=
new
Uint8Array
([
0
]);
let
token
=
new
Uint8Array
([
0
]);
try
{
userIDM
.
delUser
(
token
,
{
userIDM
.
delUser
(
token
,
{
onResult
:
(
result
,
extraInfo
)
=>
{
onResult
:
(
result
,
extraInfo
)
=>
{
console
.
log
(
'
delUser result =
'
+
result
);
console
.
log
(
'
delUser result =
'
+
result
);
console
.
log
(
'
delUser extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
console
.
log
(
'
delUser extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
}
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
delUser exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### delCred<sup>8+</sup>
### delCred<sup>8+</sup>
...
@@ -2633,12 +3981,16 @@ delCred(credentialId: Uint8Array, token: Uint8Array, callback: IIdmCallback): vo
...
@@ -2633,12 +3981,16 @@ delCred(credentialId: Uint8Array, token: Uint8Array, callback: IIdmCallback): vo
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
credentialId
=
new
Uint8Array
([
0
]);
let
credentialId
=
new
Uint8Array
([
0
]);
let
token
=
new
Uint8Array
([
0
]);
let
token
=
new
Uint8Array
([
0
]);
try
{
userIDM
.
delCred
(
credentialId
,
token
,
{
userIDM
.
delCred
(
credentialId
,
token
,
{
onResult
:
(
result
,
extraInfo
)
=>
{
onResult
:
(
result
,
extraInfo
)
=>
{
console
.
log
(
'
delCred result =
'
+
result
);
console
.
log
(
'
delCred result =
'
+
result
);
console
.
log
(
'
delCred extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
console
.
log
(
'
delCred extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
}
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
delCred exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### getAuthInfo<sup>8+</sup>
### getAuthInfo<sup>8+</sup>
...
@@ -2663,10 +4015,14 @@ getAuthInfo(callback: AsyncCallback<Array<EnrolledCredInfo>>): void;
...
@@ -2663,10 +4015,14 @@ getAuthInfo(callback: AsyncCallback<Array<EnrolledCredInfo>>): void;
**示例:**
**示例:**
```
js
```
js
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
try
{
userIDM
.
getAuthInfo
((
err
,
result
)
=>
{
userIDM
.
getAuthInfo
((
err
,
result
)
=>
{
console
.
log
(
'
getAuthInfo err =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getAuthInfo err =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getAuthInfo result =
'
+
JSON
.
stringify
(
result
));
console
.
log
(
'
getAuthInfo result =
'
+
JSON
.
stringify
(
result
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
getAuthInfo exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### getAuthInfo<sup>8+</sup>
### getAuthInfo<sup>8+</sup>
...
@@ -2691,10 +4047,14 @@ getAuthInfo(authType: AuthType, callback: AsyncCallback<Array<EnrolledCred
...
@@ -2691,10 +4047,14 @@ getAuthInfo(authType: AuthType, callback: AsyncCallback<Array<EnrolledCred
**示例:**
**示例:**
```
js
```
js
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
try
{
userIDM
.
getAuthInfo
(
account_osAccount
.
AuthType
.
PIN
,
(
err
,
result
)
=>
{
userIDM
.
getAuthInfo
(
account_osAccount
.
AuthType
.
PIN
,
(
err
,
result
)
=>
{
console
.
log
(
'
getAuthInfo err =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getAuthInfo err =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getAuthInfo result =
'
+
JSON
.
stringify
(
result
));
console
.
log
(
'
getAuthInfo result =
'
+
JSON
.
stringify
(
result
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
getAuthInfo exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
### getAuthInfo<sup>8+</sup>
### getAuthInfo<sup>8+</sup>
...
@@ -2724,11 +4084,15 @@ getAuthInfo(authType?: AuthType): Promise<Array<EnrolledCredInfo>>;
...
@@ -2724,11 +4084,15 @@ getAuthInfo(authType?: AuthType): Promise<Array<EnrolledCredInfo>>;
**示例:**
**示例:**
```
js
```
js
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
let
userIDM
=
new
account_osAccount
.
UserIdentityManager
();
try
{
userIDM
.
getAuthInfo
(
account_osAccount
.
AuthType
.
PIN
).
then
((
result
)
=>
{
userIDM
.
getAuthInfo
(
account_osAccount
.
AuthType
.
PIN
).
then
((
result
)
=>
{
console
.
log
(
'
getAuthInfo result =
'
+
JSON
.
stringify
(
result
))
console
.
log
(
'
getAuthInfo result =
'
+
JSON
.
stringify
(
result
))
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
'
getAuthInfo error =
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getAuthInfo error =
'
+
JSON
.
stringify
(
err
));
});
});
}
catch
(
e
)
{
console
.
log
(
'
getAuthInfo exception =
'
+
JSON
.
stringify
(
e
));
}
```
```
## IInputData<sup>8+</sup>
## IInputData<sup>8+</sup>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录