Merge "QS: Bring back BT/Wi-Fi sub-panels" into lmp-mr1-dev
automerge: 8c01dfc
* commit '8c01dfc5af599398c1c79f87619c302e000e3353':
QS: Bring back BT/Wi-Fi sub-panels
This commit is contained in:
@@ -132,6 +132,7 @@ public class QSTileView extends ViewGroup {
|
|||||||
mDualLabel = new QSDualTileLabel(mContext);
|
mDualLabel = new QSDualTileLabel(mContext);
|
||||||
mDualLabel.setId(android.R.id.title);
|
mDualLabel.setId(android.R.id.title);
|
||||||
mDualLabel.setBackgroundResource(R.drawable.btn_borderless_rect);
|
mDualLabel.setBackgroundResource(R.drawable.btn_borderless_rect);
|
||||||
|
mDualLabel.setFirstLineCaret(res.getDrawable(R.drawable.qs_dual_tile_caret));
|
||||||
mDualLabel.setTextColor(res.getColor(R.color.qs_tile_text));
|
mDualLabel.setTextColor(res.getColor(R.color.qs_tile_text));
|
||||||
mDualLabel.setPadding(0, mDualTileVerticalPaddingPx, 0, mDualTileVerticalPaddingPx);
|
mDualLabel.setPadding(0, mDualTileVerticalPaddingPx, 0, mDualTileVerticalPaddingPx);
|
||||||
mDualLabel.setTypeface(CONDENSED);
|
mDualLabel.setTypeface(CONDENSED);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class BluetoothTile extends QSTile<QSTile.BooleanState> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleSecondaryClick() {
|
protected void handleSecondaryClick() {
|
||||||
mHost.startSettingsActivity(BLUETOOTH_SETTINGS);
|
showDetail(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -87,7 +87,15 @@ public class WifiTile extends QSTile<QSTile.SignalState> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleSecondaryClick() {
|
protected void handleSecondaryClick() {
|
||||||
mHost.startSettingsActivity(WIFI_SETTINGS);
|
if (!mController.canConfigWifi()) {
|
||||||
|
mHost.startSettingsActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!mState.enabled) {
|
||||||
|
mController.setWifiEnabled(true);
|
||||||
|
mState.enabled = true;
|
||||||
|
}
|
||||||
|
showDetail(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -279,7 +287,9 @@ public class WifiTile extends QSTile<QSTile.SignalState> {
|
|||||||
if (item == null || item.tag == null) return;
|
if (item == null || item.tag == null) return;
|
||||||
final AccessPoint ap = (AccessPoint) item.tag;
|
final AccessPoint ap = (AccessPoint) item.tag;
|
||||||
if (!ap.isConnected) {
|
if (!ap.isConnected) {
|
||||||
mController.connect(ap);
|
if (mController.connect(ap)) {
|
||||||
|
mHost.collapsePanels();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
showDetail(false);
|
showDetail(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ public class QSTileHost implements QSTile.Host {
|
|||||||
tile.userSwitch(newUserId);
|
tile.userSwitch(newUserId);
|
||||||
}
|
}
|
||||||
mSecurity.onUserSwitched(newUserId);
|
mSecurity.onUserSwitched(newUserId);
|
||||||
|
mNetwork.onUserSwitched(newUserId);
|
||||||
mObserver.register();
|
mObserver.register();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,15 +16,20 @@
|
|||||||
|
|
||||||
package com.android.systemui.statusbar.policy;
|
package com.android.systemui.statusbar.policy;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.wifi.ScanResult;
|
import android.net.wifi.ScanResult;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
|
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.net.wifi.WifiManager.ActionListener;
|
import android.net.wifi.WifiManager.ActionListener;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
@@ -39,9 +44,13 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class WifiAccessPointController {
|
public class AccessPointController {
|
||||||
private static final String TAG = "WifiAccessPointController";
|
private static final String TAG = "AccessPointController";
|
||||||
private static final boolean DEBUG = false;
|
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 = {
|
private static final int[] ICONS = {
|
||||||
R.drawable.ic_qs_wifi_0,
|
R.drawable.ic_qs_wifi_0,
|
||||||
@@ -54,13 +63,26 @@ public class WifiAccessPointController {
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ArrayList<AccessPointCallback> mCallbacks = new ArrayList<AccessPointCallback>();
|
private final ArrayList<AccessPointCallback> mCallbacks = new ArrayList<AccessPointCallback>();
|
||||||
private final WifiManager mWifiManager;
|
private final WifiManager mWifiManager;
|
||||||
|
private final UserManager mUserManager;
|
||||||
private final Receiver mReceiver = new Receiver();
|
private final Receiver mReceiver = new Receiver();
|
||||||
|
|
||||||
private boolean mScanning;
|
private boolean mScanning;
|
||||||
|
private int mCurrentUser;
|
||||||
|
|
||||||
public WifiAccessPointController(Context context) {
|
public AccessPointController(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
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) {
|
public void addCallback(AccessPointCallback callback) {
|
||||||
@@ -81,22 +103,31 @@ public class WifiAccessPointController {
|
|||||||
if (mScanning) return;
|
if (mScanning) return;
|
||||||
if (DEBUG) Log.d(TAG, "scan!");
|
if (DEBUG) Log.d(TAG, "scan!");
|
||||||
mScanning = mWifiManager.startScan();
|
mScanning = mWifiManager.startScan();
|
||||||
|
// Grab current networks immediately while we wait for scan.
|
||||||
|
updateAccessPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect(AccessPoint ap) {
|
public boolean connect(AccessPoint ap) {
|
||||||
if (ap == null || ap.networkId < 0) return;
|
if (ap == null) return false;
|
||||||
if (DEBUG) Log.d(TAG, "connect networkId=" + ap.networkId);
|
if (DEBUG) Log.d(TAG, "connect networkId=" + ap.networkId);
|
||||||
mWifiManager.connect(ap.networkId, new ActionListener() {
|
if (ap.networkId < 0) {
|
||||||
@Override
|
// Unknown network, need to add it.
|
||||||
public void onSuccess() {
|
if (ap.hasSecurity) {
|
||||||
if (DEBUG) Log.d(TAG, "connect success");
|
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 {
|
||||||
@Override
|
mWifiManager.connect(ap.networkId, mConnectListener);
|
||||||
public void onFailure(int reason) {
|
}
|
||||||
if (DEBUG) Log.d(TAG, "connect failure reason=" + reason);
|
return false;
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireCallback(AccessPoint[] aps) {
|
private void fireCallback(AccessPoint[] aps) {
|
||||||
@@ -139,23 +170,40 @@ public class WifiAccessPointController {
|
|||||||
}
|
}
|
||||||
final String ssid = scanResult.SSID;
|
final String ssid = scanResult.SSID;
|
||||||
if (TextUtils.isEmpty(ssid) || ssids.contains(ssid)) continue;
|
if (TextUtils.isEmpty(ssid) || ssids.contains(ssid)) continue;
|
||||||
if (!configured.containsKey(ssid)) continue;
|
|
||||||
ssids.add(ssid);
|
ssids.add(ssid);
|
||||||
final WifiConfiguration config = configured.get(ssid);
|
final WifiConfiguration config = configured.get(ssid);
|
||||||
final int level = WifiManager.calculateSignalLevel(scanResult.level, ICONS.length);
|
final int level = WifiManager.calculateSignalLevel(scanResult.level, ICONS.length);
|
||||||
final AccessPoint ap = new AccessPoint();
|
final AccessPoint ap = new AccessPoint();
|
||||||
|
ap.isConfigured = config != null;
|
||||||
ap.networkId = config != null ? config.networkId : AccessPoint.NO_NETWORK;
|
ap.networkId = config != null ? config.networkId : AccessPoint.NO_NETWORK;
|
||||||
ap.ssid = ssid;
|
ap.ssid = ssid;
|
||||||
ap.iconId = ICONS[level];
|
ap.iconId = ICONS[level];
|
||||||
ap.isConnected = ap.networkId != AccessPoint.NO_NETWORK
|
ap.isConnected = ap.networkId != AccessPoint.NO_NETWORK
|
||||||
&& ap.networkId == connectedNetworkId;
|
&& ap.networkId == connectedNetworkId;
|
||||||
ap.level = level;
|
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);
|
aps.add(ap);
|
||||||
}
|
}
|
||||||
Collections.sort(aps, mByStrength);
|
Collections.sort(aps, mByStrength);
|
||||||
fireCallback(aps.toArray(new AccessPoint[aps.size()]));
|
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> () {
|
private final Comparator<AccessPoint> mByStrength = new Comparator<AccessPoint> () {
|
||||||
@Override
|
@Override
|
||||||
public int compare(AccessPoint lhs, AccessPoint rhs) {
|
public int compare(AccessPoint lhs, AccessPoint rhs) {
|
||||||
@@ -163,7 +211,7 @@ public class WifiAccessPointController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int score(AccessPoint ap) {
|
private int score(AccessPoint ap) {
|
||||||
return ap.level + (ap.isConnected ? 10 : 0);
|
return ap.level + (ap.isConnected ? 20 : 0) + (ap.isConfigured ? 10 : 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -39,11 +39,13 @@ public interface NetworkController {
|
|||||||
void addAccessPointCallback(AccessPointCallback callback);
|
void addAccessPointCallback(AccessPointCallback callback);
|
||||||
void removeAccessPointCallback(AccessPointCallback callback);
|
void removeAccessPointCallback(AccessPointCallback callback);
|
||||||
void scanForAccessPoints();
|
void scanForAccessPoints();
|
||||||
void connect(AccessPoint ap);
|
boolean connect(AccessPoint ap);
|
||||||
boolean isMobileDataSupported();
|
boolean isMobileDataSupported();
|
||||||
boolean isMobileDataEnabled();
|
boolean isMobileDataEnabled();
|
||||||
void setMobileDataEnabled(boolean enabled);
|
void setMobileDataEnabled(boolean enabled);
|
||||||
DataUsageInfo getDataUsageInfo();
|
DataUsageInfo getDataUsageInfo();
|
||||||
|
boolean canConfigWifi();
|
||||||
|
void onUserSwitched(int newUserId);
|
||||||
|
|
||||||
public interface AccessPointCallback {
|
public interface AccessPointCallback {
|
||||||
void onAccessPointsChanged(AccessPoint[] accessPoints);
|
void onAccessPointsChanged(AccessPoint[] accessPoints);
|
||||||
@@ -56,6 +58,8 @@ public interface NetworkController {
|
|||||||
public int iconId;
|
public int iconId;
|
||||||
public String ssid;
|
public String ssid;
|
||||||
public boolean isConnected;
|
public boolean isConnected;
|
||||||
|
public boolean isConfigured;
|
||||||
|
public boolean hasSecurity;
|
||||||
public int level; // 0 - 5
|
public int level; // 0 - 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
void setIsAirplaneMode(boolean is, int airplaneIcon);
|
void setIsAirplaneMode(boolean is, int airplaneIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final WifiAccessPointController mAccessPoints;
|
private final AccessPointController mAccessPoints;
|
||||||
private final MobileDataController mMobileDataController;
|
private final MobileDataController mMobileDataController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -239,7 +239,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
updateAirplaneMode();
|
updateAirplaneMode();
|
||||||
|
|
||||||
mLastLocale = mContext.getResources().getConfiguration().locale;
|
mLastLocale = mContext.getResources().getConfiguration().locale;
|
||||||
mAccessPoints = new WifiAccessPointController(mContext);
|
mAccessPoints = new AccessPointController(mContext);
|
||||||
mMobileDataController = new MobileDataController(mContext);
|
mMobileDataController = new MobileDataController(mContext);
|
||||||
mMobileDataController.setCallback(new MobileDataController.Callback() {
|
mMobileDataController.setCallback(new MobileDataController.Callback() {
|
||||||
@Override
|
@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) {
|
private void notifyMobileDataEnabled(boolean enabled) {
|
||||||
for (NetworkSignalChangedCallback cb : mSignalsChangedCallbacks) {
|
for (NetworkSignalChangedCallback cb : mSignalsChangedCallbacks) {
|
||||||
cb.onMobileDataEnabled(enabled);
|
cb.onMobileDataEnabled(enabled);
|
||||||
@@ -313,8 +323,8 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(AccessPoint ap) {
|
public boolean connect(AccessPoint ap) {
|
||||||
mAccessPoints.connect(ap);
|
return mAccessPoints.connect(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user