Merge "QS: Bring back BT/Wi-Fi sub-panels" into lmp-mr1-dev automerge: 8c01dfc
automerge: caed5a2
* commit 'caed5a29760ac1a32a0248e518b71d2d6df3d33e':
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.setId(android.R.id.title);
|
||||
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.setPadding(0, mDualTileVerticalPaddingPx, 0, mDualTileVerticalPaddingPx);
|
||||
mDualLabel.setTypeface(CONDENSED);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class BluetoothTile extends QSTile<QSTile.BooleanState> {
|
||||
|
||||
@Override
|
||||
protected void handleSecondaryClick() {
|
||||
mHost.startSettingsActivity(BLUETOOTH_SETTINGS);
|
||||
showDetail(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -87,7 +87,15 @@ public class WifiTile extends QSTile<QSTile.SignalState> {
|
||||
|
||||
@Override
|
||||
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
|
||||
@@ -279,7 +287,9 @@ public class WifiTile extends QSTile<QSTile.SignalState> {
|
||||
if (item == null || item.tag == null) return;
|
||||
final AccessPoint ap = (AccessPoint) item.tag;
|
||||
if (!ap.isConnected) {
|
||||
mController.connect(ap);
|
||||
if (mController.connect(ap)) {
|
||||
mHost.collapsePanels();
|
||||
}
|
||||
}
|
||||
showDetail(false);
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ public class QSTileHost implements QSTile.Host {
|
||||
tile.userSwitch(newUserId);
|
||||
}
|
||||
mSecurity.onUserSwitched(newUserId);
|
||||
mNetwork.onUserSwitched(newUserId);
|
||||
mObserver.register();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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");
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int reason) {
|
||||
if (DEBUG) Log.d(TAG, "connect failure reason=" + reason);
|
||||
}
|
||||
});
|
||||
} 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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user