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

Commit 8431bbe1 authored by Alex Shabalin's avatar Alex Shabalin Committed by Alexandr Shabalin
Browse files

Prevent making IPC calls during UI rendering.

`MediaSwitchingController` methods `getSelectableMediaDevice`,
`getDeselectableMediaDevice`, `getSelectedMediaDevice`, and
`getTransferableMediaDevice` end up in making expensive binder calls on
every item render.

This change puts `selected`, `transferable`, `selectable`, and
`deselectable` values as attributes of the MediaDevice and populates
them only whenever the device list is updated.

Bug: 414668703
Test: atest com.android.settingslib.media.InfoMediaManagerTest
Flag: com.android.media.flags.avoid_binder_calls_during_render
Change-Id: I0c95efcfc4a7645cde8e69e969e247f6a7a43d91
parent 66c38a10
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -270,6 +270,16 @@ flag {
    }
}

flag {
    name: "avoid_binder_calls_during_render"
    namespace: "media_better_together"
    description: "Reduces number of expensive binder calls during rendering."
    bug: "414668703"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "enable_output_switcher_personal_audio_sharing"
    namespace: "cross_device_experiences"
+2 −1
Original line number Diff line number Diff line
@@ -46,8 +46,9 @@ public class BluetoothMediaDevice extends MediaDevice {
            @NonNull Context context,
            @NonNull CachedBluetoothDevice device,
            @Nullable MediaRoute2Info info,
            @Nullable DynamicRouteAttributes dynamicRouteAttributes,
            @Nullable RouteListingPreference.Item item) {
        super(context, info, item);
        super(context, info, dynamicRouteAttributes, item);
        mCachedDevice = device;
        mAudioManager = context.getSystemService(AudioManager.class);
        initDeviceRecord();
+2 −1
Original line number Diff line number Diff line
@@ -36,8 +36,9 @@ public class ComplexMediaDevice extends MediaDevice {
    ComplexMediaDevice(
            @NonNull Context context,
            @NonNull MediaRoute2Info info,
            @Nullable DynamicRouteAttributes dynamicRouteAttributes,
            @Nullable RouteListingPreference.Item item) {
        super(context, info, item);
        super(context, info, dynamicRouteAttributes, item);
    }

    // MediaRoute2Info.getName was made public on API 34, but exists since API 30.
+24 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.media

data class DynamicRouteAttributes(
    val transferable: Boolean,
    val selected: Boolean,
    val selectable: Boolean,
    val deselectable: Boolean,
)
+2 −1
Original line number Diff line number Diff line
@@ -48,8 +48,9 @@ public class InfoMediaDevice extends MediaDevice {
    InfoMediaDevice(
            @NonNull Context context,
            @NonNull MediaRoute2Info info,
            @Nullable DynamicRouteAttributes dynamicRouteAttributes,
            @Nullable RouteListingPreference.Item item) {
        super(context, info, item);
        super(context, info, dynamicRouteAttributes, item);
        initDeviceRecord();
    }

Loading