Update scanning settings to show states in summary

Bug: 120220144
Test: build, flash, and test manually
Change-Id: I913d93c2f41e5ffea1d0b9c00d519eba327a0832
This commit is contained in:
Lifu Tang
2018-12-05 16:06:20 -08:00
parent 978aaad16f
commit bee747173f
3 changed files with 91 additions and 17 deletions

View File

@@ -2878,6 +2878,14 @@
<string name="status_prl_version">PRL version</string>
<!-- About phone screen, title for MEID for multi-sim devices -->
<string name="meid_multi_sim">MEID (sim slot %1$d)</string>
<!-- The status text when both Wi-Fi scanning and Bluetooth scanning are on. [CHAR LIMIT=120] -->
<string name="scanning_status_text_wifi_on_ble_on">Both Wi\u2011Fi and Bluetooth are allowed to determine location</string>
<!-- The status text when Wi-Fi scanning is on and Bluetooth scanning are off. [CHAR LIMIT=120] -->
<string name="scanning_status_text_wifi_on_ble_off">Only Wi\u2011Fi is allowed to determine location</string>
<!-- The status text when Wi-Fi scanning is off and Bluetooth scanning are on. [CHAR LIMIT=120] -->
<string name="scanning_status_text_wifi_off_ble_on">Only Bluetooth is allowed to determine location</string>
<!-- The status text when both Wi-Fi scanning and Bluetooth scanning are off. [CHAR LIMIT=120] -->
<string name="scanning_status_text_wifi_off_ble_off">Neither Wi\u2011Fi nor Bluetooth is allowed to determine location</string>
<!-- About phone, status item title. The phone MEID number of the current LTE/CDMA device. [CHAR LIMIT=30] -->
<string name="status_meid_number">MEID</string>
<!-- About phone, status item title. The ICCID of the current LTE device. [CHAR LIMIT=30] -->
@@ -3612,8 +3620,8 @@
<string name="location_high_battery_use">High battery use</string>
<!-- [CHAR LIMIT=30] Location settings screen, recent location requests low battery use-->
<string name="location_low_battery_use">Low battery use</string>
<!-- [CHAR LIMIT=30] Wireless background scanning settings screen, screen title -->
<string name="location_scanning_screen_title">Scanning</string>
<!-- [CHAR LIMIT=60] Wireless background scanning settings screen, screen title -->
<string name="location_scanning_screen_title">Wi\u2011Fi and Bluetooth scanning</string>
<!-- [CHAR LIMIT=130] Preference title for Wi-Fi always scanning -->
<string name="location_scanning_wifi_always_scanning_title">Wi\u2011Fi scanning</string>
<!-- Preference description text for Wi-Fi always scanning -->

View File

@@ -17,6 +17,7 @@
package com.android.settings.location;
import android.content.Context;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
@@ -25,11 +26,31 @@ import com.android.settings.core.BasePreferenceController;
public class LocationScanningPreferenceController extends BasePreferenceController {
@VisibleForTesting static final String KEY_LOCATION_SCANNING = "location_scanning";
private final Context mContext;
public LocationScanningPreferenceController(Context context) {
super(context, KEY_LOCATION_SCANNING);
mContext = context;
}
@Override
public CharSequence getSummary() {
final boolean wifiScanOn = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
final boolean bleScanOn = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
int resId;
if (wifiScanOn && bleScanOn) {
resId = R.string.scanning_status_text_wifi_on_ble_on;
} else if (wifiScanOn && !bleScanOn) {
resId = R.string.scanning_status_text_wifi_on_ble_off;
} else if (!wifiScanOn && bleScanOn) {
resId = R.string.scanning_status_text_wifi_off_ble_on;
} else {
resId = R.string.scanning_status_text_wifi_off_ble_off;
}
return mContext.getString(resId);
}
@AvailabilityStatus

View File

@@ -18,7 +18,11 @@ package com.android.settings.location;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
@@ -28,22 +32,63 @@ import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
public class LocationScanningPreferenceControllerTest {
private Context mContext;
private LocationScanningPreferenceController mController;
private LocationScanningPreferenceController mController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mController = new LocationScanningPreferenceController(mContext);
}
@Before
public void setUp() {
mController = new LocationScanningPreferenceController(RuntimeEnvironment.application);
}
@Test
public void testLocationScanning_byDefault_shouldBeShown() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testLocationScanning_byDefault_shouldBeShown() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testLocationScanning_WifiOnBleOn() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
assertThat(mController.getSummary()).isEqualTo(
mContext.getString(R.string.scanning_status_text_wifi_on_ble_on));
}
@Test
@Config(qualifiers = "mcc999")
public void testLocationScanning_ifDisabled_shouldNotBeShown() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testLocationScanning_WifiOnBleOff() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
assertThat(mController.getSummary()).isEqualTo(
mContext.getString(R.string.scanning_status_text_wifi_on_ble_off));
}
@Test
public void testLocationScanning_WifiOffBleOn() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
assertThat(mController.getSummary()).isEqualTo(
mContext.getString(R.string.scanning_status_text_wifi_off_ble_on));
}
@Test
public void testLocationScanning_WifiOffBleOff() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
assertThat(mController.getSummary()).isEqualTo(
mContext.getString(R.string.scanning_status_text_wifi_off_ble_off));
}
@Test
@Config(qualifiers = "mcc999")
public void testLocationScanning_ifDisabled_shouldNotBeShown() {
assertThat(mController.isAvailable()).isFalse();
}
}