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

Commit 9d9ef7cf authored by Vlad Popa's avatar Vlad Popa
Browse files

Only calls to AudioManager.setBluetoothAudioDeviceCategory() can reset audio type to unknown

When connecting a new BT device and the BTHelper cannot find any
metadata for that device we do not want to reset the category to unknown
since the user could have set it before to a different value

Test: manual w/o automaticBtDeviceType
Bug: 328329062
Change-Id: Id9ec300a77efcc85cbc84fab66fb886d215fdabe
parent b2989453
Loading
Loading
Loading
Loading
+12 −8
Original line number Original line Diff line number Diff line
@@ -157,7 +157,7 @@ public class AudioDeviceInventory {
     * corresponding peers in case of BLE
     * corresponding peers in case of BLE
     */
     */
    void addAudioDeviceInInventoryIfNeeded(int deviceType, String address, String peerAddress,
    void addAudioDeviceInInventoryIfNeeded(int deviceType, String address, String peerAddress,
            @AudioDeviceCategory int category) {
            @AudioDeviceCategory int category, boolean userDefined) {
        if (!isBluetoothOutDevice(deviceType)) {
        if (!isBluetoothOutDevice(deviceType)) {
            return;
            return;
        }
        }
@@ -167,7 +167,11 @@ public class AudioDeviceInventory {
                ads = findBtDeviceStateForAddress(peerAddress, deviceType);
                ads = findBtDeviceStateForAddress(peerAddress, deviceType);
            }
            }
            if (ads != null) {
            if (ads != null) {
                if (ads.getAudioDeviceCategory() != category) {
                // if category is user defined allow to change back to unknown otherwise
                // do not reset the category back to unknown since it might have been set
                // before by the user
                if (ads.getAudioDeviceCategory() != category && (userDefined
                        || category != AUDIO_DEVICE_CATEGORY_UNKNOWN)) {
                    ads.setAudioDeviceCategory(category);
                    ads.setAudioDeviceCategory(category);
                    mDeviceBroker.postUpdatedAdiDeviceState(ads);
                    mDeviceBroker.postUpdatedAdiDeviceState(ads);
                    mDeviceBroker.postPersistAudioDeviceSettings();
                    mDeviceBroker.postPersistAudioDeviceSettings();
@@ -220,9 +224,9 @@ public class AudioDeviceInventory {
    void addAudioDeviceWithCategoryInInventoryIfNeeded(@NonNull String address,
    void addAudioDeviceWithCategoryInInventoryIfNeeded(@NonNull String address,
            @AudioDeviceCategory int btAudioDeviceCategory) {
            @AudioDeviceCategory int btAudioDeviceCategory) {
        addAudioDeviceInInventoryIfNeeded(DEVICE_OUT_BLE_HEADSET,
        addAudioDeviceInInventoryIfNeeded(DEVICE_OUT_BLE_HEADSET,
                address, "", btAudioDeviceCategory);
                address, "", btAudioDeviceCategory, /*userDefined=*/true);
        addAudioDeviceInInventoryIfNeeded(DEVICE_OUT_BLUETOOTH_A2DP,
        addAudioDeviceInInventoryIfNeeded(DEVICE_OUT_BLUETOOTH_A2DP,
                address, "", btAudioDeviceCategory);
                address, "", btAudioDeviceCategory, /*userDefined=*/true);


    }
    }
    @AudioDeviceCategory
    @AudioDeviceCategory
@@ -1733,7 +1737,7 @@ public class AudioDeviceInventory {
                        purgeDevicesRoles_l();
                        purgeDevicesRoles_l();
                    } else {
                    } else {
                        addAudioDeviceInInventoryIfNeeded(device, address, "",
                        addAudioDeviceInInventoryIfNeeded(device, address, "",
                                BtHelper.getBtDeviceCategory(address));
                                BtHelper.getBtDeviceCategory(address), /*userDefined=*/false);
                    }
                    }
                    AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(
                    AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(
                            "SCO " + (AudioSystem.isInputDevice(device) ? "source" : "sink")
                            "SCO " + (AudioSystem.isInputDevice(device) ? "source" : "sink")
@@ -2023,7 +2027,7 @@ public class AudioDeviceInventory {
        updateBluetoothPreferredModes_l(btInfo.mDevice /*connectedDevice*/);
        updateBluetoothPreferredModes_l(btInfo.mDevice /*connectedDevice*/);


        addAudioDeviceInInventoryIfNeeded(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, address, "",
        addAudioDeviceInInventoryIfNeeded(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, address, "",
                BtHelper.getBtDeviceCategory(address));
                BtHelper.getBtDeviceCategory(address), /*userDefined=*/false);
    }
    }


    static final int[] CAPTURE_PRESETS = new int[] {AudioSource.MIC, AudioSource.CAMCORDER,
    static final int[] CAPTURE_PRESETS = new int[] {AudioSource.MIC, AudioSource.CAMCORDER,
@@ -2357,7 +2361,7 @@ public class AudioDeviceInventory {
                DEVICE_OUT_HEARING_AID, "makeHearingAidDeviceAvailable");
                DEVICE_OUT_HEARING_AID, "makeHearingAidDeviceAvailable");
        setCurrentAudioRouteNameIfPossible(name, false /*fromA2dp*/);
        setCurrentAudioRouteNameIfPossible(name, false /*fromA2dp*/);
        addAudioDeviceInInventoryIfNeeded(DEVICE_OUT_HEARING_AID, address, "",
        addAudioDeviceInInventoryIfNeeded(DEVICE_OUT_HEARING_AID, address, "",
                BtHelper.getBtDeviceCategory(address));
                BtHelper.getBtDeviceCategory(address), /*userDefined=*/false);
        new MediaMetrics.Item(mMetricsId + "makeHearingAidDeviceAvailable")
        new MediaMetrics.Item(mMetricsId + "makeHearingAidDeviceAvailable")
                .set(MediaMetrics.Property.ADDRESS, address != null ? address : "")
                .set(MediaMetrics.Property.ADDRESS, address != null ? address : "")
                .set(MediaMetrics.Property.DEVICE,
                .set(MediaMetrics.Property.DEVICE,
@@ -2488,7 +2492,7 @@ public class AudioDeviceInventory {
            mDeviceBroker.postAccessoryPlugMediaUnmute(device);
            mDeviceBroker.postAccessoryPlugMediaUnmute(device);
            setCurrentAudioRouteNameIfPossible(name, /*fromA2dp=*/false);
            setCurrentAudioRouteNameIfPossible(name, /*fromA2dp=*/false);
            addAudioDeviceInInventoryIfNeeded(device, address, peerAddress,
            addAudioDeviceInInventoryIfNeeded(device, address, peerAddress,
                    BtHelper.getBtDeviceCategory(address));
                    BtHelper.getBtDeviceCategory(address), /*userDefined=*/false);
        }
        }


        if (streamType == AudioSystem.STREAM_DEFAULT) {
        if (streamType == AudioSystem.STREAM_DEFAULT) {