Skip to content

Commit 28712da

Browse files
authored
android: fix BuildConfig infinite loop (#495)
Rather than create a Go struct that is set by Android, have Go call into Android to fetch build BuildConfig Updates tailscale/tailscale#13431 Signed-off-by: kari-ts <[email protected]>
1 parent 4556714 commit 28712da

File tree

5 files changed

+10
-37
lines changed

5 files changed

+10
-37
lines changed

android/src/main/java/com/tailscale/ipn/App.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import kotlinx.coroutines.cancel
3838
import kotlinx.coroutines.launch
3939
import kotlinx.serialization.encodeToString
4040
import kotlinx.serialization.json.Json
41-
import libtailscale.BuildConfig as GoBuildConfig
4241
import libtailscale.Libtailscale
4342
import java.io.File
4443
import java.io.IOException
@@ -80,6 +79,8 @@ class App : UninitializedApp(), libtailscale.AppContext, ViewModelStoreOwner {
8079

8180
override fun isPlayVersion(): Boolean = MaybeGoogle.isGoogle()
8281

82+
override fun shouldUseGoogleDNSFallback() : Boolean = BuildConfig.USE_GOOGLE_DNS_FALLBACK
83+
8384
override fun log(s: String, s1: String) {
8485
Log.d(s, s1)
8586
}
@@ -312,13 +313,6 @@ class App : UninitializedApp(), libtailscale.AppContext, ViewModelStoreOwner {
312313
}
313314
}
314315

315-
// getBuildConfig implements the libtailscale.AppContext interface.
316-
override fun getBuildConfig(): GoBuildConfig {
317-
var buildConfig = GoBuildConfig()
318-
buildConfig.useGoogleDNSFallback = BuildConfig.USE_GOOGLE_DNS_FALLBACK
319-
return buildConfig
320-
}
321-
322316
fun notifyPolicyChanged() {
323317
app.notifyPolicyChanged()
324318
}

libtailscale/backend.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ type App struct {
4444
// appCtx is a global reference to the com.tailscale.ipn.App instance.
4545
appCtx AppContext
4646

47-
// buildConfig is the build configuration for the app.
48-
buildConfig *BuildConfig
49-
5047
store *stateStore
5148
policyStore *syspolicyHandler
5249
logIDPublicAtomic atomic.Pointer[logid.PublicID]
@@ -100,8 +97,7 @@ type backend struct {
10097
// when no nameservers are provided by Tailscale.
10198
avoidEmptyDNS bool
10299

103-
appCtx AppContext
104-
buildConfig *BuildConfig
100+
appCtx AppContext
105101
}
106102

107103
type settingsFunc func(*router.Config, *dns.OSConfig) error
@@ -266,10 +262,9 @@ func (a *App) newBackend(dataDir, directFileRoot string, appCtx AppContext, stor
266262

267263
logf := logger.RusagePrefixLog(log.Printf)
268264
b := &backend{
269-
devices: newTUNDevices(),
270-
settings: settings,
271-
appCtx: appCtx,
272-
buildConfig: a.buildConfig,
265+
devices: newTUNDevices(),
266+
settings: settings,
267+
appCtx: appCtx,
273268
}
274269
var logID logid.PrivateID
275270
logID.UnmarshalText([]byte("dead0000dead0000dead0000dead0000dead0000dead0000dead0000dead0000"))

libtailscale/interfaces.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type AppContext interface {
3737
// (as opposed to F-droid/sideloaded).
3838
IsPlayVersion() bool
3939

40+
// ShouldUseGoogleDNSFallback reports whether or not to use Google for DNS fallback.
41+
ShouldUseGoogleDNSFallback() bool
42+
4043
// IsChromeOS reports whether we're on a ChromeOS device.
4144
IsChromeOS() (bool, error)
4245

@@ -57,12 +60,6 @@ type AppContext interface {
5760
// GetSyspolicyStringArrayValue returns the current string array value for the given system policy,
5861
// expressed as a JSON string.
5962
GetSyspolicyStringArrayJSONValue(key string) (string, error)
60-
61-
// GetBuildConfig gets the build configuration of the Android app.
62-
//
63-
// The returned BuildConfig should not change during the lifetime of
64-
// the app.
65-
GetBuildConfig() *BuildConfig
6663
}
6764

6865
// IPNService corresponds to our IPNService in Java.
@@ -172,11 +169,3 @@ func RequestVPN(service IPNService) {
172169
func ServiceDisconnect(service IPNService) {
173170
onDisconnect <- service
174171
}
175-
176-
// BuildConfig is a struct that represents the build configuration of the
177-
// Android application, as set in BuildConfig.java.
178-
type BuildConfig struct {
179-
// UseGoogleDNSFallback is whether to fall back to the Google public
180-
// DNS servers if the platform's DNS servers cannot be determined.
181-
UseGoogleDNSFallback bool
182-
}

libtailscale/net.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (b *backend) getDNSBaseConfig() (ret dns.OSConfig, _ error) {
287287
// DNS config are lacking, and almost all Android phones use Google
288288
// services anyway, so it's a reasonable default: it's an ecosystem the
289289
// user has selected by having an Android device.
290-
if len(ret.Nameservers) == 0 && b.buildConfig.UseGoogleDNSFallback {
290+
if len(ret.Nameservers) == 0 && b.appCtx.ShouldUseGoogleDNSFallback() {
291291
log.Printf("getDNSBaseConfig: none found; falling back to Google public DNS")
292292
ret.Nameservers = append(ret.Nameservers, googleDNSServers...)
293293
}

libtailscale/tailscale.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ func newApp(dataDir, directFileRoot string, appCtx AppContext) Application {
3838
}
3939
a.ready.Add(2)
4040

41-
// Get the build configuration, if any.
42-
if bc := appCtx.GetBuildConfig(); bc != nil {
43-
a.buildConfig = bc
44-
}
45-
4641
a.store = newStateStore(a.appCtx)
4742
a.policyStore = &syspolicyHandler{a: a}
4843
netmon.RegisterInterfaceGetter(a.getInterfaces)

0 commit comments

Comments
 (0)