Fix native bugs

This commit is contained in:
armv9 2025-02-23 19:23:20 +09:00
parent 6f7b4a125f
commit 89c1dab989
5 changed files with 30 additions and 9 deletions

View File

@ -47,7 +47,6 @@ class TestInstance(profile: ProxyEntity, val link: String, val timeout: Int) :
// don't call destroyAllJsi here
if (BuildConfig.DEBUG) Logs.d(config.config)
box = Libcore.newSingBoxInstance(config.config)
box.forTest = true
}
}

1
libcore/.gitignore vendored
View File

@ -5,3 +5,4 @@ binary*.go
/debug.go
build
.build
env_*.sh

View File

@ -10,6 +10,7 @@ import (
"runtime"
"runtime/debug"
"strings"
"sync"
"github.com/matsuridayo/libneko/protect_server"
"github.com/matsuridayo/libneko/speedtest"
@ -20,7 +21,6 @@ import (
"github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/outbound"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/service"
"github.com/sagernet/sing/service/pause"
)
@ -59,6 +59,8 @@ func ResetAllConnections(system bool) {
}
type BoxInstance struct {
access sync.Mutex
*box.Box
cancel context.CancelFunc
state int
@ -66,8 +68,6 @@ type BoxInstance struct {
v2api *boxapi.SbV2rayServer
selector *outbound.Selector
pauseManager pause.Manager
ForTest bool
}
func NewSingBoxInstance(config string) (b *BoxInstance, err error) {
@ -113,6 +113,9 @@ func NewSingBoxInstance(config string) (b *BoxInstance, err error) {
}
func (b *BoxInstance) Start() (err error) {
b.access.Lock()
defer b.access.Unlock()
defer device.DeferPanicToError("box.Start", func(err_ error) { err = err_ })
if b.state == 0 {
@ -123,6 +126,9 @@ func (b *BoxInstance) Start() (err error) {
}
func (b *BoxInstance) Close() (err error) {
b.access.Lock()
defer b.access.Unlock()
defer device.DeferPanicToError("box.Close", func(err_ error) { err = err_ })
// no double close
@ -138,7 +144,12 @@ func (b *BoxInstance) Close() (err error) {
}
// close box
common.Close(b.Box)
if b.cancel != nil {
b.cancel()
}
if b.Box != nil {
b.Box.Close()
}
return nil
}

View File

@ -1,6 +1,6 @@
#!/bin/bash
source ../../env_go.sh || true
source ./env_java.sh || true
source ../buildScript/init/env_ndk.sh
BUILD=".build"
@ -10,7 +10,11 @@ rm -rf $BUILD/android \
$BUILD/javac-output \
$BUILD/src
gomobile bind -v -androidapi 21 -cache $(realpath $BUILD) -trimpath -ldflags='-s -w' -tags='with_conntrack,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api,with_ech' . || exit 1
if [ -z "$GOPATH" ]; then
GOPATH=$(go env GOPATH)
fi
"$GOPATH"/bin/gomobile-matsuri bind -v -androidapi 21 -cache "$(realpath $BUILD)" -trimpath -ldflags='-s -w' -tags='with_conntrack,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api,with_ech' . || exit 1
rm -r libcore-sources.jar
proj=../app/libs

View File

@ -3,8 +3,12 @@
chmod -R 777 .build 2>/dev/null
rm -rf .build 2>/dev/null
if [ -z "$GOPATH" ]; then
GOPATH=$(go env GOPATH)
fi
# Install gomobile
if [ ! -f "$GOPATH/bin/gomobile" ]; then
if [ ! -f "$GOPATH/bin/gomobile-matsuri" ]; then
git clone https://github.com/MatsuriDayo/gomobile.git
pushd gomobile/cmd
pushd gomobile
@ -15,6 +19,8 @@ if [ ! -f "$GOPATH/bin/gomobile" ]; then
popd
popd
rm -rf gomobile
mv "$GOPATH/bin/gomobile" "$GOPATH/bin/gomobile-matsuri"
mv "$GOPATH/bin/gobind" "$GOPATH/bin/gobind-matsuri"
fi
gomobile init
gomobile-matsuri init