add frequency band control API

Change-Id: I6cc6cdef27d493d4ef76cec17fdca7e49d9dc8d7
This commit is contained in:
Irfan Sheriff
2010-11-04 16:57:37 -07:00
parent 3a3f24e370
commit 36f7413dab
6 changed files with 167 additions and 8 deletions

View File

@ -60,6 +60,12 @@ interface IWifiManager
void setCountryCode(String country, boolean persist);
void setFrequencyBand(int band, boolean persist);
int getFrequencyBand();
boolean isDualBandSupported();
boolean saveConfiguration();
DhcpInfo getDhcpInfo();

View File

@ -372,7 +372,26 @@ public class WifiManager {
/** Anything better than or equal to this will show the max bars. */
private static final int MAX_RSSI = -55;
/**
* Auto settings in the driver. The driver could choose to operate on both
* 2.4 GHz and 5 GHz or make a dynamic decision on selecting the band.
* @hide
*/
public static final int WIFI_FREQUENCY_BAND_AUTO = 0;
/**
* Operation on 5 GHz alone
* @hide
*/
public static final int WIFI_FREQUENCY_BAND_5GHZ = 1;
/**
* Operation on 2.4 GHz alone
* @hide
*/
public static final int WIFI_FREQUENCY_BAND_2GHZ = 2;
IWifiManager mService;
Handler mHandler;
@ -684,6 +703,51 @@ public class WifiManager {
} catch (RemoteException e) { }
}
/**
* Set the operational frequency band.
* @param band One of
* {@link #WIFI_FREQUENCY_BAND_AUTO},
* {@link #WIFI_FREQUENCY_BAND_5GHZ},
* {@link #WIFI_FREQUENCY_BAND_2GHZ},
* @param persist {@code true} if this needs to be remembered
* @hide
*/
public void setFrequencyBand(int band, boolean persist) {
try {
mService.setFrequencyBand(band, persist);
} catch (RemoteException e) { }
}
/**
* Get the operational frequency band.
* @return One of
* {@link #WIFI_FREQUENCY_BAND_AUTO},
* {@link #WIFI_FREQUENCY_BAND_5GHZ},
* {@link #WIFI_FREQUENCY_BAND_2GHZ} or
* {@code -1} on failure.
* @hide
*/
public int getFrequencyBand() {
try {
return mService.getFrequencyBand();
} catch (RemoteException e) {
return -1;
}
}
/**
* Check if the chipset supports dual frequency band (2.4 GHz and 5 GHz)
* @return {@code true} if supported, {@code false} otherwise.
* @hide
*/
public boolean isDualBandSupported() {
try {
return mService.isDualBandSupported();
} catch (RemoteException e) {
return false;
}
}
/**
* Return the DHCP-assigned addresses from the last successful DHCP request,
* if any.

View File

@ -154,6 +154,8 @@ public class WifiStateMachine extends HierarchicalStateMachine {
private AlarmManager mAlarmManager;
private PendingIntent mScanIntent;
/* Tracks current frequency mode */
private AtomicInteger mFrequencyBand = new AtomicInteger(WifiManager.WIFI_FREQUENCY_BAND_AUTO);
// Channel for sending replies.
private AsyncChannel mReplyChannel = new AsyncChannel();
@ -315,6 +317,8 @@ 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;
/* Set the frequency band */
private static final int CMD_SET_FREQUENCY_BAND = 92;
/**
* Interval in milliseconds between polling for connection
@ -329,13 +333,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
private static final int SCAN_ACTIVE = 1;
private static final int SCAN_PASSIVE = 2;
/* Auto allows 802.11A/B/G operation */
private static final int BAND_AUTO = 0;
/* 5GHz allows 802.11A operation */
private static final int BAND_5G = 1;
/* 2.4GHz allows 802.11B/G operation */
private static final int BAND_2G = 2;
private static final int SUCCESS = 1;
private static final int FAILURE = -1;
@ -875,6 +872,27 @@ public class WifiStateMachine extends HierarchicalStateMachine {
sendMessage(obtainMessage(CMD_SET_COUNTRY_CODE, countryCode));
}
/**
* Set the operational frequency band
* @param band
* @param persist {@code true} if the setting should be remembered.
*/
public void setFrequencyBand(int band, boolean persist) {
if (persist) {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.WIFI_FREQUENCY_BAND,
band);
}
sendMessage(obtainMessage(CMD_SET_FREQUENCY_BAND, band, 0));
}
/**
* Returns the operational frequency band
*/
public int getFrequencyBand() {
return mFrequencyBand.get();
}
/**
* Set bluetooth coex mode:
*
@ -995,6 +1013,15 @@ public class WifiStateMachine extends HierarchicalStateMachine {
}
}
/**
* Set the frequency band from the system setting value, if any.
*/
private void setFrequencyBand() {
int band = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.WIFI_FREQUENCY_BAND, WifiManager.WIFI_FREQUENCY_BAND_AUTO);
setFrequencyBand(band, false);
}
private void setWifiState(int wifiState) {
final int previousWifiState = mWifiState.get();
@ -1582,6 +1609,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_COUNTRY_CODE:
case CMD_SET_FREQUENCY_BAND:
case CMD_REQUEST_CM_WAKELOCK:
case CMD_CONNECT_NETWORK:
case CMD_SAVE_NETWORK:
@ -1684,6 +1712,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_COUNTRY_CODE:
case CMD_SET_FREQUENCY_BAND:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
deferMessage(message);
@ -1812,6 +1841,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_COUNTRY_CODE:
case CMD_SET_FREQUENCY_BAND:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
deferMessage(message);
@ -1909,6 +1939,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_COUNTRY_CODE:
case CMD_SET_FREQUENCY_BAND:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
deferMessage(message);
@ -2053,6 +2084,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_COUNTRY_CODE:
case CMD_SET_FREQUENCY_BAND:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
case CMD_START_SCAN:
@ -2080,6 +2112,8 @@ public class WifiStateMachine extends HierarchicalStateMachine {
/* set country code */
setCountryCode();
/* set frequency band of operation */
setFrequencyBand();
if (mIsScanMode) {
WifiNative.setScanResultHandlingCommand(SCAN_ONLY_MODE);
@ -2118,6 +2152,15 @@ public class WifiStateMachine extends HierarchicalStateMachine {
Log.e(TAG, "Failed to set country code " + country);
}
break;
case CMD_SET_FREQUENCY_BAND:
int band = message.arg1;
Log.d(TAG, "set frequency band " + band);
if (WifiNative.setBandCommand(band)) {
mFrequencyBand.set(band);
} else {
Log.e(TAG, "Failed to set frequency band " + band);
}
break;
case CMD_STOP_DRIVER:
mWakeLock.acquire();
WifiNative.stopDriverCommand();
@ -2173,6 +2216,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SET_BLUETOOTH_COEXISTENCE:
case CMD_SET_BLUETOOTH_SCAN_MODE:
case CMD_SET_COUNTRY_CODE:
case CMD_SET_FREQUENCY_BAND:
case CMD_START_PACKET_FILTERING:
case CMD_STOP_PACKET_FILTERING:
case CMD_START_SCAN: