Switch to cfg based signal_poll command

Bug: 5352916
Change-Id: Id2ba7091a5e4cc4c1e14aa2c49e5b943519019bf
This commit is contained in:
Irfan Sheriff
2011-09-26 16:30:15 -07:00
parent afe9461b52
commit 921df5cbc4
3 changed files with 33 additions and 36 deletions

View File

@@ -402,30 +402,6 @@ static jint android_net_wifi_getRssiHelper(const char *cmd)
return (jint)rssi;
}
static jint android_net_wifi_getRssiCommand(JNIEnv* env, jobject)
{
return android_net_wifi_getRssiHelper("DRIVER RSSI");
}
static jint android_net_wifi_getRssiApproxCommand(JNIEnv* env, jobject)
{
return android_net_wifi_getRssiHelper("DRIVER RSSI-APPROX");
}
static jint android_net_wifi_getLinkSpeedCommand(JNIEnv* env, jobject)
{
char reply[BUF_SIZE];
int linkspeed;
if (doCommand("DRIVER LINKSPEED", reply, sizeof(reply)) != 0) {
return (jint)-1;
}
// reply comes back in the form "LinkSpeed XX" where XX is the
// number we're interested in.
sscanf(reply, "%*s %u", &linkspeed);
return (jint)linkspeed;
}
static jstring android_net_wifi_getMacAddressCommand(JNIEnv* env, jobject)
{
char reply[BUF_SIZE];
@@ -625,10 +601,6 @@ static JNINativeMethod gWifiMethods[] = {
(void*) android_net_wifi_setBluetoothCoexistenceModeCommand },
{ "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 },
{ "reloadConfigCommand", "()Z", (void*) android_net_wifi_reloadConfigCommand },

View File

@@ -106,12 +106,6 @@ public class WifiNative {
public native static String statusCommand();
public native static int getRssiCommand();
public native static int getRssiApproxCommand();
public native static int getLinkSpeedCommand();
public native static String getMacAddressCommand();
public native static String scanResultsCommand();
@@ -209,6 +203,16 @@ public class WifiNative {
private native static String doStringCommand(String command);
/** Example output:
* RSSI=-65
* LINKSPEED=48
* NOISE=9999
* FREQUENCY=0
*/
public static String signalPoll() {
return doStringCommand("SIGNAL_POLL");
}
public static boolean wpsPbc() {
return doBooleanCommand("WPS_PBC");
}

View File

@@ -1362,7 +1362,28 @@ public class WifiStateMachine extends StateMachine {
* Fetch RSSI and linkspeed on current connection
*/
private void fetchRssiAndLinkSpeedNative() {
int newRssi = WifiNative.getRssiCommand();
int newRssi = -1;
int newLinkSpeed = -1;
String signalPoll = WifiNative.signalPoll();
if (signalPoll != null) {
String[] lines = signalPoll.split("\n");
for (String line : lines) {
String[] prop = line.split("=");
if (prop.length < 2) continue;
try {
if (prop[0].equals("RSSI")) {
newRssi = Integer.parseInt(prop[1]);
} else if (prop[0].equals("LINKSPEED")) {
newLinkSpeed = Integer.parseInt(prop[1]);
}
} catch (NumberFormatException e) {
//Ignore, defaults on rssi and linkspeed are assigned
}
}
}
if (newRssi != -1 && MIN_RSSI < newRssi && newRssi < MAX_RSSI) { // screen out invalid values
/* some implementations avoid negative values by adding 256
* so we need to adjust for that here.
@@ -1390,7 +1411,7 @@ public class WifiStateMachine extends StateMachine {
} else {
mWifiInfo.setRssi(MIN_RSSI);
}
int newLinkSpeed = WifiNative.getLinkSpeedCommand();
if (newLinkSpeed != -1) {
mWifiInfo.setLinkSpeed(newLinkSpeed);
}