Skip to content

Commit 1ef5730

Browse files
authored
Merge pull request #824 from Tencent/feature/dev
Matrix 2.1.0 for Android
2 parents ae45599 + 2e93817 commit 1ef5730

File tree

197 files changed

+10948
-2898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+10948
-2898
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
![Matrix-icon](assets/img/readme/header.png)
22
[![license](http://img.shields.io/badge/license-BSD3-brightgreen.svg?style=flat)](https://github.com/Tencent/matrix/blob/master/LICENSE)
33
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Tencent/matrix/pulls)
4-
[![WeChat Approved](https://img.shields.io/badge/Wechat%20Approved-2.0.8-red.svg)](https://github.com/Tencent/matrix/wiki)
4+
[![WeChat Approved](https://img.shields.io/badge/Wechat%20Approved-2.1.0-red.svg)](https://github.com/Tencent/matrix/wiki)
55
[![CircleCI](https://circleci.com/gh/Tencent/matrix.svg?style=shield)](https://app.circleci.com/pipelines/github/Tencent/matrix)
66

77
(中文版本请参看[这里](#matrix_cn))
@@ -215,7 +215,7 @@ At this point, Matrix has been integrated into the app and is beginning to colle
215215

216216
1. Configure `MATRIX_VERSION` in gradle.properties.
217217
``` gradle
218-
MATRIX_VERSION=2.0.8
218+
MATRIX_VERSION=2.1.0
219219
```
220220

221221
2. Add `matrix-gradle-plugin` in your build.gradle:
@@ -364,11 +364,11 @@ Then other components in Matrix could use Quikcen Backtrace to unwind stacktrace
364364

365365
#### APK Checker Usage
366366

367-
APK Checker can run independently in Jar ([matrix-apk-canary-2.0.8.jar](https://repo.maven.apache.org/maven2/com/tencent/matrix/matrix-apk-canary/2.0.8/matrix-apk-canary-2.0.8.jar)) mode, usage:
367+
APK Checker can run independently in Jar ([matrix-apk-canary-2.1.0.jar](https://repo.maven.apache.org/maven2/com/tencent/matrix/matrix-apk-canary/2.1.0/matrix-apk-canary-2.1.0.jar)) mode, usage:
368368

369369

370370
```shell
371-
java -jar matrix-apk-canary-2.0.8.jar
371+
java -jar matrix-apk-canary-2.1.0.jar
372372
Usages:
373373
--config CONFIG-FILE-PATH
374374
or
@@ -427,7 +427,7 @@ Matrix is under the BSD license. See the [LICENSE](https://github.com/Tencent/Ma
427427
428428
# <a name="matrix_cn">Matrix</a>
429429
![Matrix-icon](assets/img/readme/header.png)
430-
[![license](http://img.shields.io/badge/license-BSD3-brightgreen.svg?style=flat)](https://github.com/Tencent/matrix/blob/master/LICENSE)[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Tencent/matrix/pulls) [![WeChat Approved](https://img.shields.io/badge/Wechat%20Approved-2.0.8-red.svg)](https://github.com/Tencent/matrix/wiki)
430+
[![license](http://img.shields.io/badge/license-BSD3-brightgreen.svg?style=flat)](https://github.com/Tencent/matrix/blob/master/LICENSE)[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Tencent/matrix/pulls) [![WeChat Approved](https://img.shields.io/badge/Wechat%20Approved-2.1.0-red.svg)](https://github.com/Tencent/matrix/wiki)
431431
432432
**Matrix** 是一款微信研发并日常使用的应用性能接入框架,支持iOS, macOS和Android。
433433
Matrix 通过接入各种性能监控方案,对性能监控项的异常数据进行采集和分析,输出相应的问题分析、定位与优化建议,从而帮助开发者开发出更高质量的应用。
@@ -628,7 +628,7 @@ Matrix-android 当前监控范围包括:应用安装包大小,帧率变化
628628

629629
1. 在你项目根目录下的 gradle.properties 中配置要依赖的 Matrix 版本号,如:
630630
``` gradle
631-
MATRIX_VERSION=2.0.8
631+
MATRIX_VERSION=2.1.0
632632
```
633633

634634
2. 在你项目根目录下的 build.gradle 文件添加 Matrix 依赖,如:
@@ -774,10 +774,10 @@ WeChatBacktrace.instance().configure(getApplicationContext()).commit();
774774
775775
#### APK Checker
776776
777-
APK Check 以独立的 jar 包提供 ([matrix-apk-canary-2.0.8.jar](https://repo.maven.apache.org/maven2/com/tencent/matrix/matrix-apk-canary/2.0.8/matrix-apk-canary-2.0.8.jar)),你可以运行:
777+
APK Check 以独立的 jar 包提供 ([matrix-apk-canary-2.1.0.jar](https://repo.maven.apache.org/maven2/com/tencent/matrix/matrix-apk-canary/2.1.0/matrix-apk-canary-2.1.0.jar)),你可以运行:
778778
779779
```cmd
780-
java -jar matrix-apk-canary-2.0.8.jar
780+
java -jar matrix-apk-canary-2.1.0.jar
781781
```
782782
783783
查看 Usages 来使用它。

matrix/matrix-android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
1414
# org.gradle.parallel=true
1515
#Tue Jun 20 10:24:33 CST 2017
1616

17-
VERSION_NAME_PREFIX=2.0.8
17+
VERSION_NAME_PREFIX=2.1.0
1818
VERSION_NAME_SUFFIX=
1919
## two options: Internal (for wechat), External (for public repo)
2020
PUBLISH_CHANNEL=Internal

matrix/matrix-android/matrix-android-commons/src/main/cpp/libenhance_dlsym/EnhanceDlsym.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@
3232
#include <dlfcn.h>
3333
#include <set>
3434
#include "EnhanceDlsym.h"
35-
#include "../../../../../matrix-jectl/src/main/cpp/jectl/JeLog.h"
3635

3736
#define TAG "Matrix.EnhanceDl"
3837

38+
#include <android/log.h>
39+
40+
#define LOGD(TAG, FMT, args...) //__android_log_print(ANDROID_LOG_DEBUG, TAG, FMT, ##args)
41+
#define LOGI(TAG, FMT, args...) //__android_log_print(ANDROID_LOG_INFO, TAG, FMT, ##args)
42+
#define LOGE(TAG, FMT, args...) //__android_log_print(ANDROID_LOG_ERROR, TAG, FMT, ##args)
43+
3944
namespace enhance {
4045

4146
static std::set<DlInfo *> m_opened_info;

matrix/matrix-android/matrix-android-lib/src/main/aidl/com/tencent/matrix/lifecycle/supervisor/ISubordinateProxy.aidl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
package com.tencent.matrix.lifecycle.supervisor;
33

44
// Declare any non-default types here with import statements
5+
import com.tencent.matrix.util.MemInfo;
56

67
interface ISubordinateProxy {
78
void dispatchState(in String scene, in String stateName, in boolean state);
89
void dispatchKill(in String scene, in String targetProcess, in int targetPid);
910
void dispatchDeath(in String scene, in String targetProcess, in int targetPid, in boolean isLruKill);
1011

11-
int getPss();
12+
MemInfo getMemInfo();
1213
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// MemInfo.aidl
2+
package com.tencent.matrix.util;
3+
4+
// Declare any non-default types here with import statements
5+
6+
parcelable MemInfo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.tencent.matrix.lifecycle
2+
3+
import android.app.Application
4+
import com.tencent.matrix.lifecycle.owners.*
5+
import com.tencent.matrix.lifecycle.supervisor.*
6+
import com.tencent.matrix.util.MatrixLog
7+
import com.tencent.matrix.util.MatrixUtil
8+
9+
// @formatter:off
10+
object MatrixLifecycleLogger {
11+
12+
private var application: Application? = null
13+
private val TAG by lazy { "Matrix.lifecycle.Logger_${String.format("%-10.10s", suffix())}" }
14+
15+
private fun suffix(): String {
16+
return if (MatrixUtil.isInMainProcess(application!!)) {
17+
"Main"
18+
} else {
19+
val split = MatrixUtil.getProcessName(application!!).split(":").toTypedArray()
20+
if (split.size > 1) {
21+
split[1].takeLast(10)
22+
} else {
23+
"unknown"
24+
}
25+
}
26+
}
27+
28+
fun init(app: Application, enable: Boolean) {
29+
application = app
30+
if (!enable) {
31+
MatrixLog.i(TAG, "logger disabled")
32+
return
33+
}
34+
35+
ProcessUIResumedStateOwner.observeForever(object : ISerialObserver {
36+
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_UI_RESUMED")
37+
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_UI_PAUSED")
38+
})
39+
40+
ProcessUIStartedStateOwner.observeForever(object : ISerialObserver {
41+
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_UI_STARTED scene: ${ProcessUILifecycleOwner.recentScene}")
42+
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_UI_STOPPED scene: ${ProcessUILifecycleOwner.recentScene}")
43+
})
44+
45+
ProcessExplicitBackgroundOwner.observeForever(object : ISerialObserver {
46+
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_ENTER_EXPLICIT_BACKGROUND")
47+
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_EXIT_EXPLICIT_BACKGROUND")
48+
})
49+
50+
ProcessStagedBackgroundOwner.observeForever(object : ISerialObserver {
51+
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_ENTER_STAGED_BACKGROUND")
52+
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_EXIT_STAGED_BACKGROUND")
53+
})
54+
55+
ProcessDeepBackgroundOwner.observeForever(object : ISerialObserver {
56+
override fun on() = MatrixLog.i(TAG, "ON_PROCESS_ENTER_DEEP_BACKGROUND")
57+
override fun off() = MatrixLog.i(TAG, "ON_PROCESS_EXIT_DEEP_BACKGROUND")
58+
})
59+
60+
AppUIForegroundOwner.observeForever(object : ISerialObserver {
61+
override fun on() = MatrixLog.i(TAG, "ON_APP_UI_ENTER_FOREGROUND scene: ${ProcessSupervisor.getRecentScene()}")
62+
override fun off() = MatrixLog.i(TAG, "ON_APP_UI_EXIT_FOREGROUND scene: ${ProcessSupervisor.getRecentScene()}")
63+
})
64+
65+
AppExplicitBackgroundOwner.observeForever(object : ISerialObserver {
66+
override fun off() = MatrixLog.i(TAG, "ON_APP_EXIT_EXPLICIT_BACKGROUND")
67+
override fun on() = MatrixLog.i(TAG, "ON_APP_ENTER_EXPLICIT_BACKGROUND")
68+
})
69+
70+
AppStagedBackgroundOwner.observeForever(object : ISerialObserver {
71+
override fun off() = MatrixLog.i(TAG, "ON_APP_EXIT_STAGED_BACKGROUND")
72+
override fun on() = MatrixLog.i(TAG, "ON_APP_ENTER_STAGED_BACKGROUND")
73+
})
74+
75+
AppDeepBackgroundOwner.observeForever(object : ISerialObserver {
76+
override fun off() = MatrixLog.i(TAG, "ON_APP_EXIT_DEEP_BACKGROUND")
77+
override fun on() = MatrixLog.i(TAG, "ON_APP_ENTER_DEEP_BACKGROUND")
78+
})
79+
80+
ProcessSupervisor.addDyingListener { scene, processName, pid ->
81+
MatrixLog.i(TAG, "Dying Listener: process $pid-$processName is dying on scene $scene")
82+
false // NOT rescue
83+
}
84+
85+
ProcessSupervisor.addDeathListener { scene, processName, pid, isLruKill ->
86+
MatrixLog.i(
87+
TAG,
88+
"Death Listener: process $pid-$processName died on scene $scene, is LRU Kill? $isLruKill"
89+
)
90+
}
91+
92+
ForegroundServiceLifecycleOwner.observeForever(object : ISerialObserver {
93+
override fun on() = MatrixLog.i(TAG, "ForegroundServiceLifecycleOwner: ON")
94+
override fun off() = MatrixLog.i(TAG, "ForegroundServiceLifecycleOwner: OFF")
95+
})
96+
97+
OverlayWindowLifecycleOwner.observeForever(object : ISerialObserver {
98+
override fun on() = MatrixLog.i(TAG, "OverlayWindowLifecycleOwner: ON, hasOverlay = ${OverlayWindowLifecycleOwner.hasOverlayWindow()}, hasVisible = ${OverlayWindowLifecycleOwner.hasVisibleWindow()}")
99+
override fun off() = MatrixLog.i(TAG, "OverlayWindowLifecycleOwner: OFF, hasOverlay = ${OverlayWindowLifecycleOwner.hasOverlayWindow()}, hasVisible = ${OverlayWindowLifecycleOwner.hasVisibleWindow()}")
100+
})
101+
}
102+
}

matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/MatrixLifecycleOwnerInitializer.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ data class MatrixLifecycleConfig(
2525
*/
2626
val enableOverlayWindowMonitor: Boolean = false,
2727

28-
val lifecycleThreadConfig: LifecycleThreadConfig = LifecycleThreadConfig()
28+
val lifecycleThreadConfig: LifecycleThreadConfig = LifecycleThreadConfig(),
29+
30+
val enableLifecycleLogger: Boolean = false
2931
)
3032

3133
/**
@@ -61,6 +63,7 @@ class MatrixLifecycleOwnerInitializer {
6163
ProcessUILifecycleOwner.init(app)
6264
ForegroundServiceLifecycleOwner.init(app, config.enableFgServiceMonitor)
6365
OverlayWindowLifecycleOwner.init(config.enableOverlayWindowMonitor)
66+
MatrixLifecycleLogger.init(app, config.enableLifecycleLogger)
6467
}
6568

6669
@SuppressLint("PrivateApi", "DiscouragedPrivateApi")

matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/MatrixLifecycleThread.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.util.concurrent.*
99
private const val TAG = "Matrix.Lifecycle.Thread"
1010

1111
data class LifecycleThreadConfig(
12+
val externalExecutor: Executor? = null,
1213
val maxPoolSize: Int = 5,
1314
val keepAliveSeconds: Long = 30L,
1415
val onHeavyTaskDetected: (task: String, cost: Long) -> Unit = { task, cost ->
@@ -45,6 +46,11 @@ internal object MatrixLifecycleThread {
4546
}
4647

4748
val executor by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
49+
50+
if (config.externalExecutor != null) {
51+
return@lazy config.externalExecutor!!
52+
}
53+
4854
val idleSynchronousQueue = IdleSynchronousQueue()
4955

5056
object : ThreadPoolExecutor(

matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/ForegroundServiceLifecycleOwner.kt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.os.Handler
1010
import android.os.Message
1111
import android.os.Process
1212
import android.util.ArrayMap
13+
import com.tencent.matrix.lifecycle.MatrixLifecycleThread
1314
import com.tencent.matrix.lifecycle.StatefulOwner
1415
import com.tencent.matrix.util.MatrixLog
1516
import com.tencent.matrix.util.safeApply
@@ -19,8 +20,6 @@ import java.lang.reflect.InvocationHandler
1920
import java.lang.reflect.Method
2021
import java.lang.reflect.Proxy
2122

22-
private const val SDK_GUARD = 32
23-
2423
/**
2524
* Created by Yves on 2021/11/30
2625
*/
@@ -49,10 +48,6 @@ object ForegroundServiceLifecycleOwner : StatefulOwner() {
4948
MatrixLog.i(TAG, "disabled")
5049
return
5150
}
52-
if (Build.VERSION.SDK_INT > SDK_GUARD) { // for safety
53-
MatrixLog.e(TAG, "NOT support for api-level ${Build.VERSION.SDK_INT} yet!!!")
54-
return
55-
}
5651
inject()
5752
}
5853

@@ -127,8 +122,10 @@ object ForegroundServiceLifecycleOwner : StatefulOwner() {
127122
}
128123
STOP_SERVICE -> {
129124
ActivityThreadmH?.post {
130-
safeApply(TAG) {
131-
hasForegroundService()
125+
MatrixLifecycleThread.handler.post {
126+
safeApply(TAG) {
127+
hasForegroundService()
128+
}
132129
}
133130
}
134131
}
@@ -159,15 +156,17 @@ object ForegroundServiceLifecycleOwner : StatefulOwner() {
159156
}
160157

161158
private fun checkIfAlreadyForegrounded(componentName: ComponentName) {
162-
safeApply(TAG) {
163-
activityManager?.getRunningServices(Int.MAX_VALUE)?.filter {
164-
it.pid == Process.myPid()
165-
&& it.uid == Process.myUid()
166-
&& it.service == componentName
167-
&& it.foreground
168-
}?.forEach {
169-
MatrixLog.i(TAG, "service turned fg when create: ${it.service}")
170-
fgServiceHandler?.onStartForeground(it.service)
159+
MatrixLifecycleThread.handler.post {
160+
safeApply(TAG) {
161+
activityManager?.getRunningServices(Int.MAX_VALUE)?.filter {
162+
it.pid == Process.myPid()
163+
&& it.uid == Process.myUid()
164+
&& it.service == componentName
165+
&& it.foreground
166+
}?.forEach {
167+
MatrixLog.i(TAG, "service turned fg when create: ${it.service}")
168+
fgServiceHandler?.onStartForeground(it.service)
169+
}
171170
}
172171
}
173172
}

matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/OverlayWindowLifecycleOwner.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import android.view.WindowManager
1010
import com.tencent.matrix.lifecycle.StatefulOwner
1111
import com.tencent.matrix.util.*
1212

13-
private const val SDK_GUARD = 32
14-
1513
/**
1614
* Created by Yves on 2021/12/30
1715
*/
@@ -39,10 +37,6 @@ object OverlayWindowLifecycleOwner : StatefulOwner() {
3937
MatrixLog.i(TAG, "disabled")
4038
return
4139
}
42-
if (Build.VERSION.SDK_INT > SDK_GUARD) { // for safety
43-
MatrixLog.e(TAG, "NOT support for api-level ${Build.VERSION.SDK_INT} yet!!!")
44-
return
45-
}
4640
inject()
4741
}
4842

matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/ProcessBackgroundStateOwner.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object ProcessExplicitBackgroundOwner : StatefulOwner(), IBackgroundStatefulOwne
6868
override fun action(): Boolean {
6969
val uiForeground by lazy { ProcessUIStartedStateOwner.active() }
7070
val fgService by lazy { ForegroundServiceLifecycleOwner.hasForegroundService() }
71-
val visibleWindow by lazy { OverlayWindowLifecycleOwner.hasVisibleWindow() }
71+
val visibleWindow by lazy { OverlayWindowLifecycleOwner.hasOverlayWindow() }
7272

7373
if (uiForeground) {
7474
MatrixLog.i(TAG, "turn OFF for UI foreground")

matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/supervisor/ProcessSubordinate.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ internal object ProcessSubordinate {
9797
}
9898
}
9999

100-
fun getPss(): Int {
101-
return 0
100+
fun getMemInfo(): Array<MemInfo> {
101+
val memInfoList = ArrayList<MemInfo>()
102+
subordinateProxies.forEachSafe {
103+
it.value.memInfo?.let { m->
104+
memInfoList.add(m)
105+
}
106+
}
107+
return memInfoList.toTypedArray()
102108
}
103109
}
104110

@@ -243,9 +249,10 @@ internal object ProcessSubordinate {
243249
}
244250
}
245251

246-
override fun getPss(): Int {
247-
TODO("Not yet implemented")
248-
}
252+
override fun getMemInfo(): MemInfo = safeLet(
253+
TAG,
254+
defVal = MemInfo(amsPssInfo = PssInfo(), debugPssInfo = PssInfo())
255+
) { MemInfo.getCurrentProcessFullMemInfo() }
249256

250257
}
251258

0 commit comments

Comments
 (0)