From 28712da8d042c0a5d82072323dd59ac57275fb12 Mon Sep 17 00:00:00 2001 From: kari-ts <135075563+kari-ts@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:56:10 -0700 Subject: [PATCH] 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 --- android/src/main/java/com/tailscale/ipn/App.kt | 10 ++-------- libtailscale/backend.go | 13 ++++--------- libtailscale/interfaces.go | 17 +++-------------- libtailscale/net.go | 2 +- libtailscale/tailscale.go | 5 ----- 5 files changed, 10 insertions(+), 37 deletions(-) diff --git a/android/src/main/java/com/tailscale/ipn/App.kt b/android/src/main/java/com/tailscale/ipn/App.kt index a9430dd..95acce5 100644 --- a/android/src/main/java/com/tailscale/ipn/App.kt +++ b/android/src/main/java/com/tailscale/ipn/App.kt @@ -38,7 +38,6 @@ import kotlinx.coroutines.cancel import kotlinx.coroutines.launch import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import libtailscale.BuildConfig as GoBuildConfig import libtailscale.Libtailscale import java.io.File import java.io.IOException @@ -80,6 +79,8 @@ class App : UninitializedApp(), libtailscale.AppContext, ViewModelStoreOwner { override fun isPlayVersion(): Boolean = MaybeGoogle.isGoogle() + override fun shouldUseGoogleDNSFallback() : Boolean = BuildConfig.USE_GOOGLE_DNS_FALLBACK + override fun log(s: String, s1: String) { Log.d(s, s1) } @@ -312,13 +313,6 @@ class App : UninitializedApp(), libtailscale.AppContext, ViewModelStoreOwner { } } - // getBuildConfig implements the libtailscale.AppContext interface. - override fun getBuildConfig(): GoBuildConfig { - var buildConfig = GoBuildConfig() - buildConfig.useGoogleDNSFallback = BuildConfig.USE_GOOGLE_DNS_FALLBACK - return buildConfig - } - fun notifyPolicyChanged() { app.notifyPolicyChanged() } diff --git a/libtailscale/backend.go b/libtailscale/backend.go index 414eeeb..908b7e2 100644 --- a/libtailscale/backend.go +++ b/libtailscale/backend.go @@ -44,9 +44,6 @@ type App struct { // appCtx is a global reference to the com.tailscale.ipn.App instance. appCtx AppContext - // buildConfig is the build configuration for the app. - buildConfig *BuildConfig - store *stateStore policyStore *syspolicyHandler logIDPublicAtomic atomic.Pointer[logid.PublicID] @@ -100,8 +97,7 @@ type backend struct { // when no nameservers are provided by Tailscale. avoidEmptyDNS bool - appCtx AppContext - buildConfig *BuildConfig + appCtx AppContext } type settingsFunc func(*router.Config, *dns.OSConfig) error @@ -266,10 +262,9 @@ func (a *App) newBackend(dataDir, directFileRoot string, appCtx AppContext, stor logf := logger.RusagePrefixLog(log.Printf) b := &backend{ - devices: newTUNDevices(), - settings: settings, - appCtx: appCtx, - buildConfig: a.buildConfig, + devices: newTUNDevices(), + settings: settings, + appCtx: appCtx, } var logID logid.PrivateID logID.UnmarshalText([]byte("dead0000dead0000dead0000dead0000dead0000dead0000dead0000dead0000")) diff --git a/libtailscale/interfaces.go b/libtailscale/interfaces.go index 11e40e2..d168fef 100644 --- a/libtailscale/interfaces.go +++ b/libtailscale/interfaces.go @@ -37,6 +37,9 @@ type AppContext interface { // (as opposed to F-droid/sideloaded). IsPlayVersion() bool + // ShouldUseGoogleDNSFallback reports whether or not to use Google for DNS fallback. + ShouldUseGoogleDNSFallback() bool + // IsChromeOS reports whether we're on a ChromeOS device. IsChromeOS() (bool, error) @@ -57,12 +60,6 @@ type AppContext interface { // GetSyspolicyStringArrayValue returns the current string array value for the given system policy, // expressed as a JSON string. GetSyspolicyStringArrayJSONValue(key string) (string, error) - - // GetBuildConfig gets the build configuration of the Android app. - // - // The returned BuildConfig should not change during the lifetime of - // the app. - GetBuildConfig() *BuildConfig } // IPNService corresponds to our IPNService in Java. @@ -172,11 +169,3 @@ func RequestVPN(service IPNService) { func ServiceDisconnect(service IPNService) { onDisconnect <- service } - -// BuildConfig is a struct that represents the build configuration of the -// Android application, as set in BuildConfig.java. -type BuildConfig struct { - // UseGoogleDNSFallback is whether to fall back to the Google public - // DNS servers if the platform's DNS servers cannot be determined. - UseGoogleDNSFallback bool -} diff --git a/libtailscale/net.go b/libtailscale/net.go index c49efd6..c4cb0a8 100644 --- a/libtailscale/net.go +++ b/libtailscale/net.go @@ -287,7 +287,7 @@ func (b *backend) getDNSBaseConfig() (ret dns.OSConfig, _ error) { // DNS config are lacking, and almost all Android phones use Google // services anyway, so it's a reasonable default: it's an ecosystem the // user has selected by having an Android device. - if len(ret.Nameservers) == 0 && b.buildConfig.UseGoogleDNSFallback { + if len(ret.Nameservers) == 0 && b.appCtx.ShouldUseGoogleDNSFallback() { log.Printf("getDNSBaseConfig: none found; falling back to Google public DNS") ret.Nameservers = append(ret.Nameservers, googleDNSServers...) } diff --git a/libtailscale/tailscale.go b/libtailscale/tailscale.go index 5d08cd7..7370726 100644 --- a/libtailscale/tailscale.go +++ b/libtailscale/tailscale.go @@ -38,11 +38,6 @@ func newApp(dataDir, directFileRoot string, appCtx AppContext) Application { } a.ready.Add(2) - // Get the build configuration, if any. - if bc := appCtx.GetBuildConfig(); bc != nil { - a.buildConfig = bc - } - a.store = newStateStore(a.appCtx) a.policyStore = &syspolicyHandler{a: a} netmon.RegisterInterfaceGetter(a.getInterfaces)