harmony 鸿蒙@ohos.enterprise.systemManager (System Management)

  • 2023-10-30
  • 浏览 (380)

@ohos.enterprise.systemManager (System Management)

The systemManager module provides system management capabilities.

NOTE

  • The initial APIs of this module are supported since API version 11. 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 systemManager from '@ohos.enterprise.systemManager';

systemManager.setNTPServer

setNTPServer(admin: Want, server: string): void

Sets the NTP server information through the specified device administrator application.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_SYSTEM

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.
server string Yes NTP server addresses separated by a comma (,). For example, ntpserver1.com,ntpserver2.com.

Error codes

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

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

Example

import systemManager from '@ohos.enterprise.systemManager';
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let server: string = "ntpserver.com";
try {
  systemManager.setNTPServer(wantTemp, server);
  console.info('Succeeded in setting NTPserver');
} catch (error) {
  console.error(`Failed to set usb policy. Code is ${err.code}, message is ${err.message}`);
}

systemManager.getNTPServer

getNTPServer(admin: Want): string

Obtains the NTP server information through the specified device administrator application.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_SYSTEM

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes Device administrator application.

Return value

Type Description
string NTP server information obtained.

Error codes

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

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

Example

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

systemManager.getNTPServer(wantTemp).then((result) => {
  console.info(`Succeeded in get NTP server, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get NTP server. 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  赞