blob: 9aaf529d375fd71dde8a6f6bdfdbf6f58121a51c [file] [log] [blame]
Yvonne Jiangb3c8c712025-01-21 03:12:44 -08001/*
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 */
16package com.android.settings.supervision
17
18import android.app.supervision.flags.Flags
Yvonne Jiangadf77152025-07-30 04:36:01 -070019import android.content.ComponentName
Yvonne Jiangb3c8c712025-01-21 03:12:44 -080020import android.content.Context
Zhou Liuaee2de02025-04-18 04:26:02 +000021import android.content.Intent
22import androidx.preference.Preference
Yvonne Jiangadf77152025-07-30 04:36:01 -070023import androidx.preference.PreferenceScreen
24import com.android.settings.SettingsActivity.EXTRA_IS_SECOND_LAYER_PAGE
25import com.android.settings.activityembedding.ActivityEmbeddingRulesController
Yvonne Jiangb3c8c712025-01-21 03:12:44 -080026import com.android.settings.core.BasePreferenceController
27
28/** Controller for the top level Supervision settings Preference item. */
Zhou Liuc7868212025-05-19 23:10:18 +000029class TopLevelSupervisionPreferenceController(context: Context, key: String) :
30 BasePreferenceController(context, key) {
Yvonne Jiangadf77152025-07-30 04:36:01 -070031
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 Liuc7868212025-05-19 23:10:18 +000042 override fun handlePreferenceTreeClick(preference: Preference): Boolean {
43 if (preference.key == preferenceKey) {
Zhou Liuecd62672025-05-29 22:03:11 +000044 val intent = Intent(mContext, SupervisionDashboardActivity::class.java)
Yvonne Jiangadf77152025-07-30 04:36:01 -070045 intent.putExtra(EXTRA_IS_SECOND_LAYER_PAGE, true)
Zhou Liuc7868212025-05-19 23:10:18 +000046 mContext.startActivity(intent)
Zhou Liuaee2de02025-04-18 04:26:02 +000047 return true
48 }
49 return super.handlePreferenceTreeClick(preference)
50 }
51
Zhou Liuaee2de02025-04-18 04:26:02 +000052 override fun getAvailabilityStatus(): Int {
Zhou Liu9e85c352025-06-13 04:23:07 +000053 // 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 Jiang22d85e52025-06-26 16:22:57 -070059 (!hasNecessarySupervisionComponent &&
60 mContext.getSupervisionAppInstallActivityInfo() == null)
Zhou Liu9e85c352025-06-13 04:23:07 +000061 ) {
Zhou Liuaee2de02025-04-18 04:26:02 +000062 return UNSUPPORTED_ON_DEVICE
Zhou Liuaee2de02025-04-18 04:26:02 +000063 }
64
65 return AVAILABLE
66 }
Yvonne Jiangb3c8c712025-01-21 03:12:44 -080067}