目录

SuperPrivacyMode

This module provides APIs related to the Super Privacy mode. Your app can process services based on the current Super Privacy status.

Since: 6.0.2(22)

Modules to Import

import { superPrivacyMode } from '@kit.DeviceSecurityKit';

SuperPrivacyMode

Enumerates the Super Privacy statuses.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 6.0.2(22)

Name Value Description
OFF 0 The Super Privacy mode is disabled.
ON_WHEN_FOLDED 1 The Super Privacy mode is enabled only when the device is folded.
ALWAYS_ON 2 The Super Privacy mode is always on.

getSuperPrivacyMode

getSuperPrivacyMode(): Promise<SuperPrivacyMode>

Obtains the current Super Privacy status. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 6.0.2(22)

Returns:

Type Description
Promise<SuperPrivacyMode> Promise used to return the current Super Privacy status.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

ID Error Message
1006200002 Internal error.
1006200005 Not support super privacy.

Example:

import { superPrivacyMode } from '@kit.DeviceSecurityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const DOMAIN = 0x0000;
const TAG = "SuperPrivacyModeTest";

let mode: superPrivacyMode.SuperPrivacyMode = superPrivacyMode.SuperPrivacyMode.OFF;
try {
  mode = await superPrivacyMode.getSuperPrivacyMode();
  hilog.info(DOMAIN, TAG, `Super privacy mode = ${mode}`);
} catch (err) {
  hilog.error(DOMAIN, TAG, `call getSuperPrivacyMode interface failed, errCode:${err?.code}, errMessage:${err?.message}`);
}

on('superPrivacyModeChange')

on(type: 'superPrivacyModeChange', callback: Callback<SuperPrivacyMode>): void

Subscribes to Super Privacy status change events. This API uses an asynchronous callback to return the result.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 6.0.2(22)

Parameters:

Name Type Mandatory Description
type string Yes Event type to subscribe to. The value is fixed at superPrivacyModeChange.
callback Callback<SuperPrivacyMode> Yes Callback used to return the result.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

ID Error Message
1006200001 General error.
1006200002 Internal error.
1006200005 Not support super privacy.

Example:

import { superPrivacyMode } from '@kit.DeviceSecurityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const DOMAIN = 0x0000;
const TAG = "SuperPrivacyModeTest";

const superPrivacyChangedCallback = (superPrivacyMode: superPrivacyMode.SuperPrivacyMode): void => {
  hilog.info(DOMAIN, TAG, `super privacy mode changed, mode = ${superPrivacyMode}`);
}

hilog.info(DOMAIN, TAG, 'start register super privacy mode changed listener');
try {
  superPrivacyMode.on('superPrivacyModeChange', superPrivacyChangedCallback);
  hilog.info(DOMAIN, TAG, 'register super privacy mode change listener success');
} catch (err) {
  hilog.error(DOMAIN, TAG, `register super privacy changed listener failed, errCode:${err?.code}, errMessage:${err?.message}`);
}

off('superPrivacyModeChange')

off(type: 'superPrivacyModeChange', callback?: Callback<SuperPrivacyMode>): void

Unsubscribes from Super Privacy status change events. This API uses an asynchronous callback to return the result.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 6.0.2(22)

Parameters:

Name Type Mandatory Description
type string Yes Event type to unsubscribe from. The value is fixed at superPrivacyModeChange.
callback Callback<SuperPrivacyMode> No Callback used to return the result. If a callback is passed, the subscription to this callback is canceled. If no callback is passed, subscriptions to all callbacks are canceled.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

ID Error Message
1006200001 General error.
1006200002 Internal error.
1006200005 Not support super privacy.

Example:

import { superPrivacyMode } from '@kit.DeviceSecurityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const DOMAIN = 0x0000;
const TAG = "SuperPrivacyModeTest";

const superPrivacyChangedCallback = (superPrivacyMode: superPrivacyMode.SuperPrivacyMode): void => {
  hilog.info(DOMAIN, TAG, `super privacy mode changed, mode = ${superPrivacyMode}`);
}

hilog.info(DOMAIN, TAG, 'start unregister super privacy mode changed listener');
try {
  superPrivacyMode.off('superPrivacyModeChange', superPrivacyChangedCallback);
  hilog.info(DOMAIN, TAG, 'unregister super privacy changed listener success');
} catch (err) {
  hilog.error(DOMAIN, TAG, `unregister super privacy changed listener failed, errCode:${err?.code}, errMessage:${err?.message}`);
}

PrivacySensorType

Enumerates privacy sensor types.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 26.0.0

Name Value Description
CAMERA 0 Camera sensor.
MICROPHONE 1 Microphone sensor.
LOCATION 2 Location sensor.

PrivacySensorState

Enumerates privacy sensor statuses.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 26.0.0

Name Value Description
DEFAULT 0 Indicates that the sensor is not managed by Super Privacy mode.
ENABLED_UNDER_SUPER_PRIVACY 1 Indicates that the sensor is available under the Super Privacy mode.
DISABLED_UNDER_SUPER_PRIVACY 2 Indicates that the sensor is unavailable under the Super Privacy mode.

SuperPrivacyPolicy

Super Privacy mode control policy object, which represents the control policy applied to privacy sensors in Super Privacy mode.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Since: 26.0.0

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Name Type Read-Only Optional Description
sensorType PrivacySensorType No No Type of privacy sensor to which the policy is applied.
sensorState PrivacySensorState No No Status of the privacy sensor in the policy.

