Disable entry point of output switcher

It adds a minimum value if it shows only one available
cast device in the output switcher. Because users can only
change the volume slider or stop control in the output switcher.
It's too hidden to have the user stop cast in the UI.

- This CL will disable the entry point of the output switcher
  if there is only one available cast device in the list.
- Update test cases.

Bug: 163095048
Test: make -j42 RunSettingsRoboTests
Change-Id: I8906878e1ba769d6940041f17d83b5de6b2a32c0
This commit is contained in:
Hugh Chen
2020-09-24 17:57:19 +08:00
parent 9096f09405
commit b6840ced0d
6 changed files with 110 additions and 7 deletions

View File

@@ -18,6 +18,10 @@ package com.android.settings;
import static android.content.Intent.EXTRA_USER;
import static android.content.Intent.EXTRA_USER_ID;
import static android.media.MediaRoute2Info.TYPE_GROUP;
import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER;
import static android.media.MediaRoute2Info.TYPE_REMOTE_TV;
import static android.media.MediaRoute2Info.TYPE_UNKNOWN;
import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
@@ -53,6 +57,8 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.media.MediaRoute2Info;
import android.media.MediaRouter2Manager;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
@@ -1137,4 +1143,31 @@ public final class Utils extends com.android.settingslib.Utils {
drawable.draw(canvas);
return roundedBitmap;
}
/**
* Returns {@code true} if needed to disable media output, otherwise returns {@code false}.
*/
public static boolean isMediaOutputDisabled(
MediaRouter2Manager router2Manager, String packageName) {
boolean isMediaOutputDisabled = false;
if (!TextUtils.isEmpty(packageName)) {
final List<MediaRoute2Info> infos = router2Manager.getAvailableRoutes(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:
isMediaOutputDisabled = true;
break;
default:
isMediaOutputDisabled = false;
break;
}
}
}
return isMediaOutputDisabled;
}
}