Index Data to build Slices in Settings

The indexing is done by taking the indexable fragments from
search, grabbing their XML via SearchIndexableResources, and
then looking for controllers defined in preferences.

For each controller found, we take the combination of the
fragment providing the XML and the Preference info to create
an indexable row.

Buiding a Slice will be handled in a subsquent CL, but a
prototype can be found here: ag/3324435

Test: robotests
Bug: 67996923
Change-Id: I48668618079bcc3da55ab77b7323ee8e467073af
This commit is contained in:
Matthew Fritze
2017-12-12 16:03:22 -08:00
parent ce2b7fe988
commit 13c43f1900
18 changed files with 882 additions and 34 deletions

View File

@@ -1,7 +1,26 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.settings.slices;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@@ -19,6 +38,8 @@ import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.Locale;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SlicesDatabaseHelperTest {
@@ -30,7 +51,7 @@ public class SlicesDatabaseHelperTest {
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mSlicesDatabaseHelper = new SlicesDatabaseHelper(mContext);
mSlicesDatabaseHelper = spy(SlicesDatabaseHelper.getInstance(mContext));
mDatabase = mSlicesDatabaseHelper.getWritableDatabase();
}
@@ -47,7 +68,7 @@ public class SlicesDatabaseHelperTest {
String[] expectedNames = new String[]{
IndexColumns.KEY,
IndexColumns.TITLE,
IndexColumns.SUBTITLE,
IndexColumns.SUMMARY,
IndexColumns.SCREENTITLE,
IndexColumns.ICON_RESOURCE,
IndexColumns.FRAGMENT,
@@ -71,17 +92,48 @@ public class SlicesDatabaseHelperTest {
assertThat(newCursor.getCount()).isEqualTo(0);
}
@Test
public void testIndexState_buildAndLocaleSet() {
mSlicesDatabaseHelper.reconstruct(mDatabase);
boolean baseState = mSlicesDatabaseHelper.isSliceDataIndexed();
assertThat(baseState).isFalse();
mSlicesDatabaseHelper.setIndexedState();
boolean indexedState = mSlicesDatabaseHelper.isSliceDataIndexed();
assertThat(indexedState).isTrue();
}
@Test
public void testLocaleChanges_newIndexingState() {
mSlicesDatabaseHelper.reconstruct(mDatabase);
mSlicesDatabaseHelper.setIndexedState();
Locale.setDefault(new Locale("ca"));
assertThat(mSlicesDatabaseHelper.isSliceDataIndexed()).isFalse();
}
@Test
public void testBuildFingerprintChanges_newIndexingState() {
mSlicesDatabaseHelper.reconstruct(mDatabase);
mSlicesDatabaseHelper.setIndexedState();
doReturn("newBuild").when(mSlicesDatabaseHelper).getBuildTag();
assertThat(mSlicesDatabaseHelper.isSliceDataIndexed()).isFalse();
}
private ContentValues getDummyRow() {
ContentValues values;
values = new ContentValues();
values.put(IndexColumns.KEY, "key");
values.put(IndexColumns.TITLE, "title");
values.put(IndexColumns.SUBTITLE, "subtitle");
values.put(IndexColumns.SUMMARY, "summary");
values.put(IndexColumns.ICON_RESOURCE, 99);
values.put(IndexColumns.FRAGMENT, "fragmentClassName");
values.put(IndexColumns.CONTROLLER, "preferenceController");
return values;
}
}
}