[Output Switcher] Modify ranking rule
1. make Phone with higher ranking 2. add new state with "selected" for cast device Test: Verified on device Bug: 224870434 Bug: 224780609 Change-Id: Ief19cf0946f6df1193c0ed3e09e76ea60bfea07c
This commit is contained in:
committed by
Shaowei Shen
parent
56c6199477
commit
2cafe393b7
@@ -32,6 +32,8 @@ import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||
import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR;
|
||||
|
||||
import static com.android.settingslib.media.LocalMediaManager.MediaDeviceState.STATE_SELECTED;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Notification;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
@@ -497,9 +499,11 @@ public class InfoMediaManager extends MediaManager {
|
||||
mediaDevice = new InfoMediaDevice(mContext, mRouterManager, route,
|
||||
mPackageName);
|
||||
if (!TextUtils.isEmpty(mPackageName)
|
||||
&& getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())
|
||||
&& mCurrentConnectedDevice == null) {
|
||||
mCurrentConnectedDevice = mediaDevice;
|
||||
&& getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())) {
|
||||
mediaDevice.setState(STATE_SELECTED);
|
||||
if (mCurrentConnectedDevice == null) {
|
||||
mCurrentConnectedDevice = mediaDevice;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TYPE_BUILTIN_SPEAKER:
|
||||
|
||||
@@ -63,12 +63,14 @@ public class LocalMediaManager implements BluetoothCallback {
|
||||
@IntDef({MediaDeviceState.STATE_CONNECTED,
|
||||
MediaDeviceState.STATE_CONNECTING,
|
||||
MediaDeviceState.STATE_DISCONNECTED,
|
||||
MediaDeviceState.STATE_CONNECTING_FAILED})
|
||||
MediaDeviceState.STATE_CONNECTING_FAILED,
|
||||
MediaDeviceState.STATE_SELECTED})
|
||||
public @interface MediaDeviceState {
|
||||
int STATE_CONNECTED = 0;
|
||||
int STATE_CONNECTING = 1;
|
||||
int STATE_DISCONNECTED = 2;
|
||||
int STATE_CONNECTING_FAILED = 3;
|
||||
int STATE_SELECTED = 4;
|
||||
}
|
||||
|
||||
private final Collection<DeviceCallback> mCallbacks = new CopyOnWriteArrayList<>();
|
||||
|
||||
@@ -31,6 +31,8 @@ import static android.media.MediaRoute2Info.TYPE_USB_HEADSET;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||
|
||||
import static com.android.settingslib.media.LocalMediaManager.MediaDeviceState.STATE_SELECTED;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.MediaRoute2Info;
|
||||
@@ -55,22 +57,22 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({MediaDeviceType.TYPE_UNKNOWN,
|
||||
MediaDeviceType.TYPE_PHONE_DEVICE,
|
||||
MediaDeviceType.TYPE_USB_C_AUDIO_DEVICE,
|
||||
MediaDeviceType.TYPE_3POINT5_MM_AUDIO_DEVICE,
|
||||
MediaDeviceType.TYPE_FAST_PAIR_BLUETOOTH_DEVICE,
|
||||
MediaDeviceType.TYPE_BLUETOOTH_DEVICE,
|
||||
MediaDeviceType.TYPE_CAST_DEVICE,
|
||||
MediaDeviceType.TYPE_CAST_GROUP_DEVICE,
|
||||
MediaDeviceType.TYPE_PHONE_DEVICE})
|
||||
MediaDeviceType.TYPE_CAST_GROUP_DEVICE})
|
||||
public @interface MediaDeviceType {
|
||||
int TYPE_UNKNOWN = 0;
|
||||
int TYPE_USB_C_AUDIO_DEVICE = 1;
|
||||
int TYPE_3POINT5_MM_AUDIO_DEVICE = 2;
|
||||
int TYPE_FAST_PAIR_BLUETOOTH_DEVICE = 3;
|
||||
int TYPE_BLUETOOTH_DEVICE = 4;
|
||||
int TYPE_CAST_DEVICE = 5;
|
||||
int TYPE_CAST_GROUP_DEVICE = 6;
|
||||
int TYPE_PHONE_DEVICE = 7;
|
||||
int TYPE_PHONE_DEVICE = 1;
|
||||
int TYPE_USB_C_AUDIO_DEVICE = 2;
|
||||
int TYPE_3POINT5_MM_AUDIO_DEVICE = 3;
|
||||
int TYPE_FAST_PAIR_BLUETOOTH_DEVICE = 4;
|
||||
int TYPE_BLUETOOTH_DEVICE = 5;
|
||||
int TYPE_CAST_DEVICE = 6;
|
||||
int TYPE_CAST_GROUP_DEVICE = 7;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -305,12 +307,12 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
* The most recent used one + device group with usage info sorted by how many times the
|
||||
* device has been used.
|
||||
* 4. The order is followed below rule:
|
||||
* 1. USB-C audio device
|
||||
* 2. 3.5 mm audio device
|
||||
* 3. Bluetooth device
|
||||
* 4. Cast device
|
||||
* 5. Cast group device
|
||||
* 6. Phone
|
||||
* 1. Phone
|
||||
* 2. USB-C audio device
|
||||
* 3. 3.5 mm audio device
|
||||
* 4. Bluetooth device
|
||||
* 5. Cast device
|
||||
* 6. Cast group device
|
||||
*
|
||||
* So the device list will look like 5 slots ranked as below.
|
||||
* Rule 4 + Rule 1 + the most recently used device + Rule 3 + Rule 2
|
||||
@@ -330,6 +332,12 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
}
|
||||
}
|
||||
|
||||
if (getState() == STATE_SELECTED) {
|
||||
return -1;
|
||||
} else if (another.getState() == STATE_SELECTED) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Both devices have same connection status, compare the range zone
|
||||
if (NearbyDevice.compareRangeZones(getRangeZone(), another.getRangeZone()) != 0) {
|
||||
return NearbyDevice.compareRangeZones(getRangeZone(), another.getRangeZone());
|
||||
@@ -378,12 +386,12 @@ public abstract class MediaDevice implements Comparable<MediaDevice> {
|
||||
return s1.compareToIgnoreCase(s2);
|
||||
} else {
|
||||
// Both devices have never been used, the priority is:
|
||||
// 1. USB-C audio device
|
||||
// 2. 3.5 mm audio device
|
||||
// 3. Bluetooth device
|
||||
// 4. Cast device
|
||||
// 5. Cast group device
|
||||
// 6. Phone
|
||||
// 1. Phone
|
||||
// 2. USB-C audio device
|
||||
// 3. 3.5 mm audio device
|
||||
// 4. Bluetooth device
|
||||
// 5. Cast device
|
||||
// 6. Cast group device
|
||||
return mType < another.mType ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user