mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 22:50:05 +08:00
optimize process start
This commit is contained in:
parent
cddcd84ca6
commit
a3e529cb19
@ -54,24 +54,11 @@ class SagerNet : Application(),
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(CrashHandler)
|
Thread.setDefaultUncaughtExceptionHandler(CrashHandler)
|
||||||
|
|
||||||
if (isMainProcess || isBgProcess) {
|
if (isMainProcess || isBgProcess) {
|
||||||
// fix multi process issue in Android 9+
|
|
||||||
JavaUtil.handleWebviewDir(this)
|
|
||||||
|
|
||||||
runOnDefaultDispatcher {
|
|
||||||
PackageCache.register()
|
|
||||||
cleanWebview()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Seq.setContext(this)
|
|
||||||
updateNotificationChannels()
|
|
||||||
|
|
||||||
// nb4a: init core
|
|
||||||
externalAssets.mkdirs()
|
externalAssets.mkdirs()
|
||||||
|
Seq.setContext(this)
|
||||||
Libcore.initCore(
|
Libcore.initCore(
|
||||||
process,
|
process,
|
||||||
cacheDir.absolutePath + "/",
|
cacheDir.absolutePath + "/",
|
||||||
@ -82,6 +69,15 @@ class SagerNet : Application(),
|
|||||||
nativeInterface, nativeInterface, LocalResolverImpl
|
nativeInterface, nativeInterface, LocalResolverImpl
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// fix multi process issue in Android 9+
|
||||||
|
JavaUtil.handleWebviewDir(this)
|
||||||
|
|
||||||
|
runOnDefaultDispatcher {
|
||||||
|
PackageCache.register()
|
||||||
|
cleanWebview()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isMainProcess) {
|
if (isMainProcess) {
|
||||||
Theme.apply(this)
|
Theme.apply(this)
|
||||||
Theme.applyNightTheme()
|
Theme.applyNightTheme()
|
||||||
@ -89,10 +85,14 @@ class SagerNet : Application(),
|
|||||||
DefaultNetworkListener.start(this) {
|
DefaultNetworkListener.start(this) {
|
||||||
underlyingNetwork = it
|
underlyingNetwork = it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateNotificationChannels()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BuildConfig.DEBUG) StrictMode.setVmPolicy(
|
if (BuildConfig.DEBUG) {
|
||||||
|
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
|
||||||
|
StrictMode.setVmPolicy(
|
||||||
StrictMode.VmPolicy.Builder()
|
StrictMode.VmPolicy.Builder()
|
||||||
.detectLeakedSqlLiteObjects()
|
.detectLeakedSqlLiteObjects()
|
||||||
.detectLeakedClosableObjects()
|
.detectLeakedClosableObjects()
|
||||||
@ -101,6 +101,7 @@ class SagerNet : Application(),
|
|||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
super.onConfigurationChanged(newConfig)
|
super.onConfigurationChanged(newConfig)
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"libcore/device"
|
"libcore/device"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
_ "unsafe"
|
_ "unsafe"
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ func NekoLogClear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ForceGc() {
|
func ForceGc() {
|
||||||
go runtime.GC()
|
go debug.FreeOSMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitCore(process, cachePath, internalAssets, externalAssets string,
|
func InitCore(process, cachePath, internalAssets, externalAssets string,
|
||||||
@ -52,6 +52,8 @@ func InitCore(process, cachePath, internalAssets, externalAssets string,
|
|||||||
|
|
||||||
// sing-box fs
|
// sing-box fs
|
||||||
resourcePaths = append(resourcePaths, externalAssets)
|
resourcePaths = append(resourcePaths, externalAssets)
|
||||||
|
externalAssetsPath = externalAssets
|
||||||
|
internalAssetsPath = internalAssets
|
||||||
|
|
||||||
// Set up log
|
// Set up log
|
||||||
if maxLogSizeKb < 50 {
|
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) })
|
defer device.DeferPanicToError("InitCore-go", func(err error) { log.Println(err) })
|
||||||
device.GoDebug(process)
|
device.GoDebug(process)
|
||||||
|
|
||||||
externalAssetsPath = externalAssets
|
|
||||||
internalAssetsPath = internalAssets
|
|
||||||
|
|
||||||
// certs
|
// certs
|
||||||
pem, err := os.ReadFile(externalAssetsPath + "ca.pem")
|
pem, err := os.ReadFile(externalAssetsPath + "ca.pem")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user