Skip to content

Commit 6b7c251

Browse files
committed
适配gradle 3.6.3
1 parent ed68839 commit 6b7c251

File tree

17 files changed

+78
-80
lines changed

17 files changed

+78
-80
lines changed

blockcanary-analyzer/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ android {
2020
}
2121

2222
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
23+
api fileTree(dir: 'libs', include: ['*.jar'])
2424
}

blockcanary-analyzer/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:android="http://schemas.android.com/apk/res/android">
44

55
<!-- To store the heap dumps and leak analysis results. -->
6+
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
67
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
78
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
89

blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/BlockCanaryInternals.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.github.moduth.blockcanary;
1717

18-
import android.os.Environment;
1918
import android.os.Looper;
2019

2120
import com.github.moduth.blockcanary.internal.BlockInfo;
@@ -116,15 +115,7 @@ long getSampleDelay() {
116115
}
117116

118117
static String getPath() {
119-
String state = Environment.getExternalStorageState();
120-
String logPath = BlockCanaryInternals.getContext()
121-
== null ? "" : BlockCanaryInternals.getContext().providePath();
122-
123-
if (Environment.MEDIA_MOUNTED.equals(state)
124-
&& Environment.getExternalStorageDirectory().canWrite()) {
125-
return Environment.getExternalStorageDirectory().getPath() + logPath;
126-
}
127-
return getContext().provideContext().getFilesDir() + BlockCanaryInternals.getContext().providePath();
118+
return getContext().provideContext().getFilesDir().getPath() + BlockCanaryInternals.getContext().providePath();
128119
}
129120

130121
static File detectedBlockDirectory() {

blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LogWriter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ private static String save(String logFileName, String str) {
105105
+ logFileName + "-"
106106
+ FILE_NAME_FORMATTER.format(time) + ".log";
107107

108-
OutputStreamWriter out =
109-
new OutputStreamWriter(new FileOutputStream(path, true), "UTF-8");
108+
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path, true), "UTF-8");
110109

111110
writer = new BufferedWriter(out);
112111

blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/internal/BlockInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.github.moduth.blockcanary.internal;
1717

18+
import android.annotation.SuppressLint;
1819
import android.content.Context;
1920
import android.content.pm.PackageInfo;
2021
import android.os.Build;
@@ -31,6 +32,7 @@
3132
/**
3233
* Information to trace a block.
3334
*/
35+
@SuppressLint("HardwareIds")
3436
public class BlockInfo {
3537

3638
private static final String TAG = "BlockInfo";

blockcanary-android-no-op/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ android {
2020
}
2121

2222
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
23+
api fileTree(dir: 'libs', include: ['*.jar'])
2424
}

blockcanary-android/build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ android {
2020
}
2121

2222
dependencies {
23-
compile fileTree(include: ['*.jar'], dir: 'libs')
24-
// compile project(':blockcanary-analyzer')
25-
compile 'com.github.markzhai:blockcanary-analyzer:1.5.0'
23+
api fileTree(include: ['*.jar'], dir: 'libs')
24+
api project(':blockcanary-analyzer')
25+
api 'androidx.appcompat:appcompat:1.3.1'
26+
// api 'com.github.markzhai:blockcanary-analyzer:1.5.0'
27+
28+
// use to display notification
2629
}

blockcanary-android/src/main/java/com/github/moduth/blockcanary/DisplayService.java

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,24 @@
1515
*/
1616
package com.github.moduth.blockcanary;
1717

18-
import android.annotation.TargetApi;
18+
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
19+
import static android.os.Build.VERSION.SDK_INT;
20+
import static android.os.Build.VERSION_CODES.JELLY_BEAN;
21+
1922
import android.app.Notification;
23+
import android.app.NotificationChannel;
2024
import android.app.NotificationManager;
2125
import android.app.PendingIntent;
2226
import android.content.Context;
2327
import android.content.Intent;
24-
import android.util.Log;
28+
import android.os.Build;
29+
30+
import androidx.core.app.NotificationCompat;
31+
import androidx.core.app.NotificationManagerCompat;
2532

2633
import com.github.moduth.blockcanary.internal.BlockInfo;
2734
import com.github.moduth.blockcanary.ui.DisplayActivity;
2835

