Skip to content

Commit

Permalink
Handle "unset" 127 dB Bluetooth signal strength values
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Nov 13, 2023
1 parent 4d26c89 commit e1d320d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ public int compare(BluetoothRecord record1, BluetoothRecord record2)
default: // Signal Strength
// Signal Strength is index 0 in the array, but we also use it as the default case
// Invert the sort so that the strongest records are at the top (descending)
if (!record1.getData().hasSignalStrength() && !record2.getData().hasSignalStrength())
{
return 0;
}

if (!record1.getData().hasSignalStrength()) return -1;

if (!record2.getData().hasSignalStrength()) return 1;

return -1 * Float.compare(record1.getData().getSignalStrength().getValue(), record2.getData().getSignalStrength().getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,10 @@ private BluetoothRecord generateBluetoothSurveyRecord(BluetoothDevice device, in
dataBuilder.setRecordNumber(bluetoothRecordNumber++);

dataBuilder.setSourceAddress(sourceAddress);
dataBuilder.setSignalStrength(FloatValue.newBuilder().setValue(rssi).build());
if (txPowerLevel == UNSET_TX_POWER_LEVEL)
{
dataBuilder.setSignalStrength(FloatValue.newBuilder().setValue(rssi).build());
}

// The TX Power seems to never be set (a value of 127 indicates unset). However, I am including
// the code here in case it starts being populated in a future version of Android, or if a specific phone model
Expand Down

0 comments on commit e1d320d

Please sign in to comment.