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

1 fix log file not exit 2 fix notification not display 3 migrate to A… #143

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
2 changes: 1 addition & 1 deletion blockcanary-analyzer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
api fileTree(dir: 'libs', include: ['*.jar'])
}
1 change: 1 addition & 0 deletions blockcanary-analyzer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android">

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.github.moduth.blockcanary;

import android.os.Environment;
import android.os.Looper;

import com.github.moduth.blockcanary.internal.BlockInfo;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@
/**
* Information to trace a block.
*/
@SuppressLint("HardwareIds")
public class BlockInfo {

private static final String TAG = "BlockInfo";
Expand Down
2 changes: 1 addition & 1 deletion blockcanary-android-no-op/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
api fileTree(dir: 'libs', include: ['*.jar'])
}
9 changes: 6 additions & 3 deletions blockcanary-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ private BlockCanary() {
return;
}
mBlockCanaryCore.addBlockInterceptor(new DisplayService());

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}
Expand Down
9 changes: 4 additions & 5 deletions blockcanary-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -82,4 +84,8 @@ public List<String> provideWhiteList() {
public boolean stopWhenDebugging() {
return true;
}

@Override
public void onBlock(Context context, BlockInfo blockInfo) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion blockcanary-sample/src/main/res/layout/activity_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_height="match_parent"
tools:ignore="MergeRootFrame" />

<android.support.design.widget.FloatingActionButton
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion blockcanary-sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</LinearLayout>


<android.support.design.widget.FloatingActionButton
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
16 changes: 9 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

buildscript {
repositories {
mavenCentral()
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:3.6.4'
}
}

allprojects {
repositories {
mavenCentral()
jcenter()
mavenCentral()
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 = 30
LIBRARY_BUILD_TOOLS_VERSION = "30.0.3"
LIBRARY_MIN_SDK_VERSION = 14
LIBRARY_TARGET_SDK_VERSION = 30
}
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ org.gradle.jvmargs=-Xmx8192M
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
android.useDeprecatedNdk=true
android.useDeprecatedNdk=true
android.useAndroidX=true
android.enableJetifier=true
6 changes: 3 additions & 3 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
#Thu Feb 17 11:44:46 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
zipStoreBase=GRADLE_USER_HOME