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

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

Merge "Improve logging for Output Switcher." into main

parents 07094f5c 967ce520
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -514,6 +514,17 @@ public final class RouteListingPreference implements Parcelable {
                    mRouteId, mSelectionBehavior, mFlags, mSubText, mCustomSubtextMessage);
        }

        @Override
        public String toString() {
            return "RoutingListingPreference.Item { "
                    + "routeId=" + mRouteId
                    + ", selectionBehavior=" + getSelectionBehaviorString(mSelectionBehavior)
                    + ", flags=" + getFlagsString(mFlags)
                    + ", subtext=" + mSubText
                    + ", customSubtextMessage=" + mCustomSubtextMessage
                    + " }";
        }

        // Internal methods.

        private void validateCustomMessageSubtext() {
@@ -522,6 +533,29 @@ public final class RouteListingPreference implements Parcelable {
                    "The custom subtext message cannot be null if subtext is SUBTEXT_CUSTOM.");
        }

        private static String getFlagsString(@Flags int flags) {
            List<String> typeStrings = new ArrayList<>();
            if ((flags & FLAG_SUGGESTED) != 0) {
                typeStrings.add("SUGGESTED");
            }
            if ((flags & FLAG_ONGOING_SESSION) != 0) {
                typeStrings.add("ONGOING_SESSION");
            }
            if ((flags & FLAG_ONGOING_SESSION_MANAGED) != 0) {
                typeStrings.add("ONGOING_SESSION_MANAGED");
            }
            return String.join(/* delimiter= */ "|", typeStrings);
        }

        private static String getSelectionBehaviorString(@SelectionBehavior int selectionBehavior) {
            return switch (selectionBehavior) {
                case SELECTION_BEHAVIOR_NONE -> "NONE";
                case SELECTION_BEHAVIOR_TRANSFER -> "TRANSFER";
                case SELECTION_BEHAVIOR_GO_TO_APP -> "GO_TO_APP";
                default -> TextUtils.formatSimple("UNKNOWN(%d)", selectionBehavior);
            };
        }

        // Internal classes.

        /** Builder for {@link Item}. */
+6 −9
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHearingAid;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.MediaRoute2Info;
import android.media.RouteListingPreference;

