Skip to content

Commit 548965c

Browse files
authored
Merge pull request markzhai#86 from promeG/master
支持开发者设置:代码调试模式下是否应该停止检测
2 parents bd9ac0b + f32a401 commit 548965c

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/BlockCanaryContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,13 @@ public boolean deleteFilesInWhiteList() {
199199
public void onBlock(Context context, BlockInfo blockInfo) {
200200

201201
}
202+
203+
/**
204+
* Whether to stop monitoring when in debug mode.
205+
*
206+
* @return true if stop, false otherwise
207+
*/
208+
public boolean stopWhenDebugging() {
209+
return true;
210+
}
202211
}

blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/BlockCanaryInternals.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void onBlockEvent(long realTimeStart, long realTimeEnd,
6969
}
7070
}
7171
}
72-
}, getContext().provideBlockThreshold()));
72+
}, getContext().provideBlockThreshold(), getContext().stopWhenDebugging()));
7373

7474
LogWriter.cleanObsolete();
7575
}

blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LooperMonitor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.github.moduth.blockcanary;
1717

18+
import android.os.Debug;
1819
import android.os.SystemClock;
1920
import android.util.Printer;
2021

@@ -27,6 +28,7 @@ class LooperMonitor implements Printer {
2728
private long mStartThreadTimestamp = 0;
2829
private BlockListener mBlockListener = null;
2930
private boolean mPrintingStarted = false;
31+
private final boolean mStopWhenDebugging;
3032

3133
public interface BlockListener {
3234
void onBlockEvent(long realStartTime,
@@ -35,16 +37,20 @@ void onBlockEvent(long realStartTime,
3537
long threadTimeEnd);
3638
}
3739

38-
public LooperMonitor(BlockListener blockListener, long blockThresholdMillis) {
40+
public LooperMonitor(BlockListener blockListener, long blockThresholdMillis, boolean stopWhenDebugging) {
3941
if (blockListener == null) {
4042
throw new IllegalArgumentException("blockListener should not be null.");
4143
}
4244
mBlockListener = blockListener;
4345
mBlockThresholdMillis = blockThresholdMillis;
46+
mStopWhenDebugging = stopWhenDebugging;
4447
}
4548

4649
@Override
4750
public void println(String x) {
51+
if (mStopWhenDebugging && Debug.isDebuggerConnected()) {
52+
return;
53+
}
4854
if (!mPrintingStarted) {
4955
mStartTimestamp = System.currentTimeMillis();
5056
mStartThreadTimestamp = SystemClock.currentThreadTimeMillis();

blockcanary-sample/src/main/java/com/example/blockcanary/AppContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ public List<String> provideWhiteList() {
7777
list.add("com.whitelist");
7878
return list;
7979
}
80+
81+
@Override
82+
public boolean stopWhenDebugging() {
83+
return false;
84+
}
8085
}

0 commit comments

Comments
 (0)