Skip to content

Commit 3511552

Browse files
committed
mdm: define OnboardingFlow syspolicy on Android
Adds an MDM setting `OnboardingFlow` which allows for the intro screen to be skipped when set to true. Adds MDM Setting update to the top of MainActivity onCreate to ensure the latest MDMSettings are accurate. When attempting to do this while relying on MDMSettings being update during onResume it created a race condition where occasionally OnboardingFlow was being evaluated to the default value `show` when in reality it should be set to `hide`. Signed-off-by: zbuchheit <zachb@tailscale.com>
1 parent 6fb006e commit 3511552

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import androidx.compose.animation.slideInHorizontally
3131
import androidx.compose.animation.slideOutHorizontally
3232
import androidx.compose.material3.MaterialTheme
3333
import androidx.compose.material3.Surface
34+
import androidx.compose.runtime.LaunchedEffect
3435
import androidx.compose.runtime.collectAsState
3536
import androidx.compose.ui.Modifier
3637
import androidx.core.net.toUri
@@ -44,6 +45,7 @@ import androidx.navigation.compose.composable
4445
import androidx.navigation.compose.rememberNavController
4546
import androidx.navigation.navArgument
4647
import com.tailscale.ipn.mdm.MDMSettings
48+
import com.tailscale.ipn.mdm.ShowHide
4749
import com.tailscale.ipn.ui.model.Ipn
4850
import com.tailscale.ipn.ui.notifier.Notifier
4951
import com.tailscale.ipn.ui.theme.AppTheme
@@ -123,6 +125,11 @@ class MainActivity : ComponentActivity() {
123125
App.get()
124126
vpnViewModel = ViewModelProvider(App.get()).get(VpnViewModel::class.java)
125127

128+
val rm = getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
129+
MDMSettings.update(App.get(), rm)
130+
131+
val onboardingFlowShowHide = MDMSettings.onboardingFlow.flow.value.value
132+
126133
// (jonathan) TODO: Force the app to be portrait on small screens until we have
127134
// proper landscape layout support
128135
if (!isLandscapeCapable()) {
@@ -290,12 +297,11 @@ class MainActivity : ComponentActivity() {
290297
onNavigateHome = backTo("main"), backTo("userSwitcher"))
291298
}
292299
}
293-
294-
// Show the intro screen one time
295-
if (!introScreenViewed()) {
296-
navController.navigate("intro")
297-
setIntroScreenViewed(true)
298-
}
300+
// Checks for onboarding flow one time, if it is set to hide, skip the intro screen
301+
if (onboardingFlowShowHide == ShowHide.Show && !introScreenViewed()) {
302+
navController.navigate("intro")
303+
setIntroScreenViewed(true)
304+
}
299305
}
300306
}
301307

android/src/main/java/com/tailscale/ipn/mdm/MDMSettings.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ object MDMSettings {
9797
// Overrides the value provided by os.Hostname() in Go
9898
val hostname = StringMDMSetting("Hostname", "Device Hostname")
9999

100+
// Allows admins to skip the get started intro screen
101+
val onboardingFlow = ShowHideMDMSetting("OnboardingFlow", "Suppress the intro screen")
102+
100103
val allSettings by lazy {
101104
MDMSettings::class
102105
.declaredMemberProperties

android/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@
214214
<string name="run_as_exit_node_visibility">Run as exit node visibility</string>
215215
<string name="defines_an_auth_key_that_will_be_used_for_login">Defines an auth key that will be used for login.</string>
216216
<string name="auth_key">Auth Key</string>
217+
<string name="skips_the_intro_page_shown_to_users_that_open_the_app_for_the_first_time">Skips the intro page shown to users that open the app for the first time</string>
218+
<string name="onboarding_flow">Set Onboarding Flow</string>
217219

218220
<!-- Permissions Management -->
219221
<string name="permissions">Permissions</string>

android/src/main/res/xml/app_restrictions.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,12 @@
134134
android:key="Hostname"
135135
android:restrictionType="string"
136136
android:title="@string/hostname" />
137+
138+
<restriction
139+
android:description="@string/skips_the_intro_page_shown_to_users_that_open_the_app_for_the_first_time"
140+
android:entries="@array/show_hide_labels"
141+
android:entryValues="@array/show_hide"
142+
android:key="OnboardingFlow"
143+
android:restrictionType="choice"
144+
android:title="@string/onboarding_flow" />
137145
</restrictions>

0 commit comments

Comments
 (0)