harmony 鸿蒙@ohos.enterprise.browser (Browser Management)

2023-10-30 浏览 (564)

@ohos.enterprise.browser (Browser Management)

The browser module provides browser management, including setting, deleting, and obtaining browser policies.

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 browser from '@ohos.enterprise.browser';

browser.setPolicies

setPolicies(admin: Want, appId: string, policies: string, callback: AsyncCallback<void>): void;

Sets policies for a given browser through the specified device administrator application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_SET_BROWSER_POLICY

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
appIdstringYesApplication ID, which is used to specify the browser.
policiesstringYesPolicies to set. If this parameter is set to an empty string, the policies of the specified browser will be deleted.
callbackAsyncCallback<void>YesCallback 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.

IDError Message
9200001the application is not an administrator of the device.
9200002the 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',
};
let appId: string = 'com.example.myapplication';
let policies: string = '{"InsecurePrivateNetworkRequestsAllowed":{"level":"mandatory","scope":"machine","source":"platform","value":true},"LegacySameSiteCookieBehaviorEnabledForDomainList":{"level":"mandatory","scope":"machine","source":"platform","value":["[*.]"]}}'
browser.setPolicies(wantTemp, appId, policies, (err) => {
  if (err) {
    console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in setting browser policies');
});

browser.setPolicies

setPolicies(admin: Want, appId: string, policies: string): Promise<void>;

Sets policies for a given browser through the specified device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_SET_BROWSER_POLICY

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
appIdstringYesApplication ID, which is used to specify the browser.
policiesstringYesPolicies to set. If this parameter is set to an empty string, the policies of the specified browser will be deleted.

Return value

TypeDescription
Promise<void>Promise that returns no value. If the operation fails, an error object is thrown.

Error codes

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

IDError Message
9200001the application is not an administrator of the device.
9200002the 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',
};
let appId: string = 'com.example.myapplication';
let policies: string = '{"InsecurePrivateNetworkRequestsAllowed":{"level":"mandatory","scope":"machine","source":"platform","value":true},"LegacySameSiteCookieBehaviorEnabledForDomainList":{"level":"mandatory","scope":"machine","source":"platform","value":["[*.]"]}}'
browser.setPolicies(wantTemp, appId, policies).then(() => {
  console.info('Succeeded in setting browser policies');
}).catch((err: BusinessError) => {
  console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
});

browser.getPolicies

getPolicies(admin: Want, appId: string, callback: AsyncCallback<string>): void;

Obtains the policies of a given browser through the specified device administrator application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
appIdstringYesApplication ID, which is used to specify the browser.
callbackAsyncCallback<string>YesCallback 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.

IDError Message
9200001the application is not an administrator of the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appId: string = 'com.example.myapplication';
browser.getPolicies(wantTemp, appId, (err, result) => {
  if (err) {
    console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting  browser policies, result : ${JSON.stringify(result)}`);
});

browser.getPolicies

getPolicies(admin: Want, appId: string): Promise<string>;

Obtains the policies of a given browser through the specified device administrator application. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
appIdstringYesApplication ID, which is used to specify the browser.

Return value

TypeDescription
Promise<string>Promise used to return the browser policies obtained.

Error codes

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

IDError Message
9200001the application is not an administrator of the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appId: string = 'com.example.myapplication';
browser.getPolicies(wantTemp, appId).then((result) => {
  console.info(`Succeeded in getting browser policies, result : ${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get browser policies. Code is ${err.code}, message is ${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)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/7d406cb5160b4fc2b134dbd9664d2eda