Skip to content

Commit a4d0b20

Browse files
committed
Added debug-libraries: leakcanary and blockcanary
Up version to 468
1 parent 594ad22 commit a4d0b20

3 files changed

Lines changed: 61 additions & 7 deletions

File tree

xabber/build.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
defaultConfig {
1111
minSdkVersion 15
1212
targetSdkVersion 27
13-
versionCode 467
14-
versionName '2.2.1(467)'
13+
versionCode 468
14+
versionName '2.2.1(468)'
1515
}
1616

1717
lintOptions {
@@ -193,6 +193,15 @@ dependencies {
193193
}
194194

195195
implementation group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: '1.58'
196+
197+
// leak canary
198+
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
199+
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
200+
201+
// block canary
202+
debugImplementation 'com.github.markzhai:blockcanary-android:1.5.0'
203+
releaseCompile 'com.github.markzhai:blockcanary-no-op:1.5.0'
204+
196205
}
197206
apply plugin: 'com.google.gms.google-services'
198207

xabber/src/main/java/com/xabber/android/data/Application.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
import android.app.Activity;
1818
import android.content.Context;
1919
import android.os.Handler;
20+
import android.os.StrictMode;
2021
import android.support.annotation.NonNull;
2122
import android.support.multidex.MultiDex;
2223

2324
import com.crashlytics.android.Crashlytics;
2425
import com.crashlytics.android.core.CrashlyticsCore;
2526
import com.frogermcs.androiddevmetrics.AndroidDevMetrics;
27+
import com.github.moduth.blockcanary.BlockCanary;
28+
import com.squareup.leakcanary.LeakCanary;
2629
import com.xabber.android.BuildConfig;
2730
import com.xabber.android.R;
2831
import com.xabber.android.data.account.AccountManager;
@@ -57,8 +60,8 @@
5760
import com.xabber.android.data.roster.RosterManager;
5861
import com.xabber.android.data.xaccount.XabberAccountManager;
5962
import com.xabber.android.service.XabberService;
63+
import com.xabber.android.utils.AppBlockCanaryContext;
6064

61-
import io.fabric.sdk.android.Fabric;
6265
import org.jivesoftware.smack.provider.ProviderFileLoader;
6366
import org.jivesoftware.smack.provider.ProviderManager;
6467

@@ -74,6 +77,8 @@
7477
import java.util.concurrent.Future;
7578
import java.util.concurrent.ThreadFactory;
7679

80+
import io.fabric.sdk.android.Fabric;
81+
7782
/**
7883
* Base entry point.
7984
*
@@ -304,6 +309,30 @@ public boolean isClosing() {
304309
@Override
305310
public void onCreate() {
306311
super.onCreate();
312+
313+
if (BuildConfig.DEBUG) {
314+
/** Leak Canary */
315+
if (LeakCanary.isInAnalyzerProcess(this)) {
316+
// This process is dedicated to LeakCanary for heap analysis.
317+
// You should not init your app in this process.
318+
return;
319+
}
320+
LeakCanary.install(this);
321+
322+
/** Block Canary */
323+
BlockCanary.install(this, new AppBlockCanaryContext()).start();
324+
325+
/** Android Dev Metrics */
326+
AndroidDevMetrics.initWith(this);
327+
328+
/** Strict Mode */
329+
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
330+
.detectAll()
331+
.penaltyLog()
332+
.build());
333+
}
334+
335+
/** Crashlytics */
307336
// Set up Crashlytics, disabled for debug builds
308337
Crashlytics crashlyticsKit = new Crashlytics.Builder()
309338
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
@@ -314,10 +343,6 @@ public void onCreate() {
314343
Fabric.with(this, crashlyticsKit);
315344
}
316345

317-
if (BuildConfig.DEBUG) {
318-
AndroidDevMetrics.initWith(this);
319-
}
320-
321346
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
322347

323348
addManagers();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.xabber.android.utils;
2+
3+
import com.github.moduth.blockcanary.BlockCanaryContext;
4+
import com.xabber.android.BuildConfig;
5+
6+
7+
/**
8+
* Configuration class. Used in Block Canary - ui-block detection library for Android
9+
*/
10+
11+
public class AppBlockCanaryContext extends BlockCanaryContext {
12+
13+
public String provideQualifier() {
14+
return BuildConfig.VERSION_NAME;
15+
}
16+
17+
public int provideBlockThreshold() {
18+
return 1000;
19+
}
20+
}

0 commit comments

Comments
 (0)