Merge "Add chevron to Screen cast tile" into sc-qpr1-dev

This commit is contained in:
TreeHugger Robot
2021-08-12 22:16:46 +00:00
committed by Android (Google) Code Review
2 changed files with 86 additions and 5 deletions

View File

@@ -150,11 +150,7 @@ public class CastTile extends QSTileImpl<BooleanState> {
}
List<CastDevice> activeDevices = getActiveDevices();
// We want to pop up the media route selection dialog if we either have no active devices
// (neither routes nor projection), or if we have an active route. In other cases, we assume
// that a projection is active. This is messy, but this tile never correctly handled the
// case where multiple devices were active :-/.
if (activeDevices.isEmpty() || (activeDevices.get(0).tag instanceof RouteInfo)) {
if (willPopDetail()) {
mActivityStarter.postQSRunnableDismissingKeyguard(() -> {
showDetail(true);
});
@@ -163,6 +159,15 @@ public class CastTile extends QSTileImpl<BooleanState> {
}
}
// We want to pop up the media route selection dialog if we either have no active devices
// (neither routes nor projection), or if we have an active route. In other cases, we assume
// that a projection is active. This is messy, but this tile never correctly handled the
// case where multiple devices were active :-/.
private boolean willPopDetail() {
List<CastDevice> activeDevices = getActiveDevices();
return activeDevices.isEmpty() || (activeDevices.get(0).tag instanceof RouteInfo);
}
private List<CastDevice> getActiveDevices() {
ArrayList<CastDevice> activeDevices = new ArrayList<>();
for (CastDevice device : mController.getCastDevices()) {
@@ -234,10 +239,12 @@ public class CastTile extends QSTileImpl<BooleanState> {
state.contentDescription = state.contentDescription + ","
+ mContext.getString(R.string.accessibility_quick_settings_open_details);
state.expandedAccessibilityClassName = Button.class.getName();
state.forceExpandIcon = willPopDetail();
} else {
state.state = Tile.STATE_UNAVAILABLE;
String noWifi = mContext.getString(R.string.quick_settings_cast_no_wifi);
state.secondaryLabel = noWifi;
state.forceExpandIcon = false;
}
state.stateDescription = state.stateDescription + ", " + state.secondaryLabel;
mDetailAdapter.updateItems(devices);

View File

@@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
@@ -327,4 +328,77 @@ public class CastTileTest extends SysuiTestCase {
assertEquals(Tile.STATE_ACTIVE, mCastTile.getState().state);
assertTrue(mCastTile.getState().secondaryLabel.toString().startsWith(connected.name));
}
@Test
public void testExpandView_wifiNotConnected() {
mCastTile.refreshState();
mTestableLooper.processAllMessages();
assertFalse(mCastTile.getState().forceExpandIcon);
}
@Test
public void testExpandView_wifiEnabledNotCasting() {
enableWifiAndProcessMessages();
assertTrue(mCastTile.getState().forceExpandIcon);
}
@Test
public void testExpandView_casting_projection() {
CastController.CastDevice device = new CastController.CastDevice();
device.state = CastController.CastDevice.STATE_CONNECTED;
List<CastDevice> devices = new ArrayList<>();
devices.add(device);
when(mController.getCastDevices()).thenReturn(devices);
enableWifiAndProcessMessages();
assertFalse(mCastTile.getState().forceExpandIcon);
}
@Test
public void testExpandView_connecting_projection() {
CastController.CastDevice connecting = new CastController.CastDevice();
connecting.state = CastDevice.STATE_CONNECTING;
connecting.name = "Test Casting Device";
List<CastDevice> devices = new ArrayList<>();
devices.add(connecting);
when(mController.getCastDevices()).thenReturn(devices);
enableWifiAndProcessMessages();
assertFalse(mCastTile.getState().forceExpandIcon);
}
@Test
public void testExpandView_casting_mediaRoute() {
CastController.CastDevice device = new CastController.CastDevice();
device.state = CastDevice.STATE_CONNECTED;
device.tag = mock(MediaRouter.RouteInfo.class);
List<CastDevice> devices = new ArrayList<>();
devices.add(device);
when(mController.getCastDevices()).thenReturn(devices);
enableWifiAndProcessMessages();
assertTrue(mCastTile.getState().forceExpandIcon);
}
@Test
public void testExpandView_connecting_mediaRoute() {
CastController.CastDevice connecting = new CastController.CastDevice();
connecting.state = CastDevice.STATE_CONNECTING;
connecting.tag = mock(RouteInfo.class);
connecting.name = "Test Casting Device";
List<CastDevice> devices = new ArrayList<>();
devices.add(connecting);
when(mController.getCastDevices()).thenReturn(devices);
enableWifiAndProcessMessages();
assertTrue(mCastTile.getState().forceExpandIcon);
}
}