@@ -40,30 +39,28 @@ public class BluetoothMediaDevice extends MediaDevice {
    private static final String TAG = "BluetoothMediaDevice";

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

    BluetoothMediaDevice(
            @NonNull Context context,
            @NonNull CachedBluetoothDevice device,
            @Nullable MediaRoute2Info info,
            @Nullable MediaRoute2Info routeInfo,
            @Nullable DynamicRouteAttributes dynamicRouteAttributes,
            @Nullable RouteListingPreference.Item item) {
        this(context, device, info, dynamicRouteAttributes, item,
            @Nullable RouteListingPreference.Item rlpItem) {
        this(context, device, routeInfo, dynamicRouteAttributes, rlpItem,
                /* isMutingExpectedDevice= */ false);
    }

    BluetoothMediaDevice(
            @NonNull Context context,
            @NonNull CachedBluetoothDevice device,
            @Nullable MediaRoute2Info info,
            @Nullable MediaRoute2Info routeInfo,
            @Nullable DynamicRouteAttributes dynamicRouteAttributes,
            @Nullable RouteListingPreference.Item item,
            @Nullable RouteListingPreference.Item rlpItem,
            boolean isMutingExpectedDevice) {
        super(context, info, dynamicRouteAttributes, item);
        super(context, routeInfo, dynamicRouteAttributes, rlpItem);
        mCachedDevice = device;
        mIsMutingExpectedDevice = isMutingExpectedDevice;
        mAudioManager = context.getSystemService(AudioManager.class);
        initDeviceRecord();
    }

+2 −2
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@ public class ComplexMediaDevice extends MediaDevice {
            @NonNull Context context,
            @NonNull MediaRoute2Info info,
            @Nullable DynamicRouteAttributes dynamicRouteAttributes,
            @Nullable RouteListingPreference.Item item) {
        super(context, info, dynamicRouteAttributes, item);
            @Nullable RouteListingPreference.Item rlpItem) {
        super(context, info, dynamicRouteAttributes, rlpItem);
    }

    // MediaRoute2Info.getName was made public on API 34, but exists since API 30.
+3 −3
Original line number Diff line number Diff line
@@ -47,10 +47,10 @@ public class InfoMediaDevice extends MediaDevice {

    InfoMediaDevice(
            @NonNull Context context,
            @NonNull MediaRoute2Info info,
            @NonNull MediaRoute2Info routeInfo,
            @Nullable DynamicRouteAttributes dynamicRouteAttributes,
            @Nullable RouteListingPreference.Item item) {
        super(context, info, dynamicRouteAttributes, item);
            @Nullable RouteListingPreference.Item rlpItem) {
        super(context, routeInfo, dynamicRouteAttributes, rlpItem);
        initDeviceRecord();
    }

+28 −4
Original line number Diff line number Diff line
@@ -289,6 +289,7 @@ public abstract class InfoMediaManager {
    }

    public void startScan() {
        Log.i(TAG, "startScan()");
        startScanOnRouter();
    }

@@ -302,6 +303,7 @@ public abstract class InfoMediaManager {
    }

    public final void stopScan() {
        Log.i(TAG, "stopScan()");
        stopScanOnRouter();
    }

@@ -436,18 +438,26 @@ public abstract class InfoMediaManager {
    }

    private void dispatchDeviceListAdded(@NonNull List<MediaDevice> devices) {
        Log.i(TAG, "dispatchDeviceListAdded()");
        if (DEBUG) {
            for (MediaDevice device : devices) {
                Log.d(TAG, device.toString());
            }
        }
        for (MediaDeviceCallback callback : getCallbacks()) {
            callback.onDeviceListAdded(new ArrayList<>(devices));
        }
    }

    private void dispatchConnectedDeviceChanged(String id) {
        Log.i(TAG, "dispatchConnectedDeviceChanged(), id = " + id);
        for (MediaDeviceCallback callback : getCallbacks()) {
            callback.onConnectedDeviceChanged(id);
        }
    }

    protected void dispatchOnRequestFailed(int reason) {
        Log.i(TAG, "dispatchOnRequestFailed(), reason = " + reason);
        for (MediaDeviceCallback callback : getCallbacks()) {
            callback.onRequestFailed(reason);
        }
@@ -466,6 +476,7 @@ public abstract class InfoMediaManager {
    }

    /* package */ void connectToDevice(MediaDevice device) {
        Log.i(TAG, "connectToDevice(), device = " + device.getName() + "/" + device.getId());
        if (device.mRouteInfo == null) {
            Log.w(TAG, "Unable to connect. RouteInfo is empty");
            return;
@@ -482,6 +493,7 @@ public abstract class InfoMediaManager {
     * @return If add device successful return {@code true}, otherwise return {@code false}
     */
    boolean addDeviceToPlayMedia(MediaDevice device) {
        Log.i(TAG, "addDeviceToPlayMedia(), device = " + device.getName() + "/" + device.getId());
        final RoutingSessionInfo info = getActiveRoutingSession();
        if (!info.getSelectableRoutes().contains(device.mRouteInfo.getId())) {
            Log.w(TAG, "addDeviceToPlayMedia() Ignoring selecting a non-selectable device : "
@@ -562,6 +574,8 @@ public abstract class InfoMediaManager {
     * @return If device stop successful return {@code true}, otherwise return {@code false}
     */
    boolean removeDeviceFromPlayMedia(MediaDevice device) {
        Log.i(TAG,
                "removeDeviceFromPlayMedia(), device = " + device.getName() + "/" + device.getId());
        final RoutingSessionInfo info = getActiveRoutingSession();
        if (!info.getSelectedRoutes().contains(device.mRouteInfo.getId())) {
            Log.w(TAG, "removeDeviceFromMedia() Ignoring deselecting a non-deselectable device : "
@@ -636,6 +650,8 @@ public abstract class InfoMediaManager {
    }

    /* package */ void adjustDeviceVolume(MediaDevice device, int volume) {
        Log.i(TAG, "adjustDeviceVolume(), device = " + device.getName() + "/" + device.getId()
                + " volume = " + volume);
        if (device.mRouteInfo == null) {
            Log.w(TAG, "Unable to set volume. RouteInfo is empty");
            return;
@@ -797,6 +813,7 @@ public abstract class InfoMediaManager {
    }

    private void dispatchOnSuggestedDeviceUpdated() {
        Log.i(TAG, "dispatchOnSuggestedDeviceUpdated(), state: " + mSuggestedDeviceState);
        for (MediaDeviceCallback callback : getCallbacks()) {
            callback.onSuggestedDeviceUpdated(mSuggestedDeviceState);
        }
@@ -883,10 +900,6 @@ public abstract class InfoMediaManager {
        RoutingSessionInfo activeSession = getActiveRoutingSession();

        for (MediaRoute2Info route : getAvailableRoutes(activeSession)) {
            if (DEBUG) {
                Log.d(TAG, "buildAvailableRoutes() route : " + route.getName() + ", volume : "
                        + route.getVolume() + ", type : " + route.getType());
            }
            addMediaDevice(route, activeSession);
        }

@@ -1194,6 +1207,17 @@ public abstract class InfoMediaManager {
        static void onRouteListingPreferenceUpdated(
                RouteListingPreference routeListingPreference,
                Map<String, RouteListingPreference.Item> preferenceItemMap) {
            Log.i(TAG, "onRouteListingPreferenceUpdated(), hasRLP: " + (routeListingPreference
                    != null));
            if (DEBUG) {
                if (routeListingPreference != null) {
                    Log.d(TAG, "RouteListingPreference. useSystemOrder = "
                            + routeListingPreference.getUseSystemOrdering());
                    for (RouteListingPreference.Item rlpItem : routeListingPreference.getItems()) {
                        Log.d(TAG, rlpItem.toString());
                    }
                }
            }
            preferenceItemMap.clear();
            if (routeListingPreference != null) {
                routeListingPreference.getItems().forEach((item) ->
Loading