Merge "[Settings] Access ProxySubscriptionManager within DataUsage"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c73ee8d..d2bdc9f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -493,6 +493,7 @@
android:icon="@drawable/ic_settings_wireless">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
+ <action android:name="android.settings.TETHER_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index eb13876..bf97f1d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5034,28 +5034,28 @@
<!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
<plurals name="accessibilty_autoclick_preference_subtitle_extremely_short_delay">
- <item quantity="one">Extremely short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
- <item quantity="other">Extremely short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+ <item quantity="one">Extremely short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+ <item quantity="other">Extremely short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
</plurals>
<!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
<plurals name="accessibilty_autoclick_preference_subtitle_very_short_delay">
- <item quantity="one">Very short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
- <item quantity="other">Very short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+ <item quantity="one">Very short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+ <item quantity="other">Very short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
</plurals>
<!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
<plurals name="accessibilty_autoclick_preference_subtitle_short_delay">
- <item quantity="one">Short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
- <item quantity="other">Short delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+ <item quantity="one">Short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+ <item quantity="other">Short delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
</plurals>
<!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
<plurals name="accessibilty_autoclick_preference_subtitle_long_delay">
- <item quantity="one">Long delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
- <item quantity="other">Long delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+ <item quantity="one">Long delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+ <item quantity="other">Long delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
</plurals>
<!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
<plurals name="accessibilty_autoclick_preference_subtitle_very_long_delay">
- <item quantity="one">Very long delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
- <item quantity="other">Very long delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
+ <item quantity="one">Very long delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>
+ <item quantity="other">Very long delay (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> seconds)</item>
</plurals>
<!-- Summary for autoclick seekbar settings preference when user selected custom item. [CHAR LIMIT=35] -->
diff --git a/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarController.java b/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarController.java
index 9079c31..301d8dc 100644
--- a/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarController.java
+++ b/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarController.java
@@ -19,10 +19,8 @@
import static android.content.Context.MODE_PRIVATE;
import static com.android.settings.accessibility.ToggleAutoclickPreferenceController.KEY_DELAY_MODE;
+import static com.android.settings.accessibility.ToggleAutoclickPreferenceFragment.Quantity;
-import static java.lang.annotation.RetentionPolicy.SOURCE;
-
-import android.annotation.IntDef;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
@@ -42,8 +40,6 @@
import com.android.settingslib.core.lifecycle.events.OnResume;
import com.android.settingslib.widget.LayoutPreference;
-import java.lang.annotation.Retention;
-
/**
* Controller class that controls accessibility autoclick seekbar settings.
*/
@@ -51,16 +47,6 @@
implements LifecycleObserver, OnResume, OnPause,
SharedPreferences.OnSharedPreferenceChangeListener {
- @Retention(SOURCE)
- @IntDef({
- Quantity.OTHER,
- Quantity.ONE
- })
- @interface Quantity {
- int OTHER = 0;
- int ONE = 1;
- }
-
private static final String CONTROL_AUTOCLICK_DELAY_SECURE =
Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY;
private static final String KEY_CUSTOM_DELAY_VALUE = "custom_delay_value";
diff --git a/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
index 4a88956..5e09b2a 100644
--- a/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
@@ -19,6 +19,9 @@
import static com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController.MAX_AUTOCLICK_DELAY_MS;
import static com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController.MIN_AUTOCLICK_DELAY_MS;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import android.annotation.IntDef;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.res.Resources;
@@ -32,6 +35,7 @@
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
+import java.lang.annotation.Retention;
import java.util.ArrayList;
import java.util.List;
@@ -46,6 +50,16 @@
private static final String TAG = "AutoclickPrefFragment";
private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
+ @Retention(SOURCE)
+ @IntDef({
+ Quantity.OTHER,
+ Quantity.ONE
+ })
+ @interface Quantity {
+ int OTHER = 0;
+ int ONE = 1;
+ }
+
/**
* Resource ids from which autoclick preference summaries should be derived. The strings have
* placeholder for integer delay value.
@@ -63,12 +77,17 @@
* delay.
*
* @param resources Resources from which string should be retrieved.
- * @param delay Delay for whose value summary should be retrieved.
+ * @param delayMillis Delay for whose value summary should be retrieved.
*/
- static CharSequence getAutoclickPreferenceSummary(Resources resources, int delay) {
- int summaryIndex = getAutoclickPreferenceSummaryIndex(delay);
- return resources.getQuantityString(
- mAutoclickPreferenceSummaries[summaryIndex], delay, delay);
+ static CharSequence getAutoclickPreferenceSummary(Resources resources, int delayMillis) {
+ final int summaryIndex = getAutoclickPreferenceSummaryIndex(delayMillis);
+ final int quantity = (delayMillis == 1000) ? Quantity.ONE : Quantity.OTHER;
+ final float delaySecond = (float) delayMillis / 1000;
+ // Only show integer when delay time is 1.
+ final String decimalFormat = (delaySecond == 1) ? "%.0f" : "%.1f";
+
+ return resources.getQuantityString(mAutoclickPreferenceSummaries[summaryIndex],
+ quantity, String.format(decimalFormat, delaySecond));
}
/**
diff --git a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
index 9a327ed..bbcd13c 100644
--- a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
@@ -28,6 +28,9 @@
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Maintain and update saved bluetooth devices(bonded but not connected)
*/
@@ -54,7 +57,10 @@
if (mBluetoothAdapter.isEnabled()) {
final CachedBluetoothDeviceManager cachedManager =
mLocalManager.getCachedDeviceManager();
- for (BluetoothDevice device : mBluetoothAdapter.getMostRecentlyConnectedDevices()) {
+ final List<BluetoothDevice> bluetoothDevices =
+ mBluetoothAdapter.getMostRecentlyConnectedDevices();
+ removePreferenceIfNecessary(bluetoothDevices, cachedManager);
+ for (BluetoothDevice device : bluetoothDevices) {
final CachedBluetoothDevice cachedDevice = cachedManager.findDevice(device);
if (cachedDevice != null) {
update(cachedDevice);
@@ -65,6 +71,18 @@
}
}
+ private void removePreferenceIfNecessary(List<BluetoothDevice> bluetoothDevices,
+ CachedBluetoothDeviceManager cachedManager) {
+ for (BluetoothDevice device : new ArrayList<>(mPreferenceMap.keySet())) {
+ if (!bluetoothDevices.contains(device)) {
+ final CachedBluetoothDevice cachedDevice = cachedManager.findDevice(device);
+ if (cachedDevice != null) {
+ removePreference(cachedDevice);
+ }
+ }
+ }
+ }
+
@Override
public void update(CachedBluetoothDevice cachedDevice) {
if (isFilterMatched(cachedDevice)) {
diff --git a/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java b/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java
index 0f429c7..128f4da 100644
--- a/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java
+++ b/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java
@@ -83,7 +83,7 @@
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
synchronized (mBluetoothA2dpConfigStore) {
if (mBluetoothA2dp != null) {
- setCodecConfigPreference(null, codecConfig); // Use current active device
+ setCodecConfigPreference(mBluetoothA2dp.getActiveDevice(), codecConfig);
}
}
// Because the setting is not persisted into permanent storage, we cannot call update state
@@ -102,13 +102,14 @@
@Override
public void updateState(Preference preference) {
- if (getCodecConfig(null) == null || mPreference == null) { // Use current active device
+ BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
+ if (getCodecConfig(activeDevice) == null || mPreference == null) {
return;
}
BluetoothCodecConfig codecConfig;
synchronized (mBluetoothA2dpConfigStore) {
- codecConfig = getCodecConfig(null); // Use current active device
+ codecConfig = getCodecConfig(activeDevice);
}
final int index = getCurrentA2dpSettingIndex(codecConfig);
diff --git a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java
index 71907b6..6f1eab0 100644
--- a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java
+++ b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java
@@ -80,7 +80,7 @@
}
writeConfigurationValues(index);
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
- bluetoothA2dp.setCodecConfigPreference(null, codecConfig);
+ bluetoothA2dp.setCodecConfigPreference(bluetoothA2dp.getActiveDevice(), codecConfig);
mPreference.setSummary(((BaseBluetoothDialogPreference) mPreference).generateSummary(
index));
}
@@ -146,7 +146,8 @@
if (bluetoothA2dp == null) {
return null;
}
- final BluetoothCodecStatus codecStatus = bluetoothA2dp.getCodecStatus(null);
+ final BluetoothCodecStatus codecStatus =
+ bluetoothA2dp.getCodecStatus(bluetoothA2dp.getActiveDevice());
if (codecStatus == null) {
Log.d(TAG, "Unable to get current codec config. Codec status is null");
return null;
@@ -177,7 +178,8 @@
* @return {@link BluetoothCodecConfig}.
*/
protected BluetoothCodecConfig getSelectableByCodecType(int codecTypeValue) {
- final BluetoothCodecConfig[] configs = getSelectableConfigs(null);
+ final BluetoothCodecConfig[] configs = getSelectableConfigs(
+ mBluetoothA2dp.getActiveDevice());
if (configs == null) {
Log.d(TAG, "Unable to get selectable config. Selectable configs is empty.");
return null;
diff --git a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java
index c2977a8..8eecec9 100644
--- a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java
+++ b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java
@@ -83,9 +83,9 @@
return index;
}
// Check HD audio is enabled, display the available list.
- if (bluetoothA2dp.getOptionalCodecsEnabled(activeDevice)
+ if (bluetoothA2dp.isOptionalCodecsEnabled(activeDevice)
== BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
- BluetoothCodecConfig[] configs = getSelectableConfigs(null);
+ BluetoothCodecConfig[] configs = getSelectableConfigs(bluetoothA2dp.getActiveDevice());
if (configs != null) {
return getIndexFromConfig(configs);
}
@@ -101,7 +101,8 @@
int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
switch (index) {
case 0:
- codecTypeValue = getHighestCodec(getSelectableConfigs(null));
+ codecTypeValue = getHighestCodec(getSelectableConfigs(
+ mBluetoothA2dp.getActiveDevice()));
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
break;
case 1:
diff --git a/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java
index 8008188..714b9ab 100644
--- a/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java
+++ b/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceController.java
@@ -58,11 +58,11 @@
mPreference.setEnabled(false);
return;
}
- final boolean supported = (bluetoothA2dp.supportsOptionalCodecs(activeDevice)
+ final boolean supported = (bluetoothA2dp.isOptionalCodecsSupported(activeDevice)
== BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
mPreference.setEnabled(supported);
if (supported) {
- final boolean isEnabled = bluetoothA2dp.getOptionalCodecsEnabled(activeDevice)
+ final boolean isEnabled = bluetoothA2dp.isOptionalCodecsEnabled(activeDevice)
== BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED;
((SwitchPreference) mPreference).setChecked(isEnabled);
}
diff --git a/src/com/android/settings/users/AddUserWhenLockedPreferenceController.java b/src/com/android/settings/users/AddUserWhenLockedPreferenceController.java
index e0a9c26..f931fa4 100644
--- a/src/com/android/settings/users/AddUserWhenLockedPreferenceController.java
+++ b/src/com/android/settings/users/AddUserWhenLockedPreferenceController.java
@@ -16,25 +16,20 @@
package com.android.settings.users;
import android.content.Context;
-import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.Preference;
-import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.RestrictedSwitchPreference;
public class AddUserWhenLockedPreferenceController extends TogglePreferenceController {
private final UserCapabilities mUserCaps;
- private final LockPatternUtils mLockPatternUtils;
- public AddUserWhenLockedPreferenceController(
- Context context, String key, LockPatternUtils lockPatternUtils) {
+ public AddUserWhenLockedPreferenceController(Context context, String key) {
super(context, key);
mUserCaps = UserCapabilities.create(context);
- mLockPatternUtils = lockPatternUtils;
}
@Override
@@ -58,8 +53,6 @@
return DISABLED_FOR_USER;
} else if (mUserCaps.disallowAddUser() || mUserCaps.disallowAddUserSetByAdmin()) {
return DISABLED_FOR_USER;
- } else if (!mLockPatternUtils.isSecure(UserHandle.myUserId())) {
- return CONDITIONALLY_UNAVAILABLE;
} else {
return mUserCaps.mUserSwitcherEnabled ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 70af899..cd305e9 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -240,7 +240,7 @@
}
mAddUserWhenLockedPreferenceController = new AddUserWhenLockedPreferenceController(
- activity, KEY_ADD_USER_WHEN_LOCKED, new LockPatternUtils(getPrefContext()));
+ activity, KEY_ADD_USER_WHEN_LOCKED);
mMultiUserFooterPreferenceController = new MultiUserFooterPreferenceController(activity,
KEY_MULTIUSER_FOOTER);
@@ -1290,8 +1290,7 @@
boolean suppressAllPage) {
final List<String> niks = super.getNonIndexableKeysFromXml(context, xmlResId,
suppressAllPage);
- new AddUserWhenLockedPreferenceController(
- context, KEY_ADD_USER_WHEN_LOCKED, new LockPatternUtils(context))
+ new AddUserWhenLockedPreferenceController(context, KEY_ADD_USER_WHEN_LOCKED)
.updateNonIndexableKeys(niks);
new AutoSyncDataPreferenceController(context, null /* parent */)
.updateNonIndexableKeys(niks);
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 64814fa..9d075a7 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -1020,8 +1020,7 @@
final Context context = getContext();
final PowerManager powerManager = context.getSystemService(PowerManager.class);
final ContentResolver contentResolver = context.getContentResolver();
- return Settings.Global.getInt(contentResolver,
- Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1
+ return mWifiManager.isAutoWakeupEnabled()
&& Settings.Global.getInt(contentResolver,
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
&& Settings.Global.getInt(contentResolver,
diff --git a/src/com/android/settings/wifi/WifiSettings2.java b/src/com/android/settings/wifi/WifiSettings2.java
index 1a7d572..86effea 100644
--- a/src/com/android/settings/wifi/WifiSettings2.java
+++ b/src/com/android/settings/wifi/WifiSettings2.java
@@ -851,8 +851,7 @@
final Context context = getContext();
final PowerManager powerManager = context.getSystemService(PowerManager.class);
final ContentResolver contentResolver = context.getContentResolver();
- return Settings.Global.getInt(contentResolver,
- Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1
+ return mWifiManager.isAutoWakeupEnabled()
&& Settings.Global.getInt(contentResolver,
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
&& Settings.Global.getInt(contentResolver,
diff --git a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
index 855b329..d2a4a98 100644
--- a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
@@ -24,6 +24,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
+import android.net.wifi.WifiManager;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
@@ -57,6 +58,9 @@
@VisibleForTesting
LocationManager mLocationManager;
+ @VisibleForTesting
+ WifiManager mWifiManager;
+
private final BroadcastReceiver mLocationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -70,6 +74,7 @@
public WifiWakeupPreferenceController(Context context) {
super(context, KEY_ENABLE_WIFI_WAKEUP);
mLocationManager = (LocationManager) context.getSystemService(Service.LOCATION_SERVICE);
+ mWifiManager = context.getSystemService(WifiManager.class);
}
public void setFragment(Fragment hostFragment) {
@@ -160,13 +165,11 @@
}
private boolean getWifiWakeupEnabled() {
- return Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1;
+ return mWifiManager.isAutoWakeupEnabled();
}
private void setWifiWakeupEnabled(boolean enabled) {
- Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.WIFI_WAKEUP_ENABLED,
- enabled ? 1 : 0);
+ mWifiManager.setAutoWakeupEnabled(enabled);
}
@Override
diff --git a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
index 3993475..da11781 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
@@ -18,6 +18,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -208,4 +209,30 @@
verify(mBluetoothDeviceUpdater).removeAllDevicesFromPreference();
}
+
+ @Test
+ public void forceUpdate_deviceNotContain_removePreference() {
+ final List<BluetoothDevice> bluetoothDevices = new ArrayList<>();
+ bluetoothDevices.add(mBluetoothDevice);
+ final BluetoothDevice device2 = mock(BluetoothDevice.class);
+ final CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class);
+
+ mBluetoothDeviceUpdater.mPreferenceMap.put(device2, mPreference);
+
+ when(cachedDevice2.getDevice()).thenReturn(device2);
+ when(cachedDevice2.getAddress()).thenReturn("04:52:C7:0B:D8:3S");
+ when(mDeviceManager.findDevice(device2)).thenReturn(cachedDevice2);
+ when(mBluetoothAdapter.isEnabled()).thenReturn(true);
+ when(mBluetoothAdapter.getMostRecentlyConnectedDevices()).thenReturn(bluetoothDevices);
+ when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
+ when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
+ when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
+ when(mBluetoothDevice.isConnected()).thenReturn(false);
+
+ mBluetoothDeviceUpdater.forceUpdate();
+
+ verify(mBluetoothDeviceUpdater).removePreference(cachedDevice2);
+ verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice,
+ BluetoothDevicePreference.SortType.TYPE_NO_SORT);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java
index 802f871..7ff179e 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java
@@ -103,13 +103,15 @@
@Test
public void onIndexUpdated_checkFlow() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mCodecConfigAAC);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.onIndexUpdated(mCurrentConfig);
verify(mController).writeConfigurationValues(mCurrentConfig);
- verify(mBluetoothA2dp).setCodecConfigPreference(null, mCodecConfigAAC);
+ verify(mBluetoothA2dp).setCodecConfigPreference(
+ mBluetoothA2dp.getActiveDevice(), mCodecConfigAAC);
assertThat(mPreference.getSummary()).isEqualTo(SUMMARY);
}
@@ -134,14 +136,15 @@
assertThat(mController.getCurrentCodecConfig()).isNull();
mController.onBluetoothServiceConnected(mBluetoothA2dp);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(null);
+ when(mBluetoothA2dp.getCodecStatus(mBluetoothA2dp.getActiveDevice())).thenReturn(null);
assertThat(mController.getCurrentCodecConfig()).isNull();
}
@Test
public void getCurrentCodecConfig_verifyConfig() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
assertThat(mController.getCurrentCodecConfig()).isEqualTo(mCodecConfigAAC);
@@ -150,7 +153,8 @@
@Test
public void getSelectableConfigs_verifyConfig() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
assertThat(mController.getSelectableConfigs(null)).isEqualTo(mCodecConfigs);
@@ -159,7 +163,8 @@
@Test
public void getSelectableByCodecType_verifyConfig() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
assertThat(mController.getSelectableByCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC))
@@ -169,7 +174,8 @@
@Test
public void getSelectableByCodecType_unavailable() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
assertThat(mController.getSelectableByCodecType(
@@ -179,7 +185,8 @@
@Test
public void onBluetoothServiceConnected_verifyBluetoothA2dpConfigStore() {
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecConfigAAC.getCodecType());
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java
index 0061fc0..7c5e86e 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java
@@ -92,7 +92,8 @@
public void writeConfigurationValues_selectDefault_setHighest() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(0);
@@ -121,7 +122,8 @@
public void getSelectableIndex_verifyList() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
List<Integer> indexList = new ArrayList<>();
indexList.add(mPreference.getDefaultIndex());
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java
index 326cc22..32651ba 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java
@@ -92,7 +92,8 @@
public void writeConfigurationValues_selectDefault_setHighest() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(0);
@@ -118,7 +119,8 @@
public void getSelectableIndex_verifyList() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
List<Integer> indexList = new ArrayList<>();
indexList.add(mPreference.getDefaultIndex());
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java
index f4ed811..f93766f 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java
@@ -99,7 +99,8 @@
public void writeConfigurationValues_selectDefault_setHighest() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(0);
@@ -111,7 +112,8 @@
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(1);
@@ -138,7 +140,8 @@
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(2);
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceControllerTest.java
index 1f0daa3..0701e78 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothHDAudioPreferenceControllerTest.java
@@ -91,7 +91,7 @@
@Test
public void updateState_codecSupported_setEnable() {
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
- when(mBluetoothA2dp.supportsOptionalCodecs(mActiveDevice)).thenReturn(
+ when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference);
@@ -102,7 +102,7 @@
@Test
public void updateState_codecNotSupported_setDisable() {
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
- when(mBluetoothA2dp.supportsOptionalCodecs(mActiveDevice)).thenReturn(
+ when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_NOT_SUPPORTED);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference);
@@ -113,9 +113,9 @@
@Test
public void updateState_codecSupportedAndEnabled_checked() {
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
- when(mBluetoothA2dp.supportsOptionalCodecs(mActiveDevice)).thenReturn(
+ when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
- when(mBluetoothA2dp.getOptionalCodecsEnabled(mActiveDevice)).thenReturn(
+ when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference);
@@ -126,9 +126,9 @@
@Test
public void updateState_codecSupportedAndDisabled_notChecked() {
when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice);
- when(mBluetoothA2dp.supportsOptionalCodecs(mActiveDevice)).thenReturn(
+ when(mBluetoothA2dp.isOptionalCodecsSupported(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_SUPPORTED);
- when(mBluetoothA2dp.getOptionalCodecsEnabled(mActiveDevice)).thenReturn(
+ when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
mBluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java
index 35bd704..30e3f31 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java
@@ -110,7 +110,8 @@
public void updateState_codeTypeIsLDAC_enablePreference() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigLDAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference);
@@ -121,7 +122,8 @@
public void updateState_codeTypeAAC_disablePreference() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java
index d274a57..089acc5 100644
--- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java
@@ -93,7 +93,8 @@
mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC);
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
mController.writeConfigurationValues(0);
@@ -125,7 +126,8 @@
public void getSelectableIndex_verifyList() {
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
- when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
+ when(mBluetoothA2dp.getCodecStatus(
+ mBluetoothA2dp.getActiveDevice())).thenReturn(mCodecStatus);
mController.onBluetoothServiceConnected(mBluetoothA2dp);
List<Integer> indexList = new ArrayList<>();
indexList.add(mController.getDefaultIndex());
diff --git a/tests/robotests/src/com/android/settings/users/AddUserWhenLockedPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/users/AddUserWhenLockedPreferenceControllerTest.java
index cb5791e..b27b636 100644
--- a/tests/robotests/src/com/android/settings/users/AddUserWhenLockedPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/users/AddUserWhenLockedPreferenceControllerTest.java
@@ -18,7 +18,6 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -28,8 +27,6 @@
import androidx.preference.PreferenceScreen;
-import com.android.internal.widget.LockPatternUtils;
-import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -54,16 +51,13 @@
private Context mContext;
private ShadowUserManager mUserManager;
private AddUserWhenLockedPreferenceController mController;
- private LockPatternUtils mLockPatternUtils;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLockPatternUtils = mock(LockPatternUtils.class);
mUserManager = ShadowUserManager.getShadow();
- mController = new AddUserWhenLockedPreferenceController(
- mContext, "fake_key", mLockPatternUtils);
+ mController = new AddUserWhenLockedPreferenceController(mContext, "fake_key");
mUserManager.setSupportsMultipleUsers(true);
}
@@ -75,7 +69,6 @@
@Test
public void displayPref_NotAdmin_shouldNotDisplay() {
mUserManager.setIsAdminUser(false);
- when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
when(mScreen.findPreference(preference.getKey())).thenReturn(preference);
@@ -88,7 +81,6 @@
@Test
public void updateState_NotAdmin_shouldNotDisplayPreference() {
mUserManager.setIsAdminUser(false);
- when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
mController.updateState(preference);
@@ -101,9 +93,8 @@
mUserManager.setIsAdminUser(true);
mUserManager.setUserSwitcherEnabled(true);
mUserManager.setSupportsMultipleUsers(true);
- when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
final AddUserWhenLockedPreferenceController controller =
- new AddUserWhenLockedPreferenceController(mContext, "fake_key", mLockPatternUtils);
+ new AddUserWhenLockedPreferenceController(mContext, "fake_key");
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
controller.updateState(preference);
@@ -152,40 +143,4 @@
assertThat(Global.getInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 0))
.isEqualTo(0);
}
-
- @Test
- public void updateState_insecureLockScreen_shouldNotDisplayPreference() {
- mUserManager.setIsAdminUser(true);
- mUserManager.setUserSwitcherEnabled(true);
- mUserManager.setSupportsMultipleUsers(true);
- when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
- final AddUserWhenLockedPreferenceController controller =
- new AddUserWhenLockedPreferenceController(
- mContext, "fake_key", mLockPatternUtils);
- final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
-
- controller.updateState(preference);
-
- verify(preference).setVisible(false);
- assertThat(controller.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
- }
-
- @Test
- public void updateState_secureLockScreen_shouldDisplayPreference() {
- mUserManager.setIsAdminUser(true);
- mUserManager.setUserSwitcherEnabled(true);
- mUserManager.setSupportsMultipleUsers(true);
- when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
- final AddUserWhenLockedPreferenceController controller =
- new AddUserWhenLockedPreferenceController(
- mContext, "fake_key", mLockPatternUtils);
- final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
-
- controller.updateState(preference);
-
- verify(preference).setVisible(true);
- assertThat(controller.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.AVAILABLE);
- }
}
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSettings2Test.java b/tests/robotests/src/com/android/settings/wifi/WifiSettings2Test.java
index 320d767..e5b5eb1 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSettings2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSettings2Test.java
@@ -33,6 +33,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
+import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.UserManager;
@@ -71,6 +72,8 @@
@Mock
private PowerManager mPowerManager;
@Mock
+ private WifiManager mWifiManager;
+ @Mock
private DataUsagePreference mDataUsagePreference;
private Context mContext;
private WifiSettings2 mWifiSettings2;
@@ -85,10 +88,12 @@
mWifiSettings2 = spy(new WifiSettings2());
doReturn(mContext).when(mWifiSettings2).getContext();
doReturn(mPowerManager).when(mContext).getSystemService(PowerManager.class);
+ doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
mWifiSettings2.mAddWifiNetworkPreference = new AddWifiNetworkPreference(mContext);
mWifiSettings2.mSavedNetworksPreference = new Preference(mContext);
mWifiSettings2.mConfigureWifiSettingsPreference = new Preference(mContext);
mWifiSettings2.mWifiPickerTracker = mMockWifiPickerTracker;
+ mWifiSettings2.mWifiManager = mWifiManager;
}
@Test
@@ -157,7 +162,7 @@
@Test
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
final ContentResolver contentResolver = mContext.getContentResolver();
- Settings.Global.putInt(contentResolver, Settings.Global.WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(contentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
@@ -171,7 +176,7 @@
@Test
public void setAdditionalSettingsSummaries_wifiWakeupDisabled_displayOff() {
final ContentResolver contentResolver = mContext.getContentResolver();
- Settings.Global.putInt(contentResolver, Settings.Global.WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
mWifiSettings2.setAdditionalSettingsSummaries();
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java
index 4ed85c6..0ae3465 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java
@@ -195,7 +195,7 @@
@Test
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
final ContentResolver contentResolver = mContext.getContentResolver();
- Settings.Global.putInt(contentResolver, Settings.Global.WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(contentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
@@ -209,7 +209,7 @@
@Test
public void setAdditionalSettingsSummaries_wifiWakeupDisabled_displayOff() {
final ContentResolver contentResolver = mContext.getContentResolver();
- Settings.Global.putInt(contentResolver, Settings.Global.WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
mWifiSettings.setAdditionalSettingsSummaries();
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
index 4266c84..a41d7c8 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
@@ -17,15 +17,17 @@
package com.android.settings.wifi;
import static android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE;
-import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
import android.location.LocationManager;
+import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.text.TextUtils;
@@ -53,6 +55,8 @@
@Mock
private LocationManager mLocationManager;
@Mock
+ private WifiManager mWifiManager;
+ @Mock
private SwitchPreference mPreference;
@Before
@@ -63,6 +67,7 @@
mController.setFragment(mFragment);
mController.mLocationManager = mLocationManager;
mController.mPreference = mPreference;
+ mController.mWifiManager = mWifiManager;
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
@@ -70,20 +75,19 @@
@Test
public void setChecked_scanEnableLocationEnable_wifiWakeupEnable() {
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
mController.setChecked(true);
- assertThat(Settings.Global.getInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0))
- .isEqualTo(1);
+ verify(mWifiManager).setAutoWakeupEnabled(true);
}
@Test
public void updateState_wifiWakeupEnableScanningDisable_wifiWakeupDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
doReturn(true).when(mLocationManager).isLocationEnabled();
@@ -97,7 +101,7 @@
@Test
public void updateState_preferenceSetCheckedWhenWakeupSettingEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
@@ -111,7 +115,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
mController.updateState(preference);
@@ -123,7 +127,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
mController.updateState(preference);
@@ -134,7 +138,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingEnabledNoLocation() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
@@ -147,7 +151,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingDisabledLocationEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
@@ -160,7 +164,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabledLocationEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
doReturn(false).when(mLocationManager).isLocationEnabled();