diff --git a/blockcanary-analyzer/build.gradle b/blockcanary-analyzer/build.gradle
index 83af379..778beba 100644
--- a/blockcanary-analyzer/build.gradle
+++ b/blockcanary-analyzer/build.gradle
@@ -3,7 +3,6 @@ apply from: 'gradle-mvn-push.gradle'
android {
compileSdkVersion LIBRARY_COMPILE_SDK_VERSION
- buildToolsVersion LIBRARY_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion LIBRARY_MIN_SDK_VERSION
diff --git a/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/BlockCanaryInternals.java b/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/BlockCanaryInternals.java
index 895d0d6..648e4ca 100644
--- a/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/BlockCanaryInternals.java
+++ b/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/BlockCanaryInternals.java
@@ -30,7 +30,7 @@ public final class BlockCanaryInternals {
LooperMonitor monitor;
StackSampler stackSampler;
- CpuSampler cpuSampler;
+ //CpuSampler cpuSampler;
private static BlockCanaryInternals sInstance;
private static BlockCanaryContext sContext;
@@ -43,7 +43,7 @@ public BlockCanaryInternals() {
Looper.getMainLooper().getThread(),
sContext.provideDumpInterval());
- cpuSampler = new CpuSampler(sContext.provideDumpInterval());
+ //cpuSampler = new CpuSampler(sContext.provideDumpInterval());
setMonitor(new LooperMonitor(new LooperMonitor.BlockListener() {
@@ -56,8 +56,8 @@ public void onBlockEvent(long realTimeStart, long realTimeEnd,
if (!threadStackEntries.isEmpty()) {
BlockInfo blockInfo = BlockInfo.newInstance()
.setMainThreadTimeCost(realTimeStart, realTimeEnd, threadTimeStart, threadTimeEnd)
- .setCpuBusyFlag(cpuSampler.isCpuBusy(realTimeStart, realTimeEnd))
- .setRecentCpuRate(cpuSampler.getCpuRateInfo())
+ //.setCpuBusyFlag(cpuSampler.isCpuBusy(realTimeStart, realTimeEnd))
+ //.setRecentCpuRate(cpuSampler.getCpuRateInfo())
.setThreadStackEntries(threadStackEntries)
.flushString();
LogWriter.save(blockInfo.toString());
diff --git a/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LooperMonitor.java b/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LooperMonitor.java
index 3b697e6..03efe41 100644
--- a/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LooperMonitor.java
+++ b/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LooperMonitor.java
@@ -87,18 +87,18 @@ private void startDump() {
BlockCanaryInternals.getInstance().stackSampler.start();
}
- if (null != BlockCanaryInternals.getInstance().cpuSampler) {
- BlockCanaryInternals.getInstance().cpuSampler.start();
- }
+// if (null != BlockCanaryInternals.getInstance().cpuSampler) {
+// BlockCanaryInternals.getInstance().cpuSampler.start();
+// }
}
private void stopDump() {
if (null != BlockCanaryInternals.getInstance().stackSampler) {
BlockCanaryInternals.getInstance().stackSampler.stop();
}
-
- if (null != BlockCanaryInternals.getInstance().cpuSampler) {
- BlockCanaryInternals.getInstance().cpuSampler.stop();
- }
+//
+// if (null != BlockCanaryInternals.getInstance().cpuSampler) {
+// BlockCanaryInternals.getInstance().cpuSampler.stop();
+// }
}
}
\ No newline at end of file
diff --git a/blockcanary-android-no-op/build.gradle b/blockcanary-android-no-op/build.gradle
index 83af379..778beba 100644
--- a/blockcanary-android-no-op/build.gradle
+++ b/blockcanary-android-no-op/build.gradle
@@ -3,7 +3,6 @@ apply from: 'gradle-mvn-push.gradle'
android {
compileSdkVersion LIBRARY_COMPILE_SDK_VERSION
- buildToolsVersion LIBRARY_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion LIBRARY_MIN_SDK_VERSION
diff --git a/blockcanary-android/build.gradle b/blockcanary-android/build.gradle
index ebe613e..b048479 100644
--- a/blockcanary-android/build.gradle
+++ b/blockcanary-android/build.gradle
@@ -3,7 +3,6 @@ apply from: 'gradle-mvn-push.gradle'
android {
compileSdkVersion LIBRARY_COMPILE_SDK_VERSION
- buildToolsVersion LIBRARY_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion LIBRARY_MIN_SDK_VERSION
@@ -21,6 +20,7 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
-// compile project(':blockcanary-analyzer')
- compile 'com.github.markzhai:blockcanary-analyzer:1.5.0'
+ compile project(':blockcanary-analyzer')
+ // compile 'com.github.markzhai:blockcanary-analyzer:1.5.0'
+ implementation "com.android.support:support-compat:28.0.0"
}
diff --git a/blockcanary-android/src/main/java/com/github/moduth/blockcanary/BlockCanary.java b/blockcanary-android/src/main/java/com/github/moduth/blockcanary/BlockCanary.java
index edc0858..af5229a 100644
--- a/blockcanary-android/src/main/java/com/github/moduth/blockcanary/BlockCanary.java
+++ b/blockcanary-android/src/main/java/com/github/moduth/blockcanary/BlockCanary.java
@@ -96,7 +96,7 @@ public void stop() {
mMonitorStarted = false;
Looper.getMainLooper().setMessageLogging(null);
mBlockCanaryCore.stackSampler.stop();
- mBlockCanaryCore.cpuSampler.stop();
+ //mBlockCanaryCore.cpuSampler.stop();
}
}
diff --git a/blockcanary-android/src/main/java/com/github/moduth/blockcanary/DisplayService.java b/blockcanary-android/src/main/java/com/github/moduth/blockcanary/DisplayService.java
index 7d71590..34b93d3 100644
--- a/blockcanary-android/src/main/java/com/github/moduth/blockcanary/DisplayService.java
+++ b/blockcanary-android/src/main/java/com/github/moduth/blockcanary/DisplayService.java
@@ -17,10 +17,13 @@
import android.annotation.TargetApi;
import android.app.Notification;
+import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
+import android.os.Build;
+import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.github.moduth.blockcanary.internal.BlockInfo;
@@ -37,6 +40,7 @@
final class DisplayService implements BlockInterceptor {
private static final String TAG = "DisplayService";
+ private static final String CHANNEL_ID = "test232342";
@Override
public void onBlock(Context context, BlockInfo blockInfo) {
@@ -49,7 +53,6 @@ public void onBlock(Context context, BlockInfo blockInfo) {
show(context, contentTitle, contentText, pendingIntent);
}
- @TargetApi(HONEYCOMB)
private void show(Context context, String contentTitle, String contentText, PendingIntent pendingIntent) {
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -69,20 +72,42 @@ private void show(Context context, String contentTitle, String contentText, Pend
Log.w(TAG, "Method not found", e);
}
} else {
- Notification.Builder builder = new Notification.Builder(context)
+
+
+ createNotificationChannel(context);
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.block_canary_notification)
.setWhen(System.currentTimeMillis())
.setContentTitle(contentTitle)
.setContentText(contentText)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
- .setDefaults(Notification.DEFAULT_SOUND);
+ .setDefaults(Notification.DEFAULT_SOUND)
+ .setPriority(NotificationCompat.PRIORITY_DEFAULT);
+
if (SDK_INT < JELLY_BEAN) {
notification = builder.getNotification();
} else {
notification = builder.build();
}
}
- notificationManager.notify(0xDEAFBEEF, notification);
+ notificationManager.notify(999, notification);
+ }
+
+ private void createNotificationChannel(Context context) {
+ // Create the NotificationChannel, but only on API 26+ because
+ // the NotificationChannel class is new and not in the support library
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ CharSequence name = "canary_channel";
+ String description = "canary_channecl_desc";
+ int importance = NotificationManager.IMPORTANCE_DEFAULT;
+
+ NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
+ channel.setDescription(description);
+ // Register the channel with the system; you can't change the importance
+ // or other notification behaviors after this
+ NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(channel);
+ }
}
}
diff --git a/blockcanary-sample/build.gradle b/blockcanary-sample/build.gradle
index 32d69b8..99181c2 100644
--- a/blockcanary-sample/build.gradle
+++ b/blockcanary-sample/build.gradle
@@ -1,12 +1,13 @@
apply plugin: 'com.android.application'
+//添加 com.sensorsdata.analytics.android 插件
+apply plugin: 'com.sensorsdata.analytics.android'
android {
compileSdkVersion LIBRARY_COMPILE_SDK_VERSION
- buildToolsVersion LIBRARY_BUILD_TOOLS_VERSION
defaultConfig {
applicationId "com.example.blockcanary"
- minSdkVersion LIBRARY_MIN_SDK_VERSION
+ minSdkVersion 15
targetSdkVersion LIBRARY_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
@@ -24,6 +25,7 @@ dependencies {
debugCompile project(':blockcanary-android')
releaseCompile project(':blockcanary-android-no-op')
- compile 'com.android.support:appcompat-v7:24.2.0'
- compile 'com.android.support:design:24.2.0'
+ compile 'com.android.support:appcompat-v7:28.0.0'
+ compile 'com.android.support:design:28.0.0'
+ compile 'com.sensorsdata.analytics.android:SensorsAnalyticsSDK:3.2.0'
}
diff --git a/blockcanary-sample/src/main/AndroidManifest.xml b/blockcanary-sample/src/main/AndroidManifest.xml
index fbf6d6b..d505b8a 100644
--- a/blockcanary-sample/src/main/AndroidManifest.xml
+++ b/blockcanary-sample/src/main/AndroidManifest.xml
@@ -2,6 +2,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/blockcanary-sample/src/main/java/com/example/blockcanary/AppContext.java b/blockcanary-sample/src/main/java/com/example/blockcanary/AppContext.java
index 612df72..0e1f964 100644
--- a/blockcanary-sample/src/main/java/com/example/blockcanary/AppContext.java
+++ b/blockcanary-sample/src/main/java/com/example/blockcanary/AppContext.java
@@ -61,7 +61,7 @@ public int provideBlockThreshold() {
@Override
public boolean displayNotification() {
- return BuildConfig.DEBUG;
+ return true;
}
@Override
@@ -80,6 +80,6 @@ public List provideWhiteList() {
@Override
public boolean stopWhenDebugging() {
- return true;
+ return false;
}
}
\ No newline at end of file
diff --git a/blockcanary-sample/src/main/java/com/example/blockcanary/DemoApplication.java b/blockcanary-sample/src/main/java/com/example/blockcanary/DemoApplication.java
index 7405f27..5999ec1 100644
--- a/blockcanary-sample/src/main/java/com/example/blockcanary/DemoApplication.java
+++ b/blockcanary-sample/src/main/java/com/example/blockcanary/DemoApplication.java
@@ -19,14 +19,24 @@
import android.content.Context;
import com.github.moduth.blockcanary.BlockCanary;
+import com.sensorsdata.analytics.android.sdk.SAConfigOptions;
+import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
+
+import java.util.ArrayList;
+import java.util.List;
public class DemoApplication extends Application {
private static Context sContext;
+ /**
+ * Sensors Analytics 采集数据的地址
+ */
+ private final static String SA_SERVER_URL = "https://sdkdebugtest.datasink.sensorsdata.cn/sa?project=default&token=cfb8b60e42e0ae9b";
@Override
public void onCreate() {
super.onCreate();
+ initSensorsDataAPI();
sContext = this;
BlockCanary.install(this, new AppContext()).start();
}
@@ -34,4 +44,23 @@ public void onCreate() {
public static Context getAppContext() {
return sContext;
}
+
+ /**
+ * 初始化 Sensors Analytics SDK
+ */
+ private void initSensorsDataAPI() {
+ SensorsDataAPI.sharedInstance(this, new SAConfigOptions(SA_SERVER_URL));
+ // 打开自动采集, 并指定追踪哪些 AutoTrack 事件
+ List eventTypeList = new ArrayList<>();
+ // $AppStart
+ eventTypeList.add(SensorsDataAPI.AutoTrackEventType.APP_START);
+ // $AppEnd
+ eventTypeList.add(SensorsDataAPI.AutoTrackEventType.APP_END);
+ // $AppViewScreen
+ eventTypeList.add(SensorsDataAPI.AutoTrackEventType.APP_VIEW_SCREEN);
+ // $AppClick
+ eventTypeList.add(SensorsDataAPI.AutoTrackEventType.APP_CLICK);
+ SensorsDataAPI.sharedInstance(this).enableAutoTrack(eventTypeList);
+ SensorsDataAPI.sharedInstance().setSessionIntervalTime(20 * 1000);
+ }
}
diff --git a/blockcanary-sample/src/main/java/com/example/blockcanary/DemoFragment.java b/blockcanary-sample/src/main/java/com/example/blockcanary/DemoFragment.java
index 25b77ca..73c02ed 100644
--- a/blockcanary-sample/src/main/java/com/example/blockcanary/DemoFragment.java
+++ b/blockcanary-sample/src/main/java/com/example/blockcanary/DemoFragment.java
@@ -24,6 +24,8 @@
import android.view.ViewGroup;
import android.widget.Button;
+import com.sensorsdata.analytics.android.sdk.SensorsDataTrackViewOnClick;
+
import java.io.FileInputStream;
import java.io.IOException;
@@ -68,12 +70,13 @@ public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
+ @SensorsDataTrackViewOnClick
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
try {
- Thread.sleep(2000);
+ Thread.sleep(1300);
} catch (InterruptedException e) {
e.printStackTrace();
Log.e(DEMO_FRAGMENT, "onClick of R.id.button1: ", e);
diff --git a/build.gradle b/build.gradle
index 2e498be..3d68f68 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,9 +4,12 @@ buildscript {
repositories {
mavenCentral()
jcenter()
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.2.2'
+ classpath 'com.android.tools.build:gradle:3.4.1'
+ //添加神策分析 android-gradle-plugin 依赖
+ classpath 'com.sensorsdata.analytics.android:android-gradle-plugin2:3.1.0'
}
}
@@ -14,11 +17,11 @@ allprojects {
repositories {
mavenCentral()
jcenter()
+ google()
}
ext {
- LIBRARY_COMPILE_SDK_VERSION = 23
- LIBRARY_BUILD_TOOLS_VERSION = "23.0.3"
- LIBRARY_MIN_SDK_VERSION = 9
- LIBRARY_TARGET_SDK_VERSION = 22
+ LIBRARY_COMPILE_SDK_VERSION = 28
+ LIBRARY_MIN_SDK_VERSION = 15
+ LIBRARY_TARGET_SDK_VERSION = 28
}
}
diff --git a/gradle.properties b/gradle.properties
index d4b7bce..2942881 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -18,4 +18,4 @@ org.gradle.jvmargs=-Xmx8192M
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
-android.useDeprecatedNdk=true
\ No newline at end of file
+//android.useDeprecatedNdk=true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 586936a..1b81b82 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Apr 13 16:42:11 CST 2016
+#Mon Jul 22 16:06:00 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip