目录

Subscribes to Super Privacy mode change events.

Use Cases

Starting from version 6.0.2(22), the function of subscribing to Super Privacy mode change events is supported.

The Super Privacy mode allows users to disable sensitive components with just one tap. Currently, the sensitive components managed by the Super Privacy mode include the location service, camera, and microphone, and will be adjusted with the version evolution. Apps can call the API provided by Device Security Kit to listen for the Super Privacy status.

Constraints

This feature requires that the Super Privacy option be available on the device. To check the option, go to Settings > Privacy & security > Super Privacy on the device.

Service Process

Process description:

  1. Your app calls the on API to subscribe to the Super Privacy mode change events.

  2. Device Security Kit calls the callback function to notify your app of the mode change.

  3. Your app processes services based on the current Super Privacy mode.

  4. Your app unsubscribes from Super Privacy mode change events when the Super Privacy mode is no longer needed.

API Description

The following table lists the APIs for subscribing to and unsubscribing from Super Privacy mode change events. For details, please refer to API Reference.

API Description
on(type: 'superPrivacyModeChange', callback: Callback<SuperPrivacyMode>): void Subscribes to Super Privacy mode change events.
off(type: 'superPrivacyModeChange', callback?: Callback<SuperPrivacyMode>): void Unsubscribes from Super Privacy mode change events.

Development Procedure

  1. Import the SuperPrivacyMode module and related public modules.

    import { superPrivacyMode } from '@kit.DeviceSecurityKit';
    import { hilog } from '@kit.PerformanceAnalysisKit';
  2. Define the callback function triggered when the Super Privacy mode changes.

    const superPrivacyChangedCallback = (mode: superPrivacyMode.SuperPrivacyMode): void => {
      hilog.info(DOMAIN, TAG, `super privacy mode changed, mode = ${mode}`);
      // ...
    }
  3. Call the on API to subscribe to the Super Privacy mode change events.

    const DOMAIN = 0x0000;
    const TAG = 'SuperPrivacyModeTest';
    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}`);
      // ...
    }
  4. Call the off API to unsubscribe from the Super Privacy mode change events.

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