Skip to content

Commit 6e18e47

Browse files
committed
Work profile preferences UI
1 parent d1474ca commit 6e18e47

File tree

9 files changed

+145
-3
lines changed

9 files changed

+145
-3
lines changed

play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsContract.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ object SettingsContract {
278278
}
279279

280280
object WorkProfile {
281-
const val ID = "emm" // Enterprise Mobility Management
281+
const val ID = "workprofile"
282282
fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), ID)
283283
fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$ID"
284284

285-
const val CREATE_WORK_ACCOUNT = "emm_allow_provision"
285+
const val CREATE_WORK_ACCOUNT = "workprofile_allow_create_work_account"
286286

287287
val PROJECTION = arrayOf(
288288
CREATE_WORK_ACCOUNT

play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.google.android.gms.R
1515
import org.microg.gms.checkin.CheckinPreferences
1616
import org.microg.gms.gcm.GcmDatabase
1717
import org.microg.gms.gcm.GcmPrefs
18-
import org.microg.gms.vending.VendingPreferences
1918
import org.microg.gms.safetynet.SafetyNetPreferences
2019
import org.microg.gms.ui.settings.SettingsProvider
2120
import org.microg.gms.ui.settings.getAllSettingsProviders
@@ -51,6 +50,10 @@ class SettingsFragment : ResourceSettingsFragment() {
5150
findNavController().navigate(requireContext(), R.id.openVendingSettings)
5251
true
5352
}
53+
findPreference<Preference>(PREF_WORK_PROFILE)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
54+
findNavController().navigate(requireContext(), R.id.openWorkProfileSettings)
55+
true
56+
}
5457

