Skip to content

Commit cbb62bb

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Switch to cfg based signal_poll command"
2 parents e187d81 + 921df5c commit cbb62bb

File tree

3 files changed

+33
-36
lines changed

3 files changed

+33
-36
lines changed

core/jni/android_net_wifi_Wifi.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -402,30 +402,6 @@ static jint android_net_wifi_getRssiHelper(const char *cmd)
402402
return (jint)rssi;
403403
}
404404

405-
static jint android_net_wifi_getRssiCommand(JNIEnv* env, jobject)
406-
{
407-
return android_net_wifi_getRssiHelper("DRIVER RSSI");
408-
}
409-
410-
static jint android_net_wifi_getRssiApproxCommand(JNIEnv* env, jobject)
411-
{
412-
return android_net_wifi_getRssiHelper("DRIVER RSSI-APPROX");
413-
}
414-
415-
static jint android_net_wifi_getLinkSpeedCommand(JNIEnv* env, jobject)
416-
{
417-
char reply[BUF_SIZE];
418-
int linkspeed;
419-
420-
if (doCommand("DRIVER LINKSPEED", reply, sizeof(reply)) != 0) {
421-
return (jint)-1;
422-
}
423-
// reply comes back in the form "LinkSpeed XX" where XX is the
424-
// number we're interested in.
425-
sscanf(reply, "%*s %u", &linkspeed);
426-
return (jint)linkspeed;
427-
}
428-
429405
static jstring android_net_wifi_getMacAddressCommand(JNIEnv* env, jobject)
430406
{
431407
char reply[BUF_SIZE];
@@ -625,10 +601,6 @@ static JNINativeMethod gWifiMethods[] = {
625601
(void*) android_net_wifi_setBluetoothCoexistenceModeCommand },
626602
{ "setBluetoothCoexistenceScanModeCommand", "(Z)Z",
627603
(void*) android_net_wifi_setBluetoothCoexistenceScanModeCommand },
628-
{ "getRssiCommand", "()I", (void*) android_net_wifi_getRssiCommand },
629-
{ "getRssiApproxCommand", "()I",
630-
(void*) android_net_wifi_getRssiApproxCommand},
631-
{ "getLinkSpeedCommand", "()I", (void*) android_net_wifi_getLinkSpeedCommand },
632604
{ "getMacAddressCommand", "()Ljava/lang/String;", (void*) android_net_wifi_getMacAddressCommand },
633605
{ "saveConfigCommand", "()Z", (void*) android_net_wifi_saveConfigCommand },
634606
{ "reloadConfigCommand", "()Z", (void*) android_net_wifi_reloadConfigCommand },

wifi/java/android/net/wifi/WifiNative.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ public class WifiNative {
106106

107107
public native static String statusCommand();
108108

109-
public native static int getRssiCommand();
110-
111-
public native static int getRssiApproxCommand();
112-
113-
public native static int getLinkSpeedCommand();
114-
115109
public native static String getMacAddressCommand();
116110

117111
public native static String scanResultsCommand();
@@ -209,6 +203,16 @@ public class WifiNative {
209203

210204
private native static String doStringCommand(String command);
211205

206+
/** Example output:
207+
* RSSI=-65
208+
* LINKSPEED=48
209+
* NOISE=9999
210+
* FREQUENCY=0
211+
*/
212+
public static String signalPoll() {
213+
return doStringCommand("SIGNAL_POLL");
214+
}
215+
212216
public static boolean wpsPbc() {
213217
return doBooleanCommand("WPS_PBC");
214218
}

wifi/java/android/net/wifi/WifiStateMachine.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,28 @@ private String fetchSSID() {
13621362
* Fetch RSSI and linkspeed on current connection
13631363
*/
13641364
private void fetchRssiAndLinkSpeedNative() {
1365-
int newRssi = WifiNative.getRssiCommand();
1365+
int newRssi = -1;
1366+
int newLinkSpeed = -1;
1367+
1368+
String signalPoll = WifiNative.signalPoll();
1369+
1370+
if (signalPoll != null) {
1371+
String[] lines = signalPoll.split("\n");
1372+
for (String line : lines) {
1373+
String[] prop = line.split("=");
1374+
if (prop.length < 2) continue;
1375+
try {
1376+
if (prop[0].equals("RSSI")) {
1377+
newRssi = Integer.parseInt(prop[1]);
1378+
} else if (prop[0].equals("LINKSPEED")) {
1379+
newLinkSpeed = Integer.parseInt(prop[1]);
1380+
}
1381+
} catch (NumberFormatException e) {
1382+
//Ignore, defaults on rssi and linkspeed are assigned
1383+
}
1384+
}
1385+
}
1386+
13661387
if (newRssi != -1 && MIN_RSSI < newRssi && newRssi < MAX_RSSI) { // screen out invalid values
13671388
/* some implementations avoid negative values by adding 256
13681389
* so we need to adjust for that here.
@@ -1390,7 +1411,7 @@ private void fetchRssiAndLinkSpeedNative() {
13901411
} else {
13911412
mWifiInfo.setRssi(MIN_RSSI);
13921413
}
1393-
int newLinkSpeed = WifiNative.getLinkSpeedCommand();
1414+
13941415
if (newLinkSpeed != -1) {
13951416
mWifiInfo.setLinkSpeed(newLinkSpeed);
13961417
}

0 commit comments

Comments
 (0)