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

Commit 1287256f authored by Alexandr Shabalin's avatar Alexandr Shabalin Committed by Android (Google) Code Review
Browse files

Merge "Make BluetoothMediaDevice#isMutingExpectedDevice() read from a constant." into main

parents 686e0fd0 cd57b6e1
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -290,6 +290,16 @@ flag {
    }
}

flag {
    name: "avoid_binder_calls_for_muting_expected_device"
    namespace: "media_better_together"
    description: "Sets isMutingExpectedDevice attribute during construction of MediaDevice."
    bug: "414668703"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "enable_output_switcher_personal_audio_sharing"
    namespace: "cross_device_experiences"
+17 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.settingslib.media;

import static com.android.media.flags.Flags.avoidBinderCallsDuringRender;
import static com.android.media.flags.Flags.avoidBinderCallsForMutingExpectedDevice;
import static com.android.settingslib.media.MediaDevice.SelectionBehavior.SELECTION_BEHAVIOR_TRANSFER;

import android.annotation.NonNull;
@@ -42,6 +43,7 @@ public class BluetoothMediaDevice extends MediaDevice {

    private final CachedBluetoothDevice mCachedDevice;
    private final AudioManager mAudioManager;
    private final Boolean mIsMutingExpectedDevice;

    BluetoothMediaDevice(
            @NonNull Context context,
@@ -49,8 +51,20 @@ public class BluetoothMediaDevice extends MediaDevice {
            @Nullable MediaRoute2Info info,
            @Nullable DynamicRouteAttributes dynamicRouteAttributes,
            @Nullable RouteListingPreference.Item item) {
        this(context, device, info, dynamicRouteAttributes, item,
                /* isMutingExpectedDevice= */ false);
    }

    BluetoothMediaDevice(
            @NonNull Context context,
            @NonNull CachedBluetoothDevice device,
            @Nullable MediaRoute2Info info,
            @Nullable DynamicRouteAttributes dynamicRouteAttributes,
            @Nullable RouteListingPreference.Item item,
            Boolean isMutingExpectedDevice) {
        super(context, info, dynamicRouteAttributes, item);
        mCachedDevice = device;
        mIsMutingExpectedDevice = isMutingExpectedDevice;
        mAudioManager = context.getSystemService(AudioManager.class);
        initDeviceRecord();
    }
@@ -144,6 +158,9 @@ public class BluetoothMediaDevice extends MediaDevice {

    @Override
    public boolean isMutingExpectedDevice() {
        if (avoidBinderCallsForMutingExpectedDevice()) {
            return mIsMutingExpectedDevice;
        }
        return mAudioManager.getMutingExpectedDevice() != null && mCachedDevice.getAddress().equals(
                mAudioManager.getMutingExpectedDevice().getAddress());
    }
+4 −1
Original line number Diff line number Diff line
@@ -622,6 +622,8 @@ public class LocalMediaManager implements BluetoothCallback {
                        } else {
                            MediaDevice mutingExpectedDevice = getMutingExpectedDevice();
                            if (mutingExpectedDevice != null) {
                                Log.d(TAG, "Muting expected device added, id: "
                                        + mutingExpectedDevice.getId());
                                mMediaDevices.add(mutingExpectedDevice);
                            }
                        }
@@ -664,7 +666,8 @@ public class LocalMediaManager implements BluetoothCallback {
                        cachedDeviceManager.findDevice(device);
                if (isBondedMediaDevice(cachedDevice) && isMutingExpectedDevice(cachedDevice)) {
                    return new BluetoothMediaDevice(mContext, cachedDevice, /* info= */
                            null, /* dynamicRouteAttributes= */  null, /* item= */ null);
                            null, /* dynamicRouteAttributes= */  null, /* item= */
                            null, /* isMutingExpectedDevice= */ true);
                }
            }
            return null;
+12 −0
Original line number Diff line number Diff line
@@ -154,4 +154,16 @@ public class BluetoothMediaDeviceTest {
                null, /* dynamicRouteAttributes= */ null, null);
        assertThat(bluetoothMediaDevice.getName()).isEqualTo(TEST_CACHED_DEVICE_NAME);
    }

    @EnableFlags(Flags.FLAG_AVOID_BINDER_CALLS_FOR_MUTING_EXPECTED_DEVICE)
    @Test
    public void getIsMutingExpectedDevice_dependsOnConstructorArgument() {
        MediaDevice bluetoothMediaDevice = new BluetoothMediaDevice(mContext, mDevice,
                null, /* dynamicRouteAttributes= */ null, null);
        assertThat(bluetoothMediaDevice.isMutingExpectedDevice()).isFalse();

        MediaDevice mutingExpectedDevice = new BluetoothMediaDevice(mContext, mDevice,
                null, /* dynamicRouteAttributes= */ null, null, /* isMutingExpectedDevice= */ true);
        assertThat(mutingExpectedDevice.isMutingExpectedDevice()).isTrue();
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -498,6 +498,7 @@ public class LocalMediaManagerTest {
        mLocalMediaManager.mMediaDeviceCallback.onDeviceListAdded(devices);

        assertThat(mLocalMediaManager.mMediaDevices).hasSize(2);
        assertThat(mLocalMediaManager.mMediaDevices.getLast().isMutingExpectedDevice()).isTrue();
        verify(mCallback).onDeviceListUpdate(any());
    }

Loading