5558
findPreference<Preference>(PREF_ABOUT)!!.apply {
5659
onPreferenceClickListener = Preference.OnPreferenceClickListener {
@@ -134,6 +137,7 @@ class SettingsFragment : ResourceSettingsFragment() {
134137
const val PREF_LOCATION = "pref_location"
135138
const val PREF_CHECKIN = "pref_checkin"
136139
const val PREF_VENDING = "pref_vending"
140+
const val PREF_WORK_PROFILE = "pref_work_profile"
137141
const val PREF_ACCOUNTS = "pref_accounts"
138142
}
139143

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023, e Foundation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.microg.gms.ui
7+
8+
import android.annotation.SuppressLint
9+
import android.os.Bundle
10+
import androidx.lifecycle.lifecycleScope
11+
import androidx.preference.Preference
12+
import androidx.preference.PreferenceFragmentCompat
13+
import androidx.preference.TwoStatePreference
14+
import com.google.android.gms.R
15+
import org.microg.gms.vending.VendingPreferences
16+
import org.microg.gms.workprofile.WorkProfilePreferences
17+
18+
class WorkProfileFragment : PreferenceFragmentCompat() {
19+
private lateinit var workProfileEnabled: SwitchBarPreference
20+
21+
private lateinit var workProfilePreferences: WorkProfilePreferences
22+
23+
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
24+
addPreferencesFromResource(R.xml.preferences_work_profile)
25+
}
26+
27+
@SuppressLint("RestrictedApi")
28+
override fun onBindPreferences() {
29+
30+
workProfilePreferences = WorkProfilePreferences(requireContext().applicationContext)
31+
32+
workProfileEnabled = preferenceScreen.findPreference(PREF_CREATE_ACCOUNT) ?: workProfileEnabled
33+
workProfileEnabled.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
34+
lifecycleScope.launchWhenResumed {
35+
if (newValue is Boolean) {
36+
workProfilePreferences.allowCreateWorkAccount = newValue
37+
}
38+
updateContent()
39+
}
40+
true
41+
}
42+
}
43+
44+
override fun onResume() {
45+
super.onResume()
46+
updateContent()
47+
}
48+
49+
private fun updateContent() {
50+
lifecycleScope.launchWhenResumed {
51+
workProfileEnabled.isChecked = workProfilePreferences.allowCreateWorkAccount
52+
}
53+
}
54+
55+
companion object {
56+
const val PREF_CREATE_ACCOUNT = "workprofile_allow_create_work_account"
57+
}
58+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.microg.gms.workprofile
2+
3+
import android.content.ContentValues
4+
import android.content.Context
5+
import android.database.Cursor
6+
import org.microg.gms.settings.SettingsContract
7+
import org.microg.gms.settings.SettingsContract.CheckIn
8+
9+
class WorkProfilePreferences(private val context: Context) {
10+
private fun <T> getSettings(vararg projection: String, f: (Cursor) -> T): T =
11+
SettingsContract.getSettings(
12+
context,
13+
SettingsContract.WorkProfile.getContentUri(context),
14+
projection,
15+
f
16+
)
17+
18+
private fun setSettings(v: ContentValues.() -> Unit) =
19+
SettingsContract.setSettings(context, SettingsContract.WorkProfile.getContentUri(context), v)
20+
21+
var allowCreateWorkAccount: Boolean
22+
get() = getSettings(SettingsContract.WorkProfile.CREATE_WORK_ACCOUNT) { c -> c.getInt(0) != 0 }
23+
set(value) = setSettings { put(SettingsContract.WorkProfile.CREATE_WORK_ACCOUNT, value) }
24+
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--
2+
~ SPDX-FileCopyrightText: Android Open Source Project
3+
~ SPDX-License-Identifier: Apache-2.0
4+
-->
5+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
6+
7+
<path android:fillColor="@android:color/white" android:pathData="M20,6h-4L16,4c0,-1.11 -0.89,-2 -2,-2h-4c-1.11,0 -2,0.89 -2,2v2L4,6c-1.11,0 -1.99,0.89 -1.99,2L2,19c0,1.11 0.89,2 2,2h16c1.11,0 2,-0.89 2,-2L22,8c0,-1.11 -0.89,-2 -2,-2zM14,6h-4L10,4h4v2z"/>
8+
9+
</vector>

play-services-core/src/main/res/navigation/nav_settings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<action
2727
android:id="@+id/openVendingSettings"
2828
app:destination="@id/vendingFragment" />
29+
<action
30+
android:id="@+id/openWorkProfileSettings"
31+
app:destination="@id/workProfileFragment" />
2932
<action
3033
android:id="@+id/openMoreGoogleSettings"
3134
app:destination="@id/googleMoreFragment" />
@@ -158,6 +161,13 @@
158161
android:name="org.microg.gms.ui.VendingFragment"
159162
android:label="@string/service_name_vending" />
160163

164+
<!-- Work profile -->
165+
166+
<fragment
167+
android:id="@+id/workProfileFragment"
168+
android:name="org.microg.gms.ui.WorkProfileFragment"
169+
android:label="@string/service_name_work_profile" />
170+
161171
<!-- More -->
162172

163173
<fragment

play-services-core/src/main/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Please set up a password, PIN, or pattern lock screen."</string>
9696
<string name="service_name_mcs">Cloud Messaging</string>
9797
<string name="service_name_snet">Google SafetyNet</string>
9898
<string name="service_name_vending">Play Store services</string>
99+
<string name="service_name_work_profile">Work profile</string>
99100

100101
<string name="games_title">Google Play Games</string>
101102
<string name="games_info_title"><xliff:g example="F-Droid">%1$s</xliff:g> would like to use Play Games</string>
@@ -300,6 +301,12 @@ Please set up a password, PIN, or pattern lock screen."</string>
300301
<string name="pref_vending_asset_device_sync_summary">Applications using Play Asset Delivery will download additional assets based on the information of the device currently in use.</string>
301302
<string name="pref_vending_asset_device_sync_switch">Enable device information sync</string>
302303

304+
<string name="pref_workprofile_create_account">Allow work account setup</string>
305+
<string name="pref_workprofile_intro">When setting up a work profile for your workplace or educational institution,
306+
setup may attempt to connect to Google to enable downloading apps to that profile.</string>
307+
<string name="pref_workprofile_disclaimer">It is your responsibility to ensure that your usage of microG is in line with corporate policies.
308+
microG is provided on a best-effort basis and cannot guarantee to behave exactly as expected.</string>
309+
303310
<string name="credentials_assisted_cancel">Cancel</string>
304311
<string name="credentials_assisted_continue">Continue</string>
305312
<string name="credentials_assisted_confirmation_header">Signing you in</string>

play-services-core/src/main/res/xml/preferences_start.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
android:icon="@drawable/ic_shop"
4949
android:key="pref_vending"
5050
android:title="@string/service_name_vending" />
51+
<Preference
52+
android:icon="@drawable/ic_work"
53+
android:key="pref_work_profile"
54+
android:title="@string/service_name_work_profile" />
5155
<Preference
5256
android:icon="@drawable/dots_horizontal"
5357
android:key="pref_google_more"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ SPDX-FileCopyrightText: 2023, e Foundation
3+
~ SPDX-License-Identifier: Apache-2.0
4+
-->
5+
6+
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
7+
xmlns:app="http://schemas.android.com/apk/res-auto">
8+
9+
<org.microg.gms.ui.SwitchBarPreference
10+
android:title="@string/pref_workprofile_create_account"
11+
android:key="workprofile_allow_create_work_account"
12+
android:persistent="false" />
13+
14+
<org.microg.gms.ui.TextPreference
15+
android:key="pref_safetynet_summary"
16+
android:selectable="false"
17+
app:iconSpaceReserved="false"
18+
android:summary="@string/pref_workprofile_intro" />
19+
20+
<org.microg.gms.ui.TextPreference
21+
android:icon="@drawable/ic_circle_warn"
22+
android:selectable="false"
23+
android:summary="@string/pref_workprofile_disclaimer" />
24+
25+
</PreferenceScreen>

0 commit comments

Comments
 (0)