Skip to content

Commit

Permalink
Added debug-libraries: leakcanary and blockcanary
Browse files Browse the repository at this point in the history
Up version to 468
  • Loading branch information
Str4tocaster committed Mar 16, 2018
1 parent 594ad22 commit a4d0b20
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
13 changes: 11 additions & 2 deletions xabber/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 467
versionName '2.2.1(467)'
versionCode 468
versionName '2.2.1(468)'
}

lintOptions {
Expand Down Expand Up @@ -193,6 +193,15 @@ dependencies {
}

implementation group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: '1.58'

// leak canary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

// block canary
debugImplementation 'com.github.markzhai:blockcanary-android:1.5.0'
releaseCompile 'com.github.markzhai:blockcanary-no-op:1.5.0'

}
apply plugin: 'com.google.gms.google-services'

Expand Down
35 changes: 30 additions & 5 deletions xabber/src/main/java/com/xabber/android/data/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.StrictMode;
import android.support.annotation.NonNull;
import android.support.multidex.MultiDex;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore;
import com.frogermcs.androiddevmetrics.AndroidDevMetrics;
import com.github.moduth.blockcanary.BlockCanary;
import com.squareup.leakcanary.LeakCanary;
import com.xabber.android.BuildConfig;
import com.xabber.android.R;
import com.xabber.android.data.account.AccountManager;
Expand Down Expand Up @@ -57,8 +60,8 @@
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.data.xaccount.XabberAccountManager;
import com.xabber.android.service.XabberService;
import com.xabber.android.utils.AppBlockCanaryContext;

import io.fabric.sdk.android.Fabric;
import org.jivesoftware.smack.provider.ProviderFileLoader;
import org.jivesoftware.smack.provider.ProviderManager;

Expand All @@ -74,6 +77,8 @@
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;

import io.fabric.sdk.android.Fabric;

/**
* Base entry point.
*
Expand Down Expand Up @@ -304,6 +309,30 @@ public boolean isClosing() {
@Override
public void onCreate() {
super.onCreate();

if (BuildConfig.DEBUG) {
/** Leak Canary */
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);

/** Block Canary */
BlockCanary.install(this, new AppBlockCanaryContext()).start();

/** Android Dev Metrics */
AndroidDevMetrics.initWith(this);

/** Strict Mode */
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
}

/** Crashlytics */
// Set up Crashlytics, disabled for debug builds
Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
Expand All @@ -314,10 +343,6 @@ public void onCreate() {
Fabric.with(this, crashlyticsKit);
}

if (BuildConfig.DEBUG) {
AndroidDevMetrics.initWith(this);
}

Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

addManagers();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.xabber.android.utils;

import com.github.moduth.blockcanary.BlockCanaryContext;
import com.xabber.android.BuildConfig;


/**
* Configuration class. Used in Block Canary - ui-block detection library for Android
*/

public class AppBlockCanaryContext extends BlockCanaryContext {

public String provideQualifier() {
return BuildConfig.VERSION_NAME;
}

public int provideBlockThreshold() {
return 1000;
}
}

0 comments on commit a4d0b20

Please sign in to comment.