Merge "Fix invalid Wifi Network system crash" into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b481dae2f5
@@ -170,7 +170,20 @@ public final class WifiService extends IWifiManager.Stub {
|
|||||||
}
|
}
|
||||||
/* Client commands are forwarded to state machine */
|
/* Client commands are forwarded to state machine */
|
||||||
case WifiManager.CONNECT_NETWORK:
|
case WifiManager.CONNECT_NETWORK:
|
||||||
case WifiManager.SAVE_NETWORK:
|
case WifiManager.SAVE_NETWORK: {
|
||||||
|
WifiConfiguration config = (WifiConfiguration) msg.obj;
|
||||||
|
if (config.isValid()) {
|
||||||
|
mWifiStateMachine.sendMessage(Message.obtain(msg));
|
||||||
|
} else {
|
||||||
|
Slog.d(TAG, "ClientHandler.handleMessage ignoring msg=" + msg);
|
||||||
|
if (msg.what == WifiManager.CONNECT_NETWORK) {
|
||||||
|
replyFailed(msg, WifiManager.CONNECT_NETWORK_FAILED);
|
||||||
|
} else {
|
||||||
|
replyFailed(msg, WifiManager.SAVE_NETWORK_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case WifiManager.FORGET_NETWORK:
|
case WifiManager.FORGET_NETWORK:
|
||||||
case WifiManager.START_WPS:
|
case WifiManager.START_WPS:
|
||||||
case WifiManager.CANCEL_WPS:
|
case WifiManager.CANCEL_WPS:
|
||||||
@@ -185,6 +198,17 @@ public final class WifiService extends IWifiManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void replyFailed(Message msg, int what) {
|
||||||
|
Message reply = msg.obtain();
|
||||||
|
reply.what = what;
|
||||||
|
reply.arg1 = WifiManager.INVALID_ARGS;
|
||||||
|
try {
|
||||||
|
msg.replyTo.send(reply);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// There's not much we can do if reply can't be sent!
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private ClientHandler mClientHandler;
|
private ClientHandler mClientHandler;
|
||||||
|
|
||||||
@@ -555,7 +579,11 @@ public final class WifiService extends IWifiManager.Stub {
|
|||||||
*/
|
*/
|
||||||
public void setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {
|
public void setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {
|
||||||
enforceChangePermission();
|
enforceChangePermission();
|
||||||
mWifiController.obtainMessage(CMD_SET_AP, enabled ? 1 : 0, 0, wifiConfig).sendToTarget();
|
if (wifiConfig.isValid()) {
|
||||||
|
mWifiController.obtainMessage(CMD_SET_AP, enabled ? 1 : 0, 0, wifiConfig).sendToTarget();
|
||||||
|
} else {
|
||||||
|
Slog.e(TAG, "Invalid WifiConfiguration");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -588,7 +616,11 @@ public final class WifiService extends IWifiManager.Stub {
|
|||||||
enforceChangePermission();
|
enforceChangePermission();
|
||||||
if (wifiConfig == null)
|
if (wifiConfig == null)
|
||||||
return;
|
return;
|
||||||
mWifiStateMachine.setWifiApConfiguration(wifiConfig);
|
if (wifiConfig.isValid()) {
|
||||||
|
mWifiStateMachine.setWifiApConfiguration(wifiConfig);
|
||||||
|
} else {
|
||||||
|
Slog.e(TAG, "Invalid WifiConfiguration");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -646,10 +678,15 @@ public final class WifiService extends IWifiManager.Stub {
|
|||||||
*/
|
*/
|
||||||
public int addOrUpdateNetwork(WifiConfiguration config) {
|
public int addOrUpdateNetwork(WifiConfiguration config) {
|
||||||
enforceChangePermission();
|
enforceChangePermission();
|
||||||
if (mWifiStateMachineChannel != null) {
|
if (config.isValid()) {
|
||||||
return mWifiStateMachine.syncAddOrUpdateNetwork(mWifiStateMachineChannel, config);
|
if (mWifiStateMachineChannel != null) {
|
||||||
|
return mWifiStateMachine.syncAddOrUpdateNetwork(mWifiStateMachineChannel, config);
|
||||||
|
} else {
|
||||||
|
Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
|
Slog.e(TAG, "bad network configuration");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -348,6 +348,20 @@ public class WifiConfiguration implements Parcelable {
|
|||||||
linkProperties = new LinkProperties();
|
linkProperties = new LinkProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* indicates whether the configuration is valid
|
||||||
|
* @return true if valid, false otherwise
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public boolean isValid() {
|
||||||
|
if (allowedKeyManagement.cardinality() > 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Add more checks
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sbuf = new StringBuilder();
|
StringBuilder sbuf = new StringBuilder();
|
||||||
|
|||||||
@@ -1370,6 +1370,13 @@ public class WifiManager {
|
|||||||
/** WPS timed out {@hide} */
|
/** WPS timed out {@hide} */
|
||||||
public static final int WPS_TIMED_OUT = 7;
|
public static final int WPS_TIMED_OUT = 7;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Passed with {@link ActionListener#onFailure}.
|
||||||
|
* Indicates that the operation failed due to invalid inputs
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int INVALID_ARGS = 8;
|
||||||
|
|
||||||
/** Interface for callback invocation on an application action {@hide} */
|
/** Interface for callback invocation on an application action {@hide} */
|
||||||
public interface ActionListener {
|
public interface ActionListener {
|
||||||
/** The operation succeeded */
|
/** The operation succeeded */
|
||||||
|
|||||||
Reference in New Issue
Block a user