Skip to content

Commit

Permalink
Update proto for contextual_card_list.
Browse files Browse the repository at this point in the history
Bug: 118842350
Test: rebuild
Change-Id: I838738f56c8793a8e4d6adf43bc812777edbcd88
  • Loading branch information
Fan Zhang committed Nov 6, 2018
1 parent 92792ee commit 9a28c43
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
Binary file modified libs/contextualcards.aar
Binary file not shown.
24 changes: 18 additions & 6 deletions protos/contextual_card_list.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ message ContextualCardList {
}

message ContextualCard {
// Slice uri of the contextual card
optional string sliceUri = 1;

// {@link ContextualCardCategory}.
optional int32 category = 2;
/**
* The category of a card: this is a hint for how a card should be collected,
* ranked, and presented
*/
enum Category {
DEFAULT = 0;
SUGGESTION = 1;
POSSIBLE = 2;
IMPORTANT = 3;
EXCLUSIVE = 4;
}

/** Slice uri of the contextual card */
optional string sliceUri = 1;

// Name of the card. It should be identical in every app
/** Name of the card. It should be identical in every app */
optional string cardName = 3;
}

optional Category card_category = 4;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.android.settings.intelligence.ContextualCardProto.ContextualCardList;
import com.android.settings.wifi.WifiSlice;

import com.google.android.settings.intelligence.libs.contextualcards.ContextualCardCategory;
import com.google.android.settings.intelligence.libs.contextualcards.ContextualCardProvider;

/** Provides dynamic card for SettingsIntelligence. */
Expand All @@ -41,19 +40,19 @@ public ContextualCardList getContextualCards() {
ContextualCard.newBuilder()
.setSliceUri(WifiSlice.WIFI_URI.toString())
.setCardName(KEY_WIFI)
.setCategory(ContextualCardCategory.IMPORTANT)
.setCardCategory(ContextualCard.Category.IMPORTANT)
.build();
final ContextualCard batteryInfoCard =
ContextualCard.newBuilder()
.setSliceUri(BatterySlice.BATTERY_CARD_URI.toString())
.setCardName(BatterySlice.PATH_BATTERY_INFO)
.setCategory(ContextualCardCategory.DEFAULT)
.setCardCategory(ContextualCard.Category.DEFAULT)
.build();
final ContextualCard connectedDeviceCard =
ContextualCard.newBuilder()
.setSliceUri(ConnectedDeviceSlice.CONNECTED_DEVICE_URI.toString())
.setCardName(ConnectedDeviceSlice.PATH_CONNECTED_DEVICE)
.setCategory(ContextualCardCategory.IMPORTANT)
.setCardCategory(ContextualCard.Category.IMPORTANT)
.build();
final ContextualCardList cards = ContextualCardList.newBuilder()
.addCard(wifiCard)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;

import android.app.slice.SliceManager;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

Expand All @@ -28,38 +33,45 @@
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wifi.WifiSlice;

import com.google.android.settings.intelligence.libs.contextualcards.ContextualCardCategory;
import com.google.android.settings.intelligence.libs.contextualcards.ContextualCardProvider;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

@RunWith(SettingsRobolectricTestRunner.class)
public class SettingsContextualCardProviderTest {

@Mock
private SliceManager mSliceManager;
private ContentResolver mResolver;
private Uri mUri;
private SettingsContextualCardProvider mProvider;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mResolver = RuntimeEnvironment.application.getContentResolver();
mUri = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsContextualCardProvider.CARD_AUTHORITY)
.build();
mProvider = Robolectric.setupContentProvider(SettingsContextualCardProvider.class);
mProvider = spy(Robolectric.setupContentProvider(SettingsContextualCardProvider.class));
final Context context = spy(RuntimeEnvironment.application);
doReturn(mSliceManager).when(context).getSystemService(SliceManager.class);
doReturn(context).when(mProvider).getContext();
}

@Test
public void contentProviderCall_returnCorrectSize() throws Exception {
final int actualNo = mProvider.getContextualCards().getCardCount();

final Bundle returnValue =
mResolver.call(mUri, ContextualCardProvider.METHOD_GET_CARD_LIST, "", null);
mProvider.call(ContextualCardProvider.METHOD_GET_CARD_LIST, "", null);
final ContextualCardList cards =
ContextualCardList.parseFrom(
returnValue.getByteArray(ContextualCardProvider.BUNDLE_CARD_LIST));
Expand All @@ -76,6 +88,6 @@ public void getContextualCards_wifiSlice_shouldGetCorrectCategory() {
}
}

assertThat(wifiCard.getCategory()).isEqualTo(ContextualCardCategory.IMPORTANT);
assertThat(wifiCard.getCardCategory()).isEqualTo(ContextualCard.Category.IMPORTANT);
}
}

0 comments on commit 9a28c43

Please sign in to comment.