diff options
author | Jason Monk <jmonk@google.com> | 2014-10-27 11:38:47 -0400 |
---|---|---|
committer | Jason Monk <jmonk@google.com> | 2014-10-28 13:43:04 -0400 |
commit | 5d325074b14e102a90c211a8d7b65316158ac0e4 (patch) | |
tree | 126520264c71c8173136f11597893080ae2a3972 /packages/SystemUI/src/com/android/systemui/statusbar | |
parent | 685720309a582acc513454d674f82368479c5297 (diff) | |
download | frameworks_base-5d325074b14e102a90c211a8d7b65316158ac0e4.zip frameworks_base-5d325074b14e102a90c211a8d7b65316158ac0e4.tar.gz frameworks_base-5d325074b14e102a90c211a8d7b65316158ac0e4.tar.bz2 |
QS: Bring back BT/Wi-Fi sub-panels
Bluetooth has stayed pretty much the same, just came back.
Wi-Fi now shows the currently available networks like settings does.
Networks that require extra steps are taken to Settings to complete
the process.
Bug: 17722817
Change-Id: Idfcfd92f557b20168693ced26d4001f3708f08a4
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/statusbar')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java | 1 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/AccessPointController.java (renamed from packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiAccessPointController.java) | 84 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java | 6 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java | 18 |
4 files changed, 86 insertions, 23 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java index 2dc08d4..a4db46a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java @@ -120,6 +120,7 @@ public class QSTileHost implements QSTile.Host { tile.userSwitch(newUserId); } mSecurity.onUserSwitched(newUserId); + mNetwork.onUserSwitched(newUserId); mObserver.register(); } }; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiAccessPointController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AccessPointController.java index b800fbf..0a385d7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiAccessPointController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AccessPointController.java @@ -16,15 +16,20 @@ package com.android.systemui.statusbar.policy; +import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.ActionListener; +import android.os.UserHandle; +import android.os.UserManager; +import android.provider.Settings; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; @@ -39,9 +44,13 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -public class WifiAccessPointController { - private static final String TAG = "WifiAccessPointController"; - private static final boolean DEBUG = false; +public class AccessPointController { + private static final String TAG = "AccessPointController"; + private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); + + // This string extra specifies a network to open the connect dialog on, so the user can enter + // network credentials. This is used by quick settings for secured networks. + private static final String EXTRA_START_CONNECT_SSID = "wifi_start_connect_ssid"; private static final int[] ICONS = { R.drawable.ic_qs_wifi_0, @@ -54,13 +63,26 @@ public class WifiAccessPointController { private final Context mContext; private final ArrayList<AccessPointCallback> mCallbacks = new ArrayList<AccessPointCallback>(); private final WifiManager mWifiManager; + private final UserManager mUserManager; private final Receiver mReceiver = new Receiver(); private boolean mScanning; + private int mCurrentUser; - public WifiAccessPointController(Context context) { + public AccessPointController(Context context) { mContext = context; mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); + mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); + mCurrentUser = ActivityManager.getCurrentUser(); + } + + public boolean canConfigWifi() { + return !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, + new UserHandle(mCurrentUser)); + } + + void onUserSwitched(int newUserId) { + mCurrentUser = newUserId; } public void addCallback(AccessPointCallback callback) { @@ -81,22 +103,31 @@ public class WifiAccessPointController { if (mScanning) return; if (DEBUG) Log.d(TAG, "scan!"); mScanning = mWifiManager.startScan(); + // Grab current networks immediately while we wait for scan. + updateAccessPoints(); } - public void connect(AccessPoint ap) { - if (ap == null || ap.networkId < 0) return; + public boolean connect(AccessPoint ap) { + if (ap == null) return false; if (DEBUG) Log.d(TAG, "connect networkId=" + ap.networkId); - mWifiManager.connect(ap.networkId, new ActionListener() { - @Override - public void onSuccess() { - if (DEBUG) Log.d(TAG, "connect success"); - } - - @Override - public void onFailure(int reason) { - if (DEBUG) Log.d(TAG, "connect failure reason=" + reason); + if (ap.networkId < 0) { + // Unknown network, need to add it. + if (ap.hasSecurity) { + Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); + intent.putExtra(EXTRA_START_CONNECT_SSID, ap.ssid); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); + return true; + } else { + WifiConfiguration config = new WifiConfiguration(); + config.SSID = "\"" + ap.ssid + "\""; + config.allowedKeyManagement.set(KeyMgmt.NONE); + mWifiManager.connect(config, mConnectListener); } - }); + } else { + mWifiManager.connect(ap.networkId, mConnectListener); + } + return false; } private void fireCallback(AccessPoint[] aps) { @@ -139,23 +170,40 @@ public class WifiAccessPointController { } final String ssid = scanResult.SSID; if (TextUtils.isEmpty(ssid) || ssids.contains(ssid)) continue; - if (!configured.containsKey(ssid)) continue; ssids.add(ssid); final WifiConfiguration config = configured.get(ssid); final int level = WifiManager.calculateSignalLevel(scanResult.level, ICONS.length); final AccessPoint ap = new AccessPoint(); + ap.isConfigured = config != null; ap.networkId = config != null ? config.networkId : AccessPoint.NO_NETWORK; ap.ssid = ssid; ap.iconId = ICONS[level]; ap.isConnected = ap.networkId != AccessPoint.NO_NETWORK && ap.networkId == connectedNetworkId; ap.level = level; + // Based on Settings AccessPoint#getSecurity, keep up to date + // with better methods of determining no security or not. + ap.hasSecurity = scanResult.capabilities.contains("WEP") + || scanResult.capabilities.contains("PSK") + || scanResult.capabilities.contains("EAP"); aps.add(ap); } Collections.sort(aps, mByStrength); fireCallback(aps.toArray(new AccessPoint[aps.size()])); } + private final ActionListener mConnectListener = new ActionListener() { + @Override + public void onSuccess() { + if (DEBUG) Log.d(TAG, "connect success"); + } + + @Override + public void onFailure(int reason) { + if (DEBUG) Log.d(TAG, "connect failure reason=" + reason); + } + }; + private final Comparator<AccessPoint> mByStrength = new Comparator<AccessPoint> () { @Override public int compare(AccessPoint lhs, AccessPoint rhs) { @@ -163,7 +211,7 @@ public class WifiAccessPointController { } private int score(AccessPoint ap) { - return ap.level + (ap.isConnected ? 10 : 0); + return ap.level + (ap.isConnected ? 20 : 0) + (ap.isConfigured ? 10 : 0); } }; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java index 2ed9366..bb29d01 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java @@ -39,11 +39,13 @@ public interface NetworkController { void addAccessPointCallback(AccessPointCallback callback); void removeAccessPointCallback(AccessPointCallback callback); void scanForAccessPoints(); - void connect(AccessPoint ap); + boolean connect(AccessPoint ap); boolean isMobileDataSupported(); boolean isMobileDataEnabled(); void setMobileDataEnabled(boolean enabled); DataUsageInfo getDataUsageInfo(); + boolean canConfigWifi(); + void onUserSwitched(int newUserId); public interface AccessPointCallback { void onAccessPointsChanged(AccessPoint[] accessPoints); @@ -56,6 +58,8 @@ public interface NetworkController { public int iconId; public String ssid; public boolean isConnected; + public boolean isConfigured; + public boolean hasSecurity; public int level; // 0 - 5 } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java index b2198f6..6c0b425 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java @@ -168,7 +168,7 @@ public class NetworkControllerImpl extends BroadcastReceiver void setIsAirplaneMode(boolean is, int airplaneIcon); } - private final WifiAccessPointController mAccessPoints; + private final AccessPointController mAccessPoints; private final MobileDataController mMobileDataController; /** @@ -239,7 +239,7 @@ public class NetworkControllerImpl extends BroadcastReceiver updateAirplaneMode(); mLastLocale = mContext.getResources().getConfiguration().locale; - mAccessPoints = new WifiAccessPointController(mContext); + mAccessPoints = new AccessPointController(mContext); mMobileDataController = new MobileDataController(mContext); mMobileDataController.setCallback(new MobileDataController.Callback() { @Override @@ -249,6 +249,16 @@ public class NetworkControllerImpl extends BroadcastReceiver }); } + @Override + public boolean canConfigWifi() { + return mAccessPoints.canConfigWifi(); + } + + @Override + public void onUserSwitched(int newUserId) { + mAccessPoints.onUserSwitched(newUserId); + } + private void notifyMobileDataEnabled(boolean enabled) { for (NetworkSignalChangedCallback cb : mSignalsChangedCallbacks) { cb.onMobileDataEnabled(enabled); @@ -313,8 +323,8 @@ public class NetworkControllerImpl extends BroadcastReceiver } @Override - public void connect(AccessPoint ap) { - mAccessPoints.connect(ap); + public boolean connect(AccessPoint ap) { + return mAccessPoints.connect(ap); } @Override |