diff options
author | Irfan Sheriff <isheriff@google.com> | 2010-10-29 15:32:10 -0700 |
---|---|---|
committer | Irfan Sheriff <isheriff@google.com> | 2010-11-02 16:35:56 -0700 |
commit | ed4f28b492da3ff140bbaabbbda798a08c40ea5b (patch) | |
tree | 5676b10fe89f58e9c460e766532a24d2104fc62c /wifi/java/android | |
parent | 98444a944c9126898bc4c370f831a79bb3b30bd8 (diff) | |
download | frameworks_base-ed4f28b492da3ff140bbaabbbda798a08c40ea5b.zip frameworks_base-ed4f28b492da3ff140bbaabbbda798a08c40ea5b.tar.gz frameworks_base-ed4f28b492da3ff140bbaabbbda798a08c40ea5b.tar.bz2 |
Set country code in the driver and remove channel set
With dual band support, using country code
settings is the way to go
Bug: 2936741
Change-Id: I760dce4c43b1af19ee205c28f0d287420c8d9e85
Diffstat (limited to 'wifi/java/android')
-rw-r--r-- | wifi/java/android/net/wifi/IWifiManager.aidl | 6 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 52 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 6 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 88 |
4 files changed, 49 insertions, 103 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index 720f6ac..4bd5286 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -58,11 +58,7 @@ interface IWifiManager int getWifiEnabledState(); - int getNumAllowedChannels(); - - boolean setNumAllowedChannels(int numChannels, boolean persist); - - int[] getValidChannelCounts(); + void setCountryCode(String country, boolean persist); boolean saveConfiguration(); diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 356a0bd..c85a988 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -672,57 +672,19 @@ public class WifiManager { } /** - * Return the number of frequency channels that are allowed - * to be used in the current regulatory domain. - * @return the number of allowed channels, or {@code -1} if an error occurs + * Set the country code. + * @param countryCode country code in ISO 3166 format. + * @param persist {@code true} if this needs to be remembered * - * @hide pending API council - */ - public int getNumAllowedChannels() { - try { - return mService.getNumAllowedChannels(); - } catch (RemoteException e) { - return -1; - } - } - - /** - * Set the number of frequency channels that are allowed to be used - * in the current regulatory domain. This method should be used only - * if the correct number of channels cannot be determined automatically - * for some reason. - * @param numChannels the number of allowed channels. Must be greater than 0 - * and less than or equal to 16. - * @param persist {@code true} if you want this remembered - * @return {@code true} if the operation succeeds, {@code false} otherwise, e.g., - * {@code numChannels} is out of range. - * - * @hide pending API council + * @hide */ - public boolean setNumAllowedChannels(int numChannels, boolean persist) { + public void setCountryCode(String country, boolean persist) { try { - return mService.setNumAllowedChannels(numChannels, persist); - } catch (RemoteException e) { - return false; - } + mService.setCountryCode(country, persist); + } catch (RemoteException e) { } } /** - * Return the list of valid values for the number of allowed radio channels - * for various regulatory domains. - * @return the list of channel counts, or {@code null} if the operation fails - * - * @hide pending API council review - */ - public int[] getValidChannelCounts() { - try { - return mService.getValidChannelCounts(); - } catch (RemoteException e) { - return null; - } - } - - /** * Return the DHCP-assigned addresses from the last successful DHCP request, * if any. * @return the DHCP information diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index 3d8157c..06f945b 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -117,10 +117,6 @@ public class WifiNative { public native static int getPowerModeCommand(); - public native static boolean setNumAllowedChannelsCommand(int numChannels); - - public native static int getNumAllowedChannelsCommand(); - /** * Sets the bluetooth coexistence mode. * @@ -163,6 +159,8 @@ public class WifiNative { public native static boolean setSuspendOptimizationsCommand(boolean enabled); + public native static boolean setCountryCodeCommand(String countryCode); + /** * Wait for the supplicant to send an event, returning the event string. * @return the event string sent by the supplicant. diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 3531749..fdb50e2 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -111,7 +111,6 @@ public class WifiStateMachine extends HierarchicalStateMachine { private String mInterfaceName; - private int mNumAllowedChannels = 0; private int mLastSignalLevel = -1; private String mLastBssid; private int mLastNetworkId; @@ -271,8 +270,8 @@ public class WifiStateMachine extends HierarchicalStateMachine { * false(0) */ private static final int CMD_SET_BLUETOOTH_SCAN_MODE = 79; - /* Set number of allowed channels */ - private static final int CMD_SET_NUM_ALLOWED_CHANNELS = 80; + /* Set the country code */ + private static final int CMD_SET_COUNTRY_CODE = 80; /* Request connectivity manager wake lock before driver stop */ private static final int CMD_REQUEST_CM_WAKELOCK = 81; /* Enables RSSI poll */ @@ -308,6 +307,7 @@ public class WifiStateMachine extends HierarchicalStateMachine { private static final int CMD_START_WPS_PIN_FROM_AP = 90; /* Start Wi-Fi protected setup pin method configuration with pin obtained from device */ private static final int CMD_START_WPS_PIN_FROM_DEVICE = 91; + /** * Interval in milliseconds between polling for connection * status items that are not sent via asynchronous events. @@ -831,42 +831,17 @@ public class WifiStateMachine extends HierarchicalStateMachine { } /** - * Set the number of allowed radio frequency channels from the system - * setting value, if any. + * Set the country code + * @param countryCode following ISO 3166 format + * @param persist {@code true} if the setting should be remembered. */ - public void setNumAllowedChannels() { - try { - setNumAllowedChannels( - Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS)); - } catch (Settings.SettingNotFoundException e) { - if (mNumAllowedChannels != 0) { - setNumAllowedChannels(mNumAllowedChannels); - } - // otherwise, use the driver default + public void setCountryCode(String countryCode, boolean persist) { + if (persist) { + Settings.Secure.putString(mContext.getContentResolver(), + Settings.Secure.WIFI_COUNTRY_CODE, + countryCode); } - } - - /** - * Set the number of radio frequency channels that are allowed to be used - * in the current regulatory domain. - * @param numChannels the number of allowed channels. Must be greater than 0 - * and less than or equal to 16. - */ - public void setNumAllowedChannels(int numChannels) { - sendMessage(obtainMessage(CMD_SET_NUM_ALLOWED_CHANNELS, numChannels, 0)); - } - - /** - * Get number of allowed channels - * - * @return channel count, -1 on failure - * - * TODO: this is not a public API and needs to be removed in favor - * of asynchronous reporting. unused for now. - */ - public int getNumAllowedChannels() { - return -1; + sendMessage(obtainMessage(CMD_SET_COUNTRY_CODE, countryCode)); } /** @@ -957,7 +932,6 @@ public class WifiStateMachine extends HierarchicalStateMachine { sb.append("mWifiInfo ").append(mWifiInfo).append(LS); sb.append("mDhcpInfo ").append(mDhcpInfo).append(LS); sb.append("mNetworkInfo ").append(mNetworkInfo).append(LS); - sb.append("mNumAllowedChannels ").append(mNumAllowedChannels).append(LS); sb.append("mLastSignalLevel ").append(mLastSignalLevel).append(LS); sb.append("mLastBssid ").append(mLastBssid).append(LS); sb.append("mLastNetworkId ").append(mLastNetworkId).append(LS); @@ -977,6 +951,19 @@ public class WifiStateMachine extends HierarchicalStateMachine { * Internal private functions ********************************************************/ + /** + * Set the country code from the system setting value, if any. + */ + private void setCountryCode() { + String countryCode = Settings.Secure.getString(mContext.getContentResolver(), + Settings.Secure.WIFI_COUNTRY_CODE); + if (countryCode != null && !countryCode.isEmpty()) { + setCountryCode(countryCode, false); + } else { + //use driver default + } + } + private void setWifiState(int wifiState) { final int previousWifiState = mWifiState.get(); @@ -1563,7 +1550,7 @@ public class WifiStateMachine extends HierarchicalStateMachine { case CMD_SET_HIGH_PERF_MODE: case CMD_SET_BLUETOOTH_COEXISTENCE: case CMD_SET_BLUETOOTH_SCAN_MODE: - case CMD_SET_NUM_ALLOWED_CHANNELS: + case CMD_SET_COUNTRY_CODE: case CMD_REQUEST_CM_WAKELOCK: case CMD_CONNECT_NETWORK: case CMD_SAVE_NETWORK: @@ -1665,7 +1652,7 @@ public class WifiStateMachine extends HierarchicalStateMachine { case CMD_SET_HIGH_PERF_MODE: case CMD_SET_BLUETOOTH_COEXISTENCE: case CMD_SET_BLUETOOTH_SCAN_MODE: - case CMD_SET_NUM_ALLOWED_CHANNELS: + case CMD_SET_COUNTRY_CODE: case CMD_START_PACKET_FILTERING: case CMD_STOP_PACKET_FILTERING: deferMessage(message); @@ -1793,7 +1780,7 @@ public class WifiStateMachine extends HierarchicalStateMachine { case CMD_SET_HIGH_PERF_MODE: case CMD_SET_BLUETOOTH_COEXISTENCE: case CMD_SET_BLUETOOTH_SCAN_MODE: - case CMD_SET_NUM_ALLOWED_CHANNELS: + case CMD_SET_COUNTRY_CODE: case CMD_START_PACKET_FILTERING: case CMD_STOP_PACKET_FILTERING: deferMessage(message); @@ -1890,7 +1877,7 @@ public class WifiStateMachine extends HierarchicalStateMachine { case CMD_SET_HIGH_PERF_MODE: case CMD_SET_BLUETOOTH_COEXISTENCE: case CMD_SET_BLUETOOTH_SCAN_MODE: - case CMD_SET_NUM_ALLOWED_CHANNELS: + case CMD_SET_COUNTRY_CODE: case CMD_START_PACKET_FILTERING: case CMD_STOP_PACKET_FILTERING: deferMessage(message); @@ -2034,7 +2021,7 @@ public class WifiStateMachine extends HierarchicalStateMachine { case CMD_SET_HIGH_PERF_MODE: case CMD_SET_BLUETOOTH_COEXISTENCE: case CMD_SET_BLUETOOTH_SCAN_MODE: - case CMD_SET_NUM_ALLOWED_CHANNELS: + case CMD_SET_COUNTRY_CODE: case CMD_START_PACKET_FILTERING: case CMD_STOP_PACKET_FILTERING: case CMD_START_SCAN: @@ -2060,8 +2047,8 @@ public class WifiStateMachine extends HierarchicalStateMachine { mIsRunning = true; updateBatteryWorkSource(null); - /* Initialize channel count */ - setNumAllowedChannels(); + /* set country code */ + setCountryCode(); if (mIsScanMode) { WifiNative.setScanResultHandlingCommand(SCAN_ONLY_MODE); @@ -2093,9 +2080,12 @@ public class WifiStateMachine extends HierarchicalStateMachine { case CMD_SET_BLUETOOTH_SCAN_MODE: WifiNative.setBluetoothCoexistenceScanModeCommand(message.arg1 == 1); break; - case CMD_SET_NUM_ALLOWED_CHANNELS: - mNumAllowedChannels = message.arg1; - WifiNative.setNumAllowedChannelsCommand(message.arg1); + case CMD_SET_COUNTRY_CODE: + String country = (String) message.obj; + Log.d(TAG, "set country code " + country); + if (!WifiNative.setCountryCodeCommand(country.toUpperCase())) { + Log.e(TAG, "Failed to set country code " + country); + } break; case CMD_STOP_DRIVER: mWakeLock.acquire(); @@ -2151,7 +2141,7 @@ public class WifiStateMachine extends HierarchicalStateMachine { case CMD_SET_HIGH_PERF_MODE: case CMD_SET_BLUETOOTH_COEXISTENCE: case CMD_SET_BLUETOOTH_SCAN_MODE: - case CMD_SET_NUM_ALLOWED_CHANNELS: + case CMD_SET_COUNTRY_CODE: case CMD_START_PACKET_FILTERING: case CMD_STOP_PACKET_FILTERING: case CMD_START_SCAN: |