Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8899b27 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Store volume only when Hearing Aid devices are not active" into qt-dev

parents b99ece08 75d5ed7d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.bluetooth.Utils;
import com.android.bluetooth.a2dp.A2dpService;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ServiceFactory;

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

    // Only used to see if the metadata has changed from its previous value
    private MediaData mCurrentData;
@@ -227,6 +229,15 @@ public class AvrcpTargetService extends ProfileService {
    public void storeVolumeForDevice(BluetoothDevice device) {
        if (device == null) return;

        List<BluetoothDevice> HAActiveDevices = null;
        if (mFactory.getHearingAidService() != null) {
            HAActiveDevices = mFactory.getHearingAidService().getActiveDevices();
        }
        if (HAActiveDevices != null
                && (HAActiveDevices.get(0) != null || HAActiveDevices.get(1) != null)) {
            Log.d(TAG, "Do not store volume when Hearing Aid devices is active");
            return;
        }
        mVolumeManager.storeVolumeForDevice(device);
    }

+10 −13
Original line number Diff line number Diff line
@@ -505,6 +505,15 @@ public class HearingAidService extends ProfileService {
            Long deviceHiSyncId = mDeviceHiSyncIdMap.getOrDefault(device,
                    BluetoothHearingAid.HI_SYNC_ID_INVALID);
            if (deviceHiSyncId != mActiveDeviceHiSyncId) {
                // Give an early notification to A2DP that active device is being switched
                // to Hearing Aids before the Audio Service.
                final A2dpService a2dpService = mFactory.getA2dpService();
                if (a2dpService != null) {
                    if (DBG) {
                        Log.d(TAG, "earlyNotifyHearingAidActive for " + device);
                    }
                    a2dpService.earlyNotifyHearingAidActive();
                }
                mActiveDeviceHiSyncId = deviceHiSyncId;
                reportActiveDevice(device);
            }
@@ -519,7 +528,7 @@ public class HearingAidService extends ProfileService {
     * device; the second element is the right active device. If either or both side
     * is not active, it will be null on that position
     */
    List<BluetoothDevice> getActiveDevices() {
    public List<BluetoothDevice> getActiveDevices() {
        if (DBG) {
            Log.d(TAG, "getActiveDevices");
        }
@@ -625,18 +634,6 @@ public class HearingAidService extends ProfileService {
        StatsLog.write(StatsLog.BLUETOOTH_ACTIVE_DEVICE_CHANGED, BluetoothProfile.HEARING_AID,
                mAdapterService.obfuscateAddress(device));

        if (device != null) {
            // Give an early notification to A2DP that active device is being switched
            // to Hearing Aids before the Audio Service.
            final A2dpService a2dpService = mFactory.getA2dpService();
            if (a2dpService != null) {
                if (DBG) {
                    Log.d(TAG, "earlyNotifyHearingAidActive for " + device);
                }
                a2dpService.earlyNotifyHearingAidActive();
            }
        }

        Intent intent = new Intent(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT