Use new wifi cmd rssi-approx when polling.

Cheaper approx call should be used when polling every 3 sec for
wifi signal strength.  Fixes bug 1903653.
This commit is contained in:
Robert Greenwalt
2009-06-08 18:15:21 -07:00
parent 5519185292
commit 91f22f901b
3 changed files with 22 additions and 6 deletions

View File

@@ -307,14 +307,15 @@ static jboolean android_net_wifi_stopPacketFiltering(JNIEnv* env, jobject clazz)
return result;
}
static jint android_net_wifi_getRssiCommand(JNIEnv* env, jobject clazz)
static jint android_net_wifi_getRssiHelper(const char *cmd)
{
char reply[256];
int rssi = -200;
if (doCommand("DRIVER RSSI", reply, sizeof(reply)) != 0) {
if (doCommand(cmd, reply, sizeof(reply)) != 0) {
return (jint)-1;
}
// reply comes back in the form "<SSID> rssi XX" where XX is the
// number we're interested in. if we're associating, it returns "OK".
// beware - <SSID> can contain spaces.
@@ -328,6 +329,16 @@ static jint android_net_wifi_getRssiCommand(JNIEnv* env, jobject clazz)
return (jint)rssi;
}
static jint android_net_wifi_getRssiCommand(JNIEnv* env, jobject clazz)
{
return android_net_wifi_getRssiHelper("DRIVER RSSI");
}
static jint android_net_wifi_getRssiApproxCommand(JNIEnv* env, jobject clazz)
{
return android_net_wifi_getRssiHelper("DRIVER RSSI-APPROX");
}
static jint android_net_wifi_getLinkSpeedCommand(JNIEnv* env, jobject clazz)
{
char reply[256];
@@ -523,6 +534,8 @@ static JNINativeMethod gWifiMethods[] = {
{ "setBluetoothCoexistenceScanModeCommand", "(Z)Z",
(void*) android_net_wifi_setBluetoothCoexistenceScanModeCommand },
{ "getRssiCommand", "()I", (void*) android_net_wifi_getRssiCommand },
{ "getRssiApproxCommand", "()I",
(void*) android_net_wifi_getRssiApproxCommand},
{ "getLinkSpeedCommand", "()I", (void*) android_net_wifi_getLinkSpeedCommand },
{ "getMacAddressCommand", "()Ljava/lang/String;", (void*) android_net_wifi_getMacAddressCommand },
{ "saveConfigCommand", "()Z", (void*) android_net_wifi_saveConfigCommand },

View File

@@ -79,6 +79,8 @@ public class WifiNative {
public native static int getRssiCommand();
public native static int getRssiApproxCommand();
public native static int getLinkSpeedCommand();
public native static String getMacAddressCommand();

View File

@@ -1029,7 +1029,7 @@ public class WifiStateTracker extends NetworkStateTracker {
case EVENT_POLL_INTERVAL:
if (mWifiInfo.getSupplicantState() != SupplicantState.UNINITIALIZED) {
requestPolledInfo(mWifiInfo);
requestPolledInfo(mWifiInfo, true);
if (mWifiInfo.getSupplicantState() == SupplicantState.COMPLETED) {
setPollTimer();
}
@@ -1276,7 +1276,7 @@ public class WifiStateTracker extends NetworkStateTracker {
*/
public WifiInfo requestConnectionInfo() {
requestConnectionStatus(mWifiInfo);
requestPolledInfo(mWifiInfo);
requestPolledInfo(mWifiInfo, false);
return mWifiInfo;
}
@@ -1331,9 +1331,10 @@ public class WifiStateTracker extends NetworkStateTracker {
* Get the dynamic information that is not reported via events.
* @param info the object into which the information should be captured.
*/
private synchronized void requestPolledInfo(WifiInfo info)
private synchronized void requestPolledInfo(WifiInfo info, boolean polling)
{
int newRssi = WifiNative.getRssiCommand();
int newRssi = (polling ? WifiNative.getRssiApproxCommand():
WifiNative.getRssiCommand());
if (newRssi != -1 && -200 < newRssi && newRssi < 100) { // screen out invalid values
info.setRssi(newRssi);
/*