29-
import java.lang.reflect.InvocationTargetException;
30-
import java.lang.reflect.Method;
31-
32-
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
33-
import static android.os.Build.VERSION.SDK_INT;
34-
import static android.os.Build.VERSION_CODES.HONEYCOMB;
35-
import static android.os.Build.VERSION_CODES.JELLY_BEAN;
36-
3736
final class DisplayService implements BlockInterceptor {
3837

3938
private static final String TAG = "DisplayService";
@@ -49,39 +48,29 @@ public void onBlock(Context context, BlockInfo blockInfo) {
4948
show(context, contentTitle, contentText, pendingIntent);
5049
}
5150

52-
@TargetApi(HONEYCOMB)
5351
private void show(Context context, String contentTitle, String contentText, PendingIntent pendingIntent) {
54-
NotificationManager notificationManager = (NotificationManager)
55-
context.getSystemService(Context.NOTIFICATION_SERVICE);
52+
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
5653

5754
Notification notification;
58-
if (SDK_INT < HONEYCOMB) {
59-
notification = new Notification();
60-
notification.icon = R.drawable.block_canary_notification;
61-
notification.when = System.currentTimeMillis();
62-
notification.flags |= Notification.FLAG_AUTO_CANCEL;
63-
notification.defaults = Notification.DEFAULT_SOUND;
64-
try {
65-
Method deprecatedMethod = notification.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class);
66-
deprecatedMethod.invoke(notification, context, contentTitle, contentText, pendingIntent);
67-
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException
68-
| InvocationTargetException e) {
69-
Log.w(TAG, "Method not found", e);
70-
}
55+
String packageName = context.getPackageName();
56+
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, packageName)
57+
.setSmallIcon(R.drawable.block_canary_notification)
58+
.setWhen(System.currentTimeMillis())
59+
.setContentTitle(contentTitle)
60+
.setContentText(contentText)
61+
.setAutoCancel(true)
62+
.setContentIntent(pendingIntent)
63+
.setDefaults(Notification.DEFAULT_SOUND);
64+
if (SDK_INT >= Build.VERSION_CODES.O) {
65+
NotificationChannel notificationChannel = new NotificationChannel(packageName, packageName, NotificationManager.IMPORTANCE_LOW);
66+
notificationChannel.setDescription(packageName);
67+
notificationChannel.setShowBadge(false);
68+
notificationManager.createNotificationChannel(notificationChannel);
69+
}
70+
if (SDK_INT < JELLY_BEAN) {
71+
notification = builder.getNotification();
7172
} else {
72-
Notification.Builder builder = new Notification.Builder(context)
73-
.setSmallIcon(R.drawable.block_canary_notification)
74-
.setWhen(System.currentTimeMillis())
75-
.setContentTitle(contentTitle)
76-
.setContentText(contentText)
77-
.setAutoCancel(true)
78-
.setContentIntent(pendingIntent)
79-
.setDefaults(Notification.DEFAULT_SOUND);
80-
if (SDK_INT < JELLY_BEAN) {
81-
notification = builder.getNotification();
82-
} else {
83-
notification = builder.build();
84-
}
73+
notification = builder.build();
8574
}
8675
notificationManager.notify(0xDEAFBEEF, notification);
8776
}

blockcanary-sample/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ android {
2020
}
2121

2222
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
24-
debugCompile project(':blockcanary-android')
25-
releaseCompile project(':blockcanary-android-no-op')
23+
implementation fileTree(dir: 'libs', include: ['*.jar'])
2624

27-
compile 'com.android.support:appcompat-v7:24.2.0'
28-
compile 'com.android.support:design:24.2.0'
25+
debugImplementation project(':blockcanary-android')
26+
releaseImplementation project(':blockcanary-android-no-op')
27+
28+
implementation 'com.google.android.material:material:1.4.0'
2929
}

blockcanary-sample/src/main/java/com/example/blockcanary/AppContext.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
*/
1616
package com.example.blockcanary;
1717

18+
import android.content.Context;
1819
import android.content.pm.PackageInfo;
1920
import android.content.pm.PackageManager;
2021
import android.util.Log;
2122

2223
import com.github.moduth.blockcanary.BlockCanaryContext;
24+
import com.github.moduth.blockcanary.internal.BlockInfo;
2325

2426
import java.util.List;
2527

@@ -56,12 +58,12 @@ public int provideMonitorDuration() {
5658

5759
@Override
5860
public int provideBlockThreshold() {
59-
return 500;
61+
return 16;
6062
}
6163

6264
@Override
6365
public boolean displayNotification() {
64-
return BuildConfig.DEBUG;
66+
return true;
6567
}
6668

6769
@Override
@@ -82,4 +84,8 @@ public List<String> provideWhiteList() {
8284
public boolean stopWhenDebugging() {
8385
return true;
8486
}
87+
88+
@Override
89+
public void onBlock(Context context, BlockInfo blockInfo) {
90+
}
8591
}

0 commit comments

Comments
 (0)