Merge "Hide all complications as necessary."

This commit is contained in:
Darrell Shi
2022-02-16 00:42:03 +00:00
committed by Android (Google) Code Review
3 changed files with 75 additions and 3 deletions

View File

@@ -132,6 +132,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
public void onStartDream(@NonNull WindowManager.LayoutParams layoutParams) {
setCurrentState(Lifecycle.State.STARTED);
mExecutor.execute(() -> {
mStateController.setShouldShowComplications(shouldShowComplications());
addOverlayWindowLocked(layoutParams);
setCurrentState(Lifecycle.State.RESUMED);
mStateController.setOverlayActive(true);

View File

@@ -16,6 +16,7 @@
package com.android.systemui.dreams;
import android.service.dreams.DreamService;
import android.util.Log;
import androidx.annotation.NonNull;
@@ -84,6 +85,8 @@ public class DreamOverlayStateController implements
@Complication.ComplicationType
private int mAvailableComplicationTypes = Complication.COMPLICATION_TYPE_NONE;
private boolean mShouldShowComplications = DreamService.DEFAULT_SHOW_COMPLICATIONS;
private final Collection<Complication> mComplications = new HashSet();
@VisibleForTesting
@@ -131,7 +134,12 @@ public class DreamOverlayStateController implements
.filter(complication -> {
@Complication.ComplicationType
final int requiredTypes = complication.getRequiredTypeAvailability();
return (requiredTypes & getAvailableComplicationTypes()) == requiredTypes;
// If it should show complications, show ones whose required types are
// available. Otherwise, only show ones that don't require types.
if (mShouldShowComplications) {
return (requiredTypes & getAvailableComplicationTypes()) == requiredTypes;
}
return requiredTypes == Complication.COMPLICATION_TYPE_NONE;
})
.collect(Collectors.toCollection(HashSet::new))
: mComplications);
@@ -221,7 +229,24 @@ public class DreamOverlayStateController implements
public void setAvailableComplicationTypes(@Complication.ComplicationType int types) {
mExecutor.execute(() -> {
mAvailableComplicationTypes = types;
mCallbacks.forEach(callback -> callback.onAvailableComplicationTypesChanged());
mCallbacks.forEach(Callback::onAvailableComplicationTypesChanged);
});
}
/**
* Returns whether the dream overlay should show complications.
*/
public boolean getShouldShowComplications() {
return mShouldShowComplications;
}
/**
* Sets whether the dream overlay should show complications.
*/
public void setShouldShowComplications(boolean shouldShowComplications) {
mExecutor.execute(() -> {
mShouldShowComplications = shouldShowComplications;
mCallbacks.forEach(Callback::onAvailableComplicationTypesChanged);
});
}
}

View File

@@ -123,7 +123,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
}
@Test
public void testComplicationFiltering() {
public void testComplicationFilteringWhenShouldShowComplications() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor);
@@ -160,4 +160,50 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
}
}
@Test
public void testComplicationFilteringWhenShouldHideComplications() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor);
stateController.setShouldShowComplications(true);
final Complication alwaysAvailableComplication = Mockito.mock(Complication.class);
final Complication weatherComplication = Mockito.mock(Complication.class);
when(alwaysAvailableComplication.getRequiredTypeAvailability())
.thenReturn(Complication.COMPLICATION_TYPE_NONE);
when(weatherComplication.getRequiredTypeAvailability())
.thenReturn(Complication.COMPLICATION_TYPE_WEATHER);
stateController.addComplication(alwaysAvailableComplication);
stateController.addComplication(weatherComplication);
final DreamOverlayStateController.Callback callback =
Mockito.mock(DreamOverlayStateController.Callback.class);
stateController.setAvailableComplicationTypes(Complication.COMPLICATION_TYPE_WEATHER);
stateController.addCallback(callback);
mExecutor.runAllReady();
{
clearInvocations(callback);
stateController.setShouldShowComplications(true);
mExecutor.runAllReady();
verify(callback).onAvailableComplicationTypesChanged();
final Collection<Complication> complications = stateController.getComplications();
assertThat(complications.contains(alwaysAvailableComplication)).isTrue();
assertThat(complications.contains(weatherComplication)).isTrue();
}
{
clearInvocations(callback);
stateController.setShouldShowComplications(false);
mExecutor.runAllReady();
verify(callback).onAvailableComplicationTypesChanged();
final Collection<Complication> complications = stateController.getComplications();
assertThat(complications.contains(alwaysAvailableComplication)).isTrue();
assertThat(complications.contains(weatherComplication)).isFalse();
}
}
}