| Yvonne Jiang | b3c8c71 | 2025-01-21 03:12:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2025 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.settings.supervision |
| 17 | |
| 18 | import android.app.supervision.flags.Flags |
| Yvonne Jiang | adf7715 | 2025-07-30 04:36:01 -0700 | [diff] [blame] | 19 | import android.content.ComponentName |
| Yvonne Jiang | b3c8c71 | 2025-01-21 03:12:44 -0800 | [diff] [blame] | 20 | import android.content.Context |
| Zhou Liu | aee2de0 | 2025-04-18 04:26:02 +0000 | [diff] [blame] | 21 | import android.content.Intent |
| 22 | import androidx.preference.Preference |
| Yvonne Jiang | adf7715 | 2025-07-30 04:36:01 -0700 | [diff] [blame] | 23 | import androidx.preference.PreferenceScreen |
| 24 | import com.android.settings.SettingsActivity.EXTRA_IS_SECOND_LAYER_PAGE |
| 25 | import com.android.settings.activityembedding.ActivityEmbeddingRulesController |
| Yvonne Jiang | b3c8c71 | 2025-01-21 03:12:44 -0800 | [diff] [blame] | 26 | import com.android.settings.core.BasePreferenceController |
| 27 | |
| 28 | /** Controller for the top level Supervision settings Preference item. */ |
| Zhou Liu | c786821 | 2025-05-19 23:10:18 +0000 | [diff] [blame] | 29 | class TopLevelSupervisionPreferenceController(context: Context, key: String) : |
| 30 | BasePreferenceController(context, key) { |
| Yvonne Jiang | adf7715 | 2025-07-30 04:36:01 -0700 | [diff] [blame] | 31 | |
| 32 | override fun displayPreference(screen: PreferenceScreen) { |
| 33 | super.displayPreference(screen) |
| 34 | ActivityEmbeddingRulesController.registerTwoPanePairRuleForSettingsHome( |
| 35 | mContext, |
| 36 | ComponentName(mContext, SupervisionDashboardActivity::class.java), |
| 37 | /* secondaryIntentAction= */ null, |
| 38 | /* clearTop= */ true, |
| 39 | ) |
| 40 | } |
| 41 | |
| Zhou Liu | c786821 | 2025-05-19 23:10:18 +0000 | [diff] [blame] | 42 | override fun handlePreferenceTreeClick(preference: Preference): Boolean { |
| 43 | if (preference.key == preferenceKey) { |
| Zhou Liu | ecd6267 | 2025-05-29 22:03:11 +0000 | [diff] [blame] | 44 | val intent = Intent(mContext, SupervisionDashboardActivity::class.java) |
| Yvonne Jiang | adf7715 | 2025-07-30 04:36:01 -0700 | [diff] [blame] | 45 | intent.putExtra(EXTRA_IS_SECOND_LAYER_PAGE, true) |
| Zhou Liu | c786821 | 2025-05-19 23:10:18 +0000 | [diff] [blame] | 46 | mContext.startActivity(intent) |
| Zhou Liu | aee2de0 | 2025-04-18 04:26:02 +0000 | [diff] [blame] | 47 | return true |
| 48 | } |
| 49 | return super.handlePreferenceTreeClick(preference) |
| 50 | } |
| 51 | |
| Zhou Liu | aee2de0 | 2025-04-18 04:26:02 +0000 | [diff] [blame] | 52 | override fun getAvailabilityStatus(): Int { |
| Zhou Liu | 9e85c35 | 2025-06-13 04:23:07 +0000 | [diff] [blame] | 53 | // Hide the supervision entry in settings if the necessary supervision component is not |
| 54 | // available and can't be fixed by user. |
| 55 | val hasNecessarySupervisionComponent = |
| 56 | mContext.hasNecessarySupervisionComponent(matchAll = true) |
| 57 | if ( |
| 58 | !Flags.enableSupervisionSettingsScreen() || |
| Yvonne Jiang | 22d85e5 | 2025-06-26 16:22:57 -0700 | [diff] [blame] | 59 | (!hasNecessarySupervisionComponent && |
| 60 | mContext.getSupervisionAppInstallActivityInfo() == null) |
| Zhou Liu | 9e85c35 | 2025-06-13 04:23:07 +0000 | [diff] [blame] | 61 | ) { |
| Zhou Liu | aee2de0 | 2025-04-18 04:26:02 +0000 | [diff] [blame] | 62 | return UNSUPPORTED_ON_DEVICE |
| Zhou Liu | aee2de0 | 2025-04-18 04:26:02 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | return AVAILABLE |
| 66 | } |
| Yvonne Jiang | b3c8c71 | 2025-01-21 03:12:44 -0800 | [diff] [blame] | 67 | } |