Skip to content

Commit b999309

Browse files
authored
mdm: define OnboardingFlow syspolicy on Android (#648)
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`. updates tailscale/corp#29482 Signed-off-by: zbuchheit <[email protected]>
1 parent 5f59a36 commit b999309

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import androidx.navigation.compose.composable
4949
import androidx.navigation.compose.rememberNavController
5050
import androidx.navigation.navArgument
5151
import com.tailscale.ipn.mdm.MDMSettings
52+
import com.tailscale.ipn.mdm.ShowHide
5253
import com.tailscale.ipn.ui.model.Ipn
5354
import com.tailscale.ipn.ui.notifier.Notifier
5455
import com.tailscale.ipn.ui.theme.AppTheme
@@ -133,6 +134,9 @@ class MainActivity : ComponentActivity() {
133134
App.get()
134135
vpnViewModel = ViewModelProvider(App.get()).get(VpnViewModel::class.java)
135136

137+
val rm = getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
138+
MDMSettings.update(App.get(), rm)
139+
136140
// (jonathan) TODO: Force the app to be portrait on small screens until we have
137141
// proper landscape layout support
138142
if (!isLandscapeCapable()) {
@@ -363,9 +367,7 @@ class MainActivity : ComponentActivity() {
363367
onNavigateHome = backTo("main"), backTo("userSwitcher"))
364368
}
365369
}
366-
367-
// Show the intro screen one time
368-
if (!introScreenViewed()) {
370+
if (shouldDisplayOnboarding()) {
369371
navController.navigate("intro")
370372
setIntroScreenViewed(true)
371373
}
@@ -523,8 +525,11 @@ class MainActivity : ComponentActivity() {
523525
startActivity(intent)
524526
}
525527

526-
private fun introScreenViewed(): Boolean {
527-
return getSharedPreferences("introScreen", Context.MODE_PRIVATE).getBoolean("seen", false)
528+
private fun shouldDisplayOnboarding(): Boolean {
529+
val onboardingFlowShowHide = MDMSettings.onboardingFlow.flow.value.value
530+
val introSeen =
531+
getSharedPreferences("introScreen", Context.MODE_PRIVATE).getBoolean("seen", false)
532+
return (onboardingFlowShowHide == ShowHide.Show && !introSeen)
528533
}
529534

530535
private fun setIntroScreenViewed(seen: Boolean) {

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

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

104+
// Allows admins to skip the get started intro screen
105+
val onboardingFlow = ShowHideMDMSetting("OnboardingFlow", "Suppress the intro screen")
106+
104107
val allSettings by lazy {
105108
MDMSettings::class
106109
.declaredMemberProperties

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@
220220
<string name="run_as_exit_node_visibility">Run as exit node visibility</string>
221221
<string name="defines_an_auth_key_that_will_be_used_for_login">Defines an auth key that will be used for login.</string>
222222
<string name="auth_key">Auth Key</string>
223+
<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>
224+
<string name="onboarding_flow">Skip the Onboarding Flow</string>
223225

224226
<!-- Permissions Management -->
225227
<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
@@ -140,4 +140,12 @@
140140
android:key="Hostname"
141141
android:restrictionType="string"
142142
android:title="@string/hostname" />
143+
144+
<restriction
145+
android:description="@string/skips_the_intro_page_shown_to_users_that_open_the_app_for_the_first_time"
146+
android:entries="@array/show_hide_labels"
147+
android:entryValues="@array/show_hide"
148+
android:key="OnboardingFlow"
149+
android:restrictionType="choice"
150+
android:title="@string/onboarding_flow" />
143151
</restrictions>

0 commit comments

Comments
 (0)