• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.network.tether
17 
18 import android.content.Context
19 import android.net.TetheringManager
20 import android.os.UserManager
21 import com.android.settings.R
22 import com.android.settings.Settings.TetherSettingsActivity
23 import com.android.settings.datausage.DataSaverMainSwitchPreference
24 import com.android.settings.flags.Flags
25 import com.android.settings.network.TetherPreferenceController
26 import com.android.settings.restriction.PreferenceRestrictionMixin
27 import com.android.settings.utils.makeLaunchIntent
28 import com.android.settings.wifi.tether.WifiHotspotSwitchPreference
29 import com.android.settingslib.TetherUtil
30 import com.android.settingslib.Utils
31 import com.android.settingslib.metadata.PreferenceAvailabilityProvider
32 import com.android.settingslib.metadata.PreferenceMetadata
33 import com.android.settingslib.metadata.PreferenceTitleProvider
34 import com.android.settingslib.metadata.ProvidePreferenceScreen
35 import com.android.settingslib.metadata.preferenceHierarchy
36 import com.android.settingslib.preference.PreferenceScreenCreator
37 
38 @ProvidePreferenceScreen(TetherScreen.KEY)
39 class TetherScreen :
40     PreferenceScreenCreator,
41     PreferenceTitleProvider,
42     PreferenceAvailabilityProvider,
43     PreferenceRestrictionMixin {
44 
45     override val key: String
46         get() = KEY
47 
48     override val icon: Int
49         get() = R.drawable.ic_wifi_tethering
50 
51     override val keywords: Int
52         get() = R.string.keywords_hotspot_tethering
53 
getTitlenull54     override fun getTitle(context: Context): CharSequence? =
55         if (TetherPreferenceController.isTetherConfigDisallowed(context)) {
56             context.getText(R.string.tether_settings_title_all)
57         } else {
58             val tetheringManager = context.getSystemService(TetheringManager::class.java)!!
59             context.getText(Utils.getTetheringLabel(tetheringManager))
60         }
61 
isAvailablenull62     override fun isAvailable(context: Context) = TetherUtil.isTetherAvailable(context)
63 
64     override fun isEnabled(context: Context) = super<PreferenceRestrictionMixin>.isEnabled(context)
65 
66     override val restrictionKeys
67         get() = arrayOf(UserManager.DISALLOW_CONFIG_TETHERING)
68 
69     override fun isFlagEnabled(context: Context) = Flags.catalystTetherSettings()
70 
71     override fun hasCompleteHierarchy() = false
72 
73     override fun fragmentClass() = TetherSettings::class.java
74 
75     override fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?) =
76         makeLaunchIntent(context, TetherSettingsActivity::class.java, metadata?.key)
77 
78     override fun getPreferenceHierarchy(context: Context) =
79         preferenceHierarchy(context, this) {
80             val dataSaverStore = DataSaverMainSwitchPreference.createDataStore(context)
81             +WifiHotspotSwitchPreference(context, dataSaverStore)
82         }
83 
84     companion object {
85         const val KEY = "tether_settings"
86     }
87 }
88