public class HiChecker extends Object
You can use HiChecker to detect any file read/write or network access operation that is not supposed to take place on a specific thread, helping you fix the issue. For example, you can use HiChecker to catch file read/write on the UI thread, which should not involve such time-consuming operations. In addition, you can use HiChecker to detect process-specific resource leakage.
Sample code for adding a rule and starting detection:
if (HICHECKER_ENABLED) {
EnumSet<Rule> rules = EnumSet.of(Rule.CHECK_FILE_READ, Rule.CHECK_VM_RELEASE_MISS, Rule.CAUTION_BY_LOG);
HiChecker.addRule(rules);
}
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static interface |
HiChecker.OnCautionListener |
Obtains and handles cautions.
|
static class |
HiChecker.Rule |
Enumerates detection rules and caution rules.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static void |
addAllRules() |
Adds all rules to start detection.
|
static void |
addDefaultRules() |
Adds default rules to start detection.
|
static void |
addRule(EnumSet<HiChecker.Rule> rules) |
Adds one or more rules for HiChecker.
|
static void |
addRule(HiChecker.Rule rule) |
Adds a rule for HiChecker.
|
static boolean |
contains(HiChecker.Rule rule) |
Checks whether a specified rule is included in the added rules.
|
static EnumSet<HiChecker.Rule> |
getRule() |
Obtains all available rules.
|
static void |
notifySlowProcess(String tag) |
Notifies your application of a slow processing if the current code has invoked time-consuming operations.
|
static void |
removeAllRules() |
Removes all available rules.
|
static EnumSet<HiChecker.Rule> |
removeCheckFileReadRule() |
Removes the rule of detecting file read operations.
|
static EnumSet<HiChecker.Rule> |
removeCheckFileWriteRule() |
Removes the rule of detecting file write operations.
|
static void |
removeRule(EnumSet<HiChecker.Rule> rules) |
Removes one or more rules.
|
static void |
removeRule(HiChecker.Rule rule) |
Removes a rule.
|
static void |
setCautionListener(Executor executor,
HiChecker.OnCautionListener listener) |
Sets a callback for caution handling.
|
public static void addRule(EnumSet<HiChecker.Rule> rules)
HiChecker detects unexpected operations or gives feedback based on the added rules.
rules - Indicates one or more rules you want to add. If this parameter is null, HiChecker will not perform
detection or give feedback.HiChecker.Rulepublic static void addRule(HiChecker.Rule rule)
HiChecker detects unexpected operations or gives feedback based on the added rule.
rule - Indicates the rule you want to add. If this parameter is null, HiChecker will not perform detection
or give feedback.HiChecker.Rulepublic static void addDefaultRules()
Available default rules cover all those specific to the current thread and process, and the caution rule
(cautions just being logged, as defined by Rule.CAUTION_BY_LOG).
HiChecker.Rulepublic static void addAllRules()
Such rules cover all those specific to the current thread, process, and caution.
HiChecker.Rulepublic static void removeRule(EnumSet<HiChecker.Rule> rules)
rules - Indicates one or more rules you want to remove.HiChecker.Rulepublic static void removeRule(HiChecker.Rule rule)
rule - Indicates the rule you want to remove.HiChecker.Rulepublic static void removeAllRules()
public static EnumSet<HiChecker.Rule> getRule()
Such rules cover all those specific to the current thread, process, and caution.
public static boolean contains(HiChecker.Rule rule)
If the specified rule is thread-specific, this method only checks the current thread for that rule.
rule - Indicates the specified rule.true if the specified rule is included; returns false otherwise.HiChecker.Rulepublic static EnumSet<HiChecker.Rule> removeCheckFileWriteRule()
You can call this method when file write operations are regarded normal. After the removal, you can restore the rule if required.
public static EnumSet<HiChecker.Rule> removeCheckFileReadRule()
You can call this method when file read operations are regarded normal. After the removal, you can restore the rule if required.
public static void notifySlowProcess(String tag)
This notification helps your application avoid calling the current code in a key thread.
tag - Indicates the slow processing tag, which reflects information except for stack information.public static void setCautionListener(Executor executor, HiChecker.OnCautionListener listener)
After a caution is generated, the preset rules (such as caution logging) are applied and the caution is passed via the callback to the application for caution handling.
executor - Indicates the provided Executor object, where the callback will be executed.
If this parameter is null, a null pointer will be thrown.listener - Indicates the OnCautionListener object.
If this parameter is null, a null pointer will be thrown.HiChecker.OnCautionListener