From 82356f6e9377ed5b2cc080d854d3725e1fd1492e Mon Sep 17 00:00:00 2001 From: Zhou Liu Date: Fri, 24 Jan 2025 05:34:18 +0000 Subject: [PATCH] Create "Manage PIN" settings UI menu Test: atest SupervisionPinManagementScreenTest Test: manually on real device Bug: 390186179 Flag: android.app.supervision.flags.enable_supervision_settings_screen Change-Id: Ib53dce2a32fe9551e8877145a61c8834505d389d --- res/values/strings.xml | 4 ++ .../supervision/SupervisionDashboardScreen.kt | 1 + .../SupervisionPinManagementFragment.kt | 29 +++++++++++ .../SupervisionPinManagementScreen.kt | 51 +++++++++++++++++++ .../SupervisionPinManagementScreenTest.kt | 47 +++++++++++++++++ 5 files changed, 132 insertions(+) create mode 100644 src/com/android/settings/supervision/SupervisionPinManagementFragment.kt create mode 100644 src/com/android/settings/supervision/SupervisionPinManagementScreen.kt create mode 100644 tests/robotests/src/com/android/settings/supervision/SupervisionPinManagementScreenTest.kt diff --git a/res/values/strings.xml b/res/values/strings.xml index ce2e3985b4e..1c98bc35a53 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -14084,4 +14084,8 @@ Set up PIN to get started supervision, parental supervision, parental controls + + Manage PIN + + Add a PIN recovery method diff --git a/src/com/android/settings/supervision/SupervisionDashboardScreen.kt b/src/com/android/settings/supervision/SupervisionDashboardScreen.kt index f31b0bdfeaf..13f6a8524ae 100644 --- a/src/com/android/settings/supervision/SupervisionDashboardScreen.kt +++ b/src/com/android/settings/supervision/SupervisionDashboardScreen.kt @@ -60,6 +60,7 @@ class SupervisionDashboardScreen : PreferenceScreenCreator { +TitlelessPreferenceGroup("supervision_features_group_1") += { // Empty category for dynamic injection targeting. } + +SupervisionPinManagementScreen.KEY } companion object { diff --git a/src/com/android/settings/supervision/SupervisionPinManagementFragment.kt b/src/com/android/settings/supervision/SupervisionPinManagementFragment.kt new file mode 100644 index 00000000000..6de891ef27e --- /dev/null +++ b/src/com/android/settings/supervision/SupervisionPinManagementFragment.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.supervision + +import android.content.Context +import com.android.settingslib.preference.PreferenceFragment + +/** + * Fragment to display the Supervision PIN management page (Settings > Supervision > Manage PIN). + * + * See [SupervisionPinManagementScreen] for details on the page contents. + */ +class SupervisionPinManagementFragment : PreferenceFragment() { + override fun getPreferenceScreenBindingKey(context: Context) = + SupervisionPinManagementScreen.KEY +} diff --git a/src/com/android/settings/supervision/SupervisionPinManagementScreen.kt b/src/com/android/settings/supervision/SupervisionPinManagementScreen.kt new file mode 100644 index 00000000000..e087a284987 --- /dev/null +++ b/src/com/android/settings/supervision/SupervisionPinManagementScreen.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.supervision + +import android.content.Context +import com.android.settings.R +import com.android.settingslib.metadata.ProvidePreferenceScreen +import com.android.settingslib.metadata.preferenceHierarchy +import com.android.settingslib.preference.PreferenceScreenCreator + +/** Pin Management landing page (Settings > Supervision > Manage Pin). */ +@ProvidePreferenceScreen(SupervisionPinManagementScreen.KEY) +class SupervisionPinManagementScreen : PreferenceScreenCreator { + override val key: String + get() = KEY + + override val title: Int + get() = R.string.supervision_pin_management_preference_title + + // TODO(b/391994031): dynamically update the summary according to PIN status. + override val summary: Int + get() = R.string.supervision_pin_management_preference_summary_add + + // TODO(b/391994031): dynamically update the icon according to PIN status. + override val icon: Int + get() = R.drawable.ic_pin + + override fun fragmentClass() = SupervisionPinManagementFragment::class.java + + override fun getPreferenceHierarchy(context: Context) = + preferenceHierarchy(context, this) { + // TODO(b/391992481) implement the screen. + } + + companion object { + const val KEY = "supervision_pin_management" + } +} diff --git a/tests/robotests/src/com/android/settings/supervision/SupervisionPinManagementScreenTest.kt b/tests/robotests/src/com/android/settings/supervision/SupervisionPinManagementScreenTest.kt new file mode 100644 index 00000000000..ab37b3ca4e9 --- /dev/null +++ b/tests/robotests/src/com/android/settings/supervision/SupervisionPinManagementScreenTest.kt @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.supervision + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class SupervisionPinManagementScreenTest { + private val context: Context = ApplicationProvider.getApplicationContext() + + private val supervisionPinManagementScreen = SupervisionPinManagementScreen() + + @Test + fun key() { + assertThat(supervisionPinManagementScreen.key).isEqualTo(SupervisionPinManagementScreen.KEY) + } + + @Test + fun getTitle() { + assertThat(supervisionPinManagementScreen.getPreferenceTitle(context)) + .isEqualTo("Manage PIN") + } + + @Test + fun getSummary_addPin() { + assertThat(supervisionPinManagementScreen.getPreferenceSummary(context)) + .isEqualTo("Add a PIN recovery method") + } +}