├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── blockcanary-android-no-op ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── github │ │ └── moduth │ │ └── blockcanary │ │ ├── internal │ │ └── BlockInfo.java │ │ ├── BlockCanary.java │ │ └── BlockCanaryContext.java ├── proguard-rules.pro └── build.gradle ├── blockcanary-sample ├── src │ └── main │ │ ├── res │ │ ├── drawable │ │ │ ├── ic_done.png │ │ │ ├── btn_select.xml │ │ │ ├── background_splash.xml │ │ │ ├── btn_nor.xml │ │ │ └── btn_pre.xml │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── menu │ │ │ └── menu_demo.xml │ │ ├── values-zh │ │ │ └── strings.xml │ │ └── layout │ │ │ ├── activity_demo.xml │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── example │ │ └── blockcanary │ │ ├── DemoApplication.java │ │ ├── AppContext.java │ │ ├── DemoActivity.java │ │ └── DemoFragment.java ├── proguard-rules.pro └── build.gradle ├── blockcanary-analyzer ├── src │ └── main │ │ ├── res │ │ └── values │ │ │ └── int.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── github │ │ └── moduth │ │ └── blockcanary │ │ ├── BlockInterceptor.java │ │ ├── internal │ │ ├── BackgroundUtil.java │ │ ├── GetSingleCpuRateInfoUtils.java │ │ ├── CpuInfo.java │ │ ├── ProcessUtils.java │ │ ├── PerformanceUtils.java │ │ └── BlockInfo.java │ │ ├── HandlerThreadFactory.java │ │ ├── AbstractSampler.java │ │ ├── StackSampler.java │ │ ├── LooperMonitor.java │ │ ├── LogWriter.java │ │ ├── BlockCanaryInternals.java │ │ ├── BlockCanaryContext.java │ │ └── CpuSampler.java ├── proguard-rules.pro └── build.gradle ├── blockcanary-android ├── src │ └── main │ │ ├── res │ │ ├── drawable-xhdpi │ │ │ ├── block_canary_icon.png │ │ │ └── block_canary_notification.png │ │ ├── values │ │ │ ├── themes.xml │ │ │ └── strings.xml │ │ ├── values-v14 │ │ │ └── themes.xml │ │ ├── values-v21 │ │ │ └── themes.xml │ │ └── layout │ │ │ ├── block_canary_ref_top_row.xml │ │ │ ├── block_canary_block_row.xml │ │ │ ├── block_canary_display_leak.xml │ │ │ └── block_canary_ref_row.xml │ │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── moduth │ │ │ └── blockcanary │ │ │ ├── ui │ │ │ ├── BlockInfoCorruptException.java │ │ │ ├── MoreDetailsView.java │ │ │ ├── BlockCanaryUi.java │ │ │ ├── BlockCanaryUtils.java │ │ │ ├── DisplayConnectorView.java │ │ │ ├── BlockInfoEx.java │ │ │ ├── DetailAdapter.java │ │ │ └── DisplayActivity.java │ │ │ ├── SingleThreadFactory.java │ │ │ ├── Uploader.java │ │ │ ├── DisplayService.java │ │ │ └── BlockCanary.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── README.md ├── CHANGELOG.md ├── gradle.properties ├── gradlew.bat ├── gradlew └── LICENSE /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BzCoder/BlockCanaryCompat/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':blockcanary-android-no-op' 2 | include ':blockcanary-analyzer' 3 | include ':blockcanary-android' 4 | include ':blockcanary-sample' -------------------------------------------------------------------------------- /blockcanary-android-no-op/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/drawable/ic_done.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BzCoder/BlockCanaryCompat/HEAD/blockcanary-sample/src/main/res/drawable/ic_done.png -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BzCoder/BlockCanaryCompat/HEAD/blockcanary-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /blockcanary-analyzer/src/main/res/values/int.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 500 4 | -------------------------------------------------------------------------------- /blockcanary-android-no-op/src/main/java/com/github/moduth/blockcanary/internal/BlockInfo.java: -------------------------------------------------------------------------------- 1 | package com.github.moduth.blockcanary.internal; 2 | 3 | public class BlockInfo { 4 | } 5 | -------------------------------------------------------------------------------- /blockcanary-android/src/main/res/drawable-xhdpi/block_canary_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BzCoder/BlockCanaryCompat/HEAD/blockcanary-android/src/main/res/drawable-xhdpi/block_canary_icon.png -------------------------------------------------------------------------------- /blockcanary-android/src/main/res/drawable-xhdpi/block_canary_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BzCoder/BlockCanaryCompat/HEAD/blockcanary-android/src/main/res/drawable-xhdpi/block_canary_notification.png -------------------------------------------------------------------------------- /blockcanary-android/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /blockcanary-android/src/main/res/values-v14/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /blockcanary-android/src/main/res/values-v21/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFF5F5F5 4 | 5 | #2196F3 6 | #1976D2 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 13 16:42:11 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/menu/menu_demo.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/drawable/btn_select.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/drawable/background_splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/drawable/btn_nor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/drawable/btn_pre.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /blockcanary-analyzer/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 0dp 7 | 48dp 8 | 48dp 9 | 0.5dp 10 | 11 | -------------------------------------------------------------------------------- /blockcanary-android/src/main/res/layout/block_canary_ref_top_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/values-zh/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BlockCanary 3 | 4 | 点击按钮后,会触发主线程耗时时间,从而被BlockCanary,并记录卡慢日志,弹出notification,可以点击对应消息查看 5 | 线程\n等待\n阻塞 6 | IO\n阻塞 7 | 计算\n阻塞 8 | 尽请\n期待\n更多 9 | Settings 10 | 11 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BlockCanary 3 | 4 | After click button, main-thread consuming event will be triggered, which would be caught be BlockCanary, write to log file, and use notification to display 5 | Thread\nwait\nblock 6 | IO\nblock 7 | Computation\nblock 8 | Wait\nfor\nmore 9 | Settings 10 | 11 | -------------------------------------------------------------------------------- /blockcanary-android/src/main/java/com/github/moduth/blockcanary/ui/BlockInfoCorruptException.java: -------------------------------------------------------------------------------- 1 | package com.github.moduth.blockcanary.ui; 2 | 3 | import java.util.Locale; 4 | 5 | /** 6 | * @author markzhai on 16/8/24 7 | * @version 1.3.0 8 | */ 9 | public class BlockInfoCorruptException extends Exception { 10 | 11 | public BlockInfoCorruptException(BlockInfoEx blockInfo) { 12 | this(String.format(Locale.US, 13 | "BlockInfo (%s) is corrupt.", blockInfo.logFile.getName())); 14 | } 15 | 16 | public BlockInfoCorruptException(String detailMessage) { 17 | super(detailMessage); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 13 | 14 | 16 | 17 | -------------------------------------------------------------------------------- /blockcanary-sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/yifan/dev/sdk/adt-bundle-mac-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /blockcanary-analyzer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/yifan/dev/sdk/adt-bundle-mac-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /blockcanary-android-no-op/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/yifan/dev/sdk/adt-bundle-mac-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlockCanaryCompat 2 | [ ![Download](https://api.bintray.com/packages/bzcoder/BlockCanaryCompat/blockcanarycompat-android/images/download.svg?version=0.0.4) ](https://bintray.com/bzcoder/BlockCanaryCompat/blockcanarycompat-android/0.0.4/link) 3 | 4 | 修改自[BlockCanary](https://github.com/markzhai/AndroidPerformanceMonitor),适配Android 8.0以上版本。建议阅读源码后,根据生产实际需求修改后使用。 5 | 6 | 引入: 7 | ``` 8 | debugImplementation('com.github.bzcoder:blockcanarycompat-android:0.0.4') 9 | releaseImplementation('com.github.bzcoder:blockcanarycompat-android-no-op:0.0.4') 10 | ``` 11 | 12 | 兼容: 13 | - 高版本不能获取IMEI的问题 14 | - 高版本不弹出通知问题 15 | - 高版本无法获取CPU信息的问题 16 | 17 | 新增: 18 | - App是否在前台选项 19 | - GetSingleCpuRateInfoUtils工具类提取CPU信息单独选项 20 | - reportRecentOneMessage选项,作用为限制上报卡顿信息为一条(如果需要采集线上日志,可配合使用) 21 | -------------------------------------------------------------------------------- /blockcanary-android/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Abner/myData/mySoftware/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Need if enable display in proguarded package -------------------------------------------------------------------------------- /blockcanary-android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /blockcanary-android/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Blocks 3 | Share info 4 | Share stack dump 5 | Share with… 6 | Blocks in %s 7 | Delete 8 | Delete all 9 | Are you sure to delete all records? 10 | blocked %s ms 11 | Click for more details 12 | Yes 13 | No 14 | 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | You can watch releases [on Maven](https://oss.sonatype.org/content/groups/public/com/github/markzhai/). 4 | 5 | ## Version 1.5 *(2017-02-26)* 6 | 7 | Debug mode stop monitor. 8 | 9 | ## Version 1.4 *(2016-11-02)* 10 | 11 | - Bug fix. 12 | - Add onBlock interceptor. 13 | 14 | ### 1.4.1 (2017-01-19) 15 | 16 | - Bug fix 17 | 18 | ## Version 1.3 *(2016-08-24)* 19 | 20 | - Code refactor. 21 | - Support white-list and concern packages. 22 | 23 | ## Version 1.2 *(2016-03-16)* 24 | 25 | - Much faster! It now has almost none side-effect at run-time. 26 | 27 | ## Version 1.1 *(2016-01-23)* 28 | 29 | - Extract blockcanary to three modules. 30 | - Provide default implementation for BlockCanaryContext. 31 | 32 | ### 1.1.1 *(2016-01-25)* 33 | fix issue #19 and #23 34 | 35 | ## Version 1.0 *(2016-01-21)* 36 | 37 | Initial release. 38 | 39 | ### 1.0.1 40 | Fix no-op api not align bug. 41 | 42 | ### 1.0.2 43 | Add notification sound, fix 2.3 crash. 44 | -------------------------------------------------------------------------------- /blockcanary-android/src/main/res/layout/block_canary_block_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/BlockInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 MarkZhai (http://zhaiyifan.cn). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.moduth.blockcanary; 17 | 18 | import android.content.Context; 19 | 20 | import com.github.moduth.blockcanary.internal.BlockInfo; 21 | 22 | interface BlockInterceptor { 23 | void onBlock(Context context, BlockInfo blockInfo); 24 | } 25 | -------------------------------------------------------------------------------- /blockcanary-sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Sat Mar 05 00:07:08 CST 2016 16 | org.gradle.jvmargs=-Xmx8192M 17 | #org.gradle.jvmargs=-Xmx10248m -XX\:MaxPermSize\=512m -XX\:+HeapDumpOnOutOfMemoryError -Dfile.encoding\=UTF-8 18 | org.gradle.daemon=true 19 | org.gradle.configureondemand=true 20 | org.gradle.parallel=true 21 | android.useDeprecatedNdk=true -------------------------------------------------------------------------------- /blockcanary-sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion LIBRARY_COMPILE_SDK_VERSION 5 | buildToolsVersion LIBRARY_BUILD_TOOLS_VERSION 6 | 7 | defaultConfig { 8 | applicationId "com.example.blockcanary" 9 | minSdkVersion LIBRARY_MIN_SDK_VERSION 10 | targetSdkVersion LIBRARY_TARGET_SDK_VERSION 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | // debugImplementation('com.github.bzcoder:blockcanarycompat-android:0.0.4') 25 | // releaseImplementation('com.github.bzcoder:blockcanarycompat-android-no-op:0.0.4') 26 | api project(':blockcanary-android-no-op') 27 | // 28 | implementation('com.android.support:appcompat-v7:27.1.1') 29 | implementation('com.android.support:design:27.1.1') 30 | 31 | } 32 | -------------------------------------------------------------------------------- /blockcanary-android/src/main/res/layout/block_canary_display_leak.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 24 | 25 |