Skip to content

Commit 91f82b0

Browse files
committed
libtailscale: use syspolicy RegisterStore rather than deprecated RegisterHandler
Updates tailscale/tailscale#17022 Signed-off-by: Brad Fitzpatrick <brad@danga.com>
1 parent 981f5e8 commit 91f82b0

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

libtailscale/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type App struct {
5151
appCtx AppContext
5252

5353
store *stateStore
54-
policyStore *syspolicyHandler
54+
policyStore *syspolicyStore
5555
logIDPublicAtomic atomic.Pointer[logid.PublicID]
5656

5757
localAPIHandler http.Handler

libtailscale/syspolicy_handler.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,46 @@ import (
1010

1111
"tailscale.com/util/set"
1212
"tailscale.com/util/syspolicy"
13+
"tailscale.com/util/syspolicy/pkey"
1314
)
1415

15-
// syspolicyHandler is a syspolicy handler for the Android version of the Tailscale client,
16+
// syspolicyStore is a syspolicy Store for the Android version of the Tailscale client,
1617
// which lets the main networking code read values set via the Android RestrictionsManager.
17-
type syspolicyHandler struct {
18+
type syspolicyStore struct {
1819
a *App
1920
mu sync.RWMutex
2021
cbs set.HandleSet[func()]
2122
}
2223

23-
func (h *syspolicyHandler) ReadString(key string) (string, error) {
24+
func (h *syspolicyStore) ReadString(key pkey.Key) (string, error) {
2425
if key == "" {
2526
return "", syspolicy.ErrNoSuchKey
2627
}
27-
retVal, err := h.a.appCtx.GetSyspolicyStringValue(key)
28+
retVal, err := h.a.appCtx.GetSyspolicyStringValue(string(key))
2829
return retVal, translateHandlerError(err)
2930
}
3031

31-
func (h *syspolicyHandler) ReadBoolean(key string) (bool, error) {
32+
func (h *syspolicyStore) ReadBoolean(key pkey.Key) (bool, error) {
3233
if key == "" {
3334
return false, syspolicy.ErrNoSuchKey
3435
}
35-
retVal, err := h.a.appCtx.GetSyspolicyBooleanValue(key)
36+
retVal, err := h.a.appCtx.GetSyspolicyBooleanValue(string(key))
3637
return retVal, translateHandlerError(err)
3738
}
3839

39-
func (h *syspolicyHandler) ReadUInt64(key string) (uint64, error) {
40+
func (h *syspolicyStore) ReadUInt64(key pkey.Key) (uint64, error) {
4041
if key == "" {
4142
return 0, syspolicy.ErrNoSuchKey
4243
}
4344
// We don't have any UInt64 policy settings as of 2024-08-06.
4445
return 0, errors.New("ReadUInt64 is not implemented on Android")
4546
}
4647

47-
func (h *syspolicyHandler) ReadStringArray(key string) ([]string, error) {
48+
func (h *syspolicyStore) ReadStringArray(key pkey.Key) ([]string, error) {
4849
if key == "" {
4950
return nil, syspolicy.ErrNoSuchKey
5051
}
51-
retVal, err := h.a.appCtx.GetSyspolicyStringArrayJSONValue(key)
52+
retVal, err := h.a.appCtx.GetSyspolicyStringArrayJSONValue(string(key))
5253
if err := translateHandlerError(err); err != nil {
5354
return nil, err
5455
}
@@ -63,7 +64,7 @@ func (h *syspolicyHandler) ReadStringArray(key string) ([]string, error) {
6364
return arr, err
6465
}
6566

66-
func (h *syspolicyHandler) RegisterChangeCallback(cb func()) (unregister func(), err error) {
67+
func (h *syspolicyStore) RegisterChangeCallback(cb func()) (unregister func(), err error) {
6768
h.mu.Lock()
6869
handle := h.cbs.Add(cb)
6970
h.mu.Unlock()
@@ -74,7 +75,7 @@ func (h *syspolicyHandler) RegisterChangeCallback(cb func()) (unregister func(),
7475
}, nil
7576
}
7677

77-
func (h *syspolicyHandler) notifyChanged() {
78+
func (h *syspolicyStore) notifyChanged() {
7879
h.mu.RLock()
7980
for _, cb := range h.cbs {
8081
go cb()

libtailscale/tailscale.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
"tailscale.com/types/logger"
2020
"tailscale.com/types/logid"
2121
"tailscale.com/util/clientmetric"
22-
"tailscale.com/util/syspolicy"
22+
"tailscale.com/util/syspolicy/rsop"
23+
"tailscale.com/util/syspolicy/setting"
2324
)
2425

2526
const defaultMTU = 1280 // minimalMTU from wgengine/userspace.go
@@ -39,9 +40,9 @@ func newApp(dataDir, directFileRoot string, appCtx AppContext) Application {
3940
a.ready.Add(2)
4041

4142
a.store = newStateStore(a.appCtx)
42-
a.policyStore = &syspolicyHandler{a: a}
43+
a.policyStore = &syspolicyStore{a: a}
4344
netmon.RegisterInterfaceGetter(a.getInterfaces)
44-
syspolicy.RegisterHandler(a.policyStore)
45+
rsop.RegisterStore("DeviceHandler", setting.DeviceScope, a.policyStore)
4546
go a.watchFileOpsChanges()
4647

4748
go func() {

0 commit comments

Comments
 (0)