Loading packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java +104 −47 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager; import android.os.Handler; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Message; import android.widget.Toast; import android.widget.Toast; Loading Loading @@ -63,10 +64,12 @@ public class WifiTracker { private final boolean mIncludeScans; private final boolean mIncludeScans; private final boolean mIncludePasspoints; private final boolean mIncludePasspoints; private final MainHandler mMainHandler; private final WorkHandler mWorkHandler; private boolean mSavedNetworksExist; private boolean mSavedNetworksExist; private boolean mRegistered; private boolean mRegistered; private ArrayList<AccessPoint> mAccessPoints = new ArrayList<>(); private ArrayList<AccessPoint> mAccessPoints = new ArrayList<>(); private ArrayList<AccessPoint> mCachedAccessPoints = new ArrayList<>(); private NetworkInfo mLastNetworkInfo; private NetworkInfo mLastNetworkInfo; private WifiInfo mLastInfo; private WifiInfo mLastInfo; Loading @@ -74,23 +77,38 @@ public class WifiTracker { @VisibleForTesting @VisibleForTesting Scanner mScanner; Scanner mScanner; public WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, public WifiTracker(Context context, WifiListener wifiListener, boolean includeScans) { boolean includeSaved, boolean includeScans) { this(context, wifiListener, includeSaved, includeScans, false); this(context, wifiListener, null, includeSaved, includeScans); } } public WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, boolean includeScans, boolean includePasspoints) { public WifiTracker(Context context, WifiListener wifiListener, Looper workerLooper, this(context, wifiListener, includeSaved, includeScans, includePasspoints, boolean includeSaved, boolean includeScans) { this(context, wifiListener, workerLooper, includeSaved, includeScans, false); } public WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, boolean includeScans, boolean includePasspoints) { this(context, wifiListener, null, includeSaved, includeScans, includePasspoints); } public WifiTracker(Context context, WifiListener wifiListener, Looper workerLooper, boolean includeSaved, boolean includeScans, boolean includePasspoints) { this(context, wifiListener, workerLooper, includeSaved, includeScans, includePasspoints, (WifiManager) context.getSystemService(Context.WIFI_SERVICE)); (WifiManager) context.getSystemService(Context.WIFI_SERVICE)); } } @VisibleForTesting @VisibleForTesting WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, WifiTracker(Context context, WifiListener wifiListener, Looper workerLooper, boolean includeScans, boolean includePasspoints, WifiManager wifiManager) { boolean includeSaved, boolean includeScans, boolean includePasspoints, WifiManager wifiManager) { if (!includeSaved && !includeScans) { if (!includeSaved && !includeScans) { throw new IllegalArgumentException("Must include either saved or scans"); throw new IllegalArgumentException("Must include either saved or scans"); } } mContext = context; mContext = context; mMainHandler = new MainHandler(); mWorkHandler = new WorkHandler( workerLooper != null ? workerLooper : Looper.myLooper()); mWifiManager = wifiManager; mWifiManager = wifiManager; mIncludeSaved = includeSaved; mIncludeSaved = includeSaved; mIncludeScans = includeScans; mIncludeScans = includeScans; Loading Loading @@ -147,7 +165,7 @@ public class WifiTracker { if (mWifiManager.isWifiEnabled()) { if (mWifiManager.isWifiEnabled()) { mScanner.resume(); mScanner.resume(); } } updateAccessPoints(); mWorkHandler.sendEmptyMessage(WorkHandler.MSG_UPDATE_ACCESS_POINTS); } } /** /** Loading Loading @@ -213,16 +231,14 @@ public class WifiTracker { private void updateAccessPoints() { private void updateAccessPoints() { // Swap the current access points into a cached list. // Swap the current access points into a cached list. ArrayList<AccessPoint> tmpSwp = mAccessPoints; ArrayList<AccessPoint> cachedAccessPoints = new ArrayList<>(mAccessPoints); mAccessPoints = mCachedAccessPoints; ArrayList<AccessPoint> accessPoints = new ArrayList<>(); mCachedAccessPoints = tmpSwp; // Clear out the configs so we don't think something is saved when it isn't. // Clear out the configs so we don't think something is saved when it isn't. for (AccessPoint accessPoint : mCachedAccessPoints) { for (AccessPoint accessPoint : cachedAccessPoints) { accessPoint.clearConfig(); accessPoint.clearConfig(); } } mAccessPoints.clear(); /** Lookup table to more quickly update AccessPoints by only considering objects with the /** Lookup table to more quickly update AccessPoints by only considering objects with the * correct SSID. Maps SSID -> List of AccessPoints with the given SSID. */ * correct SSID. Maps SSID -> List of AccessPoints with the given SSID. */ Multimap<String, AccessPoint> apMap = new Multimap<String, AccessPoint>(); Multimap<String, AccessPoint> apMap = new Multimap<String, AccessPoint>(); Loading @@ -238,7 +254,7 @@ public class WifiTracker { if (config.selfAdded && config.numAssociation == 0) { if (config.selfAdded && config.numAssociation == 0) { continue; continue; } } AccessPoint accessPoint = getCachedOrCreate(config); AccessPoint accessPoint = getCachedOrCreate(config, cachedAccessPoints); if (mLastInfo != null && mLastNetworkInfo != null) { if (mLastInfo != null && mLastNetworkInfo != null) { if (config.isPasspoint() == false) { if (config.isPasspoint() == false) { accessPoint.update(mLastInfo, mLastNetworkInfo); accessPoint.update(mLastInfo, mLastNetworkInfo); Loading @@ -246,7 +262,7 @@ public class WifiTracker { } } if (mIncludeSaved) { if (mIncludeSaved) { if (!config.isPasspoint() || mIncludePasspoints) if (!config.isPasspoint() || mIncludePasspoints) mAccessPoints.add(accessPoint); accessPoints.add(accessPoint); if (config.isPasspoint() == false) { if (config.isPasspoint() == false) { apMap.put(accessPoint.getSsid(), accessPoint); apMap.put(accessPoint.getSsid(), accessPoint); Loading @@ -254,7 +270,7 @@ public class WifiTracker { } else { } else { // If we aren't using saved networks, drop them into the cache so that // If we aren't using saved networks, drop them into the cache so that // we have access to their saved info. // we have access to their saved info. mCachedAccessPoints.add(accessPoint); cachedAccessPoints.add(accessPoint); } } } } } } Loading @@ -276,7 +292,7 @@ public class WifiTracker { } } } } if (!found && mIncludeScans) { if (!found && mIncludeScans) { AccessPoint accessPoint = getCachedOrCreate(result); AccessPoint accessPoint = getCachedOrCreate(result, cachedAccessPoints); if (mLastInfo != null && mLastNetworkInfo != null) { if (mLastInfo != null && mLastNetworkInfo != null) { accessPoint.update(mLastInfo, mLastNetworkInfo); accessPoint.update(mLastInfo, mLastNetworkInfo); } } Loading @@ -296,24 +312,23 @@ public class WifiTracker { accessPoint.update(connectionConfig); accessPoint.update(connectionConfig); } } mAccessPoints.add(accessPoint); accessPoints.add(accessPoint); apMap.put(accessPoint.getSsid(), accessPoint); apMap.put(accessPoint.getSsid(), accessPoint); } } } } } } // Pre-sort accessPoints to speed preference insertion // Pre-sort accessPoints to speed preference insertion Collections.sort(mAccessPoints); Collections.sort(accessPoints); if (mListener != null) { mAccessPoints = accessPoints; mListener.onAccessPointsChanged(); mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED); } } } private AccessPoint getCachedOrCreate(ScanResult result) { private AccessPoint getCachedOrCreate(ScanResult result, ArrayList<AccessPoint> cache) { final int N = mCachedAccessPoints.size(); final int N = cache.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { if (mCachedAccessPoints.get(i).matches(result)) { if (cache.get(i).matches(result)) { AccessPoint ret = mCachedAccessPoints.remove(i); AccessPoint ret = cache.remove(i); ret.update(result); ret.update(result); return ret; return ret; } } Loading @@ -321,11 +336,11 @@ public class WifiTracker { return new AccessPoint(mContext, result); return new AccessPoint(mContext, result); } } private AccessPoint getCachedOrCreate(WifiConfiguration config) { private AccessPoint getCachedOrCreate(WifiConfiguration config, ArrayList<AccessPoint> cache) { final int N = mCachedAccessPoints.size(); final int N = cache.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { if (mCachedAccessPoints.get(i).matches(config)) { if (cache.get(i).matches(config)) { AccessPoint ret = mCachedAccessPoints.remove(i); AccessPoint ret = cache.remove(i); ret.loadConfig(config); ret.loadConfig(config); return ret; return ret; } } Loading Loading @@ -360,9 +375,7 @@ public class WifiTracker { } } if (reorder) { if (reorder) { Collections.sort(mAccessPoints); Collections.sort(mAccessPoints); if (mListener != null) { mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED); mListener.onAccessPointsChanged(); } } } } } Loading @@ -380,15 +393,13 @@ public class WifiTracker { mScanner.pause(); mScanner.pause(); } } } } if (mListener != null) { mMainHandler.obtainMessage(MainHandler.MSG_WIFI_STATE_CHANGED, state, 0).sendToTarget(); mListener.onWifiStateChanged(state); } } } public static List<AccessPoint> getCurrentAccessPoints(Context context, boolean includeSaved, public static List<AccessPoint> getCurrentAccessPoints(Context context, boolean includeSaved, boolean includeScans, boolean includePasspoints) { boolean includeScans, boolean includePasspoints) { WifiTracker tracker = new WifiTracker(context, WifiTracker tracker = new WifiTracker(context, null, includeSaved, includeScans, includePasspoints); null, null, includeSaved, includeScans, includePasspoints); tracker.forceUpdate(); tracker.forceUpdate(); return tracker.getAccessPoints(); return tracker.getAccessPoints(); } } Loading @@ -404,21 +415,67 @@ public class WifiTracker { } else if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action) || } else if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action) || WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION.equals(action) || WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION.equals(action) || WifiManager.LINK_CONFIGURATION_CHANGED_ACTION.equals(action)) { WifiManager.LINK_CONFIGURATION_CHANGED_ACTION.equals(action)) { updateAccessPoints(); mWorkHandler.sendEmptyMessage(WorkHandler.MSG_UPDATE_ACCESS_POINTS); } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { NetworkInfo info = (NetworkInfo) intent.getParcelableExtra( NetworkInfo info = (NetworkInfo) intent.getParcelableExtra( WifiManager.EXTRA_NETWORK_INFO); WifiManager.EXTRA_NETWORK_INFO); mConnected.set(info.isConnected()); mConnected.set(info.isConnected()); if (mListener != null) { mMainHandler.sendEmptyMessage(MainHandler.MSG_CONNECTED_CHANGED); mWorkHandler.sendEmptyMessage(WorkHandler.MSG_UPDATE_ACCESS_POINTS); mWorkHandler.obtainMessage(WorkHandler.MSG_UPDATE_NETWORK_INFO, info) .sendToTarget(); } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) { mWorkHandler.sendEmptyMessage(WorkHandler.MSG_UPDATE_NETWORK_INFO); } } }; private final class MainHandler extends Handler { private static final int MSG_CONNECTED_CHANGED = 0; private static final int MSG_WIFI_STATE_CHANGED = 1; private static final int MSG_ACCESS_POINT_CHANGED = 2; @Override public void handleMessage(Message msg) { if (mListener == null) { return; } switch (msg.what) { case MSG_CONNECTED_CHANGED: mListener.onConnectedChanged(); mListener.onConnectedChanged(); break; case MSG_WIFI_STATE_CHANGED: mListener.onWifiStateChanged(msg.arg1); break; case MSG_ACCESS_POINT_CHANGED: mListener.onAccessPointsChanged(); break; } } } } private final class WorkHandler extends Handler { private static final int MSG_UPDATE_ACCESS_POINTS = 0; private static final int MSG_UPDATE_NETWORK_INFO = 1; public WorkHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_UPDATE_ACCESS_POINTS: updateAccessPoints(); updateAccessPoints(); updateNetworkInfo(info); break; } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) { case MSG_UPDATE_NETWORK_INFO: updateNetworkInfo(null); updateNetworkInfo((NetworkInfo) msg.obj); break; } } } } } }; @VisibleForTesting @VisibleForTesting class Scanner extends Handler { class Scanner extends Handler { Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -756,7 +756,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, // noop // noop } } }); }); mNetworkController = new NetworkControllerImpl(mContext); mNetworkController = new NetworkControllerImpl(mContext, mHandlerThread.getLooper()); mHotspotController = new HotspotControllerImpl(mContext); mHotspotController = new HotspotControllerImpl(mContext); mBluetoothController = new BluetoothControllerImpl(mContext, mHandlerThread.getLooper()); mBluetoothController = new BluetoothControllerImpl(mContext, mHandlerThread.getLooper()); mSecurityController = new SecurityControllerImpl(mContext); mSecurityController = new SecurityControllerImpl(mContext); Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/AccessPointControllerImpl.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.ActivityManager; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.net.wifi.WifiManager.ActionListener; import android.net.wifi.WifiManager.ActionListener; import android.os.Looper; import android.os.UserHandle; import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; import android.provider.Settings; import android.provider.Settings; Loading Loading @@ -58,10 +59,10 @@ public class AccessPointControllerImpl private int mCurrentUser; private int mCurrentUser; public AccessPointControllerImpl(Context context) { public AccessPointControllerImpl(Context context, Looper bgLooper) { mContext = context; mContext = context; mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); mWifiTracker = new WifiTracker(context, this, false, true); mWifiTracker = new WifiTracker(context, this, bgLooper, false, true); mCurrentUser = ActivityManager.getCurrentUser(); mCurrentUser = ActivityManager.getCurrentUser(); } } Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java +4 −2 Original line number Original line Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.net.NetworkCapabilities; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager; import android.os.AsyncTask; import android.os.AsyncTask; import android.os.Bundle; import android.os.Bundle; import android.os.Looper; import android.provider.Settings; import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager; Loading Loading @@ -115,12 +116,13 @@ public class NetworkControllerImpl extends BroadcastReceiver /** /** * Construct this controller object and register for updates. * Construct this controller object and register for updates. */ */ public NetworkControllerImpl(Context context) { public NetworkControllerImpl(Context context, Looper bgLooper) { this(context, (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), this(context, (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE), (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE), (WifiManager) context.getSystemService(Context.WIFI_SERVICE), (WifiManager) context.getSystemService(Context.WIFI_SERVICE), SubscriptionManager.from(context), Config.readConfig(context), SubscriptionManager.from(context), Config.readConfig(context), new AccessPointControllerImpl(context), new MobileDataControllerImpl(context)); new AccessPointControllerImpl(context, bgLooper), new MobileDataControllerImpl(context)); registerListeners(); registerListeners(); } } Loading Loading
packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java +104 −47 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager; import android.os.Handler; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Message; import android.widget.Toast; import android.widget.Toast; Loading Loading @@ -63,10 +64,12 @@ public class WifiTracker { private final boolean mIncludeScans; private final boolean mIncludeScans; private final boolean mIncludePasspoints; private final boolean mIncludePasspoints; private final MainHandler mMainHandler; private final WorkHandler mWorkHandler; private boolean mSavedNetworksExist; private boolean mSavedNetworksExist; private boolean mRegistered; private boolean mRegistered; private ArrayList<AccessPoint> mAccessPoints = new ArrayList<>(); private ArrayList<AccessPoint> mAccessPoints = new ArrayList<>(); private ArrayList<AccessPoint> mCachedAccessPoints = new ArrayList<>(); private NetworkInfo mLastNetworkInfo; private NetworkInfo mLastNetworkInfo; private WifiInfo mLastInfo; private WifiInfo mLastInfo; Loading @@ -74,23 +77,38 @@ public class WifiTracker { @VisibleForTesting @VisibleForTesting Scanner mScanner; Scanner mScanner; public WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, public WifiTracker(Context context, WifiListener wifiListener, boolean includeScans) { boolean includeSaved, boolean includeScans) { this(context, wifiListener, includeSaved, includeScans, false); this(context, wifiListener, null, includeSaved, includeScans); } } public WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, boolean includeScans, boolean includePasspoints) { public WifiTracker(Context context, WifiListener wifiListener, Looper workerLooper, this(context, wifiListener, includeSaved, includeScans, includePasspoints, boolean includeSaved, boolean includeScans) { this(context, wifiListener, workerLooper, includeSaved, includeScans, false); } public WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, boolean includeScans, boolean includePasspoints) { this(context, wifiListener, null, includeSaved, includeScans, includePasspoints); } public WifiTracker(Context context, WifiListener wifiListener, Looper workerLooper, boolean includeSaved, boolean includeScans, boolean includePasspoints) { this(context, wifiListener, workerLooper, includeSaved, includeScans, includePasspoints, (WifiManager) context.getSystemService(Context.WIFI_SERVICE)); (WifiManager) context.getSystemService(Context.WIFI_SERVICE)); } } @VisibleForTesting @VisibleForTesting WifiTracker(Context context, WifiListener wifiListener, boolean includeSaved, WifiTracker(Context context, WifiListener wifiListener, Looper workerLooper, boolean includeScans, boolean includePasspoints, WifiManager wifiManager) { boolean includeSaved, boolean includeScans, boolean includePasspoints, WifiManager wifiManager) { if (!includeSaved && !includeScans) { if (!includeSaved && !includeScans) { throw new IllegalArgumentException("Must include either saved or scans"); throw new IllegalArgumentException("Must include either saved or scans"); } } mContext = context; mContext = context; mMainHandler = new MainHandler(); mWorkHandler = new WorkHandler( workerLooper != null ? workerLooper : Looper.myLooper()); mWifiManager = wifiManager; mWifiManager = wifiManager; mIncludeSaved = includeSaved; mIncludeSaved = includeSaved; mIncludeScans = includeScans; mIncludeScans = includeScans; Loading Loading @@ -147,7 +165,7 @@ public class WifiTracker { if (mWifiManager.isWifiEnabled()) { if (mWifiManager.isWifiEnabled()) { mScanner.resume(); mScanner.resume(); } } updateAccessPoints(); mWorkHandler.sendEmptyMessage(WorkHandler.MSG_UPDATE_ACCESS_POINTS); } } /** /** Loading Loading @@ -213,16 +231,14 @@ public class WifiTracker { private void updateAccessPoints() { private void updateAccessPoints() { // Swap the current access points into a cached list. // Swap the current access points into a cached list. ArrayList<AccessPoint> tmpSwp = mAccessPoints; ArrayList<AccessPoint> cachedAccessPoints = new ArrayList<>(mAccessPoints); mAccessPoints = mCachedAccessPoints; ArrayList<AccessPoint> accessPoints = new ArrayList<>(); mCachedAccessPoints = tmpSwp; // Clear out the configs so we don't think something is saved when it isn't. // Clear out the configs so we don't think something is saved when it isn't. for (AccessPoint accessPoint : mCachedAccessPoints) { for (AccessPoint accessPoint : cachedAccessPoints) { accessPoint.clearConfig(); accessPoint.clearConfig(); } } mAccessPoints.clear(); /** Lookup table to more quickly update AccessPoints by only considering objects with the /** Lookup table to more quickly update AccessPoints by only considering objects with the * correct SSID. Maps SSID -> List of AccessPoints with the given SSID. */ * correct SSID. Maps SSID -> List of AccessPoints with the given SSID. */ Multimap<String, AccessPoint> apMap = new Multimap<String, AccessPoint>(); Multimap<String, AccessPoint> apMap = new Multimap<String, AccessPoint>(); Loading @@ -238,7 +254,7 @@ public class WifiTracker { if (config.selfAdded && config.numAssociation == 0) { if (config.selfAdded && config.numAssociation == 0) { continue; continue; } } AccessPoint accessPoint = getCachedOrCreate(config); AccessPoint accessPoint = getCachedOrCreate(config, cachedAccessPoints); if (mLastInfo != null && mLastNetworkInfo != null) { if (mLastInfo != null && mLastNetworkInfo != null) { if (config.isPasspoint() == false) { if (config.isPasspoint() == false) { accessPoint.update(mLastInfo, mLastNetworkInfo); accessPoint.update(mLastInfo, mLastNetworkInfo); Loading @@ -246,7 +262,7 @@ public class WifiTracker { } } if (mIncludeSaved) { if (mIncludeSaved) { if (!config.isPasspoint() || mIncludePasspoints) if (!config.isPasspoint() || mIncludePasspoints) mAccessPoints.add(accessPoint); accessPoints.add(accessPoint); if (config.isPasspoint() == false) { if (config.isPasspoint() == false) { apMap.put(accessPoint.getSsid(), accessPoint); apMap.put(accessPoint.getSsid(), accessPoint); Loading @@ -254,7 +270,7 @@ public class WifiTracker { } else { } else { // If we aren't using saved networks, drop them into the cache so that // If we aren't using saved networks, drop them into the cache so that // we have access to their saved info. // we have access to their saved info. mCachedAccessPoints.add(accessPoint); cachedAccessPoints.add(accessPoint); } } } } } } Loading @@ -276,7 +292,7 @@ public class WifiTracker { } } } } if (!found && mIncludeScans) { if (!found && mIncludeScans) { AccessPoint accessPoint = getCachedOrCreate(result); AccessPoint accessPoint = getCachedOrCreate(result, cachedAccessPoints); if (mLastInfo != null && mLastNetworkInfo != null) { if (mLastInfo != null && mLastNetworkInfo != null) { accessPoint.update(mLastInfo, mLastNetworkInfo); accessPoint.update(mLastInfo, mLastNetworkInfo); } } Loading @@ -296,24 +312,23 @@ public class WifiTracker { accessPoint.update(connectionConfig); accessPoint.update(connectionConfig); } } mAccessPoints.add(accessPoint); accessPoints.add(accessPoint); apMap.put(accessPoint.getSsid(), accessPoint); apMap.put(accessPoint.getSsid(), accessPoint); } } } } } } // Pre-sort accessPoints to speed preference insertion // Pre-sort accessPoints to speed preference insertion Collections.sort(mAccessPoints); Collections.sort(accessPoints); if (mListener != null) { mAccessPoints = accessPoints; mListener.onAccessPointsChanged(); mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED); } } } private AccessPoint getCachedOrCreate(ScanResult result) { private AccessPoint getCachedOrCreate(ScanResult result, ArrayList<AccessPoint> cache) { final int N = mCachedAccessPoints.size(); final int N = cache.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { if (mCachedAccessPoints.get(i).matches(result)) { if (cache.get(i).matches(result)) { AccessPoint ret = mCachedAccessPoints.remove(i); AccessPoint ret = cache.remove(i); ret.update(result); ret.update(result); return ret; return ret; } } Loading @@ -321,11 +336,11 @@ public class WifiTracker { return new AccessPoint(mContext, result); return new AccessPoint(mContext, result); } } private AccessPoint getCachedOrCreate(WifiConfiguration config) { private AccessPoint getCachedOrCreate(WifiConfiguration config, ArrayList<AccessPoint> cache) { final int N = mCachedAccessPoints.size(); final int N = cache.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { if (mCachedAccessPoints.get(i).matches(config)) { if (cache.get(i).matches(config)) { AccessPoint ret = mCachedAccessPoints.remove(i); AccessPoint ret = cache.remove(i); ret.loadConfig(config); ret.loadConfig(config); return ret; return ret; } } Loading Loading @@ -360,9 +375,7 @@ public class WifiTracker { } } if (reorder) { if (reorder) { Collections.sort(mAccessPoints); Collections.sort(mAccessPoints); if (mListener != null) { mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED); mListener.onAccessPointsChanged(); } } } } } Loading @@ -380,15 +393,13 @@ public class WifiTracker { mScanner.pause(); mScanner.pause(); } } } } if (mListener != null) { mMainHandler.obtainMessage(MainHandler.MSG_WIFI_STATE_CHANGED, state, 0).sendToTarget(); mListener.onWifiStateChanged(state); } } } public static List<AccessPoint> getCurrentAccessPoints(Context context, boolean includeSaved, public static List<AccessPoint> getCurrentAccessPoints(Context context, boolean includeSaved, boolean includeScans, boolean includePasspoints) { boolean includeScans, boolean includePasspoints) { WifiTracker tracker = new WifiTracker(context, WifiTracker tracker = new WifiTracker(context, null, includeSaved, includeScans, includePasspoints); null, null, includeSaved, includeScans, includePasspoints); tracker.forceUpdate(); tracker.forceUpdate(); return tracker.getAccessPoints(); return tracker.getAccessPoints(); } } Loading @@ -404,21 +415,67 @@ public class WifiTracker { } else if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action) || } else if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action) || WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION.equals(action) || WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION.equals(action) || WifiManager.LINK_CONFIGURATION_CHANGED_ACTION.equals(action)) { WifiManager.LINK_CONFIGURATION_CHANGED_ACTION.equals(action)) { updateAccessPoints(); mWorkHandler.sendEmptyMessage(WorkHandler.MSG_UPDATE_ACCESS_POINTS); } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { NetworkInfo info = (NetworkInfo) intent.getParcelableExtra( NetworkInfo info = (NetworkInfo) intent.getParcelableExtra( WifiManager.EXTRA_NETWORK_INFO); WifiManager.EXTRA_NETWORK_INFO); mConnected.set(info.isConnected()); mConnected.set(info.isConnected()); if (mListener != null) { mMainHandler.sendEmptyMessage(MainHandler.MSG_CONNECTED_CHANGED); mWorkHandler.sendEmptyMessage(WorkHandler.MSG_UPDATE_ACCESS_POINTS); mWorkHandler.obtainMessage(WorkHandler.MSG_UPDATE_NETWORK_INFO, info) .sendToTarget(); } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) { mWorkHandler.sendEmptyMessage(WorkHandler.MSG_UPDATE_NETWORK_INFO); } } }; private final class MainHandler extends Handler { private static final int MSG_CONNECTED_CHANGED = 0; private static final int MSG_WIFI_STATE_CHANGED = 1; private static final int MSG_ACCESS_POINT_CHANGED = 2; @Override public void handleMessage(Message msg) { if (mListener == null) { return; } switch (msg.what) { case MSG_CONNECTED_CHANGED: mListener.onConnectedChanged(); mListener.onConnectedChanged(); break; case MSG_WIFI_STATE_CHANGED: mListener.onWifiStateChanged(msg.arg1); break; case MSG_ACCESS_POINT_CHANGED: mListener.onAccessPointsChanged(); break; } } } } private final class WorkHandler extends Handler { private static final int MSG_UPDATE_ACCESS_POINTS = 0; private static final int MSG_UPDATE_NETWORK_INFO = 1; public WorkHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_UPDATE_ACCESS_POINTS: updateAccessPoints(); updateAccessPoints(); updateNetworkInfo(info); break; } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) { case MSG_UPDATE_NETWORK_INFO: updateNetworkInfo(null); updateNetworkInfo((NetworkInfo) msg.obj); break; } } } } } }; @VisibleForTesting @VisibleForTesting class Scanner extends Handler { class Scanner extends Handler { Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -756,7 +756,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, // noop // noop } } }); }); mNetworkController = new NetworkControllerImpl(mContext); mNetworkController = new NetworkControllerImpl(mContext, mHandlerThread.getLooper()); mHotspotController = new HotspotControllerImpl(mContext); mHotspotController = new HotspotControllerImpl(mContext); mBluetoothController = new BluetoothControllerImpl(mContext, mHandlerThread.getLooper()); mBluetoothController = new BluetoothControllerImpl(mContext, mHandlerThread.getLooper()); mSecurityController = new SecurityControllerImpl(mContext); mSecurityController = new SecurityControllerImpl(mContext); Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/AccessPointControllerImpl.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.ActivityManager; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.net.wifi.WifiManager.ActionListener; import android.net.wifi.WifiManager.ActionListener; import android.os.Looper; import android.os.UserHandle; import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; import android.provider.Settings; import android.provider.Settings; Loading Loading @@ -58,10 +59,10 @@ public class AccessPointControllerImpl private int mCurrentUser; private int mCurrentUser; public AccessPointControllerImpl(Context context) { public AccessPointControllerImpl(Context context, Looper bgLooper) { mContext = context; mContext = context; mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); mWifiTracker = new WifiTracker(context, this, false, true); mWifiTracker = new WifiTracker(context, this, bgLooper, false, true); mCurrentUser = ActivityManager.getCurrentUser(); mCurrentUser = ActivityManager.getCurrentUser(); } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java +4 −2 Original line number Original line Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.net.NetworkCapabilities; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager; import android.os.AsyncTask; import android.os.AsyncTask; import android.os.Bundle; import android.os.Bundle; import android.os.Looper; import android.provider.Settings; import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager; Loading Loading @@ -115,12 +116,13 @@ public class NetworkControllerImpl extends BroadcastReceiver /** /** * Construct this controller object and register for updates. * Construct this controller object and register for updates. */ */ public NetworkControllerImpl(Context context) { public NetworkControllerImpl(Context context, Looper bgLooper) { this(context, (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), this(context, (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE), (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE), (WifiManager) context.getSystemService(Context.WIFI_SERVICE), (WifiManager) context.getSystemService(Context.WIFI_SERVICE), SubscriptionManager.from(context), Config.readConfig(context), SubscriptionManager.from(context), Config.readConfig(context), new AccessPointControllerImpl(context), new MobileDataControllerImpl(context)); new AccessPointControllerImpl(context, bgLooper), new MobileDataControllerImpl(context)); registerListeners(); registerListeners(); } } Loading