We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesDataSecurity EngineClassified File Protectioncom.huawei.fileprotectClass SummaryHwSfpPolicyManager

HwSfpPolicyManager

Expand

Class Info

public class HwSfpPolicyManager

Contains various methods for setting and querying file protection policies and file risk levels.

Public Method Summary

Expand

Qualifier and Type

Method Name and Description

HwSfpPolicyManager

getDefault()

Obtains a HwSfpPolicyManager instance.

int

setLabel(Context context, String filePath, String labelName, String labelValue, int flag)

Sets a risk level and protection policy for a file.

String

getLabel(Context context, String filePath, String labelName)

Obtains the risk level of a file.

int

getFlag(Context context, String filePath, String labelName)

Obtains the flag information about a file risk level.

Public Methods

getDefault

Expand

Method

public static HwSfpPolicyManager getDefault()

Obtains a HwSfpPolicyManager instance.

Return

Expand

Type

Description

HwSfpPolicyManager

An existing instance (if initialized) or a new instance (if uninitialized).

Throws

Expand

Name

Description

NoExtAPIException

When the version is not compatible.

setLabel

Expand

Method

public int setLabel(Context context, String filePath, String labelName, String labelValue, int flag)

Sets a risk level and protection policy for a file.

Parameters

Expand

Name

Description

context

App context, which is used to obtain the file storage path and determine whether the path is a CE/DE path.

filePath

File for which the risk level needs to be set. The format is filePath (absolute path+file name), for example, /data/user/0/com.tips.test/test1.txt.

labelName

Classification label name. Currently, only HwSfpPolicyManager.LABEL_NAME_SECURITY_LEVEL is supported.

labelValue

Label value, which can be S0, S1, S2, S3, or S4.

For details about the label values, see Service Introduction.

flag

Additional flag information about the label value. This parameter is valid only when labelValue is set to S3. The flag values are as follows:

  • 0x0000: Files cannot be opened, read, or written when the screen is locked.
  • 0x0001: Files can be created when the screen is locked. Files that have been opened can still be read and written.

Return

Expand

Type

Description

int

  • 0: The label is set successfully.
  • 1: Invalid input parameters.
  • 2: The file has already been labeled.
  • 3: The context does not match the target path.
  • 4: API calling error.

Throws

Expand

Name

Description

NoExtAPIException

When the version is not compatible.

getLabel

Expand

Method

public String getLabel(Context context, String filePath, String labelName)

Obtains the risk level of a file.

Parameters

Expand

Name

Description

context

App context, which is used to obtain the file storage path and determine whether the path is a CE/DE path.

filePath

File for which the risk level needs to be queried. The format is filePath (absolute path+file name), for example, /data/user/0/com.tips.test/test1.txt.

labelName

Classification label name. Currently, only HwSfpPolicyManager.LABEL_NAME_SECURITY_LEVEL is supported.

Return

Expand

Type

Description

String

  • An empty string "": The label cannot be obtained correctly.
  • "S0": Obtained label value S0.
  • "S1": Obtained label value S1.
  • "S2": Obtained label value S2.
  • "S3": Obtained label value S3.
  • "S4": Obtained label value S4.

For details about the label values, see Overview.

Throws

Expand

Name

Description

NoExtAPIException

When the version is not compatible.

getFlag

Expand

Method

public int getFlag(Context context, String filePath, String labelName)

Obtains the flag information about a file risk level.

Parameters

Expand

Name

Description

context

App context, which is used to obtain the file storage path and determine whether the path is a CE/DE path.

filePath

File for which the risk level needs to be set. The format is filePath (absolute path+file name), for example, /data/user/0/com.tips.test/test1.txt.

labelName

Classification label name. Currently, only HwSfpPolicyManager.LABEL_NAME_SECURITY_LEVEL is supported.

Return

Expand

Type

Description

int

  • Error code -1: No risk level has been set for the file and the flag fails to be obtained.
  • Flag value 0: The API is successfully called. The flag parameter is valid only when labelValue is S3. The flag value 0 indicates that files cannot be opened, read, or written when the screen is locked.
  • Flag value 1: The API is successfully called. The flag parameter is valid only when labelValue is S3. The flag value 1 indicates that files can be created when the screen is locked. Files that have been opened can still be read and written.

Throws

Expand

Name

Description

NoExtAPIException

When the version is not compatible.