Skip to content

Commit 1f61e03

Browse files
Ted Wangandroid-build-merger
authored andcommitted
Merge "Store volume only when Hearing Aid devices are not active" into qt-dev
am: e97471d Change-Id: Ibab500735229990d2efa553128f7b5156d9e2829
2 parents 61768b9 + e97471d commit 1f61e03

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/com/android/bluetooth/avrcp/AvrcpTargetService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.android.bluetooth.a2dp.A2dpService;
3535
import com.android.bluetooth.btservice.MetricsLogger;
3636
import com.android.bluetooth.btservice.ProfileService;
37+
import com.android.bluetooth.btservice.ServiceFactory;
3738

3839
import java.util.List;
3940
import java.util.Objects;
@@ -55,6 +56,7 @@ public class AvrcpTargetService extends ProfileService {
5556
private AvrcpBroadcastReceiver mReceiver;
5657
private AvrcpNativeInterface mNativeInterface;
5758
private AvrcpVolumeManager mVolumeManager;
59+
private ServiceFactory mFactory = new ServiceFactory();
5860

5961
// Only used to see if the metadata has changed from its previous value
6062
private MediaData mCurrentData;
@@ -227,6 +229,15 @@ public void volumeDeviceSwitched(BluetoothDevice device) {
227229
public void storeVolumeForDevice(BluetoothDevice device) {
228230
if (device == null) return;
229231

232+
List<BluetoothDevice> HAActiveDevices = null;
233+
if (mFactory.getHearingAidService() != null) {
234+
HAActiveDevices = mFactory.getHearingAidService().getActiveDevices();
235+
}
236+
if (HAActiveDevices != null
237+
&& (HAActiveDevices.get(0) != null || HAActiveDevices.get(1) != null)) {
238+
Log.d(TAG, "Do not store volume when Hearing Aid devices is active");
239+
return;
240+
}
230241
mVolumeManager.storeVolumeForDevice(device);
231242
}
232243

src/com/android/bluetooth/hearingaid/HearingAidService.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,15 @@ public boolean setActiveDevice(BluetoothDevice device) {
505505
Long deviceHiSyncId = mDeviceHiSyncIdMap.getOrDefault(device,
506506
BluetoothHearingAid.HI_SYNC_ID_INVALID);
507507
if (deviceHiSyncId != mActiveDeviceHiSyncId) {
508+
// Give an early notification to A2DP that active device is being switched
509+
// to Hearing Aids before the Audio Service.
510+
final A2dpService a2dpService = mFactory.getA2dpService();
511+
if (a2dpService != null) {
512+
if (DBG) {
513+
Log.d(TAG, "earlyNotifyHearingAidActive for " + device);
514+
}
515+
a2dpService.earlyNotifyHearingAidActive();
516+
}
508517
mActiveDeviceHiSyncId = deviceHiSyncId;
509518
reportActiveDevice(device);
510519
}
@@ -519,7 +528,7 @@ public boolean setActiveDevice(BluetoothDevice device) {
519528
* device; the second element is the right active device. If either or both side
520529
* is not active, it will be null on that position
521530
*/
522-
List<BluetoothDevice> getActiveDevices() {
531+
public List<BluetoothDevice> getActiveDevices() {
523532
if (DBG) {
524533
Log.d(TAG, "getActiveDevices");
525534
}
@@ -625,18 +634,6 @@ private void reportActiveDevice(BluetoothDevice device) {
625634
StatsLog.write(StatsLog.BLUETOOTH_ACTIVE_DEVICE_CHANGED, BluetoothProfile.HEARING_AID,
626635
mAdapterService.obfuscateAddress(device));
627636

628-
if (device != null) {
629-
// Give an early notification to A2DP that active device is being switched
630-
// to Hearing Aids before the Audio Service.
631-
final A2dpService a2dpService = mFactory.getA2dpService();
632-
if (a2dpService != null) {
633-
if (DBG) {
634-
Log.d(TAG, "earlyNotifyHearingAidActive for " + device);
635-
}
636-
a2dpService.earlyNotifyHearingAidActive();
637-
}
638-
}
639-
640637
Intent intent = new Intent(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED);
641638
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
642639
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT

0 commit comments

Comments
 (0)