Merge "Update "Manage PIN" entry point." into main
This commit is contained in:
25
res/drawable/ic_pin_outline.xml
Normal file
25
res/drawable/ic_pin_outline.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="960"
|
||||
android:viewportWidth="960"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160L800,160Q833,160 856.5,183.5Q880,207 880,240L880,720Q880,753 856.5,776.5Q833,800 800,800L160,800ZM260,600L306,600L306,360L270,360L200,410L224,446L260,420L260,600ZM384,600L540,600L540,560L446,560L444,558Q465,538 478.5,524Q492,510 500,502Q518,484 527,466Q536,448 536,428Q536,399 514,379.5Q492,360 458,360Q432,360 411,375Q390,390 382,414L422,430Q427,417 436.5,409.5Q446,402 458,402Q473,402 482.5,410Q492,418 492,430Q492,441 488,450.5Q484,460 470,474Q459,485 438,506Q417,527 384,560L384,600ZM680,600Q716,600 738,580Q760,560 760,528Q760,510 750,496Q740,482 722,474L722,472Q736,464 744,451.5Q752,439 752,422Q752,395 731,377.5Q710,360 678,360Q653,360 631.5,374.5Q610,389 604,410L644,426Q648,414 657,407Q666,400 678,400Q691,400 699.5,407.5Q708,415 708,426Q708,440 698,448Q688,456 672,456L654,456L654,496L674,496Q694,496 705,504Q716,512 716,526Q716,539 705,548.5Q694,558 680,558Q663,558 654,550.5Q645,543 638,524L598,540Q605,569 626.5,584.5Q648,600 680,600ZM160,720L800,720Q800,720 800,720Q800,720 800,720L800,240Q800,240 800,240Q800,240 800,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720ZM160,720Q160,720 160,720Q160,720 160,720L160,240Q160,240 160,240Q160,240 160,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720Z" />
|
||||
</vector>
|
54
src/com/android/settings/supervision/SupervisionHelper.kt
Normal file
54
src/com/android/settings/supervision/SupervisionHelper.kt
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.app.KeyguardManager
|
||||
import android.content.Context
|
||||
import android.os.UserHandle
|
||||
import android.os.UserManager
|
||||
import android.os.UserManager.USER_TYPE_PROFILE_SUPERVISING
|
||||
import androidx.annotation.VisibleForTesting
|
||||
|
||||
/** Convenience methods for interacting with the supervising user profile. */
|
||||
open class SupervisionHelper private constructor(context: Context) {
|
||||
private val mUserManager = context.getSystemService(UserManager::class.java)
|
||||
private val mKeyguardManager = context.getSystemService(KeyguardManager::class.java)
|
||||
|
||||
fun getSupervisingUserHandle(): UserHandle? {
|
||||
for (user in (mUserManager?.users ?: emptyList())) {
|
||||
if (user.userType.equals(USER_TYPE_PROFILE_SUPERVISING)) {
|
||||
return user.userHandle
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun isSupervisingCredentialSet(): Boolean {
|
||||
val supervisingUserId = getSupervisingUserHandle()?.identifier ?: return false
|
||||
return mKeyguardManager?.isDeviceSecure(supervisingUserId) ?: false
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Volatile @VisibleForTesting var sInstance: SupervisionHelper? = null
|
||||
|
||||
fun getInstance(context: Context): SupervisionHelper {
|
||||
return sInstance
|
||||
?: synchronized(this) {
|
||||
sInstance ?: SupervisionHelper(context).also { sInstance = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -83,6 +83,7 @@ class SupervisionMainSwitchPreference(context: Context) :
|
||||
val newValue = !supervisionMainSwitchStorage.getBoolean(KEY)!!
|
||||
mainSwitchPreference.setChecked(newValue)
|
||||
updateDependentPreferencesEnabledState(mainSwitchPreference, newValue)
|
||||
context.notifyPreferenceChange(SupervisionPinManagementScreen.KEY)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -110,10 +111,7 @@ class SupervisionMainSwitchPreference(context: Context) :
|
||||
isChecked: Boolean,
|
||||
) {
|
||||
preference?.parent?.forEachRecursively {
|
||||
if (
|
||||
it.parent?.key == SupervisionDashboardScreen.SUPERVISION_DYNAMIC_GROUP_1 ||
|
||||
it.key == SupervisionPinManagementScreen.KEY
|
||||
) {
|
||||
if (it.parent?.key == SupervisionDashboardScreen.SUPERVISION_DYNAMIC_GROUP_1) {
|
||||
it.isEnabled = isChecked
|
||||
}
|
||||
}
|
||||
|
@@ -17,16 +17,20 @@ package com.android.settings.supervision
|
||||
|
||||
import android.content.Context
|
||||
import com.android.settings.R
|
||||
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
|
||||
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 {
|
||||
class SupervisionPinManagementScreen : PreferenceScreenCreator, PreferenceAvailabilityProvider {
|
||||
override val key: String
|
||||
get() = KEY
|
||||
|
||||
override fun isAvailable(context: Context) =
|
||||
SupervisionHelper.getInstance(context).isSupervisingCredentialSet()
|
||||
|
||||
override val title: Int
|
||||
get() = R.string.supervision_pin_management_preference_title
|
||||
|
||||
@@ -36,7 +40,7 @@ class SupervisionPinManagementScreen : PreferenceScreenCreator {
|
||||
|
||||
// TODO(b/391994031): dynamically update the icon according to PIN status.
|
||||
override val icon: Int
|
||||
get() = R.drawable.ic_pin
|
||||
get() = R.drawable.ic_pin_outline
|
||||
|
||||
override fun fragmentClass() = SupervisionPinManagementFragment::class.java
|
||||
|
||||
|
@@ -65,7 +65,7 @@ class SupervisionDashboardScreenTest {
|
||||
val mainSwitchPreference =
|
||||
fragment.findPreference<MainSwitchPreference>(SupervisionMainSwitchPreference.KEY)!!
|
||||
val childPreference =
|
||||
fragment.findPreference<Preference>(SupervisionPinManagementScreen.KEY)!!
|
||||
fragment.findPreference<Preference>(SupervisionWebContentFiltersScreen.KEY)!!
|
||||
|
||||
assertThat(childPreference.isEnabled).isFalse()
|
||||
|
||||
@@ -89,7 +89,7 @@ class SupervisionDashboardScreenTest {
|
||||
val mainSwitchPreference =
|
||||
fragment.findPreference<MainSwitchPreference>(SupervisionMainSwitchPreference.KEY)!!
|
||||
val childPreference =
|
||||
fragment.findPreference<Preference>(SupervisionPinManagementScreen.KEY)!!
|
||||
fragment.findPreference<Preference>(SupervisionWebContentFiltersScreen.KEY)!!
|
||||
|
||||
assertThat(childPreference.isEnabled).isFalse()
|
||||
|
||||
|
@@ -15,25 +15,73 @@
|
||||
*/
|
||||
package com.android.settings.supervision
|
||||
|
||||
import android.app.KeyguardManager
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.content.pm.UserInfo
|
||||
import android.os.UserManager
|
||||
import android.os.UserManager.USER_TYPE_PROFILE_SUPERVISING
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.settings.R
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.whenever
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class SupervisionPinManagementScreenTest {
|
||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||
private val mockKeyguardManager = mock<KeyguardManager>()
|
||||
private val mockUserManager = mock<UserManager>()
|
||||
|
||||
private val context: Context =
|
||||
object : ContextWrapper(ApplicationProvider.getApplicationContext()) {
|
||||
override fun getSystemService(name: String): Any? =
|
||||
when (name) {
|
||||
Context.KEYGUARD_SERVICE -> mockKeyguardManager
|
||||
Context.USER_SERVICE -> mockUserManager
|
||||
else -> super.getSystemService(name)
|
||||
}
|
||||
}
|
||||
|
||||
private val supervisionPinManagementScreen = SupervisionPinManagementScreen()
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
SupervisionHelper.sInstance = null
|
||||
}
|
||||
|
||||
@Test
|
||||
fun key() {
|
||||
assertThat(supervisionPinManagementScreen.key).isEqualTo(SupervisionPinManagementScreen.KEY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isAvailable() {
|
||||
whenever(mockUserManager.users).thenReturn(listOf(SUPERVISING_USER_INFO))
|
||||
whenever(mockKeyguardManager.isDeviceSecure(SUPERVISING_USER_ID)).thenReturn(true)
|
||||
|
||||
assertThat(supervisionPinManagementScreen.isAvailable(context)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isAvailable_noSupervisingUser_returnsFalse() {
|
||||
whenever(mockUserManager.users).thenReturn(emptyList())
|
||||
whenever(mockKeyguardManager.isDeviceSecure(SUPERVISING_USER_ID)).thenReturn(true)
|
||||
|
||||
assertThat(supervisionPinManagementScreen.isAvailable(context)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isAvailable_noSupervisingCredential_returnsFalse() {
|
||||
whenever(mockUserManager.users).thenReturn(listOf(SUPERVISING_USER_INFO))
|
||||
whenever(mockKeyguardManager.isDeviceSecure(SUPERVISING_USER_ID)).thenReturn(false)
|
||||
|
||||
assertThat(supervisionPinManagementScreen.isAvailable(context)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getTitle() {
|
||||
assertThat(supervisionPinManagementScreen.title)
|
||||
@@ -45,4 +93,16 @@ class SupervisionPinManagementScreenTest {
|
||||
assertThat(supervisionPinManagementScreen.summary)
|
||||
.isEqualTo(R.string.supervision_pin_management_preference_summary_add)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SUPERVISING_USER_ID = 5
|
||||
val SUPERVISING_USER_INFO =
|
||||
UserInfo(
|
||||
SUPERVISING_USER_ID,
|
||||
/* name */ "supervising",
|
||||
/* iconPath */ "",
|
||||
/* flags */ 0,
|
||||
USER_TYPE_PROFILE_SUPERVISING,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user