目录

Procedure

Getting Started

Before using the classified file protection capability, import the following classes:

import android.content.Context;
import com.huawei.fileprotect.HwSfpPolicyManager;

Setting the Label

Set security level labels for files based on data importance, for the system to provide corresponding security protection measures.

  1. Obtain the HwSfpPolicyManager instance to call the methods of setting and querying the risk level of a file.
    HwSfpPolicyManager policyManager = HwSfpPolicyManager.getDefault();
    if (policyManager == null) {
        return;
    }
  2. Set the label.

    Enter the context information, and absolute path and name (filePath) of the file for which the risk level needs to be set, as well as the label value (S0, S1, S2, S3, or S4) and flag information of the label, in order to set the risk level of the file. For the description of the parameters, see setLabel.

    // Example: Set the risk level to S3 and the flag of the label to "0x0001".
    int flag  = 0x0001;
    int errorCode = policyManager.setLabel(context, filePath,
        HwSfpPolicyManager.LABEL_NAME_SECURITY_LEVEL,
        HwSfpPolicyManager.LABEL_VALUE_S3, flag);

    The value of flag can be 0 or 1. This parameter is valid only when the label value is S3. If flag is set to 0, it indicates that the screen cannot be unlocked and files cannot be read or written. If flag is 1, it indicates that new files can be added when the screen is locked, and for files that are opened, files at that level can still be read and written.

Obtaining the Label

  1. Obtain the HwSfpPolicyManager instance to call the method of querying the risk level of a file.
    HwSfpPolicyManager policyManager = HwSfpPolicyManager.getDefault();
    if (policyManager == null) {
        return;
    }
  2. Enter the absolute path and file name (filePath) to query the risk level of the file.
    String label = policyManager.getLabel(context, filePath,
        HwSfpPolicyManager.LABEL_NAME_SECURITY_LEVEL);

Obtaining the Flag Information

  1. Obtain the HwSfpPolicyManager instance to call the method of querying the flag of the risk level.
    HwSfpPolicyManager policyManager = HwSfpPolicyManager.getDefault();
    if (policyManager == null) {
        return;
    }
  2. Obtain the flag information.
    If the return value is 0 or 1, the method is successfully called. If the return value is -1, it means that the method failed to be called.
    int flag = policyManager.getFlag(context, filePath,
        HwSfpPolicyManager.LABEL_NAME_SECURITY_LEVEL);

Restrictions

  1. The compatible version is EMUI 11.0 or later.
  2. Files in the Credential Encrypted (CE) class path: S1 and S0 risk levels cannot be set for files in the CE path. Otherwise, a failure message is displayed. The S2 to S4 risk levels can be set only once. If a risk level has been set for the file, a failure message is displayed.

    When a user powers on the device, the device verifies the user validity. For example, if the user has entered the startup password to unlock the screen, the password is no longer required in subsequent data decryption. CE path of the current mobile phone system: /data/user/0.

  3. Files in the Device Encrypted (DE) class path: S2 to S4 risk levels cannot be set for the files. Only S1 and S0 risk levels can be set for only once. If a risk level has been set for the file, a failure message is displayed.

    After the user powers on the phone, data in this area can be accessed, such as Bluetooth pairing data, alarms, and ringtones. DE path of the current mobile phone system: /data/user_de/0.

  4. Currently, labels can be set only for data of the file type. It is advised that you create labels immediately after a file is created.

For other issues, see the FAQs.