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

Commit a36cebcf authored by Ted Wang's avatar Ted Wang Committed by android-build-merger
Browse files

Merge "Store volume only when Hearing Aid devices are not active"

am: ec57191f

Change-Id: Ie7823982474f0f449da4ca12794dac0d2be19a57
parents 7704e161 ec57191f
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -35,6 +35,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;
@@ -56,6 +57,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;
@@ -242,6 +244,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