Fix: Bluetooth and Wifi scanning location MainSwitch page policy transparency.
When DISALLOW_CONFIG_LOCATION is set, make location service's
MainSwitchPreference pages for wifi scanning and bluetooth scanning
unavailable too, so that intent direct access is disabled.
screenshot: http://shortn/_kkK3BMTSh1
Bug: 277333746
Bug: 277333781
Test: atest SettingsRoboTests, on device
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:7591fff234886e79c5d0210a2cf3282a69de9be9)
Merged-In: I52f9a11b1dd78a5e5dbb1bbde3cda7381c87ae39
Change-Id: I52f9a11b1dd78a5e5dbb1bbde3cda7381c87ae39
diff --git a/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java b/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java
index b491ec9..78e3184 100644
--- a/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java
+++ b/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.provider.Settings;
import android.widget.Switch;
+import android.os.UserManager;
import androidx.preference.PreferenceScreen;
@@ -33,9 +34,11 @@
implements OnMainSwitchChangeListener {
private static final String KEY_BLUETOOTH_SCANNING_SWITCH = "bluetooth_always_scanning_switch";
+ private final UserManager mUserManager;
public BluetoothScanningMainSwitchPreferenceController(Context context) {
super(context, KEY_BLUETOOTH_SCANNING_SWITCH);
+ mUserManager = UserManager.get(context);
}
@Override
@@ -49,7 +52,9 @@
@Override
public int getAvailabilityStatus() {
return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
- ? AVAILABLE
+ ? (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_LOCATION)
+ ? DISABLED_DEPENDENT_SETTING
+ : AVAILABLE)
: UNSUPPORTED_ON_DEVICE;
}
diff --git a/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java b/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java
index 546f1e1..e22b0a0 100644
--- a/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java
+++ b/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.net.wifi.WifiManager;
import android.widget.Switch;
+import android.os.UserManager;
import androidx.preference.PreferenceScreen;
@@ -34,10 +35,12 @@
private static final String KEY_WIFI_SCANNING_SWITCH = "wifi_always_scanning_switch";
private final WifiManager mWifiManager;
+ private final UserManager mUserManager;
public WifiScanningMainSwitchPreferenceController(Context context) {
super(context, KEY_WIFI_SCANNING_SWITCH);
mWifiManager = context.getSystemService(WifiManager.class);
+ mUserManager = UserManager.get(context);
}
@Override
@@ -52,7 +55,9 @@
@Override
public int getAvailabilityStatus() {
return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
- ? AVAILABLE
+ ? (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_LOCATION)
+ ? DISABLED_DEPENDENT_SETTING
+ : AVAILABLE)
: UNSUPPORTED_ON_DEVICE;
}