1 /* 2 * Copyright (C) 2020 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 17 package com.android.settings.location; 18 19 import android.content.Context; 20 import android.content.pm.PackageManager; 21 import android.provider.DeviceConfig; 22 23 import com.android.settings.R; 24 import com.android.settings.Utils; 25 import com.android.settings.core.TogglePreferenceController; 26 27 /** Controller for location indicators toggle. */ 28 public class LocationIndicatorsPreferenceController extends TogglePreferenceController { 29 LocationIndicatorsPreferenceController(Context context, String preferenceKey)30 public LocationIndicatorsPreferenceController(Context context, String preferenceKey) { 31 super(context, preferenceKey); 32 } 33 34 @Override isChecked()35 public boolean isChecked() { 36 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, 37 Utils.PROPERTY_LOCATION_INDICATORS_ENABLED, false); 38 } 39 40 @Override setChecked(boolean isChecked)41 public boolean setChecked(boolean isChecked) { 42 DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY, 43 Utils.PROPERTY_LOCATION_INDICATORS_ENABLED, Boolean.toString(isChecked), true); 44 return true; 45 } 46 47 @Override getAvailabilityStatus()48 public int getAvailabilityStatus() { 49 final boolean isEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, 50 Utils.PROPERTY_LOCATION_INDICATOR_SETTINGS_ENABLED, false); 51 if (!isEnabled) { 52 return UNSUPPORTED_ON_DEVICE; 53 } 54 // Location indicators feature is only available on devices that support location. 55 return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION) 56 ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 57 } 58 59 @Override getSliceHighlightMenuRes()60 public int getSliceHighlightMenuRes() { 61 return R.string.menu_key_location; 62 } 63 } 64