harmony 鸿蒙@ohos.enterprise.accountManager (Account Management)

  • 2023-06-24
  • 浏览 (247)

@ohos.enterprise.accountManager (Account Management)

The accountManager module provides APIs for account management of enterprise devices.

NOTE

  • The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • The APIs of this module can be used only in the stage model.

  • The APIs provided by this module can be called only by a device administrator application that is enabled.

Modules to Import

import accountManager from '@ohos.enterprise.accountManager';

accountManager.disallowAddLocalAccount

disallowAddLocalAccount(admin: Want, disallow: boolean, callback: AsyncCallback<void>): void

Disallows a device administrator application to create local user accounts. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_SET_ACCOUNT_POLICY

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.
disallow boolean Yes Whether to forbid the creation of local user accounts. The value true means to disallow the creation of local user accounts, and the value false means the opposite.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

ID Error Message
9200001 The application is not an administrator application of the device.
9200002 The administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

accountManager.disallowAddLocalAccount(wantTemp, true, (err) => {
  if (err) {
    console.error(`Failed to disallow add local account. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in disallowing add local account');
});

accountManager.disallowAddLocalAccount

disallowAddLocalAccount(admin: Want, disallow: boolean): Promise<void>

Disallows a device administrator application to create local user accounts. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_SET_ACCOUNT_POLICY

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.
disallow boolean Yes Whether to forbid the creation of local user accounts. The value true means to disallow the creation of local user accounts, and the value false means the opposite.

Return value

Type Description
Promise<void> Promise that returns no value. If the operation fails, an error object will be thrown.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes.

ID Error Message
9200001 The application is not an administrator application of the device.
9200002 The administrator application does not have permission to manage the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

accountManager.disallowAddLocalAccount(wantTemp, true).then(() => {
  console.info('Succeeded in disallowing add local account');
}).catch((err: BusinessError) => {
  console.error(`Failed to disallow add local account. Code: ${err.code}, message: ${err.message}`);
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