Merge "Paired BT devices are not displaying in volume control panel" into sc-dev
This commit is contained in:
@@ -44,6 +44,8 @@ import android.os.Build;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
@@ -56,6 +58,7 @@ import java.util.concurrent.Executors;
|
|||||||
/**
|
/**
|
||||||
* InfoMediaManager provide interface to get InfoMediaDevice list.
|
* InfoMediaManager provide interface to get InfoMediaDevice list.
|
||||||
*/
|
*/
|
||||||
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
public class InfoMediaManager extends MediaManager {
|
public class InfoMediaManager extends MediaManager {
|
||||||
|
|
||||||
private static final String TAG = "InfoMediaManager";
|
private static final String TAG = "InfoMediaManager";
|
||||||
@@ -145,9 +148,16 @@ public class InfoMediaManager extends MediaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RoutingSessionInfo getRoutingSessionInfo() {
|
private RoutingSessionInfo getRoutingSessionInfo() {
|
||||||
final List<RoutingSessionInfo> sessionInfos =
|
return getRoutingSessionInfo(mPackageName);
|
||||||
mRouterManager.getRoutingSessions(mPackageName);
|
}
|
||||||
|
|
||||||
|
private RoutingSessionInfo getRoutingSessionInfo(String packageName) {
|
||||||
|
final List<RoutingSessionInfo> sessionInfos =
|
||||||
|
mRouterManager.getRoutingSessions(packageName);
|
||||||
|
|
||||||
|
if (sessionInfos == null || sessionInfos.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return sessionInfos.get(sessionInfos.size() - 1);
|
return sessionInfos.get(sessionInfos.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,33 +377,13 @@ public class InfoMediaManager extends MediaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean shouldDisableMediaOutput(String packageName) {
|
boolean shouldDisableMediaOutput(String packageName) {
|
||||||
boolean shouldDisableMediaOutput = false;
|
|
||||||
if (TextUtils.isEmpty(packageName)) {
|
if (TextUtils.isEmpty(packageName)) {
|
||||||
Log.w(TAG, "shouldDisableMediaOutput() package name is null or empty!");
|
Log.w(TAG, "shouldDisableMediaOutput() package name is null or empty!");
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
final List<MediaRoute2Info> infos = mRouterManager.getTransferableRoutes(packageName);
|
|
||||||
if (infos.size() == 1) {
|
// Disable when there is no transferable route
|
||||||
final MediaRoute2Info info = infos.get(0);
|
return mRouterManager.getTransferableRoutes(packageName).isEmpty();
|
||||||
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 shouldDisableMediaOutput;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.R)
|
@TargetApi(Build.VERSION_CODES.R)
|
||||||
@@ -456,7 +446,7 @@ public class InfoMediaManager extends MediaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildAvailableRoutes() {
|
private void buildAvailableRoutes() {
|
||||||
for (MediaRoute2Info route : mRouterManager.getTransferableRoutes(mPackageName)) {
|
for (MediaRoute2Info route : getAvailableRoutes(mPackageName)) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "buildAvailableRoutes() route : " + route.getName() + ", volume : "
|
Log.d(TAG, "buildAvailableRoutes() route : " + route.getName() + ", volume : "
|
||||||
+ route.getVolume() + ", type : " + route.getType());
|
+ 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
|
@VisibleForTesting
|
||||||
void addMediaDevice(MediaRoute2Info route) {
|
void addMediaDevice(MediaRoute2Info route) {
|
||||||
final int deviceType = route.getType();
|
final int deviceType = route.getType();
|
||||||
|
|||||||
@@ -22,11 +22,13 @@ import android.bluetooth.BluetoothAdapter;
|
|||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.RoutingSessionInfo;
|
import android.media.RoutingSessionInfo;
|
||||||
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
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.
|
* LocalMediaManager provide interface to get MediaDevice list and transfer media to MediaDevice.
|
||||||
*/
|
*/
|
||||||
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
public class LocalMediaManager implements BluetoothCallback {
|
public class LocalMediaManager implements BluetoothCallback {
|
||||||
private static final Comparator<MediaDevice> COMPARATOR = Comparator.naturalOrder();
|
private static final Comparator<MediaDevice> COMPARATOR = Comparator.naturalOrder();
|
||||||
private static final String TAG = "LocalMediaManager";
|
private static final String TAG = "LocalMediaManager";
|
||||||
|
|||||||
Reference in New Issue
Block a user