• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

修訂60b814ba434f346779635d8fe1a91296856e474f (tree)
時間2017-06-15 11:07:05
作者Sundeep Ghuman <sghuman@goog...>
CommiterSundeep Ghuman

Log Message

Allow WifiSettings to show old APs on app resume.

If we do not have any recent scan results, show the previous APs from
when the app was last paused, by not triggering a force update.

Accompanying changes are also made in WifiTracker to prevent
onAccessPointsChanged callbacks from being invoked until the tracker
receives a new 'SCAN_RESULTS_AVAILABLE' broadcast (ag/2409026).

Bug: b/38212080
Test: runtest --path
packages/apps/Settings/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
one minute later.

Change-Id: I4f9b2ec855e057e28235b0253ab42c6b4521bebc
Merged-In: I4f9b2ec855e057e28235b0253ab42c6b4521bebc

Change Summary

差異

--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -43,7 +43,6 @@ import android.provider.Settings;
4343 import android.support.annotation.VisibleForTesting;
4444 import android.support.v7.preference.Preference;
4545 import android.support.v7.preference.PreferenceCategory;
46-import android.support.v7.preference.PreferenceManager;
4746 import android.text.TextUtils;
4847 import android.util.Log;
4948 import android.view.ContextMenu;
@@ -321,7 +320,6 @@ public class WifiSettings extends RestrictedSettingsFragment
321320
322321 if (intent.hasExtra(EXTRA_START_CONNECT_SSID)) {
323322 mOpenSsid = intent.getStringExtra(EXTRA_START_CONNECT_SSID);
324- updateAccessPointsDelayed();
325323 }
326324 }
327325
@@ -354,13 +352,28 @@ public class WifiSettings extends RestrictedSettingsFragment
354352 onWifiStateChanged(mWifiManager.getWifiState());
355353 }
356354
357- private void forceUpdateAPs() {
355+ /**
356+ * Only update the AP list if there are not any APs currently shown.
357+ *
358+ * <p>Thus forceUpdate will only be called during cold start or when toggling between wifi on
359+ * and off. In other use cases, the previous APs will remain until the next update is received
360+ * from {@link WifiTracker}.
361+ */
362+ private void conditionallyForceUpdateAPs() {
363+ if (mAccessPointsPreferenceCategory.getPreferenceCount() > 0
364+ && mAccessPointsPreferenceCategory.getPreference(0) instanceof
365+ AccessPointPreference) {
366+ // Make sure we don't update due to callbacks initiated by sticky broadcasts in
367+ // WifiTracker.
368+ Log.d(TAG, "Did not force update APs due to existing APs displayed");
369+ getView().removeCallbacks(mUpdateAccessPointsRunnable);
370+ return;
371+ }
358372 setProgressBarVisible(true);
359373 mWifiTracker.forceUpdate();
360374 if (DEBUG) {
361375 Log.d(TAG, "WifiSettings force update APs: " + mWifiTracker.getAccessPoints());
362376 }
363-
364377 getView().removeCallbacks(mUpdateAccessPointsRunnable);
365378 updateAccessPointPreferences();
366379 }
@@ -654,6 +667,7 @@ public class WifiSettings extends RestrictedSettingsFragment
654667 */
655668 @Override
656669 public void onAccessPointsChanged() {
670+ Log.d(TAG, "onAccessPointsChanged (WifiTracker) callback initiated");
657671 updateAccessPointsDelayed();
658672 }
659673
@@ -679,7 +693,7 @@ public class WifiSettings extends RestrictedSettingsFragment
679693 final int wifiState = mWifiManager.getWifiState();
680694 switch (wifiState) {
681695 case WifiManager.WIFI_STATE_ENABLED:
682- forceUpdateAPs();
696+ conditionallyForceUpdateAPs();
683697 break;
684698
685699 case WifiManager.WIFI_STATE_ENABLING:
@@ -719,6 +733,9 @@ public class WifiSettings extends RestrictedSettingsFragment
719733 }
720734 // AccessPoints are sorted by the WifiTracker
721735 final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
736+ if (DEBUG) {
737+ Log.d(TAG, "updateAccessPoints called for: " + accessPoints);
738+ }
722739
723740 boolean hasAvailableAccessPoints = false;
724741 mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
@@ -1014,6 +1031,7 @@ public class WifiSettings extends RestrictedSettingsFragment
10141031
10151032 @Override
10161033 public void onAccessPointChanged(final AccessPoint accessPoint) {
1034+ Log.d(TAG, "onAccessPointChanged (singular) callback initiated");
10171035 View view = getView();
10181036 if (view != null) {
10191037 view.post(new Runnable() {
--- a/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
+++ b/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
@@ -15,6 +15,7 @@
1515 */
1616 package com.android.settings.wifi;
1717
18+import static android.support.test.InstrumentationRegistry.getInstrumentation;
1819 import static android.support.test.espresso.Espresso.onView;
1920 import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
2021 import static android.support.test.espresso.assertion.ViewAssertions.matches;
@@ -22,13 +23,17 @@ import static android.support.test.espresso.matcher.ViewMatchers.Visibility.VISI
2223 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
2324 import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
2425 import static android.support.test.espresso.matcher.ViewMatchers.withText;
26+
2527 import static com.google.common.truth.Truth.assertThat;
28+
2629 import static org.hamcrest.Matchers.allOf;
2730 import static org.hamcrest.Matchers.not;
2831 import static org.hamcrest.Matchers.startsWith;
32+import static org.mockito.Mockito.atMost;
2933 import static org.mockito.Mockito.verify;
3034 import static org.mockito.Mockito.when;
3135
36+import android.app.Activity;
3237 import android.app.Fragment;
3338 import android.content.Context;
3439 import android.content.Intent;
@@ -41,12 +46,15 @@ import android.net.wifi.WifiSsid;
4146 import android.support.test.InstrumentationRegistry;
4247 import android.support.test.rule.ActivityTestRule;
4348 import android.support.test.runner.AndroidJUnit4;
49+
4450 import com.android.settings.Settings.WifiSettingsActivity;
4551 import com.android.settingslib.wifi.AccessPoint;
4652 import com.android.settingslib.wifi.WifiTracker;
4753 import com.android.settingslib.wifi.WifiTracker.WifiListener;
4854 import com.android.settingslib.wifi.WifiTrackerFactory;
55+
4956 import com.google.common.collect.Lists;
57+
5058 import org.junit.Before;
5159 import org.junit.Rule;
5260 import org.junit.Test;
@@ -202,4 +210,23 @@ public class WifiSettingsUiTest {
202210
203211 onView(withText(CONNECTED)).check(matches(isDisplayed()));
204212 }
213+
214+ @Test
215+ public void resumingAp_shouldNotForceUpdateWhenExistingAPsAreListed() {
216+ setWifiState(WifiManager.WIFI_STATE_ENABLED);
217+ setupConnectedAccessPoint();
218+ when(mWifiTracker.isConnected()).thenReturn(true);
219+
220+ launchActivity();
221+
222+ onView(withText(CONNECTED)).check(matches(isDisplayed()));
223+ verify(mWifiTracker).forceUpdate();
224+
225+ Activity activity = mActivityRule.getActivity();
226+ activity.finish();
227+ getInstrumentation().waitForIdleSync();
228+
229+ getInstrumentation().callActivityOnStart(activity);
230+ verify(mWifiTracker, atMost(1)).forceUpdate();
231+ }
205232 }