Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target28 #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion blockcanary-analyzer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class BlockCanaryInternals {

LooperMonitor monitor;
StackSampler stackSampler;
CpuSampler cpuSampler;
//CpuSampler cpuSampler;

private static BlockCanaryInternals sInstance;
private static BlockCanaryContext sContext;
Expand All @@ -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() {

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// }
}
}
1 change: 0 additions & 1 deletion blockcanary-android-no-op/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions blockcanary-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void stop() {
mMonitorStarted = false;
Looper.getMainLooper().setMessageLogging(null);
mBlockCanaryCore.stackSampler.stop();
mBlockCanaryCore.cpuSampler.stop();
//mBlockCanaryCore.cpuSampler.stop();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
}
}
}
10 changes: 6 additions & 4 deletions blockcanary-sample/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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'
}
23 changes: 23 additions & 0 deletions blockcanary-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<manifest package="com.example.blockcanary"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_LOGS" />
<!--使用可视化操作命名功能需配置悬浮窗权限(选配)-->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />

<application
android:name=".DemoApplication"
android:allowBackup="true"
Expand All @@ -18,8 +27,22 @@
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />

<data
android:host="debugmode"
android:scheme="sa8a9ab067" />
</intent-filter>
</activity>

<meta-data
android:name="com.sensorsdata.analytics.android.EnableLogging"
android:value="true" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int provideBlockThreshold() {

@Override
public boolean displayNotification() {
return BuildConfig.DEBUG;
return true;
}

@Override
Expand All @@ -80,6 +80,6 @@ public List<String> provideWhiteList() {

@Override
public boolean stopWhenDebugging() {
return true;
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,48 @@
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();
}

public static Context getAppContext() {
return sContext;
}

/**
* 初始化 Sensors Analytics SDK
*/
private void initSensorsDataAPI() {
SensorsDataAPI.sharedInstance(this, new SAConfigOptions(SA_SERVER_URL));
// 打开自动采集, 并指定追踪哪些 AutoTrack 事件
List<SensorsDataAPI.AutoTrackEventType> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ 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'
}
}

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
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ org.gradle.jvmargs=-Xmx8192M
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
android.useDeprecatedNdk=true
//android.useDeprecatedNdk=true
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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