diff --git a/blockcanary-analyzer/build.gradle b/blockcanary-analyzer/build.gradle
index 83af379..b405bb2 100644
--- a/blockcanary-analyzer/build.gradle
+++ b/blockcanary-analyzer/build.gradle
@@ -20,5 +20,5 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
+ api fileTree(dir: 'libs', include: ['*.jar'])
}
diff --git a/blockcanary-analyzer/src/main/AndroidManifest.xml b/blockcanary-analyzer/src/main/AndroidManifest.xml
index 36f52b2..3c73643 100644
--- a/blockcanary-analyzer/src/main/AndroidManifest.xml
+++ b/blockcanary-analyzer/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android">
+
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..f467153 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
@@ -15,7 +15,6 @@
*/
package com.github.moduth.blockcanary;
-import android.os.Environment;
import android.os.Looper;
import com.github.moduth.blockcanary.internal.BlockInfo;
@@ -116,15 +115,15 @@ long getSampleDelay() {
}
static String getPath() {
- String state = Environment.getExternalStorageState();
- String logPath = BlockCanaryInternals.getContext()
- == null ? "" : BlockCanaryInternals.getContext().providePath();
-
- if (Environment.MEDIA_MOUNTED.equals(state)
- && Environment.getExternalStorageDirectory().canWrite()) {
- return Environment.getExternalStorageDirectory().getPath() + logPath;
- }
- return getContext().provideContext().getFilesDir() + BlockCanaryInternals.getContext().providePath();
+ //String state = Environment.getExternalStorageState();
+ //String logPath = BlockCanaryInternals.getContext()
+ // == null ? "" : BlockCanaryInternals.getContext().providePath();
+ //
+ //if (Environment.MEDIA_MOUNTED.equals(state)
+ // && Environment.getExternalStorageDirectory().canWrite()) {
+ // return Environment.getExternalStorageDirectory().getPath() + logPath;
+ //}
+ return getContext().provideContext().getFilesDir().getPath() + BlockCanaryInternals.getContext().providePath();
}
static File detectedBlockDirectory() {
diff --git a/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LogWriter.java b/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LogWriter.java
index fab8b72..e16806a 100644
--- a/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LogWriter.java
+++ b/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/LogWriter.java
@@ -105,8 +105,7 @@ private static String save(String logFileName, String str) {
+ logFileName + "-"
+ FILE_NAME_FORMATTER.format(time) + ".log";
- OutputStreamWriter out =
- new OutputStreamWriter(new FileOutputStream(path, true), "UTF-8");
+ OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path, true), "UTF-8");
writer = new BufferedWriter(out);
diff --git a/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/internal/BlockInfo.java b/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/internal/BlockInfo.java
index 1b07edd..6d76977 100644
--- a/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/internal/BlockInfo.java
+++ b/blockcanary-analyzer/src/main/java/com/github/moduth/blockcanary/internal/BlockInfo.java
@@ -15,6 +15,7 @@
*/
package com.github.moduth.blockcanary.internal;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
@@ -31,6 +32,7 @@
/**
* Information to trace a block.
*/
+@SuppressLint("HardwareIds")
public class BlockInfo {
private static final String TAG = "BlockInfo";
diff --git a/blockcanary-android-no-op/build.gradle b/blockcanary-android-no-op/build.gradle
index 83af379..b405bb2 100644
--- a/blockcanary-android-no-op/build.gradle
+++ b/blockcanary-android-no-op/build.gradle
@@ -20,5 +20,5 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
+ api fileTree(dir: 'libs', include: ['*.jar'])
}
diff --git a/blockcanary-android/build.gradle b/blockcanary-android/build.gradle
index ebe613e..01794f6 100644
--- a/blockcanary-android/build.gradle
+++ b/blockcanary-android/build.gradle
@@ -20,7 +20,10 @@ android {
}
dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
-// compile project(':blockcanary-analyzer')
- compile 'com.github.markzhai:blockcanary-analyzer:1.5.0'
+ api fileTree(include: ['*.jar'], dir: 'libs')
+ api project(':blockcanary-analyzer')
+ api 'androidx.appcompat:appcompat:1.3.1'
+// api 'com.github.markzhai:blockcanary-analyzer:1.5.0'
+
+ // use to display notification
}
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..e617103 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
@@ -46,7 +46,6 @@ private BlockCanary() {
return;
}
mBlockCanaryCore.addBlockInterceptor(new DisplayService());
-
}
/**
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..db201ce 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
@@ -15,25 +15,24 @@
*/
package com.github.moduth.blockcanary;
-import android.annotation.TargetApi;
+import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
+import static android.os.Build.VERSION.SDK_INT;
+import static android.os.Build.VERSION_CODES.JELLY_BEAN;
+
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.util.Log;
+import android.os.Build;
+
+import androidx.core.app.NotificationCompat;
+import androidx.core.app.NotificationManagerCompat;
import com.github.moduth.blockcanary.internal.BlockInfo;
import com.github.moduth.blockcanary.ui.DisplayActivity;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
-import static android.os.Build.VERSION.SDK_INT;
-import static android.os.Build.VERSION_CODES.HONEYCOMB;
-import static android.os.Build.VERSION_CODES.JELLY_BEAN;
-
final class DisplayService implements BlockInterceptor {
private static final String TAG = "DisplayService";
@@ -49,39 +48,29 @@ 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);
+ NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
Notification notification;
- if (SDK_INT < HONEYCOMB) {
- notification = new Notification();
- notification.icon = R.drawable.block_canary_notification;
- notification.when = System.currentTimeMillis();
- notification.flags |= Notification.FLAG_AUTO_CANCEL;
- notification.defaults = Notification.DEFAULT_SOUND;
- try {
- Method deprecatedMethod = notification.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class);
- deprecatedMethod.invoke(notification, context, contentTitle, contentText, pendingIntent);
- } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException
- | InvocationTargetException e) {
- Log.w(TAG, "Method not found", e);
- }
+ String packageName = context.getPackageName();
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context, packageName)
+ .setSmallIcon(R.drawable.block_canary_notification)
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle(contentTitle)
+ .setContentText(contentText)
+ .setAutoCancel(true)
+ .setContentIntent(pendingIntent)
+ .setDefaults(Notification.DEFAULT_SOUND);
+ if (SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationChannel notificationChannel = new NotificationChannel(packageName, packageName, NotificationManager.IMPORTANCE_LOW);
+ notificationChannel.setDescription(packageName);
+ notificationChannel.setShowBadge(false);
+ notificationManager.createNotificationChannel(notificationChannel);
+ }
+ if (SDK_INT < JELLY_BEAN) {
+ notification = builder.getNotification();
} else {
- Notification.Builder builder = new Notification.Builder(context)
- .setSmallIcon(R.drawable.block_canary_notification)
- .setWhen(System.currentTimeMillis())
- .setContentTitle(contentTitle)
- .setContentText(contentText)
- .setAutoCancel(true)
- .setContentIntent(pendingIntent)
- .setDefaults(Notification.DEFAULT_SOUND);
- if (SDK_INT < JELLY_BEAN) {
- notification = builder.getNotification();
- } else {
- notification = builder.build();
- }
+ notification = builder.build();
}
notificationManager.notify(0xDEAFBEEF, notification);
}
diff --git a/blockcanary-sample/build.gradle b/blockcanary-sample/build.gradle
index 32d69b8..8d08dea 100644
--- a/blockcanary-sample/build.gradle
+++ b/blockcanary-sample/build.gradle
@@ -20,10 +20,9 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- debugCompile project(':blockcanary-android')
- releaseCompile project(':blockcanary-android-no-op')
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ debugImplementation project(':blockcanary-android')
+ releaseImplementation project(':blockcanary-android-no-op')
- compile 'com.android.support:appcompat-v7:24.2.0'
- compile 'com.android.support:design:24.2.0'
+ implementation 'com.google.android.material:material:1.4.0'
}
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..9175257 100644
--- a/blockcanary-sample/src/main/java/com/example/blockcanary/AppContext.java
+++ b/blockcanary-sample/src/main/java/com/example/blockcanary/AppContext.java
@@ -15,11 +15,13 @@
*/
package com.example.blockcanary;
+import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import com.github.moduth.blockcanary.BlockCanaryContext;
+import com.github.moduth.blockcanary.internal.BlockInfo;
import java.util.List;
@@ -56,12 +58,12 @@ public int provideMonitorDuration() {
@Override
public int provideBlockThreshold() {
- return 500;
+ return 16;
}
@Override
public boolean displayNotification() {
- return BuildConfig.DEBUG;
+ return true;
}
@Override
@@ -82,4 +84,8 @@ public List provideWhiteList() {
public boolean stopWhenDebugging() {
return true;
}
+
+ @Override
+ public void onBlock(Context context, BlockInfo blockInfo) {
+ }
}
\ No newline at end of file
diff --git a/blockcanary-sample/src/main/java/com/example/blockcanary/DemoActivity.java b/blockcanary-sample/src/main/java/com/example/blockcanary/DemoActivity.java
index 1c72795..50e8242 100644
--- a/blockcanary-sample/src/main/java/com/example/blockcanary/DemoActivity.java
+++ b/blockcanary-sample/src/main/java/com/example/blockcanary/DemoActivity.java
@@ -16,9 +16,9 @@
package com.example.blockcanary;
import android.os.Bundle;
-import android.support.design.widget.FloatingActionButton;
-import android.support.v7.app.AlertDialog;
-import android.support.v7.app.AppCompatActivity;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
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..210b37b 100644
--- a/blockcanary-sample/src/main/java/com/example/blockcanary/DemoFragment.java
+++ b/blockcanary-sample/src/main/java/com/example/blockcanary/DemoFragment.java
@@ -16,8 +16,8 @@
package com.example.blockcanary;
import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
diff --git a/blockcanary-sample/src/main/res/layout/activity_demo.xml b/blockcanary-sample/src/main/res/layout/activity_demo.xml
index 066c36a..98842e6 100644
--- a/blockcanary-sample/src/main/res/layout/activity_demo.xml
+++ b/blockcanary-sample/src/main/res/layout/activity_demo.xml
@@ -20,7 +20,7 @@
android:layout_height="match_parent"
tools:ignore="MergeRootFrame" />
-
-