|
2 | 2 |
|
3 | 3 | import backtraceio.library.watchdog.OnApplicationNotRespondingEvent; |
4 | 4 |
|
| 5 | + |
| 6 | +/** |
| 7 | + * Configuration settings for Application Not Responding (ANR) detection. |
| 8 | + * This class allows customization of ANR monitoring behavior, such as the timeout duration |
| 9 | + * and callback events. |
| 10 | + */ |
5 | 11 | public class BacktraceANRSettings { |
6 | | - private int timeout = 0; |
7 | | - private boolean debug = false; |
8 | | - private OnApplicationNotRespondingEvent onApplicationNotRespondingEvent = null; |
| 12 | + /** |
| 13 | + * Default timeout value in milliseconds |
| 14 | + */ |
| 15 | + public final static int DEFAULT_ANR_TIMEOUT = 5000; |
| 16 | + |
| 17 | + /** |
| 18 | + * The timeout in milliseconds after which an ANR is reported if the main thread is blocked. |
| 19 | + */ |
| 20 | + private final int timeout; |
| 21 | + |
| 22 | + /** |
| 23 | + * Flag to enable or disable additional debug logging for ANR detection. |
| 24 | + * When true, more verbose logging related to ANR monitoring might be produced. |
| 25 | + */ |
| 26 | + private final boolean debug; |
9 | 27 |
|
10 | | - public BacktraceANRSettings() { } |
| 28 | + /** |
| 29 | + * Callback interface to be invoked when an Application Not Responding event is detected. |
| 30 | + * This allows custom handling of ANR events. |
| 31 | + */ |
| 32 | + private final OnApplicationNotRespondingEvent onApplicationNotRespondingEvent; |
| 33 | + |
| 34 | + /** |
| 35 | + * Default constructor. |
| 36 | + * Initializes ANR settings with default values. |
| 37 | + */ |
| 38 | + public BacktraceANRSettings() { |
| 39 | + this(DEFAULT_ANR_TIMEOUT, null, false); |
| 40 | + } |
11 | 41 |
|
| 42 | + /** |
| 43 | + * Constructs ANR settings with specified parameters. |
| 44 | + * |
| 45 | + * @param timeout The timeout in milliseconds for ANR detection. |
| 46 | + * @param onApplicationNotRespondingEvent The callback to be invoked when an ANR is detected. |
| 47 | + * Can be null if no custom callback is needed. |
| 48 | + * @param debug True to enable debug logging for ANR detection, false otherwise. |
| 49 | + */ |
12 | 50 | public BacktraceANRSettings(int timeout, OnApplicationNotRespondingEvent onApplicationNotRespondingEvent, boolean debug) { |
13 | | - super(); |
14 | | - this.debug = debug; |
15 | | - this.onApplicationNotRespondingEvent = onApplicationNotRespondingEvent; |
16 | 51 | this.timeout = timeout; |
| 52 | + this.onApplicationNotRespondingEvent = onApplicationNotRespondingEvent; |
| 53 | + this.debug = debug; |
17 | 54 | } |
18 | 55 |
|
| 56 | + /** |
| 57 | + * Gets the configured ANR timeout in milliseconds. |
| 58 | + * |
| 59 | + * @return The timeout in milliseconds. |
| 60 | + */ |
19 | 61 | public int getTimeout() { |
20 | 62 | return timeout; |
21 | 63 | } |
22 | 64 |
|
| 65 | + /** |
| 66 | + * Checks if debug logging for ANR detection is enabled. |
| 67 | + * |
| 68 | + * @return True if debug logging is enabled, false otherwise. |
| 69 | + */ |
23 | 70 | public boolean isDebug() { |
24 | 71 | return debug; |
25 | 72 | } |
26 | 73 |
|
| 74 | + /** |
| 75 | + * Gets the configured callback for ANR events. |
| 76 | + * |
| 77 | + * @return The {@link OnApplicationNotRespondingEvent} callback, or null if none is set. |
| 78 | + */ |
27 | 79 | public OnApplicationNotRespondingEvent getOnApplicationNotRespondingEvent() { |
28 | 80 | return onApplicationNotRespondingEvent; |
29 | 81 | } |
|
0 commit comments