1 /* 2 * Copyright 2021 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.os.UserManager; 20 import android.provider.Settings; 21 22 import androidx.preference.Preference; 23 24 import com.android.settings.R; 25 import com.android.settings.core.BasePreferenceController; 26 import com.android.settingslib.RestrictedPreference; 27 28 /** 29 * Preference controller for Bluetooth scanning in Location Services. 30 */ 31 public class LocationServicesBluetoothScanningPreferenceController extends 32 BasePreferenceController { 33 LocationServicesBluetoothScanningPreferenceController(Context context, String key)34 public LocationServicesBluetoothScanningPreferenceController(Context context, String key) { 35 super(context, key); 36 } 37 38 @Override updateState(Preference preference)39 public void updateState(Preference preference) { 40 ((RestrictedPreference) preference).checkRestrictionAndSetDisabled( 41 UserManager.DISALLOW_CONFIG_LOCATION); 42 refreshSummary(preference); 43 } 44 45 @Override getSummary()46 public CharSequence getSummary() { 47 final boolean bleScanOn = Settings.Global.getInt(mContext.getContentResolver(), 48 Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1; 49 int resId = 50 bleScanOn ? R.string.scanning_status_text_on : R.string.scanning_status_text_off; 51 return mContext.getString(resId); 52 } 53 54 @AvailabilityStatus getAvailabilityStatus()55 public int getAvailabilityStatus() { 56 return mContext.getResources().getBoolean(R.bool.config_show_location_scanning) 57 ? AVAILABLE 58 : UNSUPPORTED_ON_DEVICE; 59 } 60 } 61