Fetch android users

This commit is contained in:
世界 2022-08-28 11:08:07 +08:00
parent 3117b24c68
commit 266a040806
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -2,7 +2,9 @@ package tun
import ( import (
"context" "context"
"os"
"sort" "sort"
"strconv"
"github.com/sagernet/sing/common" "github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions" E "github.com/sagernet/sing/common/exceptions"
@ -27,6 +29,19 @@ func (o *Options) BuildAndroidRules(packageManager PackageManager, errorHandler
userExcludeRange = ranges.Revert(0, userEnd, userExcludeRange) userExcludeRange = ranges.Revert(0, userEnd, userExcludeRange)
o.ExcludeUID = append(o.ExcludeUID, userExcludeRange...) o.ExcludeUID = append(o.ExcludeUID, userExcludeRange...)
} }
if len(includeUser) == 0 {
userDirs, err := os.ReadDir("/data/user")
if err == nil {
var userId uint64
for _, userDir := range userDirs {
userId, err = strconv.ParseUint(userDir.Name(), 10, 32)
if err != nil {
continue
}
includeUser = append(includeUser, uint32(userId))
}
}
}
if len(includeUser) == 0 { if len(includeUser) == 0 {
includeUser = []uint32{0} includeUser = []uint32{0}
} }