目录

Adapting to Encrypted Share

Overview

Encrypted share is a data security function built based on the system-level data leak prevention framework. When sharing a file, users can use this function to encrypt it. The encrypted file can be viewed only by specified Huawei accounts, preventing the file from being forwarded.

As a new standard OS-level file format with a .dlp extension, the encrypted file requires account authentication and permission control via system services before any operations can be performed on the recipient's device. Therefore, communication and chat applications need to call HarmonyOS capabilities to process encrypted files, ensuring seamless user experience.

Your application needs to adapt to the encrypted share function in two key steps to ensure that DLP files can be correctly sent and viewed:

Sending Encrypted Files

Users can share encrypted files in either of the following ways:

[h2]Selecting a File and Sharing it to an Application in Encrypted Mode

The user directly selects a file and shares it to the application in encrypted mode. The procedure on the device is as follows:

  1. In system applications such as Files and Gallery, select the file to be shared in encrypted mode.

  2. Tap the share button and then tap Encrypted share from the bottom functional area. Log in to your HUAWEI ID and then specify the users who can view the file.

  3. Share the encrypted file to a third-party application through the system. For example, share the file to a chat application and then send it to others.

To support the user in successfully completing the preceding process, the application must meet the following requirements:

[h2]Using the File Picker to Share Encrypted Files Within an Application

A user selects a file using the picker within the application and sets encrypted share. The procedure on the device is as follows:

  1. Select a file using the picker within the application.

  2. Tap Encrypted share from the bottom of the file picker. Sign in to your HUAWEI ID and then specify the users who can view the file.

  3. After the addition is complete, directly send the encrypted file to others within the application.

To support the user in successfully completing the preceding process, the application requires the following adaptation:

  1. Configure the DocumentSelectOptions parameter to display Encrypted share at the bottom of the file picker.

  2. Obtain the file URI through DocumentViewPicker.

  3. After obtaining the file URI, the application can send the DLP file.

    import common from '@ohos.app.ability.common';
    import picker from '@ohos.file.picker';
    
    @Component
    struct Index {
      async callFilePicker(): Promise<void> {
        try {
          let context = this.getUIContext()?.getHostContext() as common.UIAbilityContext;
          let documentSelectOptions = new picker.DocumentSelectOptions();
          documentSelectOptions.isEncryptionSupported = true; // Display the encrypted share button.
          let documentPicker = new picker.DocumentViewPicker(context);
          const documentSelectResult: Array<string> = await documentPicker.select(documentSelectOptions); // Obtain the file URI.
        } catch (err) {
          console.error('CallFilePickerSelectFile failed');
        }
      }
    
      build() {
      }
    }

Viewing Encrypted Files

Users can view encrypted files in either of the following ways:

[h2]Viewing DLP Files Through File Preview Within the Application

The procedure on the device is as follows:

  1. Tap the DLP file to be viewed in the application. The application directly opens the file preview to view the file.

To support the user in successfully completing the preceding process, the application requires the following adaptation:

  1. Before opening a DLP file, obtain the URI of the DLP file to be opened.

  2. Construct the want parameter.

  3. Pass the want parameter through startAbility and use the unified opening capability of the system to open the file.

    import Want from '@ohos.app.ability.Want';
    import { common, wantConstant } from '@kit.AbilityKit';
    
    @Component
    struct Index {
      viewDlp(dlpUri: string) {
        let context = this.getUIContext()?.getHostContext() as common.UIAbilityContext;
        let want: Want = {
          "action": "ohos.want.action.viewData",
          "uri": dlpUri, // Before opening a DLP file, obtain the URI of the DLP file to be opened.
          "flags": wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, // Grant URI authorization for the opened DLP file. By default, the file is read-only.
        }
        try {
          // Pass the want information through startAbility and call the system's unified opening capability.
          context.startAbility(want);
        } catch (err) {
          console.error('startAbility failed');
        }
      }
      build() {
      }
    }

[h2]Saving the DLP File to Files for Viewing

The procedure on the device is as follows:

  1. Select a DLP file within the application.

  2. Save the file to Files.

  3. In Files, tap the DLP file to preview it.

To support the user in successfully completing the preceding process, the application must meet the following requirements: