harmony 鸿蒙@ohos.account.osAccount (系统账号管理)
@ohos.account.osAccount (系统账号管理)
本模块提供管理系统账号的基础能力,包括系统账号的添加、删除、查询、设置、订阅、启动等功能。
说明:
本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
导入模块
import { osAccount } from '@kit.BasicServicesKit';
osAccount.getAccountManager
getAccountManager(): AccountManager
获取系统账号管理对象。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
AccountManager | 系统账号管理对象。 |
示例:
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
OsAccountType
表示系统账号类型的枚举。
系统能力: SystemCapability.Account.OsAccount。
名称 | 值 | 说明 |
---|---|---|
ADMIN | 0 | 管理员账号。 |
NORMAL | 1 | 普通账号。 |
GUEST | 2 | 访客账号。 |
AccountManager
系统账号管理类。
checkMultiOsAccountEnabled9+
checkMultiOsAccountEnabled(callback: AsyncCallback<boolean>): void
判断是否支持多系统账号。使用callback异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示支持多系统账号;返回false表示不支持。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.checkMultiOsAccountEnabled((err: BusinessError, isEnabled: boolean) => {
if (err) {
console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
}
});
} catch (err) {
console.error('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err));
}
checkMultiOsAccountEnabled9+
checkMultiOsAccountEnabled(): Promise<boolean>
判断是否支持多系统账号。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示支持多系统账号;返回false表示不支持。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
try {
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.checkMultiOsAccountEnabled().then((isEnabled: boolean) => {
console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
}).catch((err: BusinessError) => {
console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
});
} catch (err) {
console.error('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err));
}
checkOsAccountActivated(deprecated)
checkOsAccountActivated(localId: number, callback: AsyncCallback<boolean>): void
判断指定系统账号是否处于激活状态。使用callback异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示账号已激活;返回false表示账号未激活。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId. |
12300003 | Account not found. |
示例: 判断ID为100的系统账号是否处于激活状态
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
try {
accountManager.checkOsAccountActivated(localId, (err: BusinessError, isActivated: boolean) => {
if (err) {
console.error('checkOsAccountActivated failed, error:' + JSON.stringify(err));
} else {
console.log('checkOsAccountActivated successfully, isActivated:' + isActivated);
}
});
} catch (err) {
console.error('checkOsAccountActivated exception: ' + JSON.stringify(err));
}
checkOsAccountActivated(deprecated)
checkOsAccountActivated(localId: number): Promise<boolean>
判断指定系统账号是否处于激活状态。使用Promise异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示账号已激活;返回false表示账号未激活。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId. |
12300003 | Account not found. |
示例: 判断ID为100的系统账号是否处于激活状态
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
try {
accountManager.checkOsAccountActivated(localId).then((isActivated: boolean) => {
console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated);
}).catch((err: BusinessError) => {
console.error('checkOsAccountActivated failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('checkOsAccountActivated exception: ' + JSON.stringify(err));
}
isOsAccountConstraintEnabled11+
isOsAccountConstraintEnabled(constraint: string): Promise<boolean>
判断当前系统账号是否使能指定约束。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
constraint | string | 是 | 指定的约束名称。 |
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
示例: 判断ID为100的系统账号是否有禁止使用Wi-Fi的约束
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let constraint: string = 'constraint.wifi';
try {
accountManager.isOsAccountConstraintEnabled(constraint).then((isEnabled: boolean) => {
console.log('isOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
}).catch((err: BusinessError) => {
console.error('isOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('isOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
}
checkOsAccountConstraintEnabled(deprecated)
checkOsAccountConstraintEnabled(localId: number, constraint: string, callback: AsyncCallback<boolean>): void
判断指定系统账号是否具有指定约束。使用callback异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
constraint | string | 是 | 指定的约束名称。 |
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId or constraint. |
12300003 | Account not found. |
示例: 判断ID为100的系统账号是否有禁止使用Wi-Fi的约束
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
let constraint: string = 'constraint.wifi';
try {
accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err: BusinessError, isEnabled: boolean)=>{
if (err) {
console.error('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
} else {
console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
}
});
} catch (err) {
console.error('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
}
checkOsAccountConstraintEnabled(deprecated)
checkOsAccountConstraintEnabled(localId: number, constraint: string): Promise<boolean>
判断指定系统账号是否具有指定约束。使用Promise异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
constraint | string | 是 | 指定的约束名称。 |
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId or constraint. |
12300003 | Account not found. |
示例: 判断ID为100的系统账号是否有禁止使用Wi-Fi的约束
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
let constraint: string = 'constraint.wifi';
try {
accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled: boolean) => {
console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
}).catch((err: BusinessError) => {
console.error('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
}
checkOsAccountTestable9+
checkOsAccountTestable(callback: AsyncCallback<boolean>): void
检查当前系统账号是否为测试账号。使用callback异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前账号为测试账号;返回false表示当前账号非测试账号。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.checkOsAccountTestable((err: BusinessError, isTestable: boolean) => {
if (err) {
console.error('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
} else {
console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
}
});
} catch (err) {
console.error('checkOsAccountTestable error: ' + JSON.stringify(err));
}
checkOsAccountTestable9+
checkOsAccountTestable(): Promise<boolean>
检查当前系统账号是否为测试账号。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示当前账号为测试账号;返回false表示当前账号非测试账号。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.checkOsAccountTestable().then((isTestable: boolean) => {
console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
}).catch((err: BusinessError) => {
console.error('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('checkOsAccountTestable exception: ' + JSON.stringify(err));
}
isOsAccountUnlocked11+
isOsAccountUnlocked(): Promise<boolean>
检查当前系统账号是否已认证解锁。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示当前账号已认证解锁;返回false表示当前账号未认证解锁。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.isOsAccountUnlocked().then((isVerified: boolean) => {
console.log('isOsAccountUnlocked successfully, isVerified: ' + isVerified);
}).catch((err: BusinessError) => {
console.error('isOsAccountUnlocked failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('isOsAccountUnlocked exception: ' + JSON.stringify(err));
}
checkOsAccountVerified(deprecated)
checkOsAccountVerified(callback: AsyncCallback<boolean>): void
检查当前系统账号是否已认证解锁。使用callback异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。建议使用isOsAccountUnlocked替代。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前账号已认证解锁;返回false表示当前账号未认证解锁。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.checkOsAccountVerified((err: BusinessError, isVerified: boolean) => {
if (err) {
console.error('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
} else {
console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
}
});
} catch (err) {
console.error('checkOsAccountVerified exception: ' + JSON.stringify(err));
}
checkOsAccountVerified(deprecated)
checkOsAccountVerified(): Promise<boolean>
检查当前系统账号是否已认证解锁。使用Promise异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。建议使用isOsAccountUnlocked替代。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示当前账号已认证解锁;返回false表示当前账号未认证解锁。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
}).catch((err: BusinessError) => {
console.error('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('checkOsAccountVerified exception: ' + JSON.stringify(err));
}
checkOsAccountVerified(deprecated)
checkOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void
检查指定系统账号是否已验证。使用callback异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前账号已认证解锁;返回false表示当前账号未认证解锁。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId. |
12300003 | Account not found. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
try {
accountManager.checkOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
if (err) {
console.error('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
} else {
console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
}
});
} catch (err) {
console.error('checkOsAccountVerified exception: ' + err);
}
checkOsAccountVerified(deprecated)
checkOsAccountVerified(localId: number): Promise<boolean>
检查指定系统账号是否已验证。使用Promise异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。不填则检查当前系统账号是否已验证。 |
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示当前账号已认证解锁;返回false表示当前账号未认证解锁。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId. |
12300003 | Account not found. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
try {
accountManager.checkOsAccountVerified(localId).then((isVerified: boolean) => {
console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
}).catch((err: BusinessError) => {
console.error('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('checkOsAccountVerified exception: ' + JSON.stringify(err));
}
getOsAccountCount9+
getOsAccountCount(callback: AsyncCallback<number>): void
获取已创建的系统账号数量。使用callback异步回调。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<number> | 是 | 回调函数。当获取成功时,err为null,data为已创建的系统账号的数量;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getOsAccountCount((err: BusinessError, count: number) => {
if (err) {
console.error('getOsAccountCount failed, error: ' + JSON.stringify(err));
} else {
console.log('getOsAccountCount successfully, count: ' + count);
}
});
} catch (err) {
console.error('getOsAccountCount exception: ' + JSON.stringify(err));
}
getOsAccountCount9+
getOsAccountCount(): Promise<number>
获取已创建的系统账号数量。使用Promise异步回调。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回已创建的系统账号的数量。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getOsAccountCount().then((count: number) => {
console.log('getOsAccountCount successfully, count: ' + count);
}).catch((err: BusinessError) => {
console.error('getOsAccountCount failed, error: ' + JSON.stringify(err));
});
} catch(err) {
console.error('getOsAccountCount exception: ' + JSON.stringify(err));
}
getOsAccountLocalId9+
getOsAccountLocalId(callback: AsyncCallback<number>): void
获取当前进程所属的系统账号ID,使用callback异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<number> | 是 | 回调函数。当获取成功时,err为null,data为当前进程所属的系统账号ID;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getOsAccountLocalId((err: BusinessError, localId: number) => {
if (err) {
console.error('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
} else {
console.log('getOsAccountLocalId successfully, localId: ' + localId);
}
});
} catch (err) {
console.error('getOsAccountLocalId exception: ' + JSON.stringify(err));
}
getOsAccountLocalId9+
getOsAccountLocalId(): Promise<number>
获取当前进程所属的系统账号ID,使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回当前进程所属的系统账号ID。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getOsAccountLocalId().then((localId: number) => {
console.log('getOsAccountLocalId successfully, localId: ' + localId);
}).catch((err: BusinessError) => {
console.error('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('getOsAccountLocalId exception: ' + JSON.stringify(err));
}
getOsAccountLocalIdForUid9+
getOsAccountLocalIdForUid(uid: number, callback: AsyncCallback<number>): void
根据uid查询对应的系统账号ID,使用callback异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
uid | number | 是 | 进程uid。 |
callback | AsyncCallback<number> | 是 | 回调函数。如果查询成功,err为null,data为对应的系统账号ID;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid uid. |
示例: 查询值为12345678的uid所属的系统账号的账号ID
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let uid: number = 12345678;
try {
accountManager.getOsAccountLocalIdForUid(uid, (err: BusinessError, localId: number) => {
if (err) {
console.error('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
}
console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
});
} catch (err) {
console.error('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
}
getOsAccountLocalIdForUid9+
getOsAccountLocalIdForUid(uid: number): Promise<number>
根据uid查询对应的系统账号ID,使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
uid | number | 是 | 进程uid。 |
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回指定uid对应的系统账号ID。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid uid. |
示例: 查询值为12345678的uid所属的系统账号ID
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let uid: number = 12345678;
try {
accountManager.getOsAccountLocalIdForUid(uid).then((localId: number) => {
console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
}).catch((err: BusinessError) => {
console.error('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
}
getOsAccountLocalIdForUidSync10+
getOsAccountLocalIdForUidSync(uid: number): number
根据uid查询对应的系统账号ID。使用同步方式返回结果。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
uid | number | 是 | 进程uid。 |
返回值:
类型 | 说明 |
---|---|
number | 返回指定uid对应的系统账号ID。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300002 | Invalid uid. |
示例: 查询值为12345678的uid所属的系统账号ID
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let uid: number = 12345678;
try {
let localId : number = accountManager.getOsAccountLocalIdForUidSync(uid);
console.log('getOsAccountLocalIdForUidSync successfully, localId: ' + localId);
} catch (err) {
console.error('getOsAccountLocalIdForUidSync exception: ' + JSON.stringify(err));
}
getOsAccountLocalIdForDomain9+
getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void
根据域账号信息,获取与其关联的系统账号ID。使用callback异步回调。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
domainInfo | DomainAccountInfo | 是 | 域账号信息。 |
callback | AsyncCallback<number> | 是 | 回调函数。如果查询成功,err为null,data为域账号关联的系统账号ID;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid domainInfo. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let domainInfo: osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getOsAccountLocalIdForDomain(domainInfo, (err: BusinessError, localId: number) => {
if (err) {
console.error('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
} else {
console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
}
});
} catch (err) {
console.error('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
}
getOsAccountLocalIdForDomain9+
getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo): Promise<number>
根据域账号信息,获取与其关联的系统账号的账号ID。使用Promise异步回调。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
domainInfo | DomainAccountInfo | 是 | 域账号信息。 |
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回域账号关联的系统账号ID。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid domainInfo. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let domainInfo: osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
try {
accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId: number) => {
console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
}).catch((err: BusinessError) => {
console.error('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
});
} catch (err) {
console.error('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
}
getOsAccountConstraints(deprecated)
getOsAccountConstraints(localId: number, callback: AsyncCallback<Array<string>>): void
获取指定系统账号的全部约束。使用callback异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
callback | AsyncCallback<Array<string>> | 是 | 回调函数,如果获取成功,err为null,data为该系统账号的全部约束;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId. |
12300003 | Account not found. |
示例: 获取ID为100的系统账号的全部约束
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
try {
accountManager.getOsAccountConstraints(localId, (err: BusinessError, constraints: string[]) => {
if (err) {
console.error('getOsAccountConstraints failed, err: ' + JSON.stringify(err));
} else {
console.log('getOsAccountConstraints successfully, constraints: ' + JSON.stringify(constraints));
}
});
} catch (err) {
console.error('getOsAccountConstraints exception: ' + JSON.stringify(err));
}
getOsAccountConstraints(deprecated)
getOsAccountConstraints(localId: number): Promise<Array<string>>
获取指定系统账号的全部约束。使用Promise异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
返回值:
类型 | 说明 |
---|---|
Promise<Array<string>> | Promise对象,返回指定系统账号的全部约束。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId. |
12300003 | Account not found. |
示例: 获取ID为100的系统账号的全部约束
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
try {
accountManager.getOsAccountConstraints(localId).then((constraints: string[]) => {
console.log('getOsAccountConstraints, constraints: ' + constraints);
}).catch((err: BusinessError) => {
console.error('getOsAccountConstraints err: ' + JSON.stringify(err));
});
} catch (e) {
console.error('getOsAccountConstraints exception: ' + JSON.stringify(e));
}
getActivatedOsAccountLocalIds9+
getActivatedOsAccountLocalIds(callback: AsyncCallback<Array<number>>): void
查询当前处于激活状态的系统账号的ID列表。使用callback异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<Array<number>> | 是 | 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统账号的ID列表;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getActivatedOsAccountLocalIds((err: BusinessError, idArray: number[])=>{
if (err) {
console.error('getActivatedOsAccountLocalIds err:' + JSON.stringify(err));
} else {
console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length);
for(let i=0;i<idArray.length;i++) {
console.info('activated os account id: ' + idArray[i]);
}
}
});
} catch (e) {
console.error('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
}
getActivatedOsAccountLocalIds9+
getActivatedOsAccountLocalIds(): Promise<Array<number>>
查询当前处于激活状态的系统账号的ID列表。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<Array<number>> | Promise对象,返回当前处于激活状态的系统账号的ID列表。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getActivatedOsAccountLocalIds().then((idArray: number[]) => {
console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray);
}).catch((err: BusinessError) => {
console.error('getActivatedOsAccountLocalIds err: ' + JSON.stringify(err));
});
} catch (e) {
console.error('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
}
getCurrentOsAccount(deprecated)
getCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void
查询当前进程所属的系统账号的信息。使用callback异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS10+,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<OsAccountInfo> | 是 | 回调函数。如果查询成功,err为null,data为当前进程所属的系统账号信息;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getCurrentOsAccount((err: BusinessError, curAccountInfo: osAccount.OsAccountInfo)=>{
if (err) {
console.error('getCurrentOsAccount err:' + JSON.stringify(err));
} else {
console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
}
});
} catch (e) {
console.error('getCurrentOsAccount exception: ' + JSON.stringify(e));
}
getCurrentOsAccount(deprecated)
getCurrentOsAccount(): Promise<OsAccountInfo>
查询当前进程所属的系统账号的信息。使用Promise异步回调。
说明:
从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS10+,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<OsAccountInfo> | Promise对象,返回当前进程所属的系统账号信息。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getCurrentOsAccount().then((accountInfo: osAccount.OsAccountInfo) => {
console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
}).catch((err: BusinessError) => {
console.error('getCurrentOsAccount err: ' + JSON.stringify(err));
});
} catch (e) {
console.error('getCurrentOsAccount exception: ' + JSON.stringify(e));
}
getOsAccountType9+
getOsAccountType(callback: AsyncCallback<OsAccountType>): void
查询当前进程所属的系统账号的账号类型。使用callback异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<OsAccountType> | 是 | 回调函数。如果查询成功,err为null,data为当前进程所属的系统账号的账号类型;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getOsAccountType((err: BusinessError, accountType: osAccount.OsAccountType) => {
if (err) {
console.error('getOsAccountType err: ' + JSON.stringify(err));
} else {
console.log('getOsAccountType accountType: ' + accountType);
}
});
} catch (e) {
console.error('getOsAccountType exception: ' + JSON.stringify(e));
}
getOsAccountType9+
getOsAccountType(): Promise<OsAccountType>
查询当前进程所属的系统账号的账号类型。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<OsAccountType> | Promise对象,返回当前进程所属的系统账号的账号类型。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getOsAccountType().then((accountType: osAccount.OsAccountType) => {
console.log('getOsAccountType, accountType: ' + accountType);
}).catch((err: BusinessError) => {
console.error('getOsAccountType err: ' + JSON.stringify(err));
});
} catch (e) {
console.error('getOsAccountType exception: ' + JSON.stringify(e));
}
queryDistributedVirtualDeviceId9+
queryDistributedVirtualDeviceId(callback: AsyncCallback<string>): void
获取分布式虚拟设备ID。使用callback异步回调。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS(仅系统应用可申请)或 ohos.permission.DISTRIBUTED_DATASYNC
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<string> | 是 | 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.queryDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
if (err) {
console.error('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
} else {
console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID);
}
});
} catch (e) {
console.error('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
}
queryDistributedVirtualDeviceId9+
queryDistributedVirtualDeviceId(): Promise<string>
获取分布式虚拟设备ID。使用Promise异步回调。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS(仅系统应用可申请)或 ohos.permission.DISTRIBUTED_DATASYNC
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<string> | Promise对象,返回分布式虚拟设备ID。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.queryDistributedVirtualDeviceId().then((virtualID: string) => {
console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID);
}).catch((err: BusinessError) => {
console.error('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
});
} catch (e) {
console.error('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
}
getOsAccountLocalIdForSerialNumber9+
getOsAccountLocalIdForSerialNumber(serialNumber: number, callback: AsyncCallback<number>): void
通过SN码查询与其关联的系统账号的账号ID。使用callback异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
serialNumber | number | 是 | 账号SN码。 |
callback | AsyncCallback<number> | 是 | 回调函数。如果成功,err为null,data为与SN码关联的系统账号的账号ID;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid serialNumber. |
12300003 | The account indicated by serialNumber dose not exist. |
示例: 查询与SN码12345关联的系统账号的ID
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let serialNumber: number = 12345;
try {
accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
if (err) {
console.error('ger localId err:' + JSON.stringify(err));
} else {
console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
}
});
} catch (e) {
console.error('ger localId exception: ' + JSON.stringify(e));
}
getOsAccountLocalIdForSerialNumber9+
getOsAccountLocalIdForSerialNumber(serialNumber: number): Promise<number>
通过SN码查询与其关联的系统账号的账号ID。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
serialNumber | number | 是 | 账号SN码。 |
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回与SN码关联的系统账号的账号ID。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid serialNumber. |
12300003 | The account indicated by serialNumber dose not exist. |
示例: 查询与SN码12345关联的系统账号的ID
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let serialNumber: number = 12345;
try {
accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId: number) => {
console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId);
}).catch((err: BusinessError) => {
console.error('getOsAccountLocalIdForSerialNumber err: ' + JSON.stringify(err));
});
} catch (e) {
console.error('getOsAccountLocalIdForSerialNumber exception: ' + JSON.stringify(e));
}
getSerialNumberForOsAccountLocalId9+
getSerialNumberForOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void
通过系统账号ID获取与该系统账号关联的SN码。使用callback异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
callback | AsyncCallback<number> | 是 | 回调函数。如果获取成功,err为null,data为与该系统账号关联的SN码;否则为错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId. |
12300003 | Account not found. |
示例: 获取ID为100的系统账号关联的SN码
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
try {
accountManager.getSerialNumberForOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
if (err) {
console.error('ger serialNumber err:' + JSON.stringify(err));
} else {
console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
}
});
} catch (e) {
console.error('ger serialNumber exception: ' + JSON.stringify(e));
}
getSerialNumberForOsAccountLocalId9+
getSerialNumberForOsAccountLocalId(localId: number): Promise<number>
通过系统账号ID获取与该系统账号关联的SN码。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回与该系统账号关联的SN码。 |
错误码:
错误码ID | 错误信息 |
---|---|
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300002 | Invalid localId. |
12300003 | Account not found. |
示例: 获取ID为100的系统账号关联的SN码
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
try {
accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber: number) => {
console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber);
}).catch((err: BusinessError) => {
console.error('getSerialNumberForOsAccountLocalId err: ' + JSON.stringify(err));
});
} catch (e) {
console.error('getSerialNumberForOsAccountLocalId exception: ' + JSON.stringify(e));
}
isMultiOsAccountEnable(deprecated)
isMultiOsAccountEnable(callback: AsyncCallback<boolean>): void
判断是否支持多系统账号。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用checkMultiOsAccountEnabled。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示支持多系统账号;返回false表示不支持。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.isMultiOsAccountEnable((err: BusinessError, isEnabled: boolean) => {
if (err) {
console.error('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
} else {
console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
}
});
isMultiOsAccountEnable(deprecated)
isMultiOsAccountEnable(): Promise<boolean>
判断是否支持多系统账号。使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用checkMultiOsAccountEnabled。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示支持多系统账号;返回false表示不支持。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.isMultiOsAccountEnable().then((isEnabled: boolean) => {
console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
}).catch((err: BusinessError) => {
console.error('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
});
isOsAccountActived(deprecated)
isOsAccountActived(localId: number, callback: AsyncCallback<boolean>): void
判断指定系统账号是否处于激活状态。使用callback异步回调。
说明:
从 API version 7开始支持从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示账号已激活;返回false表示账号未激活。 |
示例: 判断ID为100的系统账号是否处于激活状态
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
accountManager.isOsAccountActived(localId, (err: BusinessError, isActived: boolean) => {
if (err) {
console.error('isOsAccountActived failed, err:' + JSON.stringify(err));
} else {
console.log('isOsAccountActived successfully, isActived:' + isActived);
}
});
isOsAccountActived(deprecated)
isOsAccountActived(localId: number): Promise<boolean>
判断指定系统账号是否处于激活状态。使用Promise异步回调。
说明:
从 API version 7开始支持从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示账号已激活;返回false表示账号未激活。 |
示例: 判断ID为100的系统账号是否处于激活状态
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
accountManager.isOsAccountActived(localId).then((isActived: boolean) => {
console.log('isOsAccountActived successfully, isActived: ' + isActived);
}).catch((err: BusinessError) => {
console.error('isOsAccountActived failed, error: ' + JSON.stringify(err));
});
isOsAccountConstraintEnable(deprecated)
isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback<boolean>): void
判断指定系统账号是否具有指定约束。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
constraint | string | 是 | 指定的约束名称。 |
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
示例: 判断ID为100的系统账号是否有禁止使用Wi-Fi的约束
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
let constraint: string = 'constraint.wifi';
accountManager.isOsAccountConstraintEnable(localId, constraint, (err: BusinessError, isEnabled: boolean) => {
if (err) {
console.error('isOsAccountConstraintEnable failed, error: ' + JSON.stringify(err));
} else {
console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
}
});
isOsAccountConstraintEnable(deprecated)
isOsAccountConstraintEnable(localId: number, constraint: string): Promise<boolean>
判断指定系统账号是否具有指定约束。使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
constraint | string | 是 | 指定的约束名称。 |
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 |
示例: 判断ID为100的系统账号是否有禁止使用Wi-Fi的约束
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
let constraint: string = 'constraint.wifi';
accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled: boolean) => {
console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
}).catch((err: BusinessError) => {
console.error('isOsAccountConstraintEnable err: ' + JSON.stringify(err));
});
isTestOsAccount(deprecated)
isTestOsAccount(callback: AsyncCallback<boolean>): void
检查当前系统账号是否为测试账号。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用checkOsAccountTestable。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前账号为测试账号;返回false表示当前账号非测试账号。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.isTestOsAccount((err: BusinessError, isTestable: boolean) => {
if (err) {
console.error('isTestOsAccount failed, error: ' + JSON.stringify(err));
} else {
console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
}
});
isTestOsAccount(deprecated)
isTestOsAccount(): Promise<boolean>
检查当前系统账号是否为测试账号。使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用checkOsAccountTestable。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示当前账号为测试账号;返回false表示当前账号非测试账号。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.isTestOsAccount().then((isTestable: boolean) => {
console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
}).catch((err: BusinessError) => {
console.error('isTestOsAccount failed, error: ' + JSON.stringify(err));
});
isOsAccountVerified(deprecated)
isOsAccountVerified(callback: AsyncCallback<boolean>): void
检查当前系统账号是否已验证。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用checkOsAccountVerified。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示指定账号已验证;返回false表示指定账号未验证。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.isOsAccountVerified((err: BusinessError, isVerified: boolean) => {
if (err) {
console.error('isOsAccountVerified failed, error: ' + JSON.stringify(err));
} else {
console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
}
});
isOsAccountVerified(deprecated)
isOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void
检查指定系统账号是否已验证。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示指定账号已验证;返回false表示指定账号未验证。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
accountManager.isOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
if (err) {
console.error('isOsAccountVerified failed, error: ' + JSON.stringify(err));
} else {
console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
}
});
isOsAccountVerified(deprecated)
isOsAccountVerified(localId?: number): Promise<boolean>
检查指定系统账号是否已验证。使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 否 | 系统账号ID。不填则检查当前系统账号是否已验证。 |
返回值:
类型 | 说明 |
---|---|
Promise<boolean> | Promise对象。返回true表示指定账号已验证;返回false表示指定账号未验证。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.isOsAccountVerified().then((isVerified: boolean) => {
console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
}).catch((err: BusinessError) => {
console.error('isOsAccountVerified failed, error: ' + JSON.stringify(err));
});
getCreatedOsAccountsCount(deprecated)
getCreatedOsAccountsCount(callback: AsyncCallback<number>): void
获取已创建的系统账号数量。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountCount。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<number> | 是 | 回调函数。当获取成功时,err为null,data为已创建的系统账号的数量;否则为错误对象。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.getCreatedOsAccountsCount((err: BusinessError, count: number)=>{
if (err) {
console.error('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
} else {
console.log('getCreatedOsAccountsCount successfully, count: ' + count);
}
});
getCreatedOsAccountsCount(deprecated)
getCreatedOsAccountsCount(): Promise<number>
获取已创建的系统账号数量,使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountCount。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回已创建的系统账号的数量。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.getCreatedOsAccountsCount().then((count: number) => {
console.log('getCreatedOsAccountsCount successfully, count: ' + count);
}).catch((err: BusinessError) => {
console.error('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
});
getOsAccountLocalIdFromProcess(deprecated)
getOsAccountLocalIdFromProcess(callback: AsyncCallback<number>): void
获取当前进程所属的系统账号ID,使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountLocalId。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<number> | 是 | 回调函数。当获取成功时,err为null,data为当前进程所属的系统账号ID;否则为错误对象。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.getOsAccountLocalIdFromProcess((err: BusinessError, localId: number) => {
if (err) {
console.error('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
} else {
console.log('getOsAccountLocalIdFromProcess id:: ' + localId);
}
});
getOsAccountLocalIdFromProcess(deprecated)
getOsAccountLocalIdFromProcess(): Promise<number>
获取当前进程所属的系统账号ID,使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountLocalId。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回当前进程所属的系统账号ID。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.getOsAccountLocalIdFromProcess().then((localId: number) => {
console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId);
}).catch((err: BusinessError) => {
console.error('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
});
getOsAccountLocalIdFromUid(deprecated)
getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback<number>): void
根据uid查询对应的系统账号ID。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForUid。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
uid | number | 是 | 进程uid。 |
callback | AsyncCallback<number> | 是 | 回调函数。如果查询成功,err为null,data为对应的系统账号ID;否则为错误对象。 |
示例: 查询值为12345678的uid所属的系统账号ID
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let uid: number = 12345678;
accountManager.getOsAccountLocalIdFromUid(uid, (err: BusinessError, localId: number) => {
if (err) {
console.error('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
} else {
console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
}
});
getOsAccountLocalIdFromUid(deprecated)
getOsAccountLocalIdFromUid(uid: number): Promise<number>
根据uid查询对应的系统账号ID,使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForUid。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
uid | number | 是 | 进程uid。 |
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回uid对应的系统账号ID。 |
示例: 查询值为12345678的uid所属的系统账号ID
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let uid: number = 12345678;
accountManager.getOsAccountLocalIdFromUid(uid).then((localId: number) => {
console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
}).catch((err: BusinessError) => {
console.error('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
});
getOsAccountLocalIdFromDomain(deprecated)
getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void
根据域账号信息,获取与其关联的系统账号的账号ID。使用callback异步回调。
说明:
从 API version 8开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForDomain。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
domainInfo | DomainAccountInfo | 是 | 域账号信息。 |
callback | AsyncCallback<number> | 是 | 回调函数,如果获取成功,err为null,data为域账号关联的系统账号ID;否则为错误对象。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let domainInfo: osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err: BusinessError, localId: number) => {
if (err) {
console.error('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
} else {
console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
}
});
getOsAccountLocalIdFromDomain(deprecated)
getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise<number>
根据域账号信息,获取与其关联的系统账号的账号ID。使用Promise异步回调。
说明:
从 API version 8开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForDomain。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
domainInfo | DomainAccountInfo | 是 | 域账号信息。 |
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回域账号关联的系统账号ID。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let domainInfo: osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId: number) => {
console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
}).catch((err: BusinessError) => {
console.error('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
});
getOsAccountAllConstraints(deprecated)
getOsAccountAllConstraints(localId: number, callback: AsyncCallback<Array<string>>): void
获取指定系统账号的全部约束。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
callback | AsyncCallback<Array<string>> | 是 | 回调函数。如果获取成功,err为null,data为指定系统账号的全部约束;否则为错误对象。 |
示例: 获取ID为100的系统账号的全部约束
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
accountManager.getOsAccountAllConstraints(localId, (err: BusinessError, constraints: string[])=>{
if (err) {
console.error('getOsAccountAllConstraints err:' + JSON.stringify(err));
} else {
console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints));
}
});
getOsAccountAllConstraints(deprecated)
getOsAccountAllConstraints(localId: number): Promise<Array<string>>
获取指定系统账号的全部约束。使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
返回值:
类型 | 说明 |
---|---|
Promise<Array<string>> | Promise对象,返回指定系统账号的全部约束。 |
示例: 获取ID为100的系统账号的全部约束
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
accountManager.getOsAccountAllConstraints(localId).then((constraints: string[]) => {
console.log('getOsAccountAllConstraints, constraints: ' + constraints);
}).catch((err: BusinessError) => {
console.error('getOsAccountAllConstraints err: ' + JSON.stringify(err));
});
queryActivatedOsAccountIds(deprecated)
queryActivatedOsAccountIds(callback: AsyncCallback<Array<number>>): void
查询当前处于激活状态的系统账号的ID列表。使用callback异步回调。
说明:
从 API version 8开始支持,从API version 9开始废弃。建议使用getActivatedOsAccountLocalIds。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<Array<number>> | 是 | 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统账号的ID列表;否则为错误对象。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.queryActivatedOsAccountIds((err: BusinessError, idArray: number[])=>{
if (err) {
console.error('queryActivatedOsAccountIds err:' + JSON.stringify(err));
} else {
console.log('queryActivatedOsAccountIds idArray length:' + idArray.length);
for(let i=0;i<idArray.length;i++) {
console.info('activated os account id: ' + idArray[i]);
}
}
});
queryActivatedOsAccountIds(deprecated)
queryActivatedOsAccountIds(): Promise<Array<number>>
说明:
从 API version 8开始支持,从API version 9开始废弃。建议使用getActivatedOsAccountLocalIds。
查询当前处于激活状态的系统账号的ID列表。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<Array<number>> | Promise对象,返回当前处于激活状态的系统账号的ID列表。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.queryActivatedOsAccountIds().then((idArray: number[]) => {
console.log('queryActivatedOsAccountIds, idArray: ' + idArray);
}).catch((err: BusinessError) => {
console.error('queryActivatedOsAccountIds err: ' + JSON.stringify(err));
});
queryCurrentOsAccount(deprecated)
queryCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void
查询当前进程所属的系统账号的信息。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<OsAccountInfo> | 是 | 回调函数。如果查询成功,err为null,data为当前进程所属的系统账号信息;否则为错误对象。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.queryCurrentOsAccount((err: BusinessError, curAccountInfo: osAccount.OsAccountInfo)=>{
if (err) {
console.error('queryCurrentOsAccount err:' + JSON.stringify(err));
} else {
console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
}
});
queryCurrentOsAccount(deprecated)
queryCurrentOsAccount(): Promise<OsAccountInfo>
查询当前进程所属的系统账号的信息。使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<OsAccountInfo> | Promise对象,返回当前进程所属的系统账号信息。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.queryCurrentOsAccount().then((accountInfo: osAccount.OsAccountInfo) => {
console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
}).catch((err: BusinessError) => {
console.error('queryCurrentOsAccount err: ' + JSON.stringify(err));
});
getOsAccountTypeFromProcess(deprecated)
getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): void
查询当前进程所属的系统账号的账号类型。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountType。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<OsAccountType> | 是 | 回调函数。如果查询成功,err为null,data为当前进程所属的系统账号的账号类型;否则为错误对象。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.getOsAccountTypeFromProcess((err: BusinessError, accountType: osAccount.OsAccountType) => {
if (err) {
console.error('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
} else {
console.log('getOsAccountTypeFromProcess accountType: ' + accountType);
}
});
getOsAccountTypeFromProcess(deprecated)
getOsAccountTypeFromProcess(): Promise<OsAccountType>
查询当前进程所属的系统账号的账号类型。使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountType。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<OsAccountType> | Promise对象,返回当前进程所属的系统账号的账号类型。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.getOsAccountTypeFromProcess().then((accountType: osAccount.OsAccountType) => {
console.log('getOsAccountTypeFromProcess, accountType: ' + accountType);
}).catch((err: BusinessError) => {
console.error('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
});
getDistributedVirtualDeviceId(deprecated)
getDistributedVirtualDeviceId(callback: AsyncCallback<string>): void
获取分布式虚拟设备ID。使用callback异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用queryDistributedVirtualDeviceId。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS(仅系统应用可申请)或 ohos.permission.DISTRIBUTED_DATASYNC
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<string> | 是 | 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.getDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
if (err) {
console.error('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
} else {
console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID);
}
});
getDistributedVirtualDeviceId(deprecated)
getDistributedVirtualDeviceId(): Promise<string>
获取分布式虚拟设备ID。使用Promise异步回调。
说明:
从 API version 7开始支持,从API version 9开始废弃。建议使用queryDistributedVirtualDeviceId。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS(仅系统应用可申请)或 ohos.permission.DISTRIBUTED_DATASYNC
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<string> | Promise对象,返回分布式虚拟设备ID。 |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
accountManager.getDistributedVirtualDeviceId().then((virtualID: string) => {
console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID);
}).catch((err: BusinessError) => {
console.error('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
});
getOsAccountLocalIdBySerialNumber(deprecated)
getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback<number>): void
通过SN码查询与其关联的系统账号的账号ID。使用callback异步回调。
说明:
从 API version 8开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForSerialNumber。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
serialNumber | number | 是 | 账号SN码。 |
callback | AsyncCallback<number> | 是 | 回调函数。如果查询成功,err为null,data为与SN码关联的系统账号的账号ID;否则为错误对象。 |
示例: 查询与SN码12345关联的系统账号的ID
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let serialNumber: number = 12345;
accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
if (err) {
console.error('ger localId err:' + JSON.stringify(err));
} else {
console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
}
});
getOsAccountLocalIdBySerialNumber(deprecated)
getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise<number>
通过SN码查询与其关联的系统账号的账号ID。使用Promise异步回调。
说明:
从 API version 8开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForSerialNumber。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
serialNumber | number | 是 | 账号SN码。 |
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回与SN码关联的系统账号的账号ID。 |
示例: 查询与SN码12345关联的系统账号的ID
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let serialNumber: number = 12345;
accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId: number) => {
console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId);
}).catch((err: BusinessError) => {
console.error('getOsAccountLocalIdBySerialNumber err: ' + JSON.stringify(err));
});
getSerialNumberByOsAccountLocalId(deprecated)
getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void
通过系统账号ID获取与该系统账号关联的SN码。使用callback异步回调。
说明:
从 API version 8开始支持,从API version 9开始废弃。建议使用getSerialNumberForOsAccountLocalId。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
callback | AsyncCallback<number> | 是 | 回调函数。如果获取成功,err为null,data为与该系统账号关联的SN码;否则为错误对象。 |
示例: 获取ID为100的系统账号关联的SN码
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
accountManager.getSerialNumberByOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
if (err) {
console.error('ger serialNumber err:' + JSON.stringify(err));
} else {
console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
}
});
getSerialNumberByOsAccountLocalId(deprecated)
getSerialNumberByOsAccountLocalId(localId: number): Promise<number>
通过系统账号ID获取与该系统账号关联的SN码。使用Promise异步回调。
说明:
从 API version 8开始支持,从API version 9开始废弃。建议使用getSerialNumberForOsAccountLocalId。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象,返回与该系统账号关联的SN码。 |
示例: 获取ID为100的系统账号关联的SN码
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber: number) => {
console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber);
}).catch((err: BusinessError) => {
console.error('getSerialNumberByOsAccountLocalId err: ' + JSON.stringify(err));
});
getOsAccountName12+
getOsAccountName(): Promise<string>
查询调用方所属系统账号的名称。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<string> | Promise对象,返回调用方所属系统账号的名称。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getOsAccountName().then((name: string) => {
console.log('getOsAccountName, name: ' + name);
}).catch((err: BusinessError) => {
console.error('getOsAccountName err: ' + err);
});
} catch (e) {
console.error('getOsAccountName exception: ' + e);
}
getForegroundOsAccountLocalId15+
getForegroundOsAccountLocalId(): Promise<number>;
获取前台系统账号的ID。
系统能力: SystemCapability.Account.OsAccount
返回值:
类型 | 说明 |
---|---|
Promise<number> | Promise对象。返回前台系统账号的ID。 |
错误码:
错误码ID | 错误信息 |
---|---|
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
try {
accountManager.getForegroundOsAccountLocalId().then((localId: number) => {
console.log('getForegroundOsAccountLocalId, localId: ' + localId);
}).catch((err: BusinessError) => {
console.error('getForegroundOsAccountLocalId err: ' + JSON.stringify(err));
});
} catch (e) {
console.error('getForegroundOsAccountLocalId exception: ' + JSON.stringify(e));
}
getOsAccountDomainInfo15+
getOsAccountDomainInfo(localId: number): Promise<DomainAccountInfo>;
获取指定系统账号关联的域账号信息。
需要权限: ohos.permission.GET_DOMAIN_ACCOUNTS 和 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限允许系统应用和企业应用进行申请。
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
返回值:
类型 | 说明 |
---|---|
Promise<DomainAccountInfo> | Promise对象。返回与指定系统账号关联的域账号信息。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
12300001 | The system service works abnormally. |
12300003 | OS account not found. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let localId: number = 100;
accountManager.getOsAccountDomainInfo(localId).then((domainAccountInfo: osAccount.DomainAccountInfo) => {
if (domainAccountInfo === null) {
console.log('The target OS account is not a domain account.')
} else {
console.log('getOsAccountDomainInfo domain: ' + domainAccountInfo.domain);
console.log('getOsAccountDomainInfo accountName: ' + domainAccountInfo.accountName);
}
}).catch((err: BusinessError) => {
console.error('getOsAccountDomainInfo err: ' + JSON.stringify(err));
})
DomainAccountManager18+
域账号管理类。
updateAccountInfo18+
updateAccountInfo(oldAccountInfo: DomainAccountInfo, newAccountInfo: DomainAccountInfo): Promise<void>
修改指定域账号信息。使用Promise异步回调。
需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.MANAGE_DOMAIN_ACCOUNTS
系统能力: SystemCapability.Account.OsAccount
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
oldAccountInfo | DomainAccountInfo | 是 | 指示旧域账号信息。 |
newAccountInfo | DomainAccountInfo | 是 | 指示新域账号信息。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | Promise对象,无返回结果的Promise对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
801 | Capability not supported. |
12300001 | The system service works abnormally. |
12300002 | The new account info is invalid. |
12300003 | The old account not found. |
12300004 | The new account already exists. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let oldDomainInfo: osAccount.DomainAccountInfo =
{domain: 'testDomain', accountName: 'oldtestAccountName'};
let newDomainInfo: osAccount.DomainAccountInfo =
{domain: 'testDomain', accountName: 'newtestAccountName'};
try {
osAccount.DomainAccountManager.updateAccountInfo(oldDomainInfo, newDomainInfo).then(() => {
console.log('updateAccountInfo, success');
}).catch((err: BusinessError) => {
console.error('updateAccountInfo err: ' + err);
});
} catch (e) {
console.error('updateAccountInfo exception: ' + e);
}
OsAccountInfo
表示系统账号信息。
系统能力: SystemCapability.Account.OsAccount
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
localId | number | 是 | 系统账号ID。 |
localName | string | 是 | 系统账号名称。 |
type | OsAccountType | 是 | 系统账号类型。 |
constraints | Array<string> | 是 | 系统账号约束,默认为空。 |
isVerified(deprecated) | boolean | 是 | 账号是否验证。true表示指定账号已验证;false表示指定账号未验证。 说明:从API version 7开始支持,从API version 11开始废弃。 |
isUnlocked11+ | boolean | 是 | 账号是否已解锁(EL2级别目录是否解密)。true表示指定账号已解锁;false表示指定账号未解锁。 |
photo8+ | string | 是 | 系统账号头像,默认为空。 |
createTime8+ | number | 是 | 系统账号创建时间。 |
lastLoginTime8+ | number | 是 | 系统账号最后一次登录时间,默认为空。 |
serialNumber8+ | number | 是 | 系统账号SN码。 |
isActived(deprecated) | boolean | 是 | 系统账号激活状态。true表示指定账号处于激活状态;false表示指定账号处于未激活状态。 说明:从API version 7开始支持,从API version 11开始废弃。 |
isActivated11+ | boolean | 是 | 系统账号激是否激活。true表示指定账号已激活;false表示指定账号未激活。 |
isCreateCompleted8+ | boolean | 是 | 系统账号创建是否完整。true表示指定账号已创建完整;false表示指定账号未创建完整。 |
distributedInfo | distributedAccount.DistributedInfo | 是 | 分布式账号信息,默认为空。 |
domainInfo8+ | DomainAccountInfo | 是 | 域账号信息,默认为空。 |
DomainAccountInfo8+
表示域账号信息。
系统能力: SystemCapability.Account.OsAccount
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
domain | string | 是 | 域名。 |
accountName | string | 是 | 域账号名。 |
serverConfigId18+ | string | 否 | 域账号配置ID。 |
DomainServerConfig18+
域服务器配置。
系统能力: SystemCapability.Account.OsAccount
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
parameters | Record |
是 | 服务器配置参数。 |
id | string | 是 | 服务器配置标识。 |
domain | string | 是 | 服务器所属的域。 |
DomainServerConfigManager18+
域服务器配置管理类。
addServerConfig18+
static addServerConfig(parameters: Record<string, Object>): Promise<DomainServerConfig>
添加域服务器配置。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
需要权限: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
parameters | Record |
是 | 指示域服务器配置参数。 |
返回值:
类型 | 说明 |
---|---|
Promise<DomainServerConfig> | Promise对象,返回新添加的域服务器配置。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
801 | Capability not supported. |
12300001 | The system service works abnormally. |
12300002 | Invalid server config parameters. |
12300211 | Server unreachable. |
12300213 | Server config already exists. |
12300215 | The number of server config reaches the upper limit. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let configParams: Record<string, Object> = {
'uri': 'test.example.com',
'port': 100
};
osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
serverConfig: osAccount.DomainServerConfig) => {
console.log('add server configuration successfully, the return config: ' + JSON.stringify(serverConfig));
}).catch((err: BusinessError) => {
console.error('add server configuration failed, error: ' + JSON.stringify(err));
});
removeServerConfig18+
static removeServerConfig(configId: string): Promise<void>
删除域服务器配置。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
需要权限: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
configId | string | 是 | 指示服务器配置标识。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | Promise对象,无返回结果的Promise对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
801 | Capability not supported. |
12300001 | The system service works abnormally. |
12300212 | Server config not found. |
12300214 | Server config has been associated with an account. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let configParams: Record<string, Object> = {
'uri': 'test.example.com',
'port': 100
};
osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
serverConfig: osAccount.DomainServerConfig) => {
console.log('add domain server configuration successfully, the added config: ' + JSON.stringify(serverConfig));
osAccount.DomainServerConfigManager.removeServerConfig(serverConfig.id);
console.log('remove domain server configuration successfully');
}).catch((err: BusinessError) => {
console.error('add server configuration failed, error: ' + JSON.stringify(err));
});
updateServerConfig18+
static updateServerConfig(configId: string, parameters: Record<string, Object>): Promise<DomainServerConfig>
更新域服务器配置。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
需要权限: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
configId | string | 是 | 指示服务器配置标识。 |
parameters | Record<string, Object> | 是 | 指示域服务器配置参数。 |
返回值:
类型 | 说明 |
---|---|
Promise<DomainServerConfig> | Promise对象,返回更新后的域服务器配置。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
801 | Capability not supported. |
12300001 | The system service works abnormally. |
12300002 | Invalid server config parameters. |
12300211 | Server unreachable. |
12300212 | Server config not found. |
12300213 | Server config already exists. |
12300214 | Server config has been associated with an account. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let configParams: Record<string, Object> = {
'uri': 'test.example.com',
'port': 100
};
osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
serverConfig: osAccount.DomainServerConfig) => {
console.log('add domain server configuration successfully, the added config: ' + JSON.stringify(serverConfig));
osAccount.DomainServerConfigManager.updateServerConfig(serverConfig.id, configParams).then((data) => {
console.log('update domain server configuration successfully, return config: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.error('update domain server configuration failed, error: ' + JSON.stringify(err));
});
}).catch((err: BusinessError) => {
console.error('add server configuration failed, error: ' + JSON.stringify(err));
});
getServerConfig18+
static getServerConfig(configId: string): Promise<DomainServerConfig>
获取域服务器配置。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
需要权限: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
configId | string | 是 | 指示服务器配置标识。 |
返回值:
类型 | 说明 |
---|---|
Promise<DomainServerConfig> | Promise对象,返回获取的域服务器配置。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
801 | Capability not supported. |
12300001 | The system service works abnormally. |
12300212 | Server config not found. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let configParams: Record<string, Object> = {
'uri': 'test.example.com',
'port': 100
};
osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
serverConfig: osAccount.DomainServerConfig) => {
console.log('add domain server configuration successfully, the added config: ' + JSON.stringify(serverConfig));
osAccount.DomainServerConfigManager.getServerConfig(serverConfig.id).then((data: osAccount.DomainServerConfig) => {
console.log('get domain server configuration successfully, return config: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.error('get domain server configuration failed, error: ' + JSON.stringify(err));
});
}).catch((err: BusinessError) => {
console.error('add server configuration failed, error: ' + JSON.stringify(err));
});
getAllServerConfigs18+
static getAllServerConfigs(): Promise<Array<DomainServerConfig>>
获取所有域服务器配置。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
需要权限: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS
返回值:
类型 | 说明 |
---|---|
Promise<Array<DomainServerConfig>> | Promise对象,返回获取的所有域服务器配置。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
801 | Capability not supported. |
12300001 | The system service works abnormally. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let configParams: Record<string, Object> = {
'uri': 'test.example.com',
'port': 100
};
osAccount.DomainServerConfigManager.addServerConfig(configParams).then((
serverConfig: osAccount.DomainServerConfig) => {
console.log('add domain server configuration successfully, the added config: ' + JSON.stringify(serverConfig));
osAccount.DomainServerConfigManager.getAllServerConfigs().then((data: Array<osAccount.DomainServerConfig>) => {
console.log('get all domain server configuration successfully, return config: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.error('get all domain server configuration failed, error: ' + JSON.stringify(err));
});
}).catch((err: BusinessError) => {
console.error('add server configuration failed, error: ' + JSON.stringify(err));
});
getAccountServerConfig18+
static getAccountServerConfig(domainAccountInfo: DomainAccountInfo): Promise<DomainServerConfig>
获取目标域账号的服务器配置。使用Promise异步回调。
系统能力: SystemCapability.Account.OsAccount
需要权限: ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
domainAccountInfo | DomainAccountInfo | 是 | 指示目标域账号信息。 |
返回值:
类型 | 说明 |
---|---|
Promise<DomainServerConfig> | Promise对象,返回目标账号的域服务器配置。 |
错误码:
错误码ID | 错误信息 |
---|---|
201 | Permission denied. |
801 | Capability not supported. |
12300001 | The system service works abnormally. |
12300003 | Domain account not found. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
let accountInfo: osAccount.DomainAccountInfo = {
'accountName': 'demoName',
'domain': 'demoDomain'
};
osAccount.DomainServerConfigManager.getAccountServerConfig(accountInfo).then((
serverConfig: osAccount.DomainServerConfig) => {
console.log('get account server configuration successfully, the return config: ' + JSON.stringify(serverConfig));
}).catch((err: BusinessError) => {
console.error('add server configuration failed, error: ' + JSON.stringify(err));
});
系统账号约束列表
约束 | 说明 |
---|---|
constraint.wifi | 禁止使用Wi-Fi |
constraint.wifi.set | 禁止配置Wi-Fi |
constraint.locale.set | 禁止配置设备语言 |
constraint.app.accounts | 禁止添加和删除应用账号 |
constraint.apps.install | 禁止安装应用 |
constraint.apps.uninstall | 禁止卸载应用 |
constraint.location.shared | 禁止打开位置共享 |
constraint.unknown.sources.install | 禁止安装未知来源的应用 |
constraint.global.unknown.app.install | 禁止所有用户安装未知来源的应用 |
constraint.bluetooth.set | 禁止配置蓝牙 |
constraint.bluetooth | 禁止使用蓝牙 |
constraint.bluetooth.share | 禁止共享使用蓝牙 |
constraint.usb.file.transfer | 禁止通过USB传输文件 |
constraint.credentials.set | 禁止配置用户凭据 |
constraint.os.account.remove | 禁止删除用户 |
constraint.managed.profile.remove | 禁止删除此用户的托管配置文件 |
constraint.debug.features.use | 禁止启用或访问调试功能 |
constraint.vpn.set | 禁止配置VPN |
constraint.date.time.set | 禁止配置日期时间和时区 |
constraint.tethering.config | 禁止配置Tethering |
constraint.network.reset | 禁止重置网络设置 |
constraint.factory.reset | 禁止出厂设置 |
constraint.os.account.create | 禁止创建新用户 |
constraint.add.managed.profile | 禁止添加托管配置文件 |
constraint.apps.verify.disable | 强制应用程序验证 |
constraint.cell.broadcasts.set | 禁止配置小区广播 |
constraint.mobile.networks.set | 禁止配置移动网络 |
constraint.control.apps | 禁止在设置或启动模块中修改应用程序 |
constraint.physical.media | 禁止装载物理外部介质 |
constraint.microphone | 禁止使用麦克风 |
constraint.microphone.unmute | 禁止取消麦克风静音 |
constraint.volume.adjust | 禁止调整音量 |
constraint.calls.outgoing | 禁止拨打外呼电话 |
constraint.sms.use | 禁止发送或接收短信 |
constraint.fun | 禁止享受乐趣 |
constraint.windows.create | 禁止创建应用程序窗口以外的窗口 |
constraint.system.error.dialogs | 禁止显示崩溃或无响应应用程序的系统错误对话框 |
constraint.cross.profile.copy.paste | 禁止通过将数据粘贴到其他用户或配置文件来导出剪贴板内容 |
constraint.beam.outgoing | 禁止使用NFC从应用程序传送数据 |
constraint.wallpaper | 禁止管理壁纸 |
constraint.safe.boot | 禁止进入安全引导模式 |
constraint.parent.profile.app.linking | 禁止父配置文件中的应用程序处理来自托管配置文件的Web链接 |
constraint.audio.record | 禁止录制音频 |
constraint.camera.use | 禁止使用摄像机 |
constraint.os.account.background.run | 禁止在后台运行 |
constraint.data.roam | 禁止漫游通话时使用蜂窝数据 |
constraint.os.account.set.icon | 禁止修改用户头像 |
constraint.wallpaper.set | 禁止设置壁纸 |
constraint.oem.unlock | 禁止启用oem解锁 |
constraint.device.unmute | 禁止取消设备静音 |
constraint.password.unified | 禁止托管配置文件与主用户进行统一锁屏质询 |
constraint.autofill | 禁止使用自动填充服务 |
constraint.content.capture | 禁止捕获用户屏幕 |
constraint.content.suggestions | 禁止接收内容建议 |
constraint.os.account.activate | 禁止前台启动用户 |
constraint.location.set | 禁止配置位置服务 |
constraint.airplane.mode.set | 禁止飞行模式 |
constraint.brightness.set | 禁止配置亮度 |
constraint.share.into.profile | 禁止将主要用户的文件/图片/数据共享到托管配置文件中 |
constraint.ambient.display | 禁止显示环境 |
constraint.screen.timeout.set | 禁止配置屏幕关闭的超时 |
constraint.print | 禁止打印 |
constraint.private.dns.set | 禁止配置专用DNS |
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Basic Services Kit(基础服务)
harmony 鸿蒙Print_PrintAttributes
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