OSDN Git Service

Keep access point list updated once in short time
authorFan Zhang <zhfan@google.com>
Wed, 17 Jan 2018 17:12:48 +0000 (09:12 -0800)
committerFan Zhang <zhfan@google.com>
Wed, 17 Jan 2018 17:13:10 +0000 (09:13 -0800)
The function onAccessPointsChanged will be called many times
and access points will be updated many times in 300ms. So check
if the same event exists before calling postDelayed.

Fixes: 68230819
Test: Manual test
Change-Id: Id098e1b77c28b62a5495c3369ed950531e59dba2

src/com/android/settings/wifi/WifiSettings.java

index 95944f2..83d9c18 100644 (file)
@@ -33,6 +33,7 @@ import android.net.wifi.WifiManager;
 import android.net.wifi.WpsInfo;
 import android.nfc.NfcAdapter;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.PowerManager;
 import android.provider.Settings;
 import android.support.annotation.VisibleForTesting;
@@ -687,8 +688,13 @@ public class WifiSettings extends RestrictedSettingsFragment
     private void updateAccessPointsDelayed() {
         // Safeguard from some delayed event handling
         if (getActivity() != null && !mIsRestricted && mWifiManager.isWifiEnabled()) {
+            final View view = getView();
+            final Handler handler = view.getHandler();
+            if (handler != null && handler.hasCallbacks(mUpdateAccessPointsRunnable)) {
+                return;
+            }
             setProgressBarVisible(true);
-            getView().postDelayed(mUpdateAccessPointsRunnable, 300 /* delay milliseconds */);
+            view.postDelayed(mUpdateAccessPointsRunnable, 300 /* delay milliseconds */);
         }
     }