Skip to content

Commit d7a96c9

Browse files
authored
Fix: Activate A2DP audio profile for AirPods after system reboot on Linx (#212)
Fix: Activate A2DP audio profile for AirPods after system reboot - Add A2DP profile activation on system wake-up - Add A2DP profile activation when BlueZ detects connection - Add A2DP profile activation for already connected devices on startup Fixes issue where AirPods microphone works but audio output is unavailable after reboot
1 parent b732c66 commit d7a96c9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

linux/main.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ class AirPodsTrayApp : public QObject {
9696
QBluetoothDeviceInfo device(address, "", 0);
9797
if (isAirPodsDevice(device)) {
9898
connectToDevice(device);
99+
100+
// On startup after reboot, activate A2DP profile for already connected AirPods
101+
QTimer::singleShot(2000, this, [this, address]()
102+
{
103+
QString formattedAddress = address.toString().replace(":", "_");
104+
mediaController->setConnectedDeviceMacAddress(formattedAddress);
105+
mediaController->activateA2dpProfile();
106+
LOG_INFO("A2DP profile activation attempted for AirPods found on startup");
107+
});
99108
return;
100109
}
101110
}
@@ -397,6 +406,23 @@ public slots:
397406
{
398407
LOG_INFO("System is waking up, starting ble scan");
399408
m_bleManager->startScan();
409+
410+
// Check if AirPods are already connected and activate A2DP profile
411+
if (areAirpodsConnected() && m_deviceInfo && !m_deviceInfo->bluetoothAddress().isEmpty())
412+
{
413+
LOG_INFO("AirPods already connected after wake-up, re-activating A2DP profile");
414+
mediaController->setConnectedDeviceMacAddress(m_deviceInfo->bluetoothAddress().replace(":", "_"));
415+
416+
// Always activate A2DP profile after system wake since the profile might have been lost
417+
QTimer::singleShot(1000, this, [this]()
418+
{
419+
mediaController->activateA2dpProfile();
420+
LOG_INFO("A2DP profile activation attempted after system wake-up");
421+
});
422+
}
423+
424+
// Also check for already connected devices via BlueZ
425+
monitor->checkAlreadyConnectedDevices();
400426
}
401427

402428
private slots:
@@ -445,6 +471,20 @@ private slots:
445471
{
446472
QBluetoothDeviceInfo device(QBluetoothAddress(address), name, 0);
447473
connectToDevice(device);
474+
475+
// After system reboot, AirPods might be connected but A2DP profile not active
476+
// Attempt to activate A2DP profile after a delay to ensure connection is established
477+
QTimer::singleShot(2000, this, [this, address]()
478+
{
479+
if (!address.isEmpty())
480+
{
481+
QString formattedAddress = address;
482+
formattedAddress = formattedAddress.replace(":", "_");
483+
mediaController->setConnectedDeviceMacAddress(formattedAddress);
484+
mediaController->activateA2dpProfile();
485+
LOG_INFO("A2DP profile activation attempted for newly connected device");
486+
}
487+
});
448488
}
449489

450490
void onDeviceDisconnected(const QBluetoothAddress &address)

0 commit comments

Comments
 (0)