Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10652a95 authored by Vinit Deshapnde's avatar Vinit Deshapnde
Browse files

Fix invalid Wifi Network system crash

There is some validation code that is eventually detecting that we
have an invalid network; only the result is a crash. The right thing
to do is to do validation up front; and fail calls if the network
configuration looks invalid.

Bug: 10571289

Change-Id: I100506b777a34b26ac9a310ba508140560f87a90
parent 2def6148
Loading
Loading
Loading
Loading
+43 −6
Original line number Diff line number Diff line
@@ -170,7 +170,20 @@ public final class WifiService extends IWifiManager.Stub {
                }
                /* Client commands are forwarded to state machine */
                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.START_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;

@@ -547,7 +571,11 @@ public final class WifiService extends IWifiManager.Stub {
     */
    public void setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {
        enforceChangePermission();
        if (wifiConfig.isValid()) {
            mWifiController.obtainMessage(CMD_SET_AP, enabled ? 1 : 0, 0, wifiConfig).sendToTarget();
        } else {
            Slog.e(TAG, "Invalid WifiConfiguration");
        }
    }

    /**
@@ -580,7 +608,11 @@ public final class WifiService extends IWifiManager.Stub {
        enforceChangePermission();
        if (wifiConfig == null)
            return;
        if (wifiConfig.isValid()) {
            mWifiStateMachine.setWifiApConfiguration(wifiConfig);
        } else {
            Slog.e(TAG, "Invalid WifiConfiguration");
        }
    }

    /**
@@ -638,12 +670,17 @@ public final class WifiService extends IWifiManager.Stub {
     */
    public int addOrUpdateNetwork(WifiConfiguration config) {
        enforceChangePermission();
        if (config.isValid()) {
            if (mWifiStateMachineChannel != null) {
                return mWifiStateMachine.syncAddOrUpdateNetwork(mWifiStateMachineChannel, config);
            } else {
                Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
                return -1;
            }
        } else {
            Slog.e(TAG, "bad network configuration");
            return -1;
        }
    }

     /**
+14 −0
Original line number Diff line number Diff line
@@ -348,6 +348,20 @@ public class WifiConfiguration implements Parcelable {
        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
    public String toString() {
        StringBuilder sbuf = new StringBuilder();
+7 −0
Original line number Diff line number Diff line
@@ -1366,6 +1366,13 @@ public class WifiManager {
    /** WPS timed out {@hide} */
    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} */
    public interface ActionListener {
        /** The operation succeeded */