Before using the classified file protection capability, import the following classes:
import android.content.Context; import com.huawei.fileprotect.HwSfpPolicyManager;
Set security level labels for files based on data importance, for the system to provide corresponding security protection measures.
HwSfpPolicyManager policyManager = HwSfpPolicyManager.getDefault();
if (policyManager == null) {
return;
} 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.
HwSfpPolicyManager policyManager = HwSfpPolicyManager.getDefault();
if (policyManager == null) {
return;
} String label = policyManager.getLabel(context, filePath,
HwSfpPolicyManager.LABEL_NAME_SECURITY_LEVEL); HwSfpPolicyManager policyManager = HwSfpPolicyManager.getDefault();
if (policyManager == null) {
return;
} int flag = policyManager.getFlag(context, filePath,
HwSfpPolicyManager.LABEL_NAME_SECURITY_LEVEL);
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.
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.
For other issues, see the FAQs.