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

Commit ed49886d authored by Neha Jain's avatar Neha Jain Committed by Automerger Merge Worker
Browse files

Merge "Paired BT devices are not displaying in volume control panel" into sc-dev am: 060a4009

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15460611

Change-Id: I18762f1d142bd2f871ae0ecfb2c00fdf34403573
parents 8bb8e1fc 060a4009
Loading
Loading
Loading
Loading
+39 −26
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ import android.os.Build;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.RequiresApi;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -56,6 +58,7 @@ import java.util.concurrent.Executors;
/**
 * InfoMediaManager provide interface to get InfoMediaDevice list.
 */
@RequiresApi(Build.VERSION_CODES.R)
public class InfoMediaManager extends MediaManager {

    private static final String TAG = "InfoMediaManager";
@@ -145,9 +148,16 @@ public class InfoMediaManager extends MediaManager {
    }

    private RoutingSessionInfo getRoutingSessionInfo() {
        return getRoutingSessionInfo(mPackageName);
    }

    private RoutingSessionInfo getRoutingSessionInfo(String packageName) {
        final List<RoutingSessionInfo> sessionInfos =
                mRouterManager.getRoutingSessions(mPackageName);
                mRouterManager.getRoutingSessions(packageName);

        if (sessionInfos == null || sessionInfos.isEmpty()) {
            return null;
        }
        return sessionInfos.get(sessionInfos.size() - 1);
    }

@@ -367,33 +377,13 @@ public class InfoMediaManager extends MediaManager {
    }

    boolean shouldDisableMediaOutput(String packageName) {
        boolean shouldDisableMediaOutput = false;
        if (TextUtils.isEmpty(packageName)) {
            Log.w(TAG, "shouldDisableMediaOutput() package name is null or empty!");
            return false;
        }
        final List<MediaRoute2Info> infos = mRouterManager.getTransferableRoutes(packageName);
        if (infos.size() == 1) {
            final MediaRoute2Info info = infos.get(0);
            final int deviceType = info.getType();
            switch (deviceType) {
                case TYPE_UNKNOWN:
                case TYPE_REMOTE_TV:
                case TYPE_REMOTE_SPEAKER:
                case TYPE_GROUP:
                    shouldDisableMediaOutput = true;
                    break;
                default:
                    shouldDisableMediaOutput = false;
                    break;
            }
        }
        if (DEBUG) {
            Log.d(TAG, "shouldDisableMediaOutput() MediaRoute2Info size : " + infos.size()
                    + ", package name : " + packageName + ", shouldDisableMediaOutput : "
                    + shouldDisableMediaOutput);
            return true;
        }
        return shouldDisableMediaOutput;

        // Disable when there is no transferable route
        return mRouterManager.getTransferableRoutes(packageName).isEmpty();
    }

    @TargetApi(Build.VERSION_CODES.R)
@@ -456,7 +446,7 @@ public class InfoMediaManager extends MediaManager {
    }

    private void buildAvailableRoutes() {
        for (MediaRoute2Info route : mRouterManager.getTransferableRoutes(mPackageName)) {
        for (MediaRoute2Info route : getAvailableRoutes(mPackageName)) {
            if (DEBUG) {
                Log.d(TAG, "buildAvailableRoutes() route : " + route.getName() + ", volume : "
                        + route.getVolume() + ", type : " + route.getType());
@@ -465,6 +455,29 @@ public class InfoMediaManager extends MediaManager {
        }
    }

    private List<MediaRoute2Info> getAvailableRoutes(String packageName) {
        final List<MediaRoute2Info> infos = new ArrayList<>();
        RoutingSessionInfo routingSessionInfo = getRoutingSessionInfo(packageName);
        if (routingSessionInfo != null) {
            infos.addAll(mRouterManager.getSelectedRoutes(routingSessionInfo));
        }
        final List<MediaRoute2Info> transferableRoutes =
                mRouterManager.getTransferableRoutes(packageName);
        for (MediaRoute2Info transferableRoute : transferableRoutes) {
            boolean alreadyAdded = false;
            for (MediaRoute2Info mediaRoute2Info : infos) {
                if (TextUtils.equals(transferableRoute.getId(), mediaRoute2Info.getId())) {
                    alreadyAdded = true;
                    break;
                }
            }
            if (!alreadyAdded) {
                infos.add(transferableRoute);
            }
        }
        return infos;
    }

    @VisibleForTesting
    void addMediaDevice(MediaRoute2Info route) {
        final int deviceType = route.getType();
+3 −0
Original line number Diff line number Diff line
@@ -22,11 +22,13 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.media.RoutingSessionInfo;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.bluetooth.A2dpProfile;
@@ -49,6 +51,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
/**
 * LocalMediaManager provide interface to get MediaDevice list and transfer media to MediaDevice.
 */
@RequiresApi(Build.VERSION_CODES.R)
public class LocalMediaManager implements BluetoothCallback {
    private static final Comparator<MediaDevice> COMPARATOR = Comparator.naturalOrder();
    private static final String TAG = "LocalMediaManager";