Add a new column for slices_index table.
To distinguish public and non-public slices, add public_slice column to the database so we can return corresponding results based on this value. Bug: 141088937 Test: robotests Change-Id: I05d003875a8be27e5cb735b4814eb86d6dc40174
This commit is contained in:
@@ -73,6 +73,8 @@ public class SliceData {
|
||||
|
||||
private final String mUnavailableSliceSubtitle;
|
||||
|
||||
private final boolean mIsPublicSlice;
|
||||
|
||||
public String getKey() {
|
||||
return mKey;
|
||||
}
|
||||
@@ -117,6 +119,10 @@ public class SliceData {
|
||||
return mUnavailableSliceSubtitle;
|
||||
}
|
||||
|
||||
public boolean isPublicSlice() {
|
||||
return mIsPublicSlice;
|
||||
}
|
||||
|
||||
private SliceData(Builder builder) {
|
||||
mKey = builder.mKey;
|
||||
mTitle = builder.mTitle;
|
||||
@@ -129,6 +135,7 @@ public class SliceData {
|
||||
mPreferenceController = builder.mPrefControllerClassName;
|
||||
mSliceType = builder.mSliceType;
|
||||
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
|
||||
mIsPublicSlice = builder.mIsPublicSlice;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -168,6 +175,8 @@ public class SliceData {
|
||||
|
||||
private String mUnavailableSliceSubtitle;
|
||||
|
||||
private boolean mIsPublicSlice;
|
||||
|
||||
public Builder setKey(String key) {
|
||||
mKey = key;
|
||||
return this;
|
||||
@@ -224,6 +233,11 @@ public class SliceData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setIsPublicSlice(boolean isPublicSlice) {
|
||||
mIsPublicSlice = isPublicSlice;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SliceData build() {
|
||||
if (TextUtils.isEmpty(mKey)) {
|
||||
throw new InvalidSliceDataException("Key cannot be empty");
|
||||
|
@@ -212,6 +212,7 @@ class SliceDataConverter {
|
||||
final int sliceType = controller.getSliceType();
|
||||
final String unavailableSliceSubtitle = bundle.getString(
|
||||
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
|
||||
final boolean isPublicSlice = controller.isPublicSlice();
|
||||
|
||||
final SliceData xmlSlice = new SliceData.Builder()
|
||||
.setKey(key)
|
||||
@@ -224,6 +225,7 @@ class SliceDataConverter {
|
||||
.setFragmentName(fragmentName)
|
||||
.setSliceType(sliceType)
|
||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||
.setIsPublicSlice(isPublicSlice)
|
||||
.build();
|
||||
|
||||
xmlSliceData.add(xmlSlice);
|
||||
|
@@ -36,7 +36,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
private static final String DATABASE_NAME = "slices_index.db";
|
||||
private static final String SHARED_PREFS_TAG = "slices_shared_prefs";
|
||||
|
||||
private static final int DATABASE_VERSION = 7;
|
||||
private static final int DATABASE_VERSION = 8;
|
||||
|
||||
public interface Tables {
|
||||
String TABLE_SLICES_INDEX = "slices_index";
|
||||
@@ -98,6 +98,11 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
* The uri of slice.
|
||||
*/
|
||||
String SLICE_URI = "slice_uri";
|
||||
|
||||
/**
|
||||
* Whether the slice should be exposed publicly.
|
||||
*/
|
||||
String PUBLIC_SLICE = "public_slice";
|
||||
}
|
||||
|
||||
private static final String CREATE_SLICES_TABLE =
|
||||
@@ -124,6 +129,12 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
IndexColumns.SLICE_TYPE +
|
||||
", " +
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
|
||||
", "
|
||||
+
|
||||
IndexColumns.PUBLIC_SLICE
|
||||
+
|
||||
" INTEGER DEFAULT 0 "
|
||||
+
|
||||
");";
|
||||
|
||||
private final Context mContext;
|
||||
|
@@ -112,6 +112,7 @@ class SlicesIndexer implements Runnable {
|
||||
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
|
||||
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
dataRow.getUnavailableSliceSubtitle());
|
||||
values.put(IndexColumns.PUBLIC_SLICE, dataRow.isPublicSlice());
|
||||
|
||||
database.replaceOrThrow(Tables.TABLE_SLICES_INDEX, null /* nullColumnHack */,
|
||||
values);
|
||||
|
@@ -41,6 +41,11 @@ public class FakePreferenceController extends BasePreferenceController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPublicSlice() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
|
@@ -128,6 +128,7 @@ public class SliceDataConverterTest {
|
||||
assertThat(fakeSlice.getSliceType()).isEqualTo(SliceData.SliceType.SLIDER);
|
||||
assertThat(fakeSlice.getUnavailableSliceSubtitle()).isEqualTo(
|
||||
"subtitleOfUnavailableSlice"); // from XML
|
||||
assertThat(fakeSlice.isPublicSlice()).isTrue();
|
||||
}
|
||||
|
||||
private void assertFakeA11ySlice(SliceData fakeSlice) {
|
||||
|
@@ -52,7 +52,8 @@ public class SliceDataTest {
|
||||
.setUri(URI)
|
||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||
.setSliceType(SLICE_TYPE)
|
||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE)
|
||||
.setIsPublicSlice(true);
|
||||
|
||||
SliceData data = builder.build();
|
||||
|
||||
@@ -67,6 +68,7 @@ public class SliceDataTest {
|
||||
assertThat(data.getPreferenceController()).isEqualTo(PREF_CONTROLLER);
|
||||
assertThat(data.getSliceType()).isEqualTo(SLICE_TYPE);
|
||||
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
assertThat(data.isPublicSlice()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test(expected = SliceData.InvalidSliceDataException.class)
|
||||
|
@@ -75,6 +75,7 @@ public class SlicesDatabaseHelperTest {
|
||||
IndexColumns.CONTROLLER,
|
||||
IndexColumns.SLICE_TYPE,
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
IndexColumns.PUBLIC_SLICE
|
||||
};
|
||||
|
||||
assertThat(columnNames).isEqualTo(expectedNames);
|
||||
|
@@ -105,8 +105,8 @@ public class SlicesIndexerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertSliceData_mockDataInserted() {
|
||||
final List<SliceData> sliceData = getDummyIndexableData();
|
||||
public void testInsertSliceData_nonPublicSlice_mockDataInserted() {
|
||||
final List<SliceData> sliceData = getDummyIndexableData(false);
|
||||
doReturn(sliceData).when(mManager).getSliceData();
|
||||
|
||||
mManager.run();
|
||||
@@ -140,6 +140,53 @@ public class SlicesIndexerTest {
|
||||
assertThat(cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE)))
|
||||
.isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
assertThat(cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.PUBLIC_SLICE))).isEqualTo(0);
|
||||
cursor.moveToNext();
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertSliceData_publicSlice_mockDataInserted() {
|
||||
final List<SliceData> sliceData = getDummyIndexableData(true);
|
||||
doReturn(sliceData).when(mManager).getSliceData();
|
||||
|
||||
mManager.run();
|
||||
|
||||
final SQLiteDatabase db = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||
try (Cursor cursor = db.rawQuery("SELECT * FROM slices_index", null)) {
|
||||
assertThat(cursor.getCount()).isEqualTo(sliceData.size());
|
||||
|
||||
cursor.moveToFirst();
|
||||
for (int i = 0; i < sliceData.size(); i++) {
|
||||
assertThat(cursor.getString(cursor.getColumnIndex(IndexColumns.KEY)))
|
||||
.isEqualTo(KEYS[i]);
|
||||
assertThat(cursor.getString(cursor.getColumnIndex(IndexColumns.TITLE)))
|
||||
.isEqualTo(TITLES[i]);
|
||||
assertThat(
|
||||
cursor.getString(cursor.getColumnIndex(IndexColumns.FRAGMENT)))
|
||||
.isEqualTo(FRAGMENT_NAME);
|
||||
assertThat(cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.SCREENTITLE))).isEqualTo(SCREEN_TITLE);
|
||||
assertThat(
|
||||
cursor.getString(cursor.getColumnIndex(IndexColumns.KEYWORDS)))
|
||||
.isEqualTo(KEYWORDS);
|
||||
assertThat(
|
||||
cursor.getInt(cursor.getColumnIndex(IndexColumns.ICON_RESOURCE)))
|
||||
.isEqualTo(ICON);
|
||||
assertThat(
|
||||
cursor.getString(cursor.getColumnIndex(IndexColumns.CONTROLLER)))
|
||||
.isEqualTo(PREF_CONTROLLER);
|
||||
assertThat(cursor.getInt(cursor.getColumnIndex(IndexColumns.SLICE_TYPE)))
|
||||
.isEqualTo(SLICE_TYPE);
|
||||
assertThat(cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE)))
|
||||
.isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
assertThat(cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.PUBLIC_SLICE))).isEqualTo(1);
|
||||
cursor.moveToNext();
|
||||
}
|
||||
} finally {
|
||||
@@ -162,7 +209,7 @@ public class SlicesIndexerTest {
|
||||
db.close();
|
||||
}
|
||||
|
||||
private List<SliceData> getDummyIndexableData() {
|
||||
private List<SliceData> getDummyIndexableData(boolean isPublicSlice) {
|
||||
final List<SliceData> sliceData = new ArrayList<>();
|
||||
final SliceData.Builder builder = new SliceData.Builder()
|
||||
.setSummary(SUMMARY)
|
||||
@@ -175,6 +222,10 @@ public class SlicesIndexerTest {
|
||||
.setSliceType(SLICE_TYPE)
|
||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
if (isPublicSlice) {
|
||||
builder.setIsPublicSlice(true);
|
||||
}
|
||||
|
||||
for (int i = 0; i < KEYS.length; i++) {
|
||||
builder.setKey(KEYS[i]).setTitle(TITLES[i]);
|
||||
sliceData.add(builder.build());
|
||||
|
Reference in New Issue
Block a user