mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-18 22:20:06 +08:00
Fix native bugs
This commit is contained in:
parent
6f7b4a125f
commit
89c1dab989
@ -47,7 +47,6 @@ class TestInstance(profile: ProxyEntity, val link: String, val timeout: Int) :
|
|||||||
// don't call destroyAllJsi here
|
// don't call destroyAllJsi here
|
||||||
if (BuildConfig.DEBUG) Logs.d(config.config)
|
if (BuildConfig.DEBUG) Logs.d(config.config)
|
||||||
box = Libcore.newSingBoxInstance(config.config)
|
box = Libcore.newSingBoxInstance(config.config)
|
||||||
box.forTest = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
1
libcore/.gitignore
vendored
1
libcore/.gitignore
vendored
@ -5,3 +5,4 @@ binary*.go
|
|||||||
/debug.go
|
/debug.go
|
||||||
build
|
build
|
||||||
.build
|
.build
|
||||||
|
env_*.sh
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/matsuridayo/libneko/protect_server"
|
"github.com/matsuridayo/libneko/protect_server"
|
||||||
"github.com/matsuridayo/libneko/speedtest"
|
"github.com/matsuridayo/libneko/speedtest"
|
||||||
@ -20,7 +21,6 @@ import (
|
|||||||
"github.com/sagernet/sing-box/constant"
|
"github.com/sagernet/sing-box/constant"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
"github.com/sagernet/sing-box/outbound"
|
"github.com/sagernet/sing-box/outbound"
|
||||||
"github.com/sagernet/sing/common"
|
|
||||||
"github.com/sagernet/sing/service"
|
"github.com/sagernet/sing/service"
|
||||||
"github.com/sagernet/sing/service/pause"
|
"github.com/sagernet/sing/service/pause"
|
||||||
)
|
)
|
||||||
@ -59,6 +59,8 @@ func ResetAllConnections(system bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BoxInstance struct {
|
type BoxInstance struct {
|
||||||
|
access sync.Mutex
|
||||||
|
|
||||||
*box.Box
|
*box.Box
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
state int
|
state int
|
||||||
@ -66,8 +68,6 @@ type BoxInstance struct {
|
|||||||
v2api *boxapi.SbV2rayServer
|
v2api *boxapi.SbV2rayServer
|
||||||
selector *outbound.Selector
|
selector *outbound.Selector
|
||||||
pauseManager pause.Manager
|
pauseManager pause.Manager
|
||||||
|
|
||||||
ForTest bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSingBoxInstance(config string) (b *BoxInstance, err error) {
|
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) {
|
func (b *BoxInstance) Start() (err error) {
|
||||||
|
b.access.Lock()
|
||||||
|
defer b.access.Unlock()
|
||||||
|
|
||||||
defer device.DeferPanicToError("box.Start", func(err_ error) { err = err_ })
|
defer device.DeferPanicToError("box.Start", func(err_ error) { err = err_ })
|
||||||
|
|
||||||
if b.state == 0 {
|
if b.state == 0 {
|
||||||
@ -123,6 +126,9 @@ func (b *BoxInstance) Start() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BoxInstance) Close() (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_ })
|
defer device.DeferPanicToError("box.Close", func(err_ error) { err = err_ })
|
||||||
|
|
||||||
// no double close
|
// no double close
|
||||||
@ -138,7 +144,12 @@ func (b *BoxInstance) Close() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// close box
|
// close box
|
||||||
common.Close(b.Box)
|
if b.cancel != nil {
|
||||||
|
b.cancel()
|
||||||
|
}
|
||||||
|
if b.Box != nil {
|
||||||
|
b.Box.Close()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source ../../env_go.sh || true
|
source ./env_java.sh || true
|
||||||
source ../buildScript/init/env_ndk.sh
|
source ../buildScript/init/env_ndk.sh
|
||||||
|
|
||||||
BUILD=".build"
|
BUILD=".build"
|
||||||
@ -10,7 +10,11 @@ rm -rf $BUILD/android \
|
|||||||
$BUILD/javac-output \
|
$BUILD/javac-output \
|
||||||
$BUILD/src
|
$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
|
rm -r libcore-sources.jar
|
||||||
|
|
||||||
proj=../app/libs
|
proj=../app/libs
|
||||||
|
|||||||
@ -3,8 +3,12 @@
|
|||||||
chmod -R 777 .build 2>/dev/null
|
chmod -R 777 .build 2>/dev/null
|
||||||
rm -rf .build 2>/dev/null
|
rm -rf .build 2>/dev/null
|
||||||
|
|
||||||
|
if [ -z "$GOPATH" ]; then
|
||||||
|
GOPATH=$(go env GOPATH)
|
||||||
|
fi
|
||||||
|
|
||||||
# Install gomobile
|
# Install gomobile
|
||||||
if [ ! -f "$GOPATH/bin/gomobile" ]; then
|
if [ ! -f "$GOPATH/bin/gomobile-matsuri" ]; then
|
||||||
git clone https://github.com/MatsuriDayo/gomobile.git
|
git clone https://github.com/MatsuriDayo/gomobile.git
|
||||||
pushd gomobile/cmd
|
pushd gomobile/cmd
|
||||||
pushd gomobile
|
pushd gomobile
|
||||||
@ -15,6 +19,8 @@ if [ ! -f "$GOPATH/bin/gomobile" ]; then
|
|||||||
popd
|
popd
|
||||||
popd
|
popd
|
||||||
rm -rf gomobile
|
rm -rf gomobile
|
||||||
|
mv "$GOPATH/bin/gomobile" "$GOPATH/bin/gomobile-matsuri"
|
||||||
|
mv "$GOPATH/bin/gobind" "$GOPATH/bin/gobind-matsuri"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gomobile init
|
gomobile-matsuri init
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user