mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-18 09:14:01 -04:00
bluetooth: treat alias-is-address as the only unnamed case when sorting scan results
fixes #3761
This commit is contained in:
@@ -339,6 +339,13 @@ Singleton {
|
||||
});
|
||||
}
|
||||
|
||||
function hasRealName(device) {
|
||||
const name = device.name || device.deviceName || "";
|
||||
if (!name)
|
||||
return false;
|
||||
return name !== (device.address || "").replace(/:/g, "-");
|
||||
}
|
||||
|
||||
function sortDevices(devices) {
|
||||
return devices.sort((a, b) => {
|
||||
const aName = a.name || a.deviceName || "";
|
||||
@@ -346,8 +353,8 @@ Singleton {
|
||||
const aAddr = a.address || "";
|
||||
const bAddr = b.address || "";
|
||||
|
||||
const aHasRealName = aName.includes(" ") && aName.length > 3;
|
||||
const bHasRealName = bName.includes(" ") && bName.length > 3;
|
||||
const aHasRealName = hasRealName(a);
|
||||
const bHasRealName = hasRealName(b);
|
||||
|
||||
if (aHasRealName && !bHasRealName)
|
||||
return -1;
|
||||
|
||||
@@ -446,3 +446,14 @@ test("LHDC codecs carry a name, description and category", () => {
|
||||
assert.equal(context.codecNameFromProfile("a2dp-sink"), "");
|
||||
assert.equal(context.codecNameFromProfile("a2dp-sink-aac"), "AAC");
|
||||
});
|
||||
|
||||
// BlueZ Alias falls back to the dashed address when a device sends no name.
|
||||
test("scan list sorts named devices above alias-is-address devices", () => {
|
||||
const context = methods(["hasRealName", "sortDevices"]);
|
||||
const sorted = context.sortDevices([
|
||||
{ name: "23-5F-24-05-F3-4A", address: "23:5F:24:05:F3:4A" },
|
||||
{ name: "ATH-M20xBT", address: "AA:BB:CC:DD:EE:FF" },
|
||||
{ name: "", deviceName: "", address: "01:02:03:04:05:06" }
|
||||
]);
|
||||
assert.deepEqual(sorted.map(d => d.address), ["AA:BB:CC:DD:EE:FF", "01:02:03:04:05:06", "23:5F:24:05:F3:4A"]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user