SuperPrivacyPolicyInfo

Super Privacy mode status and privacy sensor control policy information.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 26.0.0

Name Type Read-Only Optional Description
superPrivacyMode SuperPrivacyMode No No Super Privacy mode status.
superPrivacyPolicies SuperPrivacyPolicy[] No No Super Privacy control policies of the privacy sensor. The array length must be 3.

getSuperPrivacyPolicies

getSuperPrivacyPolicies(): Promise<SuperPrivacyPolicyInfo>

Obtains information about Super Privacy control policies. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 26.0.0

Returns:

Type Description
Promise<SuperPrivacyPolicyInfo> Promise used to return the Super Privacy control policy information.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

ID Error Message
1006200001 General error.
1006200002 Internal error.
1006200005 Not support super privacy.

Example:

import { superPrivacyMode } from '@kit.DeviceSecurityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const DOMAIN = 0x0000;
const TAG = "SuperPrivacyModeTest";

try {
  const policyInfo = await superPrivacyMode.getSuperPrivacyPolicies();
  hilog.info(DOMAIN, TAG, `Super privacy mode = ${policyInfo.superPrivacyMode}`);
  hilog.info(DOMAIN, TAG, `Super privacy policies = ${JSON.stringify(policyInfo.superPrivacyPolicies)}`);
} catch (err) {
  hilog.error(DOMAIN, TAG, `call getSuperPrivacyPolicies interface failed, errCode:${err?.code}, errMessage:${err?.message}`);
}

onSuperPrivacyModeOrPolicyChange

onSuperPrivacyModeOrPolicyChange(callback: Callback<SuperPrivacyPolicyInfo>): void

Subscribes to Super Privacy mode or control policy change events. This API uses an asynchronous callback to return the result.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 26.0.0

Parameters:

Name Type Mandatory Description
callback Callback<SuperPrivacyPolicyInfo> Yes Callback used to return the Super Privacy control policy information.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

ID Error Message
1006200001 General error.
1006200002 Internal error.
1006200005 Not support super privacy.

Example:

import { superPrivacyMode } from '@kit.DeviceSecurityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const DOMAIN = 0x0000;
const TAG = "SuperPrivacyModeTest";

const superPrivacyPolicyChangedCallback = (policyInfo: superPrivacyMode.SuperPrivacyPolicyInfo): void => {
  hilog.info(DOMAIN, TAG, `super privacy mode or policy changed`);
  hilog.info(DOMAIN, TAG, `Super privacy mode = ${policyInfo.superPrivacyMode}`);
  hilog.info(DOMAIN, TAG, `Super privacy policies = ${JSON.stringify(policyInfo.superPrivacyPolicies)}`);
}

hilog.info(DOMAIN, TAG, 'start register super privacy mode or policy changed listener');
try {
  superPrivacyMode.onSuperPrivacyModeOrPolicyChange(superPrivacyPolicyChangedCallback);
  hilog.info(DOMAIN, TAG, 'register super privacy mode or policy change listener success');
} catch (err) {
  hilog.error(DOMAIN, TAG, `register super privacy mode or policy changed listener failed, errCode:${err?.code}, errMessage:${err?.message}`);
}

offSuperPrivacyModeOrPolicyChange

offSuperPrivacyModeOrPolicyChange(callback?: Callback<SuperPrivacyPolicyInfo>): void

Unsubscribes from Super Privacy mode or control policy change events. This API uses an asynchronous callback to return the result.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.SecurityPrivacyServer

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets that support the Super Privacy mode. On phones, PCs/2-in-1 devices, and tablets that do not support the Super Privacy mode, it returns error code 1006200005. Comply with Constraints during development.

Since: 26.0.0

Parameters:

Name Type Mandatory Description
callback Callback<SuperPrivacyPolicyInfo> No Callback used to return the Super Privacy control policy information. If a callback is passed, the subscription to this callback is canceled. If no callback is passed, subscriptions to all callbacks are canceled.

Error codes:

For details about the error codes, please refer to ArkTS API Error Codes.

ID Error Message
1006200001 General error.
1006200002 Internal error.
1006200005 Super Privacy is not supported by the device.

Example:

import { superPrivacyMode } from '@kit.DeviceSecurityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

const DOMAIN = 0x0000;
const TAG = "SuperPrivacyModeTest";

const superPrivacyPolicyChangedCallback = (policyInfo: superPrivacyMode.SuperPrivacyPolicyInfo): void => {
  hilog.info(DOMAIN, TAG, `super privacy mode or policy changed`);
  hilog.info(DOMAIN, TAG, `Super privacy mode = ${policyInfo.superPrivacyMode}`);
  hilog.info(DOMAIN, TAG, `Super privacy policies = ${JSON.stringify(policyInfo.superPrivacyPolicies)}`);
}

hilog.info(DOMAIN, TAG, 'start unregister super privacy mode or policy changed listener');
try {
  superPrivacyMode.offSuperPrivacyModeOrPolicyChange(superPrivacyPolicyChangedCallback);
  hilog.info(DOMAIN, TAG, 'unregister super privacy mode or policy changed listener success');
} catch (err) {
  hilog.error(DOMAIN, TAG, `unregister super privacy mode or policy changed listener failed, errCode:${err?.code}, errMessage:${err?.message}`);
}