Keep access point list updated once in short time

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
This commit is contained in:
Fan Zhang
2018-01-17 09:12:48 -08:00
parent 85cd77c9f2
commit a958478501

View File

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