Merge "Import translations. DO NOT MERGE" into oc-dr1-dev
diff --git a/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java b/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java
index 5a2dcb2..7d2cc18 100644
--- a/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java
+++ b/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java
@@ -20,7 +20,7 @@
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
-import android.text.TextUtils;
+import android.util.Log;
import com.android.settings.R;
import com.android.settings.widget.SummaryUpdater;
@@ -29,9 +29,7 @@
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import java.util.Set;
/**
@@ -39,6 +37,7 @@
* bluetooth summary info.
*/
public final class BluetoothSummaryUpdater extends SummaryUpdater implements BluetoothCallback {
+ private static final String TAG = "BluetoothSummaryUpdater";
private final LocalBluetoothManager mBluetoothManager;
private final LocalBluetoothAdapter mBluetoothAdapter;
@@ -58,6 +57,9 @@
public void onBluetoothStateChanged(int bluetoothState) {
mEnabled = bluetoothState == BluetoothAdapter.STATE_ON
|| bluetoothState == BluetoothAdapter.STATE_TURNING_ON;
+ if (!mEnabled) {
+ mConnectionState = BluetoothAdapter.STATE_DISCONNECTED;
+ }
notifyChangeIfNeeded();
}
@@ -161,7 +163,6 @@
if (devices == null || devices.isEmpty()) {
return null;
}
-
for (BluetoothDevice device : devices) {
if (device.isConnected()) {
deviceName = device.getName();
@@ -171,7 +172,14 @@
}
}
}
-
+ if (deviceName == null) {
+ Log.w(TAG, "getConnectedDeviceSummary, deviceName is null, numBondedDevices="
+ + devices.size());
+ for (BluetoothDevice device : devices) {
+ Log.w(TAG, "getConnectedDeviceSummary, device=" + device.getName() + "["
+ + device.getAddress() + "]" + ", isConnected=" + device.isConnected());
+ }
+ }
return count > 1 ? mContext.getString(R.string.bluetooth_connected_multiple_devices_summary)
: mContext.getString(R.string.bluetooth_connected_summary, deviceName);
}
diff --git a/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java b/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
index b57ff6a..b4e6158 100644
--- a/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
+++ b/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
@@ -108,7 +108,7 @@
}
private void logValue(String key, Object value, boolean forceLog) {
- final String prefKey = mTag + "/" + key;
+ final String prefKey = buildPrefKey(mTag, key);
if (!forceLog && !mPreferenceKeySet.contains(prefKey)) {
// Pref key doesn't exist in set, this is initial display so we skip metrics but
// keeps track of this key.
@@ -116,7 +116,7 @@
return;
}
// TODO: Remove count logging to save some resource.
- mMetricsFeature.count(mContext, prefKey + "|" + value, 1);
+ mMetricsFeature.count(mContext, buildCountName(prefKey, value), 1);
final Pair<Integer, Object> valueData;
if (value instanceof Long) {
@@ -131,11 +131,10 @@
} else if (value instanceof Float) {
valueData = Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_FLOAT_VALUE,
value);
- } else if (value instanceof String){
- valueData = Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_VALUE,
- value);
+ } else if (value instanceof String) {
+ valueData = Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_VALUE, value);
} else {
- Log.w(LOG_TAG, "Tried to log unloggable object" + value);
+ Log.w(LOG_TAG, "Tried to log unloggable object" + value);
valueData = null;
}
if (valueData != null) {
@@ -157,6 +156,14 @@
new AsyncPackageCheck().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, key, value);
}
+ public static String buildCountName(String prefKey, Object value) {
+ return prefKey + "|" + value;
+ }
+
+ public static String buildPrefKey(String tag, String key) {
+ return tag + "/" + key;
+ }
+
private class AsyncPackageCheck extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
diff --git a/src/com/android/settings/display/WallpaperPreferenceController.java b/src/com/android/settings/display/WallpaperPreferenceController.java
index eb91052..b2e0f7b 100644
--- a/src/com/android/settings/display/WallpaperPreferenceController.java
+++ b/src/com/android/settings/display/WallpaperPreferenceController.java
@@ -13,27 +13,54 @@
*/
package com.android.settings.display;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
+import android.text.TextUtils;
+import android.util.Log;
+import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import static android.os.UserManager.DISALLOW_SET_WALLPAPER;
+import java.util.List;
+
public class WallpaperPreferenceController extends PreferenceController {
+ private static final String TAG = "WallpaperPrefController";
+
public static final String KEY_WALLPAPER = "wallpaper";
+ private final String mWallpaperPackage;
+ private final String mWallpaperClass;
+
public WallpaperPreferenceController(Context context) {
super(context);
+ mWallpaperPackage = mContext.getString(R.string.config_wallpaper_picker_package);
+ mWallpaperClass = mContext.getString(R.string.config_wallpaper_picker_class);
}
@Override
public boolean isAvailable() {
- return true;
+ if (TextUtils.isEmpty(mWallpaperPackage) || TextUtils.isEmpty(mWallpaperClass)) {
+ Log.e(TAG, "No Wallpaper picker specified!");
+ return false;
+ }
+ final ComponentName componentName =
+ new ComponentName(mWallpaperPackage, mWallpaperClass);
+ final PackageManager pm = mContext.getPackageManager();
+ final Intent intent = new Intent();
+ intent.setComponent(componentName);
+ final List<ResolveInfo> resolveInfos =
+ pm.queryIntentActivities(intent, 0 /* flags */);
+ return resolveInfos != null && resolveInfos.size() != 0;
}
@Override
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index e3d732b..b3cd872 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -146,8 +146,9 @@
// account creation outside of setup wizard.
private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
// This string extra specifies a network to open the connect dialog on, so the user can enter
- // network credentials. This is used by quick settings for secured networks.
- private static final String EXTRA_START_CONNECT_SSID = "wifi_start_connect_ssid";
+ // network credentials. This is used by quick settings for secured networks, among other
+ // things.
+ public static final String EXTRA_START_CONNECT_SSID = "wifi_start_connect_ssid";
// should Next button only be enabled when we have a connection?
private boolean mEnableNextOnConnection;
@@ -756,6 +757,21 @@
changeNextButtonState(mWifiTracker.isConnected());
}
+ /** Helper method to return whether an AccessPoint is disabled due to a wrong password */
+ private static boolean isDisabledByWrongPassword(AccessPoint accessPoint) {
+ WifiConfiguration config = accessPoint.getConfig();
+ if (config == null) {
+ return false;
+ }
+ WifiConfiguration.NetworkSelectionStatus networkStatus =
+ config.getNetworkSelectionStatus();
+ if (networkStatus == null || networkStatus.isNetworkEnabled()) {
+ return false;
+ }
+ int reason = networkStatus.getNetworkSelectionDisableReason();
+ return WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD == reason;
+ }
+
private void updateAccessPointPreferences() {
// in case state has changed
if (!mWifiManager.isWifiEnabled()) {
@@ -791,10 +807,11 @@
preference.setKey(key);
preference.setOrder(index);
if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
- && !accessPoint.isSaved()
&& accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
- onPreferenceTreeClick(preference);
- mOpenSsid = null;
+ if (!accessPoint.isSaved() || isDisabledByWrongPassword(accessPoint)) {
+ onPreferenceTreeClick(preference);
+ mOpenSsid = null;
+ }
}
mAccessPointsPreferenceCategory.addPreference(preference);
accessPoint.setListener(WifiSettings.this);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java
index 4f57ecc..e3f00d8 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java
@@ -44,8 +44,11 @@
import java.util.List;
import java.util.Set;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -133,6 +136,36 @@
}
@Test
+ public void onBluetoothStateChanged_ConnectedDisabledEnabled_shouldSendDisconnectedSummary() {
+ final boolean[] connected = {false};
+ final List<CachedBluetoothDevice> devices = new ArrayList<>();
+ devices.add(mock(CachedBluetoothDevice.class));
+ doAnswer(invocation -> connected[0]).when(devices.get(0)).isConnected();
+ when(mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy())
+ .thenReturn(devices);
+ when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_DISCONNECTED);
+ prepareConnectedDevice(false);
+
+ mSummaryUpdater.register(true);
+ verify(mListener).onSummaryChanged(mContext.getString(R.string.disconnected));
+
+ connected[0] = true;
+ when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTED);
+ mSummaryUpdater.onConnectionStateChanged(null /* device */,
+ BluetoothAdapter.STATE_CONNECTED);
+ verify(mListener).onSummaryChanged(
+ mContext.getString(R.string.bluetooth_connected_summary, DEVICE_NAME));
+
+ mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF);
+ verify(mListener).onSummaryChanged(mContext.getString(R.string.bluetooth_disabled));
+
+ connected[0] = false;
+ mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_TURNING_ON);
+ verify(mListener, times(2)).onSummaryChanged(mContext.getString(R.string.disconnected));
+ verify(mListener, times(4)).onSummaryChanged(anyString());
+ }
+
+ @Test
public void onConnectionStateChanged_connected_shouldSendConnectedMessage() {
final List<CachedBluetoothDevice> devices = new ArrayList<>();
devices.add(mock(CachedBluetoothDevice.class));
diff --git a/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java
new file mode 100644
index 0000000..1419ad5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.display;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class WallpaperPreferenceControllerTest {
+
+ private static final String WALLPAPER_PACKAGE = "TestPkg";
+ private static final String WALLPAPER_CLASS = "TestCls";
+
+ @Mock
+ private Context mContext;
+ @Mock
+ private PackageManager mPackageManager;
+
+ private WallpaperPreferenceController mController;
+
+ @Before
+ public void setUp() throws PackageManager.NameNotFoundException {
+ MockitoAnnotations.initMocks(this);
+ when(mContext.getString(R.string.config_wallpaper_picker_package))
+ .thenReturn(WALLPAPER_PACKAGE);
+ when(mContext.getString(R.string.config_wallpaper_picker_class))
+ .thenReturn(WALLPAPER_CLASS);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+
+ mController = new WallpaperPreferenceController(mContext);
+ }
+
+ @Test
+ public void isAvailable_wallpaerPickerEnabled_shouldReturnTrue() {
+ final List<ResolveInfo> resolveInfos = new ArrayList<>();
+ resolveInfos.add(mock(ResolveInfo.class));
+ when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt()))
+ .thenReturn(resolveInfos);
+
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_wallpaerPickerDisbled_shouldReturnFalseAndNoCrash() {
+ when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt())).thenReturn(null);
+
+ assertThat(mController.isAvailable()).isFalse();
+
+ final List<ResolveInfo> resolveInfos = new ArrayList<>();
+ when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt()))
+ .thenReturn(resolveInfos);
+
+ assertThat(mController.isAvailable()).isFalse();
+ // should not crash
+ }
+}
diff --git a/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java b/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
index a85d591..cbd9546 100644
--- a/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
+++ b/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
@@ -22,6 +22,7 @@
import static android.support.test.espresso.matcher.ViewMatchers.Visibility.VISIBLE;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
+import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.google.common.truth.Truth.assertThat;
@@ -43,6 +44,7 @@
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiSsid;
+import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
@@ -67,24 +69,25 @@
@RunWith(AndroidJUnit4.class)
public class WifiSettingsUiTest {
-
- // TODO(b/37714546): Investigate why resource ids are not resolving correctly in the test apk,
- // then remove this manual string entry
- /** R.string.wifi_configure_settings_preference_title */
- private static final String WIFI_PREFERENCES = "Wi\u2011Fi preferences";
- /** R.string.wifi_saved_access_points_label */
- private static final String SAVED_NETWORKS = "Saved networks";
- /** R.string.wifi_empty_list_wifi_off */
- private static final String WIFI_OFF_MESSAGE = "To see available networks, turn Wi\u2011Fi on.";
- /** R.string.wifi_display_status_connected */
- private static final String CONNECTED = "Connected";
-
private static final String TEST_SSID = "\"Test Ssid\"";
private static final String TEST_UNQUOTED_SSID = "Test Ssid";
private static final String TEST_BSSID = "0a:08:5c:67:89:00";
private static final int TEST_RSSI = 123;
private static final int TEST_NETWORK_ID = 1;
+ // Keys used to lookup resources by name (see the resourceId/resourceString helper methods).
+ private static final String ID = "id";
+ private static final String STRING = "string";
+ private static final String WIFI_CONFIGURE_SETTINGS_PREFERENCE_TITLE =
+ "wifi_configure_settings_preference_title";
+ private static final String WIFI_SAVED_ACCESS_POINTS_LABEL = "wifi_saved_access_points_label";
+ private static final String WIFI_EMPTY_LIST_WIFI_OFF = "wifi_empty_list_wifi_off";
+ private static final String WIFI_DISPLAY_STATUS_CONNECTED = "wifi_display_status_connected";
+ private static final String WIFI_PASSWORD = "wifi_password";
+ private static final String WIFI_SHOW_PASSWORD = "wifi_show_password";
+ private static final String PASSWORD_LAYOUT = "password_layout";
+ private static final String PASSWORD = "password";
+
@Mock
private WifiTracker mWifiTracker;
@Mock
@@ -104,6 +107,21 @@
when(mWifiTracker.getManager()).thenReturn(mWifiManager);
}
+ /**
+ * Helper to get around the problem that directly accessing settings resource id's from
+ * com.android.settings.R via R.(type).(name) (eg R.id.password or
+ * R.string.wifi_configure_settings_preference_title) may not work due to mismatched resource
+ * ids. See b/37714546 and b/63546650.
+ */
+ private int resourceId(String type, String name) {
+ return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
+ }
+
+ /** Similar to {@link #resourceId}, but for accessing R.string.<name> values. */
+ private String resourceString(String name) {
+ return mContext.getResources().getString(resourceId(STRING, name));
+ }
+
private void setupConnectedAccessPoint() {
WifiConfiguration config = new WifiConfiguration();
config.SSID = TEST_SSID;
@@ -123,14 +141,20 @@
assertThat(accessPoint.getBssid()).isEqualTo(TEST_BSSID);
assertThat(accessPoint.getNetworkInfo()).isNotNull();
assertThat(accessPoint.isActive()).isTrue();
- assertThat(accessPoint.getSettingsSummary()).isEqualTo(CONNECTED);
+ assertThat(accessPoint.getSettingsSummary()).isEqualTo(
+ resourceString(WIFI_DISPLAY_STATUS_CONNECTED));
when(mWifiTracker.getAccessPoints()).thenReturn(
Lists.asList(accessPoint, new AccessPoint[]{}));
}
- private void launchActivity() {
- mActivityRule.launchActivity(new Intent("android.settings.WIFI_SETTINGS"));
+ /** Launch the activity via an Intent with a String extra. */
+ private void launchActivity(String extraName, String extraValue) {
+ Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
+ if (extraName != null && extraValue != null) {
+ intent.putExtra(extraName, extraValue);
+ }
+ mActivityRule.launchActivity(intent);
verify(mWifiTracker).getManager();
@@ -140,6 +164,11 @@
assertThat(mWifiListener).isNotNull();
}
+ /** Helper to launch the activity with no extra. */
+ private void launchActivity() {
+ launchActivity(null, null);
+ }
+
private void setWifiState(int wifiState) {
when(mWifiManager.getWifiState()).thenReturn(wifiState);
when(mWifiManager.isWifiEnabled()).thenReturn(wifiState == WifiManager.WIFI_STATE_ENABLED);
@@ -159,7 +188,8 @@
public void shouldShowWifiPreferences() {
launchActivity();
- onView(withText(WIFI_PREFERENCES)).check(matches(isDisplayed()));
+ onView(withText(resourceId(STRING, WIFI_CONFIGURE_SETTINGS_PREFERENCE_TITLE))).check(
+ matches(isDisplayed()));
}
@Test
@@ -169,7 +199,8 @@
launchActivity();
- onView(withText(SAVED_NETWORKS)).check(matches(not(isDisplayed())));
+ onView(withText(resourceId(STRING, WIFI_SAVED_ACCESS_POINTS_LABEL))).check(
+ matches(not(isDisplayed())));
}
@Test
@@ -179,7 +210,8 @@
launchActivity();
- onView(withText(SAVED_NETWORKS)).check(doesNotExist());
+ onView(withText(resourceId(STRING, WIFI_SAVED_ACCESS_POINTS_LABEL))).check(
+ doesNotExist());
}
@Test
@@ -189,7 +221,7 @@
launchActivity();
- onView(allOf(withText(SAVED_NETWORKS),
+ onView(allOf(withText(resourceId(STRING, WIFI_SAVED_ACCESS_POINTS_LABEL)),
withEffectiveVisibility(VISIBLE))).check(matches(isDisplayed()));
}
@@ -200,7 +232,8 @@
launchActivity();
callOnWifiStateChanged(WifiManager.WIFI_STATE_DISABLED);
- onView(withText(startsWith(WIFI_OFF_MESSAGE))).check(matches(isDisplayed()));
+ onView(withText(startsWith(resourceString(WIFI_EMPTY_LIST_WIFI_OFF)))).check(
+ matches(isDisplayed()));
}
@Test
@@ -210,7 +243,8 @@
launchActivity();
callOnWifiStateChanged(WifiManager.WIFI_STATE_ENABLED);
- onView(withText(startsWith(WIFI_OFF_MESSAGE))).check(doesNotExist());
+ onView(withText(startsWith(resourceString(WIFI_EMPTY_LIST_WIFI_OFF)))).check(
+ doesNotExist());
}
@Test
@@ -221,7 +255,8 @@
launchActivity();
- onView(withText(CONNECTED)).check(matches(isDisplayed()));
+ onView(withText(resourceString(WIFI_DISPLAY_STATUS_CONNECTED))).check(
+ matches(isDisplayed()));
}
@Test
@@ -232,7 +267,8 @@
launchActivity();
- onView(withText(CONNECTED)).check(matches(isDisplayed()));
+ onView(withText(resourceString(WIFI_DISPLAY_STATUS_CONNECTED))).check(
+ matches(isDisplayed()));
verify(mWifiTracker).forceUpdate();
Activity activity = mActivityRule.getActivity();
@@ -247,7 +283,9 @@
public void changingSecurityStateOnApShouldNotCauseMultipleListItems() {
setWifiState(WifiManager.WIFI_STATE_ENABLED);
TestAccessPointBuilder builder = new TestAccessPointBuilder(mContext)
- .setSsid(TEST_SSID).setSecurity(AccessPoint.SECURITY_NONE);
+ .setSsid(TEST_SSID)
+ .setSecurity(AccessPoint.SECURITY_NONE)
+ .setRssi(TEST_RSSI);
AccessPoint open = builder.build();
builder.setSecurity(AccessPoint.SECURITY_EAP);
@@ -258,7 +296,7 @@
// Return a different security state each time getAccessPoints is invoked
when(mWifiTracker.getAccessPoints())
- .thenReturn(Lists.newArrayList(open, eap))
+ .thenReturn(Lists.newArrayList(open))
.thenReturn(Lists.newArrayList(eap))
.thenReturn(Lists.newArrayList(wep));
@@ -272,4 +310,53 @@
mWifiListener.onAccessPointsChanged();
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
}
+
+ @Test
+ public void wrongPasswordSavedNetwork() {
+ setWifiState(WifiManager.WIFI_STATE_ENABLED);
+
+ // Set up an AccessPoint that is disabled due to incorrect password.
+ WifiConfiguration config = new WifiConfiguration();
+ config.SSID = TEST_SSID;
+ config.BSSID = TEST_BSSID;
+ config.networkId = TEST_NETWORK_ID;
+ config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
+
+ WifiConfiguration.NetworkSelectionStatus selectionStatus =
+ new WifiConfiguration.NetworkSelectionStatus();
+ selectionStatus.setNetworkSelectionDisableReason(
+ WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD);
+ selectionStatus.setNetworkSelectionStatus(
+ WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED);
+ config.setNetworkSelectionStatus(selectionStatus);
+
+ WifiInfo wifiInfo = new WifiInfo();
+ wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(TEST_UNQUOTED_SSID));
+ wifiInfo.setBSSID(TEST_BSSID);
+ wifiInfo.setRssi(TEST_RSSI);
+ wifiInfo.setNetworkId(TEST_NETWORK_ID);
+ AccessPoint accessPoint = new AccessPoint(mContext, config);
+ accessPoint.update(config, wifiInfo, null);
+
+ // Make sure we've set up our access point correctly.
+ assertThat(accessPoint.getSsidStr()).isEqualTo(TEST_UNQUOTED_SSID);
+ assertThat(accessPoint.getBssid()).isEqualTo(TEST_BSSID);
+ assertThat(accessPoint.isActive()).isFalse();
+ assertThat(accessPoint.getConfig()).isNotNull();
+ WifiConfiguration.NetworkSelectionStatus networkStatus =
+ accessPoint.getConfig().getNetworkSelectionStatus();
+ assertThat(networkStatus).isNotNull();
+ assertThat(networkStatus.isNetworkEnabled()).isFalse();
+ assertThat(networkStatus.getNetworkSelectionDisableReason()).isEqualTo(
+ WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD);
+
+ when(mWifiTracker.getAccessPoints()).thenReturn(Lists.newArrayList(accessPoint));
+ launchActivity(WifiSettings.EXTRA_START_CONNECT_SSID, accessPoint.getSsidStr());
+
+ // Make sure that the password dialog is visible.
+ onView(withText(resourceId(STRING, WIFI_PASSWORD))).check(matches(isDisplayed()));
+ onView(withText(resourceId(STRING, WIFI_SHOW_PASSWORD))).check(matches(isDisplayed()));
+ onView(withId(resourceId(ID, PASSWORD_LAYOUT))).check(matches(isDisplayed()));
+ onView(withId(resourceId(ID, PASSWORD))).check(matches(isDisplayed()));
+ }
}