Merge "Make Wifi and Bluetooth Slices not dismissable."

This commit is contained in:
TreeHugger Robot
2020-01-21 10:56:58 +00:00
committed by Android (Google) Code Review
5 changed files with 168 additions and 14 deletions

View File

@@ -19,6 +19,7 @@ package com.android.settings.homepage.contextualcards;
import static com.android.settings.homepage.contextualcards.ContextualCardManager.KEY_CONTEXTUAL_CARDS;
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH;
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_HALF_WIDTH;
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_STICKY;
import static com.google.common.truth.Truth.assertThat;
@@ -109,8 +110,8 @@ public class ContextualCardManagerTest {
mManager = new ContextualCardManager(mContext, mLifecycle, outState);
final List<String> actualCards = mManager.mSavedCards.stream().collect(Collectors.toList());
final List<String> expectedCards = Arrays.asList("test_wifi", "test_flashlight",
"test_connected", "test_gesture", "test_battery");
final List<String> expectedCards = Arrays.asList("test_low_storage", "test_flashlight",
"test_dark_theme", "test_gesture", "test_battery");
assertThat(actualCards).containsExactlyElementsIn(expectedCards);
}
@@ -347,8 +348,9 @@ public class ContextualCardManagerTest {
final ConditionContextualCardController conditionController =
pool.getController(mContext,
ContextualCard.CardType.CONDITIONAL);
final OnStart controller = spy((OnStart)conditionController);
doReturn(controller).when(pool).getController(mContext, ContextualCard.CardType.CONDITIONAL);
final OnStart controller = spy((OnStart) conditionController);
doReturn(controller).when(pool).getController(mContext,
ContextualCard.CardType.CONDITIONAL);
manager.onWindowFocusChanged(true /* hasWindowFocus */);
@@ -365,8 +367,9 @@ public class ContextualCardManagerTest {
final ConditionContextualCardController conditionController =
pool.getController(mContext,
ContextualCard.CardType.CONDITIONAL);
final OnStart controller = spy((OnStart)conditionController);
doReturn(controller).when(pool).getController(mContext, ContextualCard.CardType.CONDITIONAL);
final OnStart controller = spy((OnStart) conditionController);
doReturn(controller).when(pool).getController(mContext,
ContextualCard.CardType.CONDITIONAL);
manager.onWindowFocusChanged(true /* hasWindowFocus */);
@@ -384,7 +387,8 @@ public class ContextualCardManagerTest {
pool.getController(mContext,
ContextualCard.CardType.CONDITIONAL);
final OnStop controller = spy((OnStop) conditionController);
doReturn(controller).when(pool).getController(mContext, ContextualCard.CardType.CONDITIONAL);
doReturn(controller).when(pool).getController(mContext,
ContextualCard.CardType.CONDITIONAL);
manager.onWindowFocusChanged(false /* hasWindowFocus */);
@@ -400,7 +404,8 @@ public class ContextualCardManagerTest {
pool.getController(mContext,
ContextualCard.CardType.CONDITIONAL);
final OnStop controller = spy((OnStop) conditionController);
doReturn(controller).when(pool).getController(mContext, ContextualCard.CardType.CONDITIONAL);
doReturn(controller).when(pool).getController(mContext,
ContextualCard.CardType.CONDITIONAL);
manager.onWindowFocusChanged(false /* hasWindowFocus */);
@@ -540,6 +545,85 @@ public class ContextualCardManagerTest {
}
}
@Test
public void getCardsWithViewType_hasWifiSlice_shouldHaveOneStickyCard() {
final List<ContextualCard> cards = new ArrayList<>();
cards.add(buildContextualCard(CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI.toString()));
cards.add(buildContextualCard(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString()));
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE
);
final List<ContextualCard> cardListWithWifi = buildCategoriedCards(cards, categories);
final List<ContextualCard> result = mManager.getCardsWithViewType(cardListWithWifi);
assertThat(result).hasSize(cards.size());
assertThat(result.get(0).getViewType()).isEqualTo(VIEW_TYPE_STICKY);
assertThat(result.get(1).getViewType()).isEqualTo(VIEW_TYPE_FULL_WIDTH);
}
@Test
public void getCardsWithViewType_hasBluetoothDeviceSlice_shouldHaveOneStickyCard() {
final List<ContextualCard> cards = new ArrayList<>();
cards.add(buildContextualCard(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI.toString()));
cards.add(buildContextualCard(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString()));
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE
);
final List<ContextualCard> cardListWithBT = buildCategoriedCards(cards, categories);
final List<ContextualCard> result = mManager.getCardsWithViewType(cardListWithBT);
assertThat(result).hasSize(cards.size());
assertThat(result.get(0).getViewType()).isEqualTo(VIEW_TYPE_STICKY);
assertThat(result.get(1).getViewType()).isEqualTo(VIEW_TYPE_FULL_WIDTH);
}
@Test
public void getCardsWithViewType_hasWifiAndBtDeviceSlice_shouldHaveTwoStickyCards() {
final List<ContextualCard> cards = new ArrayList<>();
cards.add(buildContextualCard(CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI.toString()));
cards.add(buildContextualCard(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI.toString()));
cards.add(buildContextualCard(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString()));
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE
);
final List<ContextualCard> cardListWithWifiBT = buildCategoriedCards(cards, categories);
final List<ContextualCard> result = mManager.getCardsWithViewType(cardListWithWifiBT);
assertThat(result).hasSize(cards.size());
assertThat(result.stream()
.filter(card -> card.getViewType() == VIEW_TYPE_STICKY)
.count())
.isEqualTo(2);
}
@Test
public void getCardsWithViewType_noWifiOrBtDeviceSlice_shouldNotHaveStickyCard() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE
);
final List<ContextualCard> cardListWithoutWifiBT =
buildCategoriedCards(getContextualCardList(), categories);
final List<ContextualCard> result = mManager.getCardsWithViewType(cardListWithoutWifiBT);
assertThat(result).hasSize(cardListWithoutWifiBT.size());
assertThat(result.stream()
.filter(card -> card.getViewType() == VIEW_TYPE_STICKY)
.count())
.isEqualTo(0);
}
@Test
public void getCardsToKeep_hasSavedCard_shouldResetSavedCards() {
final List<String> savedCardNames = new ArrayList<>();
@@ -572,9 +656,9 @@ public class ContextualCardManagerTest {
private List<ContextualCard> getContextualCardList() {
final List<ContextualCard> cards = new ArrayList<>();
cards.add(new ContextualCard.Builder()
.setName("test_wifi")
.setName("test_low_storage")
.setCardType(ContextualCard.CardType.SLICE)
.setSliceUri(CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI)
.setSliceUri(CustomSliceRegistry.LOW_STORAGE_SLICE_URI)
.setViewType(VIEW_TYPE_FULL_WIDTH)
.build());
cards.add(new ContextualCard.Builder()
@@ -585,9 +669,9 @@ public class ContextualCardManagerTest {
.setViewType(VIEW_TYPE_FULL_WIDTH)
.build());
cards.add(new ContextualCard.Builder()
.setName("test_connected")
.setName("test_dark_theme")
.setCardType(ContextualCard.CardType.SLICE)
.setSliceUri(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI)
.setSliceUri(CustomSliceRegistry.DARK_THEME_SLICE_URI)
.setViewType(VIEW_TYPE_FULL_WIDTH)
.build());
cards.add(new ContextualCard.Builder()