optimize process start

This commit is contained in:
armv9 2025-09-04 12:25:37 +09:00
parent cddcd84ca6
commit a3e529cb19
2 changed files with 29 additions and 29 deletions

View File

@ -54,10 +54,21 @@ class SagerNet : Application(),
override fun onCreate() {
super.onCreate()
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
Thread.setDefaultUncaughtExceptionHandler(CrashHandler)
if (isMainProcess || isBgProcess) {
externalAssets.mkdirs()
Seq.setContext(this)
Libcore.initCore(
process,
cacheDir.absolutePath + "/",
filesDir.absolutePath + "/",
externalAssets.absolutePath + "/",
DataStore.logBufSize,
DataStore.logLevel > 0,
nativeInterface, nativeInterface, LocalResolverImpl
)
// fix multi process issue in Android 9+
JavaUtil.handleWebviewDir(this)
@ -67,21 +78,6 @@ class SagerNet : Application(),
}
}
Seq.setContext(this)
updateNotificationChannels()
// nb4a: init core
externalAssets.mkdirs()
Libcore.initCore(
process,
cacheDir.absolutePath + "/",
filesDir.absolutePath + "/",
externalAssets.absolutePath + "/",
DataStore.logBufSize,
DataStore.logLevel > 0,
nativeInterface, nativeInterface, LocalResolverImpl
)
if (isMainProcess) {
Theme.apply(this)
Theme.applyNightTheme()
@ -89,17 +85,22 @@ class SagerNet : Application(),
DefaultNetworkListener.start(this) {
underlyingNetwork = it
}
updateNotificationChannels()
}
}
if (BuildConfig.DEBUG) StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.detectLeakedRegistrationObjects()
.penaltyLog()
.build()
)
if (BuildConfig.DEBUG) {
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.detectLeakedRegistrationObjects()
.penaltyLog()
.build()
)
}
}
override fun onConfigurationChanged(newConfig: Configuration) {

View File

@ -5,7 +5,7 @@ import (
"libcore/device"
"os"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
_ "unsafe"
@ -29,7 +29,7 @@ func NekoLogClear() {
}
func ForceGc() {
go runtime.GC()
go debug.FreeOSMemory()
}
func InitCore(process, cachePath, internalAssets, externalAssets string,
@ -52,6 +52,8 @@ func InitCore(process, cachePath, internalAssets, externalAssets string,
// sing-box fs
resourcePaths = append(resourcePaths, externalAssets)
externalAssetsPath = externalAssets
internalAssetsPath = internalAssets
// Set up log
if maxLogSizeKb < 50 {
@ -69,9 +71,6 @@ func InitCore(process, cachePath, internalAssets, externalAssets string,
defer device.DeferPanicToError("InitCore-go", func(err error) { log.Println(err) })
device.GoDebug(process)
externalAssetsPath = externalAssets
internalAssetsPath = internalAssets
// certs
pem, err := os.ReadFile(externalAssetsPath + "ca.pem")
if err == nil {