Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3826e4f

Browse files
committed
[release] upgrade to 1.0.9
1 parenta3e9634 commit3826e4f

File tree

8 files changed

+83
-33
lines changed

8 files changed

+83
-33
lines changed

‎README.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![](https://img.shields.io/badge/Android-4.4%20--%2013-blue.svg?style=flat)
44
![](https://img.shields.io/badge/arch-armeabi--v7a%20%7C%20arm64--v8a-blue.svg?style=flat)
5-
![](https://img.shields.io/badge/release-1.0.8-red.svg?style=flat)
5+
![](https://img.shields.io/badge/release-1.0.9-red.svg?style=flat)
66

77
**Android Bitmap Monitor** 是一个 Android 图片内存分析工具,可以帮助开发者快速发现应用的图片使用是否合理,支持在线下和线上使用。
88

@@ -20,7 +20,8 @@
2020

2121
|版本|变更| 备注|
2222
|---|---| ---|
23-
|1.0.8|修复使用 Glide 加载的图片,还原时可能为纯黑的问题;支持 no-op 依赖(感谢[yibaoshan](https://github.com/yibaoshan))|此版本有问题,mavenCentral 服务问题新版本暂未升级成功,请先使用 1.0.7|
23+
|1.0.9|优化性能,减少主线程耗时||
24+
|1.0.8|修复使用 Glide 加载的图片,还原时可能为纯黑的问题;支持 no-op 依赖(感谢[yibaoshan](https://github.com/yibaoshan))|此版本性能欠佳,建议使用 1.0.9|
2425
|1.0.7|完善悬浮窗和图片列表功能,修复悬浮窗可能出现多个的问题||
2526

2627
##功能介绍
@@ -86,11 +87,11 @@ android {
8687
8788
dependencies {
8889
//依赖方式 1,如果线上线下都要使用,可以通过以下方式依赖
89-
implementation 'io.github.shixinzhang:android-bitmap-monitor:1.0.8'
90+
implementation 'io.github.shixinzhang:android-bitmap-monitor:1.0.9'
9091
9192
//依赖方式 2,如果不希望正式包中有代码运行,可以通过以下方式依赖
92-
releaseImplementation 'io.github.shixinzhang:android-bitmap-monitor-no-op:1.0.8'
93-
debugImplementation 'io.github.shixinzhang:android-bitmap-monitor:1.0.8'
93+
releaseImplementation 'io.github.shixinzhang:android-bitmap-monitor-no-op:1.0.9'
94+
debugImplementation 'io.github.shixinzhang:android-bitmap-monitor:1.0.9'
9495
}
9596
```
9697

‎app/build.gradle‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ dependencies {
4242
// debugImplementation project(path: ':library')
4343
// releaseImplementation project(path: ':library-no-op')
4444

45-
debugImplementation'io.github.shixinzhang:android-bitmap-monitor:1.0.8'
46-
releaseImplementation'io.github.shixinzhang:android-bitmap-monitor-no-op:1.0.8'
45+
debugImplementation'io.github.shixinzhang:android-bitmap-monitor:1.0.9'
46+
releaseImplementation'io.github.shixinzhang:android-bitmap-monitor-no-op:1.0.9'
4747

4848
// implementation project(path: ':library')
49-
// implementation 'io.github.shixinzhang:android-bitmap-monitor:1.0.8'
50-
// implementation 'io.github.shixinzhang:android-bitmap-monitor-no-op:1.0.8'
49+
// implementation 'io.github.shixinzhang:android-bitmap-monitor:1.0.9'
50+
// implementation 'io.github.shixinzhang:android-bitmap-monitor-no-op:1.0.9'
5151

5252
implementation'com.github.bumptech.glide:glide:4.14.2'
5353
annotationProcessor'com.github.bumptech.glide:compiler:4.14.2'

‎library-no-op/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ if (project.hasProperty("uploadToMavenCentral") && project.property("uploadToMav
6969

7070
groupId"io.github.shixinzhang"
7171
artifactId"android-bitmap-monitor-no-op"
72-
version"1.0.8"
72+
version"1.0.9"
7373

7474
afterEvaluate {
7575
from components.release

‎library/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if (project.hasProperty("uploadToMavenCentral") && project.property("uploadToMav
8787

8888
groupId"io.github.shixinzhang"
8989
artifactId"android-bitmap-monitor"
90-
version"1.0.8"
90+
version"1.0.9"
9191

9292
afterEvaluate {
9393
from components.release

‎library/src/main/cpp/bitmap_monitor.cpp‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ bool restore_image(JNIEnv *env, jobject bitmap_obj, unsigned int width, unsigned
4141
if (env ==nullptr || bitmap_obj ==nullptr || copy_file_path ==nullptr) {
4242
returnfalse;
4343
}
44+
jboolean object_recycled = env->IsSameObject(bitmap_obj,nullptr);
45+
46+
if (object_recycled == JNI_TRUE) {
47+
//not reachable
48+
returnfalse;
49+
}
50+
4451
void *pixels;
4552
if (AndroidBitmap_lockPixels(env, bitmap_obj, &pixels) ==0) {
4653
LOGI("restore_image, width: %d, height: %d, %s", width, height, copy_file_path);
@@ -392,12 +399,12 @@ jint do_hook_bitmap(long bitmap_recycle_check_interval,
392399
}
393400

394401
extern"C"
395-
jobjectdo_dump_info(JNIEnv *env,bool justCount) {
396-
jclass bitmap_record_class = env->FindClass(
397-
"top/shixinzhang/bitmapmonitor/BitmapRecord");
402+
jobjectdo_dump_info(JNIEnv *env,bool justCount,bool ensureRestoreImage) {
398403

399-
jmethodID bitmap_record_constructor_method = env->GetMethodID(bitmap_record_class,"<init>",
400-
"(JIIIIJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
404+
405+
if (g_ctx.java_vm !=nullptr) {
406+
g_ctx.java_vm->AttachCurrentThread(&env,nullptr);
407+
}
401408

402409
if (!g_ctx.record_mutex.try_lock()) {
403410
returnnullptr;
@@ -408,7 +415,7 @@ jobject do_dump_info(JNIEnv *env, bool justCount) {
408415
longlong remain_bitmap_size =0;
409416
int index =0;
410417
jobjectArray java_bitmap_record_array = env->NewObjectArray(remain_bitmap_count,
411-
bitmap_record_class,nullptr);
418+
g_ctx.bitmap_record_class,nullptr);
412419

413420
for (auto record : bitmap_records) {
414421
remain_bitmap_size += record.height * record.stride;
@@ -420,11 +427,7 @@ jobject do_dump_info(JNIEnv *env, bool justCount) {
420427
jstring current_scene = record.current_scene;
421428
bool restore_succeed = record.restore_succeed;
422429

423-
if (g_ctx.java_vm !=nullptr) {
424-
g_ctx.java_vm->AttachCurrentThread(&env,nullptr);
425-
}
426-
427-
if (save_path !=nullptr && !restore_succeed) {
430+
if (ensureRestoreImage && save_path !=nullptr && !restore_succeed) {
428431
//Need get pixels and restore again
429432
char *path =const_cast<char *>(env->GetStringUTFChars(save_path,0));
430433
unsignedint bit_per_pixel = record.stride / record.width;
@@ -436,8 +439,8 @@ jobject do_dump_info(JNIEnv *env, bool justCount) {
436439

437440
//每一条记录
438441
jobject java_record = env->NewObject(
439-
bitmap_record_class,
440-
bitmap_record_constructor_method,
442+
g_ctx.bitmap_record_class,
443+
g_ctx.bitmap_record_constructor_method,
441444
(jlong) record.native_ptr,
442445
(jint) record.width,
443446
(jint) record.height,
@@ -520,6 +523,16 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
520523
jclass bitmap_jclass = env->FindClass("android/graphics/Bitmap");
521524
g_ctx.native_ptr_field = env->GetFieldID(bitmap_jclass,"mNativePtr","J");
522525

526+
jclass bitmap_record_clz = env->FindClass(
527+
"top/shixinzhang/bitmapmonitor/BitmapRecord");
528+
g_ctx.bitmap_record_class = (jclass)env->NewGlobalRef(bitmap_record_clz);
529+
530+
if (g_ctx.bitmap_record_class !=nullptr) {
531+
g_ctx.bitmap_record_constructor_method = env->GetMethodID(g_ctx.bitmap_record_class,
532+
"<init>",
533+
"(JIIIIJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
534+
}
535+
523536
g_ctx.dump_stack_method = dump_stack_method_id;
524537
g_ctx.get_current_scene_method = get_current_scene_method_id;
525538
g_ctx.inited =true;
@@ -554,11 +567,11 @@ Java_top_shixinzhang_bitmapmonitor_BitmapMonitor_dumpBitmapCountNative(JNIEnv *e
554567
if (!g_ctx.open_hook) {
555568
returnnullptr;
556569
}
557-
returndo_dump_info(env,true);
570+
returndo_dump_info(env,true,false);
558571
}
559572

560573
extern"C"
561574
JNIEXPORT jobject JNICALL
562-
Java_top_shixinzhang_bitmapmonitor_BitmapMonitor_dumpBitmapInfoNative(JNIEnv *env, jclass clazz) {
563-
returndo_dump_info(env,false);
575+
Java_top_shixinzhang_bitmapmonitor_BitmapMonitor_dumpBitmapInfoNative(JNIEnv *env, jclass clazz, jboolean ensureRestoreImage) {
576+
returndo_dump_info(env,false, ensureRestoreImage);
564577
}

‎library/src/main/cpp/bitmap_monitor.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ struct BitmapMonitorContext {
4747
jmethodID bitmap_recycled_method;
4848
jclass bitmap_monitor_jclass;
4949
jfieldID native_ptr_field;
50+
5051
jmethodID dump_stack_method;
5152
jmethodID get_current_scene_method;
53+
5254
jclass bitmap_info_jclass;
5355
jmethodID report_bitmap_data_method;
5456

57+
jclass bitmap_record_class;
58+
jmethodID bitmap_record_constructor_method;
59+
5560
std::vector<BitmapRecord> bitmap_records;
5661

5762
int64_t create_bitmap_count;

‎library/src/main/java/top/shixinzhang/bitmapmonitor/BitmapMonitor.java‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
importjava.util.List;
1313

1414
importandroidx.annotation.Keep;
15+
importandroidx.annotation.WorkerThread;
1516

1617
importtop.shixinzhang.bitmapmonitor.ui.FloatWindow;
1718

@@ -112,8 +113,14 @@ public static void toggleFloatWindowVisibility(boolean show) {
112113
/**
113114
* 获取这段期间 hook 的 bitmap 数据 (包括总数和具体各个图片的信息)
114115
*/
116+
@WorkerThread
115117
publicstaticBitmapMonitorDatadumpBitmapInfo() {
116-
returndumpBitmapInfoNative();
118+
returndumpBitmapInfoNative(false);
119+
}
120+
121+
@WorkerThread
122+
publicstaticBitmapMonitorDatadumpBitmapInfo(booleanensureRestoreImage) {
123+
returndumpBitmapInfoNative(true);
117124
}
118125

119126
/**
@@ -233,12 +240,12 @@ public static Config getConfig() {
233240
privatestaticnativeBitmapMonitorDatadumpBitmapCountNative();
234241

235242
/**
236-
*获取数量和堆栈信息
237-
*
243+
*Get all bitmap info
244+
* @param ensureRestoreImage whether need check and restore again
238245
* @return
239246
*/
240247
@Keep
241-
privatestaticnativeBitmapMonitorDatadumpBitmapInfoNative();
248+
privatestaticnativeBitmapMonitorDatadumpBitmapInfoNative(booleanensureRestoreImage);
242249

243250
publicstaticclassConfig {
244251
//检查 Bitmap 是否回收的间隔,单位:秒

‎library/src/main/java/top/shixinzhang/bitmapmonitor/ui/BitmapRecordsActivity.java‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
importandroid.content.Context;
77
importandroid.content.Intent;
88
importandroid.os.Bundle;
9+
importandroid.os.Handler;
10+
importandroid.os.Looper;
911
importandroid.view.LayoutInflater;
1012
importandroid.view.View;
1113
importandroid.view.ViewGroup;
@@ -53,11 +55,33 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
5355

5456
tvSortBySize.setOnClickListener(this);
5557
tvSortByTime.setOnClickListener(this);
56-
bindData();
58+
requestData();
59+
}
60+
61+
privatevoidrequestData() {
62+
newThread(newRunnable() {
63+
@Override
64+
publicvoidrun() {
65+
data =BitmapMonitor.dumpBitmapInfo(true);
66+
if (data ==null) {
67+
return;
68+
}
69+
70+
bindDataInMainThread();
71+
}
72+
}).start();
73+
}
74+
75+
privatevoidbindDataInMainThread() {
76+
newHandler(Looper.getMainLooper()).post(newRunnable() {
77+
@Override
78+
publicvoidrun() {
79+
bindData();
80+
}
81+
});
5782
}
5883

5984
privatevoidbindData() {
60-
data =BitmapMonitor.dumpBitmapInfo();
6185
if (data ==null) {
6286
return;
6387
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp