Allow WifiSettings to show old APs on app resume. am: 4ae59dde43
am: 6ab460c354
Change-Id: I1f3b7d405ea6e98d4cfa0a69b4468494f7867d4a
This commit is contained in:
@@ -43,7 +43,6 @@ import android.provider.Settings;
|
|||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceCategory;
|
import android.support.v7.preference.PreferenceCategory;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
@@ -321,7 +320,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
if (intent.hasExtra(EXTRA_START_CONNECT_SSID)) {
|
if (intent.hasExtra(EXTRA_START_CONNECT_SSID)) {
|
||||||
mOpenSsid = intent.getStringExtra(EXTRA_START_CONNECT_SSID);
|
mOpenSsid = intent.getStringExtra(EXTRA_START_CONNECT_SSID);
|
||||||
updateAccessPointsDelayed();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,13 +352,28 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
onWifiStateChanged(mWifiManager.getWifiState());
|
onWifiStateChanged(mWifiManager.getWifiState());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forceUpdateAPs() {
|
/**
|
||||||
|
* Only update the AP list if there are not any APs currently shown.
|
||||||
|
*
|
||||||
|
* <p>Thus forceUpdate will only be called during cold start or when toggling between wifi on
|
||||||
|
* and off. In other use cases, the previous APs will remain until the next update is received
|
||||||
|
* from {@link WifiTracker}.
|
||||||
|
*/
|
||||||
|
private void conditionallyForceUpdateAPs() {
|
||||||
|
if (mAccessPointsPreferenceCategory.getPreferenceCount() > 0
|
||||||
|
&& mAccessPointsPreferenceCategory.getPreference(0) instanceof
|
||||||
|
AccessPointPreference) {
|
||||||
|
// Make sure we don't update due to callbacks initiated by sticky broadcasts in
|
||||||
|
// WifiTracker.
|
||||||
|
Log.d(TAG, "Did not force update APs due to existing APs displayed");
|
||||||
|
getView().removeCallbacks(mUpdateAccessPointsRunnable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setProgressBarVisible(true);
|
setProgressBarVisible(true);
|
||||||
mWifiTracker.forceUpdate();
|
mWifiTracker.forceUpdate();
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "WifiSettings force update APs: " + mWifiTracker.getAccessPoints());
|
Log.d(TAG, "WifiSettings force update APs: " + mWifiTracker.getAccessPoints());
|
||||||
}
|
}
|
||||||
|
|
||||||
getView().removeCallbacks(mUpdateAccessPointsRunnable);
|
getView().removeCallbacks(mUpdateAccessPointsRunnable);
|
||||||
updateAccessPointPreferences();
|
updateAccessPointPreferences();
|
||||||
}
|
}
|
||||||
@@ -654,6 +667,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onAccessPointsChanged() {
|
public void onAccessPointsChanged() {
|
||||||
|
Log.d(TAG, "onAccessPointsChanged (WifiTracker) callback initiated");
|
||||||
updateAccessPointsDelayed();
|
updateAccessPointsDelayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,7 +693,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
final int wifiState = mWifiManager.getWifiState();
|
final int wifiState = mWifiManager.getWifiState();
|
||||||
switch (wifiState) {
|
switch (wifiState) {
|
||||||
case WifiManager.WIFI_STATE_ENABLED:
|
case WifiManager.WIFI_STATE_ENABLED:
|
||||||
forceUpdateAPs();
|
conditionallyForceUpdateAPs();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WifiManager.WIFI_STATE_ENABLING:
|
case WifiManager.WIFI_STATE_ENABLING:
|
||||||
@@ -720,6 +734,9 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
// AccessPoints are sorted by the WifiTracker
|
// AccessPoints are sorted by the WifiTracker
|
||||||
final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
|
final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "updateAccessPoints called for: " + accessPoints);
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasAvailableAccessPoints = false;
|
boolean hasAvailableAccessPoints = false;
|
||||||
mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
|
mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
|
||||||
@@ -1015,6 +1032,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccessPointChanged(final AccessPoint accessPoint) {
|
public void onAccessPointChanged(final AccessPoint accessPoint) {
|
||||||
|
Log.d(TAG, "onAccessPointChanged (singular) callback initiated");
|
||||||
View view = getView();
|
View view = getView();
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
view.post(new Runnable() {
|
view.post(new Runnable() {
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -45,6 +46,7 @@ import org.mockito.MockitoAnnotations;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
||||||
import static android.support.test.espresso.Espresso.onView;
|
import static android.support.test.espresso.Espresso.onView;
|
||||||
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
|
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
|
||||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||||
@@ -52,10 +54,14 @@ import static android.support.test.espresso.matcher.ViewMatchers.Visibility.VISI
|
|||||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
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.withEffectiveVisibility;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.allOf;
|
import static org.hamcrest.Matchers.allOf;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.atMost;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -217,4 +223,23 @@ public class WifiSettingsUiTest {
|
|||||||
|
|
||||||
onView(withText(CONNECTED)).check(matches(isDisplayed()));
|
onView(withText(CONNECTED)).check(matches(isDisplayed()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void resumingAp_shouldNotForceUpdateWhenExistingAPsAreListed() {
|
||||||
|
setWifiState(WifiManager.WIFI_STATE_ENABLED);
|
||||||
|
setupConnectedAccessPoint();
|
||||||
|
when(mWifiTracker.isConnected()).thenReturn(true);
|
||||||
|
|
||||||
|
launchActivity();
|
||||||
|
|
||||||
|
onView(withText(CONNECTED)).check(matches(isDisplayed()));
|
||||||
|
verify(mWifiTracker).forceUpdate();
|
||||||
|
|
||||||
|
Activity activity = mActivityRule.getActivity();
|
||||||
|
activity.finish();
|
||||||
|
getInstrumentation().waitForIdleSync();
|
||||||
|
|
||||||
|
getInstrumentation().callActivityOnStart(activity);
|
||||||
|
verify(mWifiTracker, atMost(1)).forceUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user