mPaaS provides a data cleanup mechanism that handles continuous startup crashes. If the application freezes or an important thread (main thread, multidex.init thread, or ApplicationAgent.init thread) crashes before the mPaaS framework completes startup, the framework may trigger data cleanup. You can customize this mechanism to clean SharedPreference files and database files in different situations. In rare cases, it can delete all application data to restore normal operation. This feature is available in the 10.1.32, 10.1.60, 10.1.68, and 10.2.3 series baselines.
To protect important data, mPaaS provides a whitelist feature for the data cleanup mechanism. You can add an object file to the whitelist to prevent it from being cleaned.
The data cleanup mechanism is only available for the Portal&Bundle connection type.
Whitelist solution 1.0
Whitelist solution 1.0 lets you dynamically set the whitelist by calling an API in MPFramework at the appropriate time.
Supported baselines
Whitelist solution 1.0 supports the 10.1.32, 10.1.60, 10.1.68, and 10.2.3 series baselines.
Whitelist solution 1.0 does not work if a crash triggers the cleanup mechanism before the whitelist is set. If you use the 10.1.32 series baseline, upgrade the baseline to 10.2.3 to use whitelist solution 2.0. For more information, see Whitelist solution 2.0.
Integration steps
Call the API to set the cleanup whitelist at the appropriate time. The APIs are as follows:
/**
* Sets the SharedPreference whitelist. If a whitelist was previously set, it is overwritten.
*/
public static void setSPWhiteList(List<String> whiteList);
/**
* Adds items to the SharedPreference whitelist. Items are appended.
*
* @param whiteList
*/
public static void addSPWhiteList(List<String> whiteList);
/**
* Gets the configured database whitelist.
*
* @return
*/
public static List<String> getDBWhiteList();
/**
* Sets the database whitelist. If a whitelist was previously set, it is overwritten.
*/
public static void setDBWhiteList(List<String> whiteList) ;
/**
* Adds items to the database whitelist. Items are appended.
*
* @param whiteList
*/
public static void addDBWhiteList(List<String> whiteList);
Whitelist solution 2.0
In whitelist solution 2.0, when the cleanup mechanism is triggered, the framework uses reflection to load the whitelist class configured by the developer and prioritizes the custom cleanup policy.
Supported baselines
Whitelist solution 2.0 supports the 10.1.60, 10.1.68, and 10.2.3 series baselines. Note the following:
-
For the 10.1.60 baseline, version 10.1.60.10 or later is required.
-
For the 10.1.68 baseline, version 10.1.68.4 or later is required.
Integration steps
-
Inherit
com.mpaas.framework.adapter.api.ClearDataStrategyand implement the related interfaces.public abstract class ClearDataStrategy { public ClearDataStrategy() { } /** * Specifies whether to enable the cleanup mechanism. * If this method returns false, no files are cleaned. * If this method returns true, the cleanup policy is executed. You can return a list of files to protect through getSPWhiteList and getDBWhiteList. * * @return */ public abstract boolean enableClearDataStrategy(); /** * If the cleanup mechanism is enabled, this interface returns the SharedPreference files to protect. * * @return */ public List<String> getSPWhiteList() { return null; } /** * If the cleanup mechanism is enabled, this interface returns the DB files to protect. * * @return */ public List<String> getDBWhiteList() { return null; } } -
Configure the policy class information in the Portal's
AndroidManifestfile.NoteBecause
ClearDataStrategyis called using reflection, do not obfuscateClearDataStrategy.<meta-data android:name="ClearDataStrategy" android:value="com.mpaas.demo.launcher.ClearDataStrategy" />