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.location
17 
18 import android.content.Context
19 import android.location.LocationManager
20 import com.android.settings.R
21 import com.android.settings.flags.Flags
22 import com.android.settingslib.metadata.PreferenceIconProvider
23 import com.android.settingslib.metadata.PreferenceSummaryProvider
24 import com.android.settingslib.metadata.ProvidePreferenceScreen
25 import com.android.settingslib.metadata.preferenceHierarchy
26 import com.android.settingslib.preference.PreferenceScreenCreator
27 
28 @ProvidePreferenceScreen
29 class LocationScreen : PreferenceScreenCreator, PreferenceSummaryProvider, PreferenceIconProvider {
30     override val key: String
31         get() = KEY
32 
33     override val title: Int
34         get() = R.string.location_settings_title
35 
36     override val keywords: Int
37         get() = R.string.keywords_location
38 
getSummarynull39     override fun getSummary(context: Context): CharSequence? {
40         var locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
41         return if (locationManager.isLocationEnabled) {
42             context.getString(R.string.location_settings_loading_app_permission_stats)
43         } else {
44             context.getString(R.string.location_settings_summary_location_off)
45         }
46     }
47 
getIconnull48     override fun getIcon(context: Context) =
49         when {
50             Flags.homepageRevamp() -> R.drawable.ic_settings_location_filled
51             else -> R.drawable.ic_settings_location
52         }
53 
isFlagEnablednull54     override fun isFlagEnabled(context: Context) = Flags.catalystLocationSettings()
55 
56     override fun hasCompleteHierarchy() = false
57 
58     override fun fragmentClass() = LocationSettings::class.java
59 
60     override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) {}
61 
62     companion object {
63         const val KEY = "location_settings"
64     }
65 }
66