mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-03 20:07:40 +03:00
Fix include_android_user
This commit is contained in:
parent
e01ce3a8a7
commit
3117b24c68
3 changed files with 26 additions and 15 deletions
|
@ -5,7 +5,7 @@ import E "github.com/sagernet/sing/common/exceptions"
|
|||
type PackageManager interface {
|
||||
Start() error
|
||||
Close() error
|
||||
IDByPackage(packageName string) ([]uint32, bool)
|
||||
IDByPackage(packageName string) (uint32, bool)
|
||||
IDBySharedPackage(sharedPackage string) (uint32, bool)
|
||||
PackageByID(id uint32) (string, bool)
|
||||
SharedPackageByID(id uint32) (string, bool)
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
type packageManager struct {
|
||||
callback PackageManagerCallback
|
||||
watcher *fsnotify.Watcher
|
||||
idByPackage map[string][]uint32
|
||||
idByPackage map[string]uint32
|
||||
sharedByPackage map[string]uint32
|
||||
packageById map[uint32]string
|
||||
sharedById map[uint32]string
|
||||
|
@ -78,7 +78,7 @@ func (m *packageManager) Close() error {
|
|||
return common.Close(common.PtrOrNil(m.watcher))
|
||||
}
|
||||
|
||||
func (m *packageManager) IDByPackage(packageName string) ([]uint32, bool) {
|
||||
func (m *packageManager) IDByPackage(packageName string) (uint32, bool) {
|
||||
id, loaded := m.idByPackage[packageName]
|
||||
return id, loaded
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ func (m *packageManager) updatePackages() error {
|
|||
}
|
||||
|
||||
func (m *packageManager) decodePackages(decoder *xml.Decoder) error {
|
||||
idByPackage := make(map[string][]uint32)
|
||||
idByPackage := make(map[string]uint32)
|
||||
sharedByPackage := make(map[string]uint32)
|
||||
packageById := make(map[uint32]string)
|
||||
sharedById := make(map[uint32]string)
|
||||
|
@ -149,7 +149,7 @@ func (m *packageManager) decodePackages(decoder *xml.Decoder) error {
|
|||
if userID == 0 && name == "" {
|
||||
continue
|
||||
}
|
||||
idByPackage[name] = append(idByPackage[name], uint32(userID))
|
||||
idByPackage[name] = uint32(userID)
|
||||
packageById[uint32(userID)] = name
|
||||
case "shared-user":
|
||||
var name string
|
||||
|
|
31
tun_rules.go
31
tun_rules.go
|
@ -15,23 +15,33 @@ const (
|
|||
)
|
||||
|
||||
func (o *Options) BuildAndroidRules(packageManager PackageManager, errorHandler E.Handler) {
|
||||
var includeUser []uint32
|
||||
if len(o.IncludeAndroidUser) > 0 {
|
||||
o.IncludeAndroidUser = common.Uniq(o.IncludeAndroidUser)
|
||||
sort.Ints(o.IncludeAndroidUser)
|
||||
var userExcludeRange []ranges.Range[uint32]
|
||||
for _, androidUser := range o.IncludeAndroidUser {
|
||||
o.IncludeUID = append(o.IncludeUID, ranges.New[uint32](uint32(androidUser)*androidUserRange, uint32(androidUser+1)*androidUserRange-1))
|
||||
includeUser = append(includeUser, uint32(androidUser))
|
||||
userExcludeRange = append(userExcludeRange, ranges.New[uint32](uint32(androidUser)*androidUserRange, uint32(androidUser+1)*androidUserRange-1))
|
||||
}
|
||||
userExcludeRange = ranges.Revert(0, userEnd, userExcludeRange)
|
||||
o.ExcludeUID = append(o.ExcludeUID, userExcludeRange...)
|
||||
}
|
||||
if len(includeUser) == 0 {
|
||||
includeUser = []uint32{0}
|
||||
}
|
||||
if len(o.IncludePackage) > 0 {
|
||||
o.IncludePackage = common.Uniq(o.IncludePackage)
|
||||
for _, packageName := range o.IncludePackage {
|
||||
if sharedId, loaded := packageManager.IDBySharedPackage(packageName); loaded {
|
||||
o.IncludeUID = append(o.IncludeUID, ranges.NewSingle(sharedId))
|
||||
for _, androidUser := range includeUser {
|
||||
o.IncludeUID = append(o.IncludeUID, ranges.NewSingle(sharedId+androidUser*androidUserRange))
|
||||
}
|
||||
continue
|
||||
}
|
||||
if ids, loaded := packageManager.IDByPackage(packageName); loaded {
|
||||
for _, id := range ids {
|
||||
o.IncludeUID = append(o.IncludeUID, ranges.NewSingle(id))
|
||||
if userId, loaded := packageManager.IDByPackage(packageName); loaded {
|
||||
for _, androidUser := range includeUser {
|
||||
o.IncludeUID = append(o.IncludeUID, ranges.NewSingle(userId+androidUser*androidUserRange))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
@ -42,12 +52,13 @@ func (o *Options) BuildAndroidRules(packageManager PackageManager, errorHandler
|
|||
o.ExcludePackage = common.Uniq(o.ExcludePackage)
|
||||
for _, packageName := range o.ExcludePackage {
|
||||
if sharedId, loaded := packageManager.IDBySharedPackage(packageName); loaded {
|
||||
o.ExcludeUID = append(o.ExcludeUID, ranges.NewSingle(sharedId))
|
||||
continue
|
||||
for _, androidUser := range includeUser {
|
||||
o.ExcludeUID = append(o.ExcludeUID, ranges.NewSingle(sharedId+androidUser*androidUserRange))
|
||||
}
|
||||
}
|
||||
if ids, loaded := packageManager.IDByPackage(packageName); loaded {
|
||||
for _, id := range ids {
|
||||
o.ExcludeUID = append(o.ExcludeUID, ranges.NewSingle(id))
|
||||
if userId, loaded := packageManager.IDByPackage(packageName); loaded {
|
||||
for _, androidUser := range includeUser {
|
||||
o.ExcludeUID = append(o.ExcludeUID, ranges.NewSingle(userId+androidUser*androidUserRange))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue