Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 28871428 authored by Yvonne Jiang's avatar Yvonne Jiang
Browse files

Update "Manage PIN" entry point.

- Updates default icon to outlined version
- Makes availability conditional on existence of supervising credential
- Does not disable entry point when the main switch is disabled

Bug: 405159398
Test: atest SupervisionPinManagementScreenTest
Test: atest SupervisionDashboardScreenTest
Flag: android.app.supervision.flags.enable_supervision_settings_screen
Change-Id: I764a6b767019007a93aacf29ecf47677e16cb058
parent 10c60497
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<!--
    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 −0
Original line number Diff line number Diff line
/*
 * 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 }
                }
        }
    }
}
+2 −4
Original line number Diff line number Diff line
@@ -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
            }
        }
+6 −2
Original line number Diff line number Diff line
@@ -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

+2 −2
Original line number Diff line number Diff line
@@ -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()

Loading