Skip to content

Commit

Permalink
Unified SDK version
Browse files Browse the repository at this point in the history
Signed-off-by: xueqiushi <xueqiushi@kuaishou.com>
  • Loading branch information
alhah committed May 16, 2022
1 parent ed10520 commit 1ccfce5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import com.kwai.koom.base.MonitorManager
object CommonInitTask : InitTask {
override fun init(application: Application) {
val config = CommonConfig.Builder()
.setApplication(application) // Set application
.setVersionNameInvoker { "1.0.0" } // Set version name, java leak feature use it
.build()
.setApplication(application) // Set application
.setVersionNameInvoker { "1.0.0" } // Set version name, java leak feature use it
.setSdkVersionMatch(Build.VERSION.SDK_INT <= Build.VERSION_CODES.S && Build.VERSION.SDK_INT
>= Build.VERSION_CODES.LOLLIPOP) // Set if current sdk version is supported
.build()

MonitorManager.initCommonConfig(config)
.apply { onApplicationCreate() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@

package com.kwai.koom.fastdump;

import static com.kwai.koom.base.Monitor_ApplicationKt.sdkVersionMatch;
import static com.kwai.koom.base.Monitor_SoKt.loadSoQuietly;

import java.io.IOException;

import android.os.Build;
import android.os.Debug;

import com.kwai.koom.base.MonitorBuildConfig;
import com.kwai.koom.base.MonitorLog;
import com.kwai.koom.base.MonitorManager;

public class ForkJvmHeapDumper implements HeapDumper {
private static final String TAG = "OOMMonitor_ForkJvmHeapDumper";
Expand Down Expand Up @@ -56,8 +59,7 @@ private void init () {
@Override
public synchronized boolean dump(String path) {
MonitorLog.i(TAG, "dump " + path);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
|| Build.VERSION.SDK_INT > Build.VERSION_CODES.S) {
if (!sdkVersionMatch()) {
throw new UnsupportedOperationException("dump failed caused by sdk version not supported!");
}
init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.kwai.koom.javaoom.hprof;

import static com.kwai.koom.base.Monitor_ApplicationKt.sdkVersionMatch;
import static com.kwai.koom.base.Monitor_SoKt.loadSoQuietly;

import android.os.Build;
Expand Down Expand Up @@ -53,8 +54,7 @@ private void init() {
@Override
public synchronized boolean dump(String path) {
MonitorLog.i(TAG, "dump " + path);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
|| Build.VERSION.SDK_INT > Build.VERSION_CODES.S) {
if (!sdkVersionMatch()) {
throw new UnsupportedOperationException("dump failed caused by sdk version not supported!");
}
init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ object OOMMonitor : LoopMonitor<OOMMonitorConfig>(), LifecycleEventObserver {
}

override fun call(): LoopState {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
|| Build.VERSION.SDK_INT > Build.VERSION_CODES.S
) {
if (!sdkVersionMatch()) {
return LoopState.Terminate
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CommonConfig private constructor(

// MonitorBuildConfig common properties
internal val debugMode: Boolean,
internal val sdkVersionMatch: Boolean,
internal val versionNameInvoker: () -> String,

internal val logger: Logger,
Expand All @@ -53,6 +54,7 @@ class CommonConfig private constructor(
private lateinit var mApplication: Application

private var mDebugMode = true
private var mSdkVersionMatch = false
private lateinit var mVersionNameInvoker: () -> String
private lateinit var mDeviceIdInvoker: (() -> String)

Expand All @@ -76,6 +78,10 @@ class CommonConfig private constructor(
mDebugMode = debugMode
}

fun setSdkVersionMatch(sdkVersionMatch: Boolean) = apply {
mSdkVersionMatch = sdkVersionMatch
}

fun setVersionNameInvoker(versionNameInvoker: () -> String) = apply {
mVersionNameInvoker = versionNameInvoker
}
Expand Down Expand Up @@ -118,6 +124,7 @@ class CommonConfig private constructor(
application = mApplication,

debugMode = mDebugMode,
sdkVersionMatch = mSdkVersionMatch,
versionNameInvoker = mVersionNameInvoker,

rootFileInvoker = mRootFileInvoker ?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.kwai.koom.base
import android.os.Build

object MonitorBuildConfig {

@JvmStatic
val DEBUG by lazy { MonitorManager.commonConfig.debugMode }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ fun Application.registerProcessLifecycleObserver(observer: LifecycleEventObserve
fun Application.unregisterProcessLifecycleObserver(observer: LifecycleEventObserver) =
_lifecycleEventObservers.remove(observer)

fun sdkVersionMatch(): Boolean {
return MonitorManager.commonConfig.sdkVersionMatch
}

internal fun registerApplicationExtension() {
getApplication().registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
private fun updateCurrentActivityWeakRef(activity: Activity) {
Expand Down

0 comments on commit 1ccfce5

Please sign in to comment.