Merge "Show Dream Home Controls regardless of overlay on dream." into tm-qpr-dev

This commit is contained in:
Victor Truong
2023-03-24 00:37:43 +00:00
committed by Android (Google) Code Review
3 changed files with 91 additions and 22 deletions

View File

@@ -27,6 +27,8 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dreams.complication.Complication;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.statusbar.policy.CallbackController;
import java.util.ArrayList;
@@ -102,15 +104,27 @@ public class DreamOverlayStateController implements
private final Collection<Complication> mComplications = new HashSet();
private final FeatureFlags mFeatureFlags;
private final int mSupportedTypes;
@VisibleForTesting
@Inject
public DreamOverlayStateController(@Main Executor executor,
@Named(DREAM_OVERLAY_ENABLED) boolean overlayEnabled) {
@Named(DREAM_OVERLAY_ENABLED) boolean overlayEnabled,
FeatureFlags featureFlags) {
mExecutor = executor;
mOverlayEnabled = overlayEnabled;
mFeatureFlags = featureFlags;
if (DEBUG) {
Log.d(TAG, "Dream overlay enabled:" + mOverlayEnabled);
}
if (mFeatureFlags.isEnabled(Flags.ALWAYS_SHOW_HOME_CONTROLS_ON_DREAMS)) {
mSupportedTypes = Complication.COMPLICATION_TYPE_NONE
| Complication.COMPLICATION_TYPE_HOME_CONTROLS;
} else {
mSupportedTypes = Complication.COMPLICATION_TYPE_NONE;
}
}
/**
@@ -179,7 +193,7 @@ public class DreamOverlayStateController implements
if (mShouldShowComplications) {
return (requiredTypes & getAvailableComplicationTypes()) == requiredTypes;
}
return requiredTypes == Complication.COMPLICATION_TYPE_NONE;
return (requiredTypes & mSupportedTypes) == requiredTypes;
})
.collect(Collectors.toCollection(HashSet::new))
: mComplications);

View File

@@ -428,6 +428,11 @@ object Flags {
1004,
"enable_low_light_clock_undocked", teamfood = true)
// TODO(b/273509374): Tracking Bug
@JvmField
val ALWAYS_SHOW_HOME_CONTROLS_ON_DREAMS = unreleasedFlag(1006,
"always_show_home_controls_on_dreams")
// 1100 - windowing
@Keep
@JvmField

View File

@@ -32,6 +32,8 @@ import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.dreams.complication.Complication;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.time.FakeSystemClock;
@@ -53,17 +55,21 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Mock
Complication mComplication;
@Mock
private FeatureFlags mFeatureFlags;
final FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
when(mFeatureFlags.isEnabled(Flags.ALWAYS_SHOW_HOME_CONTROLS_ON_DREAMS)).thenReturn(false);
}
@Test
public void testStateChange_overlayActive() {
final DreamOverlayStateController stateController = new DreamOverlayStateController(
mExecutor, true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.addCallback(mCallback);
stateController.setOverlayActive(true);
mExecutor.runAllReady();
@@ -84,8 +90,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Test
public void testCallback() {
final DreamOverlayStateController stateController = new DreamOverlayStateController(
mExecutor, true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.addCallback(mCallback);
// Add complication and verify callback is notified.
@@ -110,8 +115,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Test
public void testNotifyOnCallbackAdd() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor, true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.addComplication(mComplication);
mExecutor.runAllReady();
@@ -124,8 +128,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Test
public void testNotifyOnCallbackAddOverlayDisabled() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor, false);
final DreamOverlayStateController stateController = getDreamOverlayStateController(false);
stateController.addComplication(mComplication);
mExecutor.runAllReady();
@@ -139,8 +142,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Test
public void testComplicationFilteringWhenShouldShowComplications() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor, true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.setShouldShowComplications(true);
final Complication alwaysAvailableComplication = Mockito.mock(Complication.class);
@@ -179,8 +181,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Test
public void testComplicationFilteringWhenShouldHideComplications() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor, true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.setShouldShowComplications(true);
final Complication alwaysAvailableComplication = Mockito.mock(Complication.class);
@@ -226,8 +227,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Test
public void testComplicationWithNoTypeNotFiltered() {
final Complication complication = Mockito.mock(Complication.class);
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor, true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.addComplication(complication);
mExecutor.runAllReady();
assertThat(stateController.getComplications(true).contains(complication))
@@ -236,8 +236,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Test
public void testNotifyLowLightChanged() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor, true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.addCallback(mCallback);
mExecutor.runAllReady();
@@ -252,8 +251,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Test
public void testNotifyLowLightExit() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor, true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.addCallback(mCallback);
mExecutor.runAllReady();
@@ -276,8 +274,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
@Test
public void testNotifyEntryAnimationsFinishedChanged() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor, true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.addCallback(mCallback);
mExecutor.runAllReady();
@@ -289,4 +286,57 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
verify(mCallback, times(1)).onStateChanged();
assertThat(stateController.areEntryAnimationsFinished()).isTrue();
}
@Test
public void testShouldShowComplicationsSetToFalse_stillShowsSupportedTypes_featureEnabled() {
when(mFeatureFlags.isEnabled(Flags.ALWAYS_SHOW_HOME_CONTROLS_ON_DREAMS)).thenReturn(true);
final DreamOverlayStateController stateController = getDreamOverlayStateController(true);
stateController.setShouldShowComplications(true);
final Complication noneComplication = Mockito.mock(Complication.class);
when(noneComplication.getRequiredTypeAvailability())
.thenReturn(Complication.COMPLICATION_TYPE_NONE);
final Complication homeControlsComplication = Mockito.mock(Complication.class);
when(homeControlsComplication.getRequiredTypeAvailability())
.thenReturn(Complication.COMPLICATION_TYPE_HOME_CONTROLS);
stateController.addComplication(noneComplication);
stateController.addComplication(homeControlsComplication);
final DreamOverlayStateController.Callback callback =
Mockito.mock(DreamOverlayStateController.Callback.class);
stateController.setAvailableComplicationTypes(
Complication.COMPLICATION_TYPE_HOME_CONTROLS);
stateController.addCallback(callback);
mExecutor.runAllReady();
{
clearInvocations(callback);
stateController.setShouldShowComplications(true);
mExecutor.runAllReady();
verify(callback).onAvailableComplicationTypesChanged();
final Collection<Complication> complications = stateController.getComplications();
assertThat(complications.contains(noneComplication)).isTrue();
assertThat(complications.contains(homeControlsComplication)).isTrue();
}
{
clearInvocations(callback);
stateController.setShouldShowComplications(false);
mExecutor.runAllReady();
verify(callback).onAvailableComplicationTypesChanged();
final Collection<Complication> complications = stateController.getComplications();
assertThat(complications.contains(noneComplication)).isTrue();
assertThat(complications.contains(homeControlsComplication)).isTrue();
}
}
private DreamOverlayStateController getDreamOverlayStateController(boolean overlayEnabled) {
return new DreamOverlayStateController(mExecutor, overlayEnabled, mFeatureFlags);
}
}