All Products
Search
Document Center

Data cleansing allowlist

Last Updated: Apr 01, 2021

Background

To cope with the possibility of continuous crashes upon startup, mPaaS has established a data cleanup mechanism. This data cleanup mechanism is customizable, and can be configured to clean up the SharedPreference and database in different situations, and even wipe all the data in an application under very special circumstances to ensure the normal operation of the application. This mechanism is currently available for 10.1.32, 10.1.60, and 10.1.68 series baselines.

To protect important data, mPaaS provides the cleanup allowlist function in the data cleanup mechanism. You can protect a target file from being cleaned up by adding it to the cleanup allowlist.

Note: The data cleanup mechanism is available only in Component-based access mode.

Cleanup allowlist scheme 1.0

Introduction

The cleanup allowlist scheme 1.0 invokes an API in MPFramework to dynamically set the allowlist when appropriate.

Supported baselines

The cleanup allowlist scheme 1.0 supports 10.1.32, 10.1.60, and 10.1.68 series baselines.

If the cleanup mechanism has been triggered due to crash before the allowlist is set, the cleanup allowlist scheme 1.0 will not come into effect. If you use the 10.1.32 series baseline, we recommend that you upgrade the baseline to 10.1.60 or 10.1.68 to use the upgraded cleanup allowlist scheme 2.0. For more information, see Cleanup Allowlist Scheme 2.0.

Procedure

Invoke the API to set the cleanup allowlist where appropriate. The API is as follows:

  1. /**
  2. * Sets the SharedPreference allowlist. If this has been set before, the previous data will be cleared.
  3. */
  4. public static void setSPWhiteList(List<String> whiteList);
  5. /**
  6. * Adds another SharedPreference allowlist.
  7. *
  8. * @param whiteList
  9. */
  10. public static void addSPWhiteList(List<String> whiteList);
  11. /**
  12. * Gets the set database allowlist.
  13. *
  14. * @return
  15. */
  16. public static List<String> getDBWhiteList();
  17. /**
  18. * Sets the database allowlist. If this has been set before, the previous data will be cleared.
  19. */
  20. public static void setDBWhiteList(List<String> whiteList) ;
  21. /**
  22. * Adds another database allowlist.
  23. *
  24. * @param whiteList
  25. */
  26. public static void addDBWhiteList(List<String> whiteList);

Cleanup allowlist scheme 2.0

Introduction

The cleanup allowlist scheme 2.0 works in such a way that when the cleanup mechanism is triggered, the framework loads the developer-configured allowlist by reflection to set classes, and first reads the defined cleanup policy.

Supported baselines

The cleanup allowlist scheme 2.0 supports 10.1.60 and 10.1.68 series baselines. Where:

  • The 10.1.60 baseline needs to be 10.1.60.10 or later versions.
  • The 10.1.68 baseline needs to be 10.1.68.4 or later versions.

Procedure

  1. Inherits com.mpaas.framework.adapter.api.ClearDataStrategy to implement related APIs.
  1. public abstract class ClearDataStrategy {
  2. public ClearDataStrategy() {
  3. }
  4. /**
  5. * Whether to enable the cleanup mechanism.
  6. * If false is returned, no file will be cleared up.
  7. * If it returns true, the cleanup strategy will be implemented. You can use getSPWhiteList and getDBWhiteList to return a list of files that need to be guaranteed.
  8. *
  9. * @return
  10. */
  11. public abstract boolean enableClearDataStrategy();
  12. /**
  13. * If the cleanup mechanism is enabled, the SharedPreference file that needs to be protected is returned through this API.
  14. *
  15. * @return
  16. */
  17. public List<String> getSPWhiteList() {
  18. return null;
  19. }
  20. /**
  21. * If the cleanup mechanism is enabled, the db file that needs to be protected is returned through this API.
  22. *
  23. * @return
  24. */
  25. public List<String> getDBWhiteList() {
  26. return null;
  27. }
  28. }

2.Configure the strategy information in the AndroidManifest of Portal.

Note: Since ClearDataStrategy needs to be called reflectively, ClearDataStrategy cannot be confused.
  1. <meta-data
  2. android:name="ClearDataStrategy"
  3. android:value="com.mpaas.demo.launcher.ClearDataStrategy" />