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

Commit d4f3958b authored by Irfan Sheriff's avatar Irfan Sheriff Committed by Android (Google) Code Review
Browse files

Merge "Make setNumAllowedChannels asynchronous"

parents e1bd78b4 d8f614c9
Loading
Loading
Loading
Loading
+32 −10
Original line number Diff line number Diff line
@@ -168,6 +168,7 @@ public class WifiService extends IWifiManager.Stub {
    private static final int MESSAGE_UPDATE_STATE       = 5;
    private static final int MESSAGE_START_ACCESS_POINT = 6;
    private static final int MESSAGE_STOP_ACCESS_POINT  = 7;
    private static final int MESSAGE_SET_CHANNELS       = 8;


    private final  WifiHandler mWifiHandler;
@@ -1542,6 +1543,7 @@ public class WifiService extends IWifiManager.Stub {
        Slog.i(TAG, "WifiService trying to setNumAllowed to "+numChannels+
                " with persist set to "+persist);
        enforceChangePermission();

        /*
         * Validate the argument. We'd like to let the Wi-Fi driver do this,
         * but if Wi-Fi isn't currently enabled, that's not possible, and
@@ -1559,13 +1561,28 @@ public class WifiService extends IWifiManager.Stub {
            return false;
        }

        if (mWifiHandler == null) return false;

        Message.obtain(mWifiHandler,
                MESSAGE_SET_CHANNELS, numChannels, (persist ? 1 : 0)).sendToTarget();

        return true;
    }

    /**
     * sets the number of allowed radio frequency channels synchronously
     * @param numChannels the number of allowed channels. Must be greater than 0
     * and less than or equal to 16.
     * @param persist {@code true} if the setting should be remembered.
     * @return {@code true} if the operation succeeds, {@code false} otherwise
     */
    private boolean setNumAllowedChannelsBlocking(int numChannels, boolean persist) {
        if (persist) {
            Settings.Secure.putInt(mContext.getContentResolver(),
                    Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS,
                    numChannels);
        }
        mWifiStateTracker.setNumAllowedChannels(numChannels);
        return true;
        return mWifiStateTracker.setNumAllowedChannels(numChannels);
    }

    /**
@@ -1904,6 +1921,11 @@ public class WifiService extends IWifiManager.Stub {
                                             (WifiConfiguration) msg.obj);
                    sWakeLock.release();
                    break;

                case MESSAGE_SET_CHANNELS:
                    setNumAllowedChannelsBlocking(msg.arg1, msg.arg2 == 1);
                    break;

            }
        }
    }